Class: PictureTag::Instructions::ArgSplitter
- Inherits:
-
Object
- Object
- PictureTag::Instructions::ArgSplitter
- Defined in:
- lib/jekyll_picture_tag/instructions/arg_splitter.rb
Overview
This class takes in the arguments passed to the liquid tag, and splits it up into ‘words’ (correctly handling quotes and backslash escapes.)
To handle quotes and backslash escaping, we have to parse the string by characters to break it up correctly. I’m sure there’s a library to do this, but it’s not that much code honestly. If this starts getting big, we’ll pull in a new dependency.
Instance Attribute Summary collapse
-
#words ⇒ Object
readonly
Returns the value of attribute words.
Instance Method Summary collapse
-
#initialize(raw_params) ⇒ ArgSplitter
constructor
A new instance of ArgSplitter.
Constructor Details
#initialize(raw_params) ⇒ ArgSplitter
Returns a new instance of ArgSplitter.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/jekyll_picture_tag/instructions/arg_splitter.rb', line 14 def initialize(raw_params) @words = [] @word = '' @in_quotes = false @escaped = false raw_params.each_char { |c| handle_char(c) } add_word # We have to explicitly add the last one. end |
Instance Attribute Details
#words ⇒ Object (readonly)
Returns the value of attribute words.
12 13 14 |
# File 'lib/jekyll_picture_tag/instructions/arg_splitter.rb', line 12 def words @words end |