Class: PufferPages::Liquid::Tags::Assets

Inherits:
Liquid::Tag
  • Object
show all
Defined in:
lib/puffer_pages/liquid/tags/assets.rb

Constant Summary collapse

Syntax =
/^(#{::Liquid::QuotedFragment}+)/

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, markup, tokens) ⇒ Assets

Returns a new instance of Assets.



8
9
10
11
12
13
14
15
16
# File 'lib/puffer_pages/liquid/tags/assets.rb', line 8

def initialize(tag_name, markup, tokens)
  if markup =~ Syntax
    @paths = variables_from_string(markup)
  else
    raise SyntaxError.new("Syntax Error in '#{tag_name}' - Valid syntax: #{tag_name} path [, path, path ...]")
  end

  super
end

Instance Method Details

#render(context) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/puffer_pages/liquid/tags/assets.rb', line 18

def render(context)
  paths = @paths.map {|path| "'#{context[path]}'" }.join(', ')

  erb = case @tag_name
  when 'javascripts'
    "<%= javascript_include_tag #{paths} %>"
  when 'stylesheets'
    "<%= stylesheet_link_tag #{paths} %>"
  end

  context.registers[:tracker].register(erb)
end