Class: Xhive::BaseTag

Inherits:
Liquid::Tag
  • Object
show all
Defined in:
lib/xhive/base_tag.rb

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, markup, tokens) ⇒ BaseTag

Public: initializes the tag. Also stores the passed attributes.

Example: transforms this liquid meta tag some_tag attr1:foo attr2:bar %

into #<SomeTag attributes: { :attr1 => 'foo', :attr2 => 'bar' }>


11
12
13
14
15
16
17
18
# File 'lib/xhive/base_tag.rb', line 11

def initialize(tag_name, markup, tokens)
  @attributes = {}
  markup.scan(::Liquid::TagAttributes) do |key, value|
    # Remove single or double quotes around the quoted fragment before storing them in attributes
    @attributes[key.to_sym] = value.gsub("'",'').gsub('"','')
  end
  super
end

Instance Method Details

#render(context) ⇒ Object

Public: renders the tag.

context - The hash containing a set of external attributes.

Returns: the rendered tag or a list of errors.



26
27
28
29
30
31
32
33
34
# File 'lib/xhive/base_tag.rb', line 26

def render(context)
  if (errors = check_parameters).empty?
    process_parameters(context)
    route = Xhive::Router::Route.find(rest_url)
    render_inline?(route, context) ? render_inline(route) : render_widget_tag
  else
    errors
  end
end