class Bunto::LunrJsSearch::PageRenderer

Public Class Methods

new(site) click to toggle source
# File lib/bunto_lunr_js_search/page_renderer.rb, line 6
def initialize(site)
  @site = site
end

Public Instance Methods

prepare(item) click to toggle source

render item, but without using its layout

# File lib/bunto_lunr_js_search/page_renderer.rb, line 11
def prepare(item)
  layout = item.data["layout"]
  begin
    item.data.delete("layout")

    if item.is_a?(Bunto::Document)          
      output = Bunto::Renderer.new(@site, item).run
    else
      item.render({}, @site.site_payload)
      output = item.output  
    end
  ensure
    # restore original layout
    item.data["layout"] = layout
  end

  output
end
render(item) click to toggle source

render the item, parse the output and get all text inside <p> elements

# File lib/bunto_lunr_js_search/page_renderer.rb, line 31
def render(item)
  layoutless = item.dup

  Nokogiri::HTML(prepare(layoutless)).text
end