<commit_before>require 'pathname'
module Rokko
  class Layout < Mustache
    self.template_path = File.dirname(__FILE__)
    
    def initialize(doc)
      @doc = doc
      @options = @doc.options
    end
    
    def title
      File.basename(@doc.file)
    end
    
    def styles
      if @options[:local]
        docco = File.read(File.join(File.dirname(__FILE__), 'assets', 'docco.css'))
        highlight = File.read(File.join(File.dirname(__FILE__), 'assets', 'highlight.css'))

        "<style type=\"text/css\" media=\"screen, projection\">#{docco}\n#{highlight}</style>"
      else
        "<link rel=\"stylesheet\" href=\"http://github.com/vast/rokko/raw/v#{::Rokko::VERSION}/lib/rokko/assets/docco.css\" />
         <link rel=\"stylesheet\" href=\"http://github.com/vast/rokko/raw/v#{::Rokko::VERSION}/lib/rokko/assets/highlight.css\" />"
      end
    end
    
    def highlight_js
      js = if @options[:local]
        "<script>#{File.read(File.join(File.dirname(__FILE__), 'assets', 'highlight.pack.js'))}</script>"
      else
        "<script src=\"http://github.com/vast/rokko/raw/v#{::Rokko::VERSION}/lib/rokko/assets/highlight.pack.js\"></script>"
      end
      
      js + "\n" + "<script>hljs.initHighlightingOnLoad();</script>\n"
    end
    
    def sections
      num = 0
      @doc.sections.map do |docs,code|
        {
          :docs => docs,
          :code => code,
          :num => (num += 1)
        }
      end
    end
    
    def sources?
      @doc.sources.length > 1
    end
    
    def sources
      @doc.sources.sort.map do |source|
        {
          :path => source,
          :basename => File.basename(source),
          :url => relative_url(source)
        }
      end
    end
    
    private
    def relative_url(source)
      if(@doc.options[:preserve_urls])
        source.sub(Regexp.new("#{File.extname(source)}$"), ".html")
      else
        relative_path = Pathname.new(File.dirname(source)).relative_path_from(Pathname(File.dirname(@doc.file))).to_s
        "#{relative_path}/#{File.basename(source).sub(Regexp.new("#{File.extname(source)}$"), ".html")}"
      end
    end

  end
end<commit_msg>fix assets and index.html problems<commit_after>require 'pathname'
module Rokko
  class Layout < Mustache
    self.template_path = File.dirname(__FILE__)
    
    def initialize(doc)
      @doc = doc
      @options = @doc.options
    end
    
    def title
      File.basename(@doc.file)
    end
    
    def styles
      if @options[:local]
        docco = File.read(File.join(File.dirname(__FILE__), 'assets', 'docco.css'))
        highlight = File.read(File.join(File.dirname(__FILE__), 'assets', 'highlight.css'))

        "<style type=\"text/css\" media=\"screen, projection\">#{docco}\n#{highlight}</style>"
      else
        "<link rel=\"stylesheet\" href=\"http://vast.github.com/rokko/v#{::Rokko::VERSION}/assets/docco.css\" />
         <link rel=\"stylesheet\" href=\"http://vast.github.com/rokko/v#{::Rokko::VERSION}/assets/highlight.css\" />"
      end
    end
    
    def highlight_js
      js = if @options[:local]
        "<script>#{File.read(File.join(File.dirname(__FILE__), 'assets', 'highlight.pack.js'))}</script>"
      else
        "<script src=\"http://vast.github.com/rokko/v#{::Rokko::VERSION}/assets/highlight.pack.js\"></script>"
      end
      
      js + "\n" + "<script>hljs.initHighlightingOnLoad();</script>\n"
    end
    
    def sections
      num = 0
      @doc.sections.map do |docs,code|
        {
          :docs => docs,
          :code => code,
          :num => (num += 1)
        }
      end
    end
    
    def sources?
      @doc.sources.length > 1
    end
    
    def sources
      sources = @doc.sources.sort.map do |source|
        {
          :path => source,
          :basename => File.basename(source),
          :url => relative_url(source)
        }
      end

      if @doc.options[:index] || @doc.options[:generate_index]
        sources.unshift({:path => 'index.html', :basename => 'index', :url => relative_url('index.html')})
      end
    end
    
    private
    def relative_url(source)
      if(@doc.options[:preserve_urls])
        source.sub(Regexp.new("#{File.extname(source)}$"), ".html")
      else
        relative_path = Pathname.new(File.dirname(source)).relative_path_from(Pathname(File.dirname(@doc.file))).to_s
        "#{relative_path}/#{File.basename(source).sub(Regexp.new("#{File.extname(source)}$"), ".html")}"
      end
    end

  end
end
{'fraction_non_alphanumeric': 0.17135835567470956, 'fraction_numerical': 0.0013404825737265416, 'mean_word_length': 2.3385533184190903, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 40, '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': '3350488', 'n_tokens_mistral': 1466, 'n_tokens_neox': 1465, 'n_words': 234}