Module: Jekyll::AsciiDoc::Utils
Constant Summary collapse
- NewLine =
%(\n)- StandaloneOptionLine =
%([%standalone]#{NewLine})- AttributeReferenceRx =
/\\?\{(\w+(?:[\-]\w+)*)\}/
Instance Method Summary collapse
- #get_converter(site) ⇒ Object
- #has_front_matter?(dlg_method, asciidoc_ext_re, path) ⇒ Boolean
- #hashify_attributes(attrs, initial = {}) ⇒ Object
-
#parse_yaml_value(val) ⇒ Object
Parse the specified value as though it is a single-line value part of a YAML key/value pair.
- #resolve_attribute_refs(text, table) ⇒ Object
- #symbolize_keys(hash) ⇒ Object
Instance Method Details
#get_converter(site) ⇒ Object
55 56 57 |
# File 'lib/jekyll-asciidoc/utils.rb', line 55 def get_converter site site.find_converter_instance Converter end |
#has_front_matter?(dlg_method, asciidoc_ext_re, path) ⇒ Boolean
8 9 10 |
# File 'lib/jekyll-asciidoc/utils.rb', line 8 def has_front_matter? dlg_method, asciidoc_ext_re, path (::File.extname path) =~ asciidoc_ext_re ? true : (dlg_method.call path) end |
#hashify_attributes(attrs, initial = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/jekyll-asciidoc/utils.rb', line 16 def hashify_attributes attrs, initial = {} if (is_array = ::Array === attrs) || ::Hash === attrs attrs.each_with_object(initial) {|entry, new_attrs| key, val = is_array ? ((entry.split '=', 2) + ['', ''])[0..1] : entry if key.start_with? '!' new_attrs[key[1..-1]] = nil elsif key.end_with? '!' new_attrs[key.chop] = nil else new_attrs[key] = val ? (resolve_attribute_refs val, new_attrs) : nil end } else initial end end |
#parse_yaml_value(val) ⇒ Object
Parse the specified value as though it is a single-line value part of a YAML key/value pair.
Attempt to parse the specified String value as though it is a single-line value part of a YAML key/value pair. If the value fails to parse, wrap the value in single quotes (after escaping any single quotes in the value) and parse it as a character sequence. If the value is empty, return an empty String.
val - The String value to parse.
Returns an [Object] parsed from the string-based YAML value or empty
- String
-
if the specified value is empty.
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/jekyll-asciidoc/utils.rb', line 72 def parse_yaml_value val if val.empty? '' else begin ::SafeYAML.load %(--- #{val}) rescue val = val.gsub '\'', '\'\'' if val.include? '\'' ::SafeYAML.load %(--- \'#{val}\') end end end |
#resolve_attribute_refs(text, table) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/jekyll-asciidoc/utils.rb', line 33 def resolve_attribute_refs text, table if text.empty? text elsif text.include? '{' text.gsub AttributeReferenceRx do if $&.start_with? '\\' $&[1..-1] elsif (value = table[$1]) value else $& end end else text end end |
#symbolize_keys(hash) ⇒ Object
51 52 53 |
# File 'lib/jekyll-asciidoc/utils.rb', line 51 def symbolize_keys hash hash.each_with_object({}) {|(key, val), accum| accum[key.to_sym] = val } end |