Sha256: 4e164827b989faba2ad7efdce279e386c356295c25de17adfd4446d99e1add2a
Contents?: true
Size: 1.68 KB
Versions: 1
Compression:
Stored size: 1.68 KB
Contents
require_dependency Locomotive::Engine.root.join('app', 'models', 'locomotive', 'page').to_s Locomotive::Page.class_eval do include Locomotive::Search::Extension ## fields ## field :searchable, type: Boolean, default: true ## behaviours ## search_by [:title, :searchable_content, store: [:search_type, :label, :site_id, :fullpath]], if: :is_searchable? ## methods def search_type 'page' end def label self.title end def indexable_id if respond_to?(:site_id) "site_#{site_id}_page_#{id}" else "page_#{id}" end end def is_searchable? !not_found? && searchable? && published? end def searchable_content [].tap do |content| # # 1. add the editable elements # self.editable_elements.each do |element| # # we don't want to include fixed editable elements of children. # next if !element.is_a?(Locomotive::EditableText) || (element.fixed? && element.from_parent?) # content << element.content # end # add the raw template by rendering it (will render the editable elements) # get a simple version of the template. not need to apply the "layout" # for instance. # then, render this template template = self.raw_template.sub(/\{\%\s*extends [^%]*\s*\%\}/, '') # modify the context instance so that the exceptions which might raise # won't be displayed in the rendered output. context = ::Liquid::Context.new({}, {}, { site: site, page: self }, false) context.instance_eval do def handle_error(e); '' end end # render the page content << ::Liquid::Template.parse(template, {}).render(context) end.join("\n") end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
locomotivecms-search-0.3.0 | app/models/locomotive/page.rb |