<commit_before>module PageFragments::FragmentsHelper
  def fragments(options={})
    root = fragments_root(options.delete(:root))
    safe_join(all_fragments(root).map { |f| fragment(f, options) }, "\n")
  end
  
  def fragment(fragment, options={})
    fragment = Wheelhouse::Page.get(fragment) if fragment.is_a?(String)
    content_tag(:div, render_fragment(fragment), { :id => fragment.dom_id }.merge(options))
  end

private
  def render_fragment(fragment)
    old_page, @page = @page, fragment
    render :template => @page._template, :prefixes => [@page._template_prefix]
  ensure
    @page = old_page
  end
  
  def all_fragments(root=site.navigation)
    result = []
    root.each do |k, v|
      result << k.reload if k.is_a?(Wheelhouse::Page) && k.fragment?
      result += all_fragments(v)
    end
    result
  end
  
  def fragments_root(root)
    root ? site.navigation.find { |n| [n, n.id, n.label[:en]].include?(root) } : site.navigation
  end
end<commit_msg>Render only one level deep of page fragments<commit_after>module PageFragments::FragmentsHelper
  def fragments(options={})
    root = fragment_root(options.delete(:root))
    fragments = Wheelhouse::Page.where(:parent_id => root.id).fragments

    safe_join(fragments.map { |f| fragment(f, options) }, "\n")
  end
  
  def fragment(fragment, options={})
    fragment = Wheelhouse::Page.get(fragment) if fragment.is_a?(String)
    content_tag(:div, render_fragment(fragment), { :id => fragment.dom_id }.merge(options))
  end

private
  def render_fragment(fragment)
    old_page, @page = @page, fragment
    render :template => @page._template, :prefixes => [@page._template_prefix]
  ensure
    @page = old_page
  end

  def fragment_root(root)
    case root
    when Wheelhouse::Resource::Node
      root
    when String
      site.nodes.where("label.en" => root).first
    else
      node
    end
  end
end
{'fraction_non_alphanumeric': 0.1332979288369623, 'fraction_numerical': 0.0, 'mean_word_length': 3.8431876606683804, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '2957', 'n_tokens_mistral': 617, 'n_tokens_neox': 613, 'n_words': 135}