<commit_before>require 'fredit/version'
if Rails.version < '3.1.0'
  require 'fredit/template30'
else
  require 'fredit/template31'
end
require 'uri'

module Fredit
  extend self

  LINK_CSS = "margin:0;margin-top:-1em;padding:1px;font-size:10px;background-color:#a3f66c;border:1px solid #666;"

  def rel_path(path)
    path.sub(Rails.root.to_s + '/', '')
  end

  def rel_paths(paths)
    paths.map {|x| rel_path(x)}
  end

  # TODO change this to be compatible with HAML
  def link(x)
    s = %Q| <a style="#{LINK_CSS}" href="/fredit?file=#{URI.escape(x)}" target="_blank">#{x}</a> |
    s.strip.html_safe
  end

  def entries(glob)
    Dir[Rails.root + glob].entries.map {|e| rel_path(e)}
  end

  def editables
    css = entries('public/**/*.css') 
    js = entries('public/**/*.js')
    views = entries('app/views/**/*.html.*')
    {:css => css, :views => views, :javascript => js}
  end

  def add_fredit_link(template, s)
    return s unless template_editable?(template)
    if s =~ /^\s*<!DOCTYPE/ && s =~ /<body[^>]*>/
      s.sub(/<body[^>]*>/, '\&' + fredit_link(template))
    else
      fredit_link(template) + s
    end
  end

  def fredit_link(template)
    source_file = Fredit.rel_path template.identifier
    edit_link = "<div style='color:red'>#{Fredit.link(source_file)}</div>".html_safe
  end

  def template_editable?(template)
    template.identifier.index(Rails.root.to_s) == 0 &&
      template.formats && 
      template.formats.include?(:html)
  end


end

require 'fredit/engine'
<commit_msg>support Rails 3.1 asset directory<commit_after>require 'fredit/version'
if Rails.version < '3.1.0'
  require 'fredit/template30'
else
  require 'fredit/template31'
end
require 'uri'

module Fredit
  extend self

  LINK_CSS = "margin:0;margin-top:-1em;padding:1px;font-size:10px;background-color:#a3f66c;border:1px solid #666;"

  def rel_path(path)
    path.sub(Rails.root.to_s + '/', '')
  end

  def rel_paths(paths)
    paths.map {|x| rel_path(x)}
  end

  # TODO change this to be compatible with HAML
  def link(x)
    s = %Q| <a style="#{LINK_CSS}" href="/fredit?file=#{URI.escape(x)}" target="_blank">#{x}</a> |
    s.strip.html_safe
  end

  def entries(glob)
    Dir[glob].entries.map {|e| rel_path(e)}
  end

  def editables
    prefix = File.directory?(Rails.root + 'app/assets') ? 'app/assets' : 'public'
    css = entries(prefix + '/stylesheets/*') 
    js = entries(prefix + '/javascripts/*')
    views = entries('app/views/**/*.html.*')
    {:css => css, :views => views, :javascript => js}
  end

  def add_fredit_link(template, s)
    return s unless template_editable?(template)
    if s =~ /^\s*<!DOCTYPE/ && s =~ /<body[^>]*>/
      s.sub(/<body[^>]*>/, '\&' + fredit_link(template))
    else
      fredit_link(template) + s
    end
  end

  def fredit_link(template)
    source_file = Fredit.rel_path template.identifier
    edit_link = "<div style='color:red'>#{Fredit.link(source_file)}</div>".html_safe
  end

  def template_editable?(template)
    template.identifier.index(Rails.root.to_s) == 0 &&
      template.formats && 
      template.formats.include?(:html)
  end


end

require 'fredit/engine'

{'fraction_non_alphanumeric': 0.1721728081321474, 'fraction_numerical': 0.013341804320203304, 'mean_word_length': 3.537463976945245, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 25, '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': '599347', 'n_tokens_mistral': 1209, 'n_tokens_neox': 1160, 'n_words': 228}