Class: Nanoc::DataSources::Filesystem::Parser Private
- Inherits:
-
Object
- Object
- Nanoc::DataSources::Filesystem::Parser
- Defined in:
- lib/nanoc/data_sources/filesystem/parser.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Defined Under Namespace
Classes: ParseResult
Constant Summary collapse
- SEPARATOR =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
/(-{5}|-{3})/.source
Instance Method Summary collapse
- #call(content_filename, meta_filename) ⇒ ParseResult private
- #frontmatter?(filename) ⇒ Boolean private
-
#initialize(config:) ⇒ Parser
constructor
private
A new instance of Parser.
- #parse_metadata(data, filename) ⇒ Hash private
- #parse_with_frontmatter(content_filename) ⇒ ParseResult private
- #parse_with_separate_meta_filename(content_filename, meta_filename) ⇒ ParseResult private
- #verify_meta(meta, filename) ⇒ Object private
Constructor Details
#initialize(config:) ⇒ Parser
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Parser.
20 21 22 |
# File 'lib/nanoc/data_sources/filesystem/parser.rb', line 20 def initialize(config:) @config = config end |
Instance Method Details
#call(content_filename, meta_filename) ⇒ ParseResult
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
25 26 27 28 29 30 31 |
# File 'lib/nanoc/data_sources/filesystem/parser.rb', line 25 def call(content_filename, ) if (content_filename, ) else parse_with_frontmatter(content_filename) end end |
#frontmatter?(filename) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
73 74 75 76 |
# File 'lib/nanoc/data_sources/filesystem/parser.rb', line 73 def frontmatter?(filename) data = Tools.read_file(filename, config: @config) /\A#{SEPARATOR}\s*$/.match?(data) end |
#parse_metadata(data, filename) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/nanoc/data_sources/filesystem/parser.rb', line 61 def (data, filename) begin = Nanoc::Core::YamlLoader.load(data) || {} rescue => e raise Errors::UnparseableMetadata.new(filename, e) end (, filename) end |
#parse_with_frontmatter(content_filename) ⇒ ParseResult
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/nanoc/data_sources/filesystem/parser.rb', line 42 def parse_with_frontmatter(content_filename) data = Tools.read_file(content_filename, config: @config) unless /\A#{SEPARATOR}\s*$/.match?(data) return ParseResult.new(content: data, attributes: {}, attributes_data: '') end pieces = data.split(/^#{SEPARATOR}[ \t]*\r?\n?/, 3) if pieces.size < 4 raise Errors::InvalidFormat.new(content_filename) end = (pieces[2], content_filename) content = pieces[4].sub(/\A\n/, '') ParseResult.new(content:, attributes: , attributes_data: pieces[2]) end |
#parse_with_separate_meta_filename(content_filename, meta_filename) ⇒ ParseResult
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
34 35 36 37 38 39 |
# File 'lib/nanoc/data_sources/filesystem/parser.rb', line 34 def (content_filename, ) content = content_filename ? Tools.read_file(content_filename, config: @config) : '' = Tools.read_file(, config: @config) = (, ) ParseResult.new(content:, attributes: , attributes_data: ) end |
#verify_meta(meta, filename) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
78 79 80 81 82 |
# File 'lib/nanoc/data_sources/filesystem/parser.rb', line 78 def (, filename) return if .is_a?(Hash) raise Errors::InvalidMetadata.new(filename, .class) end |