Class: Jekyll::J1LunrSearch::PageRenderer

Inherits:
Object
  • Object
show all
Defined in:
lib/starter_web/_plugins/index/lunr.rb

Instance Method Summary collapse

Constructor Details

#initialize(site) ⇒ PageRenderer

Returns a new instance of PageRenderer.



266
267
268
# File 'lib/starter_web/_plugins/index/lunr.rb', line 266

def initialize(site)
  @site = site
end

Instance Method Details

#prepare(item) ⇒ Object

render item, but without using its layout



272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
# File 'lib/starter_web/_plugins/index/lunr.rb', line 272

def prepare(item)
  layout = item.data['layout']
  begin
    item.data['layout'] = nil

    if item.is_a?(Jekyll::Document)
      output = Jekyll::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) ⇒ Object

render the item, parse the output and get all text elements



294
295
296
297
# File 'lib/starter_web/_plugins/index/lunr.rb', line 294

def render(item)
  layoutless = item.dup
  Nokogiri::HTML(prepare(layoutless)).text
end