Class: Locomotive::SearchExt::Assign
- Inherits:
-
Liquid::Tag
- Object
- Liquid::Tag
- Locomotive::SearchExt::Assign
- Includes:
- ActionView::Helpers::SanitizeHelper
- Defined in:
- lib/locomotive/search_ext/plugin/assign.rb
Constant Summary collapse
- Syntax =
/(#{::Liquid::VariableSignature}+)\s*to\s*(#{::Liquid::VariableSignature}+):\s*(#{::Liquid::VariableSignature}+)/
Instance Method Summary collapse
-
#initialize(tag_name, markup, tokens, context) ⇒ Assign
constructor
A new instance of Assign.
- #render(context) ⇒ Object
Constructor Details
#initialize(tag_name, markup, tokens, context) ⇒ Assign
Returns a new instance of Assign.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/locomotive/search_ext/plugin/assign.rb', line 7 def initialize(tag_name, markup, tokens, context) if markup =~ Syntax @results = $1 @target = $2 @description = "#{@target}_description" @flag = $3 @options = {} markup.scan(::Liquid::TagAttributes) { |key, value| @options[key.to_sym] = value.gsub(/"|'/, '') } else raise ::Liquid::SyntaxError.new("Syntax Error in 'search_assign' - Valid syntax: search_assign results to variable: pagetag") end super end |
Instance Method Details
#render(context) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/locomotive/search_ext/plugin/assign.rb', line 22 def render(context) @site = context.registers[:site] @result = context[@results][0] result_data = false if @result['content_type_slug'] # its a model entry model = @site.content_types.where(slug: @result['content_type_slug']).first model_item = model.entries.find(@result['original_id']).to_liquid result_data = model_item if model_item context[@flag.to_s] = model.name context[@description.to_s] = @result else # it is a page page = @site.pages.find(@result['original_id']).to_liquid result_data = page if page context[@flag.to_s] = false res = @result['highlighted']['searchable_content'] context[@description] = (res) end context[@target.to_s] = result_data Rails.logger.error(result_data) "" end |