<commit_before>class NavItem < ActiveRecord::Base
  before_save :raise_abstract_error

  acts_as_nested_set
  has_crud searchable: [:id, :title, :url], settings: false

  crud.config do
    fields parent_id:     { type: :hidden },
           alias_id:      { type: :tree },
           if:            { type: :code },
           unless:        { type: :code },
           method:        { type: :code },
           highlights_on: { type: :code },
           content_block: { type: :code }

    config :admin do
      index fields: [:id, :title, :url]
      form  fields: [:title, :url, :is_hidden, :parent_id]
    end
  end

  def raise_abstract_error
    raise "Cannot directly instantiate an Abstract NavItem" if self.class == NavItem
  end

  def titlize
    title
  end

  alias :to_s :titleize

  def is_what?
    raise_abstract_error
  end

  def toggle_hidden!
    update_attribute(:is_hidden, !is_hidden)
  end

  def hidden
    is_hidden? ? "Un-hide" : "Hide"
  end

  def is_hidden?
    is_hidden
  end

  def nav_key
    "key_#{id}"
  end

  def options
    hash = {}
    hash[:if] = Proc.new { eval(self.if, @@binding) } unless self.if.blank?
    hash[:unless] = Proc.new { eval(self.unless, @@binding) } unless self.unless.blank?
    hash[:method] = method unless method.blank?
    hash[:highlights_on] = Proc.new { eval(highlights_on, @@binding) } unless highlights_on.blank?
    hash
  end

  def to_hash
    hash = {
      key:   nav_key,
      name:  title,
      url:   url,
      items: content_block.blank? ? children.collect { |c| c.to_hash unless c.is_hidden }.compact : eval(content_block)
    }
    hash[:options] = options unless options.blank?
    hash
  end

  def draggable?
    true
  end

  def self.navigation(key=nil, get_binding=binding())
    @@binding = get_binding
    start = NavItem.find_by_key(key) || RootNavItem.root
    start.children.collect { |c| c.to_hash unless c.is_hidden }.compact
  end
end<commit_msg>Changed NavItem to render content_block as main element not a child<commit_after>class NavItem < ActiveRecord::Base
  before_save :raise_abstract_error

  acts_as_nested_set
  has_crud searchable: [:id, :title, :url], settings: false

  crud.config do
    fields parent_id:     { type: :hidden },
           alias_id:      { type: :tree },
           if:            { type: :code },
           unless:        { type: :code },
           method:        { type: :code },
           highlights_on: { type: :code },
           content_block: { type: :code }

    config :admin do
      index fields: [:id, :title, :url]
      form  fields: [:title, :url, :is_hidden, :parent_id]
    end
  end

  def raise_abstract_error
    raise "Cannot directly instantiate an Abstract NavItem" if self.class == NavItem
  end

  def titlize
    title
  end

  alias :to_s :titleize

  def is_what?
    raise_abstract_error
  end

  def toggle_hidden!
    update_attribute(:is_hidden, !is_hidden)
  end

  def hidden
    is_hidden? ? "Un-hide" : "Hide"
  end

  def is_hidden?
    is_hidden
  end

  def nav_key
    "key_#{id}"
  end

  def options
    hash = {}
    hash[:if] = Proc.new { eval(self.if, @@binding) } unless self.if.blank?
    hash[:unless] = Proc.new { eval(self.unless, @@binding) } unless self.unless.blank?
    hash[:method] = method unless method.blank?
    hash[:highlights_on] = Proc.new { eval(highlights_on, @@binding) } unless highlights_on.blank?
    hash
  end

  def to_hash
    hash = {}
    if content_block.blank?
      hash = {
        key:   nav_key,
        name:  title,
        url:   url,
        items: children.collect { |c| c.to_hash unless c.is_hidden }.compact
      }
    else
      hash = eval(content_block, @@binding)
    end
    hash[:options] = options unless options.blank?
    hash
  end

  def draggable?
    true
  end

  def self.navigation(key=nil, get_binding=binding())
    @@binding = get_binding
    start = NavItem.find_by_key(key) || RootNavItem.root
    start.children.collect { |c| c.to_hash unless c.is_hidden }.compact
  end
end
{'fraction_non_alphanumeric': 0.11008946322067595, 'fraction_numerical': 0.0, 'mean_word_length': 2.530701754385965, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '773353', 'n_tokens_mistral': 1388, 'n_tokens_neox': 1334, 'n_words': 351}