<commit_before>require 'haml'
require 'extlib'

module Sinatra::Templates
  alias :haml_orig :haml
  def haml(template, options={})
    options = options.merge!(:layout => false) if template.to_s.start_with? '_'
    haml_orig template, options
  end
end

def render_objects(sym, resource, key=nil)
  #cache_key = "#{resource.storage_name}.#{key}"
  response["Cache-Control"] = "max-age=300, public"
  objects = key.nil? ? resource.all : resource.first(key => params[key])
  haml sym, :locals => { sym => objects }
end

def create_partial(sym, code)
  template sym, &lambda { code }
end

PAT_ROUTEKEY = Regexp.compile('(.*):([^/]+)(.*?$)')
def create_get(route, resource)
  m = PAT_ROUTEKEY.match(route)
  key = m && m.captures[1].to_sym
	name = names = resource.storage_name
  name = Extlib::Inflection::singular(name) unless key.nil?
  get route, &lambda { render_objects name.to_sym, resource, key }
  partial = m.nil? ?
    "%a(href='#{route}')> #{names.capitalize}" :
    "%a(href='#{m.captures[0]}#"+"{#{name}.#{key}}#{m.captures[2]}')= #{name}"
	create_partial "_#{name}_a".to_sym, partial
end


def link_to(object, options=nil)
  unless object.nil?<commit_msg>increase cache time and watch out for nils in partials<commit_after>require 'haml'
require 'extlib'

module Sinatra::Templates
  alias :haml_orig :haml
  def haml(template, options={})
    options = options.merge!(:layout => false) if template.to_s.start_with? '_'
    haml_orig template, options
  end
end

def render_objects(sym, resource, key=nil)
  #cache_key = "#{resource.storage_name}.#{key}"
  response["Cache-Control"] = "max-age=3600, public"
  objects = key.nil? ? resource.all : resource.first(key => params[key])
  haml sym, :locals => { sym => objects }
end

def create_partial(sym, code)
  p code
  template sym, &lambda { code }
end

PAT_ROUTEKEY = Regexp.compile('(.*):([^/]+)(.*?$)')
def create_get(route, resource)
  m = PAT_ROUTEKEY.match(route)
  key = m && m.captures[1].to_sym
	name = names = resource.storage_name
  name = Extlib::Inflection::singular(name) unless key.nil?
  get route, &lambda { render_objects name.to_sym, resource, key }
  partial = m.nil? ?
    "%a(href='#{route}')> #{names.capitalize}" : "\
- if #{name}
  %a(href='#{m.captures[0]}#"+"{#{name}.#{key}}#{m.captures[2]}')= #{name}"
	create_partial "_#{name}_a".to_sym, partial
end


def link_to(object, options=nil)
  unless object.nil?
{'fraction_non_alphanumeric': 0.18140116763969974, 'fraction_numerical': 0.005421184320266889, 'mean_word_length': 4.9088669950738915, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '2695204', 'n_tokens_mistral': 894, 'n_tokens_neox': 893, 'n_words': 190}