class Jekyll::Assets::Liquid::Tag::Parser
Constants
- ACCEPT
Attributes
args[R]
raw_args[R]
Public Class Methods
new(args, tag, processed: false, raw_args: nil)
click to toggle source
# File lib/jekyll/assets/liquid/tag/parser.rb, line 61 def initialize(args, tag, processed: false, raw_args: nil) if processed && raw_args @args = args @raw_args = raw_args @tag = tag elsif processed && !raw_args raise ArgumentError, "You must provide raw_args if you pre-process." "Please provide the raw args." else @tag = tag @raw_args = args parse_raw set_accept end end
Public Instance Methods
parse_liquid(context)
click to toggle source
# File lib/jekyll/assets/liquid/tag/parser.rb, line 81 def parse_liquid(context) return self unless context.is_a?(Object::Liquid::Context) liquid = context.registers[:site].liquid_renderer.file("(jekyll:assets)") out = parse_hash_liquid(to_h, liquid, context) self.class.new(out, @tag, { :raw_args => @raw_args, :processed => true }) end
proxies()
click to toggle source
# File lib/jekyll/assets/liquid/tag/parser.rb, line 101 def proxies keys = (args.keys - Proxies.base_keys - [:file, :html]) args.select do |key, _| keys.include?(key) end end
proxies?()
click to toggle source
# File lib/jekyll/assets/liquid/tag/parser.rb, line 110 def proxies? proxies.any? end
to_html()
click to toggle source
# File lib/jekyll/assets/liquid/tag/parser.rb, line 93 def to_html (self[:html] || {}).map do |key, val| val == true || val == "true" ? key.to_s : %Q( #{key}="#{val}") end.join end
Private Instance Methods
as_bool_or_html(hash, key)
click to toggle source
# File lib/jekyll/assets/liquid/tag/parser.rb, line 155 def as_bool_or_html(hash, key) okey = key key, sub_key = key if Proxies.has?(key, @tag, "@#{sub_key}") (hash[key.to_sym] ||= {})[sub_key.to_sym] = true else (hash[:html] ||= {})[key] = okey[1] end end
as_proxy(hash, key)
click to toggle source
# File lib/jekyll/assets/liquid/tag/parser.rb, line 169 def as_proxy(hash, key) key, sub_key, val = key if Proxies.has?(key, @tag, sub_key) (hash[key.to_sym] ||= {})[sub_key.to_sym] = val elsif Proxies.has?(key) raise UnknownProxyError end end
from_shellwords()
click to toggle source
# File lib/jekyll/assets/liquid/tag/parser.rb, line 195 def from_shellwords Shellwords.shellwords(@raw_args) end
parse_col(hash, key)
click to toggle source
# File lib/jekyll/assets/liquid/tag/parser.rb, line 145 def parse_col(hash, key) key.push(key.delete_at(-1).gsub(/\:/, ":")) return as_proxy hash, key if key.size == 3 return as_bool_or_html hash, key if key.size == 2 || key.size == 1 raise UnescapedColonError end
parse_hash_liquid(hash_, liquid, context)
click to toggle source
# File lib/jekyll/assets/liquid/tag/parser.rb, line 117 def parse_hash_liquid(hash_, liquid, context) hash_.each_with_object({}) do |(key, val), hash| val = liquid.parse(val).render(context) if val.is_a?(String) val = parse_hash_liquid(val, liquid, context) if val.is_a?(Hash) hash[key] = val end end
parse_raw()
click to toggle source
# File lib/jekyll/assets/liquid/tag/parser.rb, line 128 def parse_raw @args = from_shellwords.each_with_index.each_with_object({}) do |(key, index), hash| if index == 0 then hash.store(:file, key) elsif key =~ /:/ && (key = key.split(/(?<!\):/)) parse_col hash, key else (hash[:html] ||= {})[key] = true end hash end end
set_accept()
click to toggle source
# File lib/jekyll/assets/liquid/tag/parser.rb, line 183 def set_accept if ACCEPT.key?(@tag) && (!@args.key?(:sprockets) || !@args[:sprockets].key?(:accept)) (@args[:sprockets] ||= {})[:accept] = ACCEPT[@tag] end end