Class: Liquid::Tag::Parser
- Inherits:
-
Object
- Object
- Liquid::Tag::Parser
- Extended by:
- Forwardable
- Defined in:
- lib/liquid/tag/parser.rb,
lib/liquid/tag/parser/version.rb
Constant Summary collapse
- FALSE =
–
'!'
- FLOAT =
%r!\A\d+\.\d+\Z!.freeze
- QUOTE =
%r!(["'])([^\1]*)(\1)!.freeze
- SPECIAL =
%r{(?<!\\)([@!:=])}.freeze
- BOOL =
%r{\A(?<!\\)([!@])([\w:]+)\z}.freeze
- UNQUOTED_SPECIAL =
%r{(?<!\\)(://)}.freeze
- SPECIAL_ESCAPED =
%r{\\([@!:=])}.freeze
- KEY =
%r{\b(?<!\\):}.freeze
- INT =
%r!^\d+$!.freeze
- TRUE =
'@'
- VERSION =
'2.0.2'
Instance Attribute Summary collapse
-
#args ⇒ Object
(also: #raw_args)
readonly
Returns the value of attribute args.
Instance Method Summary collapse
-
#initialize(raw, defaults: {}, sep: '=') ⇒ Parser
constructor
A new instance of Parser.
-
#skippable_loop(skip: [], hash: false) ⇒ Hash<Symbol,Object>, Array<String>
Consumes a block and wraps around reusably on arguments.
-
#to_h(skip: [], html: false) ⇒ Hash<Object>, Array<String>
Converts arguments into an HTML hash (or to arguments).
-
#to_html(skip: []) ⇒ String
Converts the arguments into an HTML attribute string.
Constructor Details
#initialize(raw, defaults: {}, sep: '=') ⇒ Parser
Returns a new instance of Parser.
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/liquid/tag/parser.rb', line 53 def initialize(raw, defaults: {}, sep: '=') @sep = sep @unescaped_sep = sep @rsep = Regexp.escape(sep) @escaped_sep_regexp = %r!\\(#{@rsep})! @sep_regexp = %r{\b(?<!\\)(#{@rsep})} @escaped_sep = "\\#{@sep}" @args = defaults @raw = raw parse end |
Instance Attribute Details
#args ⇒ Object (readonly) Also known as: raw_args
Returns the value of attribute args.
12 13 14 |
# File 'lib/liquid/tag/parser.rb', line 12 def args @args end |
Instance Method Details
#skippable_loop(skip: [], hash: false) ⇒ Hash<Symbol,Object>, Array<String>
Consumes a block and wraps around reusably on arguments.
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/liquid/tag/parser.rb', line 70 def skippable_loop(skip: [], hash: false) @args.each_with_object(hash ? {} : []) do |(key, val), obj| next obj if skip_in_html?(key: key, val: val, skips: skip) yield( [ key, val ], obj ) end end |
#to_h(skip: [], html: false) ⇒ Hash<Object>, Array<String>
Converts arguments into an HTML hash (or to arguments).
100 101 102 103 104 105 106 |
# File 'lib/liquid/tag/parser.rb', line 100 def to_h(skip: [], html: false) return @args unless html skippable_loop(skip: skip, hash: true) do |(k, v), o| o[k] = v end end |
#to_html(skip: []) ⇒ String
Converts the arguments into an HTML attribute string.
88 89 90 91 92 |
# File 'lib/liquid/tag/parser.rb', line 88 def to_html(skip: []) skippable_loop(skip: skip, hash: false) do |(k, v), o| o << (v == true ? k.to_s : "#{k}=\"#{v}\"") end.join(' ') end |