require_relative "proxies" require "forwardable" module Jekyll module Assets module Liquid # ----------------------------------------------------------------------- # 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 %} # ----------------------------------------------------------------------- class Tag class Parser attr_reader :args, :raw_args extend Forwardable def_delegator :@args, :to_h def_delegator :@args, :has_key? def_delegator :@args, :fetch_or_store def_delegator :@args, :fetch def_delegator :@args, :store def_delegator :@args, :[] # ------------------------------------------------------------------- Accept = { "css" => "text/css", "js" => "application/javascript" } # ------------------------------------------------------------------- class UnescapedColonError < StandardError def initialize super "Unescaped double colon argument." end end # ------------------------------------------------------------------- class UnknownProxyError < StandardError def initialize super "Unknown proxy argument." end end # ------------------------------------------------------------------- def initialize(args, tag) @raw_args, @tags = args, tag @tag = tag parse_raw set_accept end # ------------------------------------------------------------------- def to_html @args.fetch(:html, {}).map do |key, val| %Q{ #{key}="#{val}"} end. \ join end # ------------------------------------------------------------------- def proxies keys = (args.keys - Proxies.base_keys - [:file, :html]) args.select do |key, _| keys.include?(key) end end # ------------------------------------------------------------------- def has_proxies? proxies.any? end # ------------------------------------------------------------------- private def parse_raw @args = from_shellwords.each_with_index.inject({}) do |hash, (key, index)| if index == 0 then hash.store(:file, key) elsif key =~ /:/ && (key = key.split(/(?