Class: Pandocomatic::PandocMetadata
- Inherits:
-
Hash
- Object
- Hash
- Pandocomatic::PandocMetadata
- Defined in:
- lib/pandocomatic/pandoc_metadata.rb
Overview
PandocMetadata represents the metadata with pandoc options set in templates and input files.
Class Method Summary collapse
-
.empty(src_format, ignore_pandocomatic: false) ⇒ PandocMetadata[ empty metadata with only pandoc's source format
Create an empty metadata object with only the source format set.
-
.load(input, path: nil, ignore_pandocomatic: false) ⇒ PandocMetadata
Collect the metadata embedded in the src file and create a new PandocMetadata instance.
-
.load_file(src, ignore_pandocomatic: false) ⇒ PandocMetadata
Collect the metadata embedded in the src file and create a new PandocMetadata instance.
-
.pandoc2yaml(input) ⇒ String
Extract the YAML metadata from an input string.
Instance Method Summary collapse
-
#initialize(hash = {}, unique: true) ⇒ PandocMetadata
constructor
Creat e new PandocMetadata object based on the properties contained in a Hash.
-
#pandoc_options ⇒ Hash
Get the pandoc options for this PandocMetadata object.
-
#pandoc_options? ⇒ Boolean
Does this PandocMetadata object has a pandoc options property?.
-
#pandocomatic ⇒ Hash
Get the pandocomatic property of this PandocMetadata object.
-
#pandocomatic? ⇒ Boolean
Does this PandocMetadata object have a pandocomatic property?.
-
#template? ⇒ Boolean
Does this PandocMetadata object use a template?.
-
#template_name ⇒ String
Get the used template’s name.
-
#templates ⇒ Array
Get all the templates of this PandocMetadata oject.
-
#unique? ⇒ Boolean
Did the metadata contain multiple pandocomatic blocks?.
Constructor Details
#initialize(hash = {}, unique: true) ⇒ PandocMetadata
Creat e new PandocMetadata object based on the properties contained in a Hash
at most once.
109 110 111 112 113 |
# File 'lib/pandocomatic/pandoc_metadata.rb', line 109 def initialize(hash = {}, unique: true) super() merge! hash @unique = unique end |
Class Method Details
.empty(src_format, ignore_pandocomatic: false) ⇒ PandocMetadata[ empty metadata with only pandoc's source format
Create an empty metadata object with only the source format set.
configuration in YAML metadata blocks set.
56 57 58 59 60 |
# File 'lib/pandocomatic/pandoc_metadata.rb', line 56 def self.empty(src_format, ignore_pandocomatic: false) = PandocMetadata.new ['pandocomatic_'] = { 'pandoc' => { 'from' => src_format } } unless ignore_pandocomatic end |
.load(input, path: nil, ignore_pandocomatic: false) ⇒ PandocMetadata
Collect the metadata embedded in the src file and create a new PandocMetadata instance
configuration in YAML metadata blocks extracted.
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/pandocomatic/pandoc_metadata.rb', line 84 def self.load(input, path: nil, ignore_pandocomatic: false) yaml, pandocomatic_blocks = (input, path) if yaml.empty? PandocMetadata.new else = PandocMetadata.new PandocomaticYAML.load(yaml, path), unique: pandocomatic_blocks <= 1 if ignore_pandocomatic .delete('pandocomatic') .delete('pandocomatic_') end end end |
.load_file(src, ignore_pandocomatic: false) ⇒ PandocMetadata
Collect the metadata embedded in the src file and create a new PandocMetadata instance
68 69 70 |
# File 'lib/pandocomatic/pandoc_metadata.rb', line 68 def self.load_file(src, ignore_pandocomatic: false) self.load File.read(src), path: src, ignore_pandocomatic: end |
.pandoc2yaml(input) ⇒ String
Extract the YAML metadata from an input string
45 46 47 |
# File 'lib/pandocomatic/pandoc_metadata.rb', line 45 def self.pandoc2yaml(input) (input).first end |
Instance Method Details
#pandoc_options ⇒ Hash
Get the pandoc options for this PandocMetadata object
179 180 181 182 183 184 185 |
# File 'lib/pandocomatic/pandoc_metadata.rb', line 179 def if pandocomatic['pandoc'] else {} end end |
#pandoc_options? ⇒ Boolean
Does this PandocMetadata object has a pandoc options property?
201 202 203 |
# File 'lib/pandocomatic/pandoc_metadata.rb', line 201 def pandocomatic? and pandocomatic.key? 'pandoc' and !pandocomatic['pandoc'].nil? end |
#pandocomatic ⇒ Hash
Get the pandocomatic property of this PandocMetadata object
191 192 193 194 195 |
# File 'lib/pandocomatic/pandoc_metadata.rb', line 191 def pandocomatic return self['pandocomatic'] if key? 'pandocomatic' self['pandocomatic_'] if key? 'pandocomatic_' end |
#pandocomatic? ⇒ Boolean
Does this PandocMetadata object have a pandocomatic property?
property named “pandocomatic_”. False otherwise.
Note. For backward compatibility with older versions of pandocomatic, properties named “pandocomatic” (without the trailing underscore) are also accepted.
166 167 168 169 170 171 172 173 |
# File 'lib/pandocomatic/pandoc_metadata.rb', line 166 def pandocomatic? config = nil if key?('pandocomatic') || key?('pandocomatic_') config = self['pandocomatic'] if key? 'pandocomatic' config = self['pandocomatic_'] if key? 'pandocomatic_' end config.is_a? Hash end |
#template? ⇒ Boolean
Does this PandocMetadata object use a template?
127 128 129 |
# File 'lib/pandocomatic/pandoc_metadata.rb', line 127 def template? pandocomatic? and pandocomatic.key? 'use-template' and !pandocomatic['use-template'].empty? end |
#template_name ⇒ String
Get the used template’s name
150 151 152 153 154 155 156 |
# File 'lib/pandocomatic/pandoc_metadata.rb', line 150 def template_name if template? pandocomatic['use-template'] else '' end end |
#templates ⇒ Array
Get all the templates of this PandocMetadata oject
135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/pandocomatic/pandoc_metadata.rb', line 135 def templates if template? if pandocomatic['use-template'].is_a? Array pandocomatic['use-template'] else [pandocomatic['use-template']] end else [''] end end |
#unique? ⇒ Boolean
Did the metadata contain multiple pandocomatic blocks?
in the metadata
119 120 121 |
# File 'lib/pandocomatic/pandoc_metadata.rb', line 119 def unique? @unique end |