<commit_before>class FrameRenderer
  attr_reader :thingy, :template, :partial, :options
  def initialize(thingy, partial, template, options={})
    @thingy = thingy
    @template = template
    @partial = partial || default_partial
    @options = options
  end

  def self.for(thingy, partial, template, opts={})
    if thingy.respond_to?(:each)
      CollectionFrameRenderer.new(thingy, partial, template, opts)
    else
      RecordFrameRenderer.new(thingy, partial, template, opts)
    end
  end

  def default_partial
    'show'
  end

  def to_s
    template.content_tag(:div, inner, html_options)
  end

  def inner
    begin
      template.render render_options
    rescue ActionView::MissingTemplate => e
      if !partial.starts_with?('/')
        @partial = "/#{partial}"
        retry
      else
        raise e
      end
    end
  end

  def html_options
    css.each do |clss|
      template.add_class_to_html_options options, clss
    end
    options[:data] = meta.to_json
    options
  end

  def partial_name
    if partial.index('/')
      partial.split('/').last
    else
      partial
    end
  end

  def css
    ['frame', partial_name]
  end

  def meta
    {
      :href => request.url, 
      :action => controller.action_name, 
      :controller => controller.controller_name
    }
  end

  def render_options
    {
      :layout => '/layouts/toolbox',
      :object => thingy,
      :partial => partial
    }
  end

  def controller
    template.send(:controller)
  end

  def request
    template.send(:request)
  end
end

class RecordFrameRenderer < FrameRenderer
  alias_method :record, :thingy
  def meta
    super.merge({
      :title => record.title || "#{record.class_name} ##{record.id}", 
      :resource_name => template.resource_name,<commit_msg>frame title for new record<commit_after>class FrameRenderer
  attr_reader :thingy, :template, :partial, :options
  def initialize(thingy, partial, template, options={})
    @thingy = thingy
    @template = template
    @partial = partial || default_partial
    @options = options
  end

  def self.for(thingy, partial, template, opts={})
    if thingy.respond_to?(:each)
      CollectionFrameRenderer.new(thingy, partial, template, opts)
    else
      RecordFrameRenderer.new(thingy, partial, template, opts)
    end
  end

  def default_partial
    'show'
  end

  def to_s
    template.content_tag(:div, inner, html_options)
  end

  def inner
    begin
      template.render render_options
    rescue ActionView::MissingTemplate => e
      if !partial.starts_with?('/')
        @partial = "/#{partial}"
        retry
      else
        raise e
      end
    end
  end

  def html_options
    css.each do |clss|
      template.add_class_to_html_options options, clss
    end
    options[:data] = meta.to_json
    options
  end

  def partial_name
    if partial.index('/')
      partial.split('/').last
    else
      partial
    end
  end

  def css
    ['frame', partial_name]
  end

  def meta
    {
      :href => request.url, 
      :action => controller.action_name, 
      :controller => controller.controller_name
    }
  end

  def render_options
    {
      :layout => '/layouts/toolbox',
      :object => thingy,
      :partial => partial
    }
  end

  def controller
    template.send(:controller)
  end

  def request
    template.send(:request)
  end
end

class RecordFrameRenderer < FrameRenderer
  alias_method :record, :thingy
  def meta
    super.merge({
      :title => record.new_record? ? "new #{record.class_name}" : (record.title || "#{record.class_name} ##{record.id}"), 
      :resource_name => template.resource_name,
{'fraction_non_alphanumeric': 0.10360980986497657, 'fraction_numerical': 0.0, 'mean_word_length': 2.651911468812877, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '8713', 'n_tokens_mistral': 1132, 'n_tokens_neox': 1109, 'n_words': 282}