Module: Eggshell::FormatHandler::Utils

Included in:
Bundles::Basic::BasicFormatHandlers
Defined in:
lib/eggshell/format-handler.rb

Instance Method Summary collapse

Instance Method Details

#parse_args(arg_str) ⇒ 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.

Returns:

  • An array where the last element is always a {Hash}



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/eggshell/format-handler.rb', line 28

def parse_args(arg_str)
	raw_args = arg_str.split(/(?<!\\)\|/)
	args = raw_args.shift.split(/ ; /)
	map = {}
	raw_args.each do |rarg|
		k, v = rarg.split('=', 2)
		map[k] = v
	end
	args << map
	args
end