Module: Eggshell::FormatHandler::Utils
- Defined in:
- lib/eggshell/format-handler.rb
Instance Method Summary collapse
-
#parse_args(arg_str, no_direct = false) ⇒ Object
Parses arguments in the form: ‘arg0 ; arg1 ; …|att=val|att2=val|…`.
Instance Method Details
#parse_args(arg_str, no_direct = false) ⇒ Object
Parses arguments in the form: ‘arg0 ; arg1 ; …|att=val|att2=val|…`
The first portion is the direct argument. For instance, a link like ‘[~ link ; text ~]` or an image like `[! src ; alt !]`. The remaining piped args are key-value pairs (use `\|` to escape) which might be embedded in the tag or signal some further transformations.
If any contexts don’t use direct arguments, set {no_direct} to ‘true`. This will produce a 1-element array with a map.
interpreted as a direct arguments list. arguments.
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/eggshell/format-handler.rb', line 35 def parse_args(arg_str, no_direct = false) return [] if !arg_str || arg_str == '' raw_args = arg_str.split(/(?<!\\)\|/) args = [] args += raw_args.shift.split(/ ; /) if !no_direct map = {} raw_args.each do |rarg| k, v = rarg.split('=', 2) map[k] = v end args << map args end |