<commit_before>module Stumpwise
  class Navbar
    include ActionView::Helpers::CaptureHelper
    include ActionView::Helpers::TagHelper
    include ActionView::Helpers::AssetTagHelper
    include ActionView::Helpers::UrlHelper
    include ActionView::Helpers::TextHelper
    
    attr_reader :accepts_contributions, :contribute_url
    attr_accessor :output_buffer

    def initialize(site, logged_in)
      @site = site
      @accepts_contributions = site.can_accept_contributions?
      @contribute_url = site.contribute_url
      @logged_in = logged_in
    end
    
    def logged_in?
      !!@logged_in
    end
    
    def header_markup
      load_stylesheets + load_jquery + load_javascript
    end
    
    def body_markup
      add_navbar_markup + initialize_campaign_site + load_analytics_javascript
    end
    
    private
      def load_stylesheets
        <<-BLOCK
          #{stylesheet}
          <!--[if lt IE 9]>#{ie_stylesheet}<![endif]-->
        BLOCK
      end
      
      def load_jquery
        "<script>!window.jQuery && document.write('<script src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js\"><\\/script>')</script>"
      end
    
      def load_javascript
        <<-BLOCK
          <!-- Setup Primary Google Analytics account -->
          <script>var _gaq = [['_setAccount','UA-15839704-1']];</script>
        
          #{javascript}
    		  <!--[if lt IE 9]>#{ie_javascript}<![endif]-->
    		BLOCK
      end
    
      def add_navbar_markup
        if @site.can_accept_contributions?
          content_tag :div, :id => 'stumpwise-bar' do
            self.output_buffer << "\n"
            link_to 'http://stumpwise.com', :class => "stumpwise-bar-button", :id => "stumpwise-bar-logo" do
              image_tag "navbar/logo.png", :class => "stumpwise-bar-button-img", :alt => "Powered by Stumpwise"
            end
            self.output_buffer << "\n"
            link_to '/admin', :class => "stumpwise-bar-button", :id => "stumpwise-bar-admin" do
              if logged_in?
                image_tag "navbar/dashboard.png", :class => "stumpwise-bar-button-img"
              else
                image_tag "navbar/login.png", :class => "stumpwise-bar-button-img"
              end
            end
            self.output_buffer << "\n"
            link_to '/join', :class => "stumpwise-bar-button", :id => "stumpwise-bar-join" do
              image_tag "navbar/join.png", :class => "stumpwise-bar-button-img"
            end
            self.output_buffer << "\n"
            link_to @site.contribute_url, :class => "stumpwise-bar-button", :id => "stumpwise-bar-contribute" do
              image_tag "navbar/contribute-blue.png", :class => "stumpwise-bar-button-img"
            end
            self.output_buffer << "\n"
          end
        else
          content_tag :div, :id => 'stumpwise-bar' do
            self.output_buffer << "\n"
            link_to 'http://stumpwise.com', :class => "stumpwise-bar-button", :id => "stumpwise-bar-logo" do
              image_tag "navbar/logo.png", :class => "stumpwise-bar-button-img", :alt => "Powered by Stumpwise"
            end
            self.output_buffer << "\n"
            link_to '/join', :class => "stumpwise-bar-button", :id => "stumpwise-bar-join" do
              image_tag "navbar/join.png", :class => "stumpwise-bar-button-img"
            end
            self.output_buffer << "\n"
          end
        end
      end
    
      def initialize_campaign_site
        <<-BLOCK
          <script>
            $(document).ready(function(){
              $(this).campaignSite({#{initialization_opts}});
              SW.trackPageview();
            });
          </script>
        BLOCK
      end
    <commit_msg>FIX: Dashboard button not visible unless site's contribution processing is activated<commit_after>module Stumpwise
  class Navbar
    include ActionView::Helpers::CaptureHelper
    include ActionView::Helpers::TagHelper
    include ActionView::Helpers::AssetTagHelper
    include ActionView::Helpers::UrlHelper
    include ActionView::Helpers::TextHelper
    
    attr_reader :accepts_contributions, :contribute_url
    attr_accessor :output_buffer

    def initialize(site, logged_in)
      @site = site
      @accepts_contributions = site.can_accept_contributions?
      @contribute_url = site.contribute_url
      @logged_in = logged_in
    end
    
    def logged_in?
      !!@logged_in
    end
    
    def header_markup
      load_stylesheets + load_jquery + load_javascript
    end
    
    def body_markup
      add_navbar_markup + initialize_campaign_site + load_analytics_javascript
    end
    
    private
      def load_stylesheets
        <<-BLOCK
          #{stylesheet}
          <!--[if lt IE 9]>#{ie_stylesheet}<![endif]-->
        BLOCK
      end
      
      def load_jquery
        "<script>!window.jQuery && document.write('<script src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js\"><\\/script>')</script>"
      end
    
      def load_javascript
        <<-BLOCK
          <!-- Setup Primary Google Analytics account -->
          <script>var _gaq = [['_setAccount','UA-15839704-1']];</script>
        
          #{javascript}
    		  <!--[if lt IE 9]>#{ie_javascript}<![endif]-->
    		BLOCK
      end
    
      def add_navbar_markup
        if @site.can_accept_contributions?
          content_tag :div, :id => 'stumpwise-bar' do
            self.output_buffer << "\n"
            link_to 'http://stumpwise.com', :class => "stumpwise-bar-button", :id => "stumpwise-bar-logo" do
              image_tag "navbar/logo.png", :class => "stumpwise-bar-button-img", :alt => "Powered by Stumpwise"
            end
            self.output_buffer << "\n"
            link_to '/admin', :class => "stumpwise-bar-button", :id => "stumpwise-bar-admin" do
              if logged_in?
                image_tag "navbar/dashboard.png", :class => "stumpwise-bar-button-img"
              else
                image_tag "navbar/login.png", :class => "stumpwise-bar-button-img"
              end
            end
            self.output_buffer << "\n"
            link_to '/join', :class => "stumpwise-bar-button", :id => "stumpwise-bar-join" do
              image_tag "navbar/join.png", :class => "stumpwise-bar-button-img"
            end
            self.output_buffer << "\n"
            link_to @site.contribute_url, :class => "stumpwise-bar-button", :id => "stumpwise-bar-contribute" do
              image_tag "navbar/contribute-blue.png", :class => "stumpwise-bar-button-img"
            end
            self.output_buffer << "\n"
          end
        else
          content_tag :div, :id => 'stumpwise-bar' do
            self.output_buffer << "\n"
            link_to 'http://stumpwise.com', :class => "stumpwise-bar-button", :id => "stumpwise-bar-logo" do
              image_tag "navbar/logo.png", :class => "stumpwise-bar-button-img", :alt => "Powered by Stumpwise"
            end
            self.output_buffer << "\n"
            link_to '/admin', :class => "stumpwise-bar-button", :id => "stumpwise-bar-admin" do
              if logged_in?
                image_tag "navbar/dashboard.png", :class => "stumpwise-bar-button-img"
              else
                image_tag "navbar/login.png", :class => "stumpwise-bar-button-img"
              end
            end
            self.output_buffer << "\n"
            link_to '/join', :class => "stumpwise-bar-button", :id => "stumpwise-bar-join" do
              image_tag "navbar/join.png", :class => "stumpwise-bar-button-img"
            end
            self.output_buffer << "\n"
          end
        end
      end
    
      def initialize_campaign_site
        <<-BLOCK
          <script>
            $(document).ready(function(){
              $(this).campaignSite({#{initialization_opts}});
              SW.trackPageview();
            });
          </script>
        BLOCK
      end
    
{'fraction_non_alphanumeric': 0.12993566292418318, 'fraction_numerical': 0.0035322316134729407, 'mean_word_length': 1.9659558548447438, 'pattern_counts': {'":': 0, '<': 75, '<?xml version=': 0, '>': 79, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6114636', 'n_tokens_mistral': 2447, 'n_tokens_neox': 2390, 'n_words': 462}