<commit_before>class RestfulFormWrapper
  def initialize(template, form_builder)
    @template = template
    @form_builder = form_builder
  end

  def method_missing(method, field, options = {})
    @template.open 'div', :class => field.to_s, :id => "#{field}_field" do
      @template.open('label', options[:label] || field.to_s.titleize,
           :for => "#{@template.instance_variable_name.singularize}_#{field}")
      @template.puts @template.find_and_preserve(@form_builder.send(method, field))
    end
  end
end

module ApplicationHelper

  # Generally useful tools

  def restful_form
    options = {
      :url  => params[:action] == 'new' ? objects_path : object_path,
      :html => params[:action] == 'new' ? {}           : {:method => :put}
    }

    form_for(instance_variable_name.singularize, options) do |f|
      yield(RestfulFormWrapper.new(self, f)) if block_given?
    end
  end

  def silk_tag(name, opts = {})
    image_tag("silk/#{name}.png", opts)
  end

  def absolute_anchors(text, url)
    text.gsub(/href=(["'])#/) { "href=#{$1}#{url}#" }
  end

  def preview_button(path, element)
    submit_to_remote 'submit', 'Preview', :url => path + '.js',
      :html => {:class => 'button'}, :method => :post,
      :loading => "$(#{element.to_json}).spin()",
      :failure => "$(#{element.to_json}).update(\"<h3 class='failure'>Preview Failed</h3>\")"
  end

  def xml_stylesheet(name)
    "<?xml-stylesheet href=\"http://#{Nex3::Config['blog']['site']}#{stylesheet_path name}\" type=\"text/css\" ?>"
  end

  # Stuff for the application-wide layout

  def flash_display
    flash.each do |type, content|
      open 'div', content, :class => type.to_s
    end
  end

  def sidebar_admin_links
    [
     ['New Post', new_post_url],
     ['Manage Users', users_url],
     ['Sign Out', signout_url, {:method => :delete}]
    ]
  end

  def sidebar_links
    [
     ['About Me', {:controller => 'static', :action => 'show', :page => 'about'}],
     ['Feed', posts_path + '.atom'],
     ['Sign In', signin_path],
    ] + (admin? ? sidebar_admin_links : [])
  end
end<commit_msg>The signin link shouldn't appear if the user is already signed in.<commit_after>class RestfulFormWrapper
  def initialize(template, form_builder)
    @template = template
    @form_builder = form_builder
  end

  def method_missing(method, field, options = {})
    @template.open 'div', :class => field.to_s, :id => "#{field}_field" do
      @template.open('label', options[:label] || field.to_s.titleize,
           :for => "#{@template.instance_variable_name.singularize}_#{field}")
      @template.puts @template.find_and_preserve(@form_builder.send(method, field))
    end
  end
end

module ApplicationHelper

  # Generally useful tools

  def restful_form
    options = {
      :url  => params[:action] == 'new' ? objects_path : object_path,
      :html => params[:action] == 'new' ? {}           : {:method => :put}
    }

    form_for(instance_variable_name.singularize, options) do |f|
      yield(RestfulFormWrapper.new(self, f)) if block_given?
    end
  end

  def silk_tag(name, opts = {})
    image_tag("silk/#{name}.png", opts)
  end

  def absolute_anchors(text, url)
    text.gsub(/href=(["'])#/) { "href=#{$1}#{url}#" }
  end

  def preview_button(path, element)
    submit_to_remote 'submit', 'Preview', :url => path + '.js',
      :html => {:class => 'button'}, :method => :post,
      :loading => "$(#{element.to_json}).spin()",
      :failure => "$(#{element.to_json}).update(\"<h3 class='failure'>Preview Failed</h3>\")"
  end

  def xml_stylesheet(name)
    "<?xml-stylesheet href=\"http://#{Nex3::Config['blog']['site']}#{stylesheet_path name}\" type=\"text/css\" ?>"
  end

  # Stuff for the application-wide layout

  def flash_display
    flash.each do |type, content|
      open 'div', content, :class => type.to_s
    end
  end

  def sidebar_admin_links
    [
     ['New Post', new_post_url],
     ['Manage Users', users_url],
     ['Sign Out', signout_url, {:method => :delete}]
    ]
  end

  def sidebar_links
    [
     ['About Me', {:controller => 'static', :action => 'show', :page => 'about'}],
     ['Feed', posts_path + '.atom'],
    ] + (admin? ? sidebar_admin_links : [['Sign In', signin_path]])
  end
end
{'fraction_non_alphanumeric': 0.17734338200659444, 'fraction_numerical': 0.0018841262364578427, 'mean_word_length': 3.4658254468980023, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '4718018', 'n_tokens_mistral': 1446, 'n_tokens_neox': 1409, 'n_words': 314}