Module: Yarrow::Tools::FrontMatter Deprecated
- Included in:
- Content::CollectionExpander
- Defined in:
- lib/yarrow/tools/front_matter.rb
Overview
Deprecated.
Maintained here as it is still used in a number of places but needs to be removed soon
Instance Method Summary collapse
- #extract_split_content(text, options = {}) ⇒ Object
- #read_split_content(path, options = {}) ⇒ Object
Instance Method Details
#extract_split_content(text, options = {}) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/yarrow/tools/front_matter.rb', line 11 def extract_split_content(text, ={}) pattern = /^(---\s*\n.*?\n?)^(---\s*$\n?)/m if text =~ pattern content = text.sub(pattern, "") begin if .key?(:symbolize_keys) = YAML.load($1, symbolize_names: true) else = YAML.load($1) end return [content, ] rescue Psych::SyntaxError => error if defined? ::Logger # todo: application wide logger #logger = ::Logger.new(STDOUT) #logger.error "#{error.message}" end return [content, nil] end end [text, nil] end |
#read_split_content(path, options = {}) ⇒ Object
7 8 9 |
# File 'lib/yarrow/tools/front_matter.rb', line 7 def read_split_content(path, ={}) extract_split_content(File.read(path, :encoding => 'utf-8'), ) end |