class Jekyll::Assets::Liquid::Tag


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 %}

Constants

AcceptableTags

Tags that we allow our users to use.


Alias

Allows us to normalize tags so we can simplify logic.


Tags

The HTML version of every tag that we accept.


Attributes

args[R]

Public Class Methods

new(tag, args, tokens) click to toggle source

Calls superclass method
# File lib/jekyll/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

Public Instance Methods

render(context) click to toggle source

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.

# File lib/jekyll/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_jekyll_dependency(site, sprockets, page, asset)
  process_tag(args, sprockets, asset)

rescue => e
  capture_and_out_error(
    site, e
  )
end

Private Instance Methods

_ext_for(type) click to toggle source

# File lib/jekyll/assets/liquid/tag.rb, line 203
def _ext_for(type)
  out = Sprockets.mime_exts.select do |k, v|
    v == type
  end

  out.keys              .first
end
_find_asset(file, args, sprockets) click to toggle source

# File lib/jekyll/assets/liquid/tag.rb, line 179
def _find_asset(file, args, sprockets)
  if args.empty? then sprockets.manifest.find(file).first
  elsif args.size == 1 && args.key?(:accept)
    if File.extname(file) == ""
      file = file + _ext_for(args[
        :accept
      ])
    end

    sprockets.manifest.find(file).find do |asset|
      asset.content_type == args[
        :accept
      ]
    end
  else
    sprockets.find_asset(
      file, args
    )
  end
end
add_as_jekyll_dependency(site, sprockets, page, asset) click to toggle source

# File lib/jekyll/assets/liquid/tag.rb, line 145
def add_as_jekyll_dependency(site, sprockets, page, asset)
  if page && sprockets.digest?
    site.regenerator.add_dependency(
      site.in_source_dir(page), site.in_source_dir(asset.logical_path)
    )
  end
end
build_html(args, sprockets, asset, path = get_path(sprockets, asset)) click to toggle source

# File lib/jekyll/assets/liquid/tag.rb, line 126
def build_html(args, sprockets, asset, path = get_path(sprockets, asset))
  return path if @tag == "asset_path"
  return asset.to_s if @tag == "asset" || @tag == "asset_source"
  data = args.key?(:data) && args[:data].key?(:uri) ? asset.data_uri : path
  format(Tags[@tag], data, args.to_html)
end
capture_and_out_error(site, error) click to toggle source

There is no guarantee that Jekyll will pass on the error for some reason (unless you are just booting up) so we capture that error and always output it, it can lead to some double errors but I would rather there be a double error than no error.


# File lib/jekyll/assets/liquid/tag.rb, line 220
def capture_and_out_error(site, error)
  if error.is_a?(Sass::SyntaxError)
    file = error.sass_filename.gsub(/#{Regexp.escape(site.source)}\//, "")
    Jekyll.logger.error(%Q(Error in #{file}:#{error.sass_line} #{
      error
    }))

  else
    Jekyll.logger.error(
      "", error.to_s
    )
  end

  raise error
end
find_asset(args, sprockets) click to toggle source

# File lib/jekyll/assets/liquid/tag.rb, line 156
def find_asset(args, sprockets)
  out = _find_asset(args[:file],
    args[:sprockets] ||= {}, sprockets
  )

  if !out
    raise(
      AssetNotFoundError, args[
        :file
      ]
    )

  else
    out.liquid_tags << self
    !args.proxies?? out : ProxiedAsset.new(
      out, args, sprockets, self
    )
  end
end
from_alias(tag) click to toggle source

# File lib/jekyll/assets/liquid/tag.rb, line 110
def from_alias(tag)
  Alias.key?(tag) ? Alias[tag] : tag
end
get_path(sprockets, asset) click to toggle source

# File lib/jekyll/assets/liquid/tag.rb, line 136
def get_path(sprockets, asset)
  sprockets.prefix_path(
    sprockets.digest?? asset.digest_path : asset.logical_path
  )
end
process_tag(args, sprockets, asset) click to toggle source

# File lib/jekyll/assets/liquid/tag.rb, line 117
def process_tag(args, sprockets, asset)
  sprockets.manifest.add(asset) unless @tag == "asset_source"
  Defaults.set_defaults_for!(@tag, args ||= {}, asset, sprockets)
  build_html(args, sprockets, asset)
end