Class: Bunto::Assets::Liquid::Tag

Inherits:
Liquid::Tag
  • Object
show all
Defined in:
lib/bunto/assets/liquid/tag/parser.rb,
lib/bunto/assets/liquid/tag.rb,
lib/bunto/assets/liquid/tag/proxies.rb,
lib/bunto/assets/liquid/tag/defaults.rb,
lib/bunto/assets/liquid/tag/proxied_asset.rb,
lib/bunto/assets/liquid/tag/defaults/image.rb

Overview


Examples:

- {% tag value argument:value %}
- {% tag value "argument:value" %}
- {% tag value argument:"I have spaces" %}
- {% tag value argument:value\:with\:colon %}
- {% tag value argument:"I can even escape \\: here too!" %}
- {% tag value proxy:key:value %}

Defined Under Namespace

Modules: Defaults, Proxies Classes: AssetNotFoundError, Parser, ProxiedAsset

Constant Summary collapse

AcceptableTags =

Tags that we allow our users to use.


%W(
  img
  image
  javascript
  asset_source
  stylesheet
  asset_path
  style
  asset
  css
  js
).freeze
Tags =

The HTML version of every tag that we accept.


{
  "css" => %{<link type="text/css" rel="stylesheet" href="%s"%s>},
  "js"  => %{<script type="text/javascript" src="%s"%s></script>},
  "img" => %{<img src="%s"%s>}
}.freeze
Alias =

Allows us to normalize tags so we can simplify logic.


{
  "image" => "img",
  "stylesheet" => "css",
  "javascript" => "js",
  "style" => "css"
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag, args, tokens) ⇒ Tag




73
74
75
76
77
78
79
80
# File 'lib/bunto/assets/liquid/tag.rb', line 73

def initialize(tag, args, tokens)
  tag = tag.to_s
  @tokens = tokens
  @tag = from_alias(tag)
  @args = Parser.new(args, @tag)
  @og_tag = tag
  super
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



17
18
19
# File 'lib/bunto/assets/liquid/tag.rb', line 17

def args
  @args
end

Instance Method Details

#render(context) ⇒ Object


NOTE: We only attach to the regenerator if you are using digested

assets, otherwise we forego any association with it so that we keep
your builds ultra fast, this is ideal in dev.  Disable digests and
let us process independent so the entire site isn't regenerated
because of a single asset change.



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/bunto/assets/liquid/tag.rb', line 90

def render(context)
  site = context.registers[:site]
  page = context.registers.fetch(:page, {})
  args = @args.parse_liquid(context)
  sprockets = site.sprockets
  page = page["path"]

  asset = find_asset(args, sprockets)
  add_as_bunto_dependency(site, sprockets, page, asset)
  process_tag(args, sprockets, asset)

rescue => e
  capture_and_out_error(
    site, e
  )
end