Module: Bridgetown::FrontMatter::Importer
- Included in:
- Layout, Model::RepoOrigin
- Defined in:
- lib/bridgetown-core/front_matter/importer.rb
Class Method Summary collapse
-
.included(klass) ⇒ Object
Requires klass#content and klass#front_matter_line_count accessors.
Instance Method Summary collapse
Class Method Details
.included(klass) ⇒ Object
Requires klass#content and klass#front_matter_line_count accessors
7 8 9 |
# File 'lib/bridgetown-core/front_matter/importer.rb', line 7 def self.included(klass) klass.include Bridgetown::FrontMatter::RubyDSL end |
Instance Method Details
#read_front_matter(file_path) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/bridgetown-core/front_matter/importer.rb', line 11 def read_front_matter(file_path) file_contents = File.read( file_path, **Bridgetown::Utils.merged_file_read_opts(Bridgetown::Current.site, {}) ) fm_result = nil Loaders.for(self).each do |loader| fm_result = loader.read(file_contents, file_path:) and break end if fm_result self.content = fm_result.content self.front_matter_line_count = fm_result.line_count fm_result.front_matter elsif is_a?(Layout) self.content = file_contents {} else yaml_data = YAMLParser.load_file(file_path) (yaml_data.is_a?(Array) ? { rows: yaml_data } : yaml_data) end end |