Class: Middleman::CoreExtensions::FrontMatter
- Inherits:
-
Extension
- Object
- Extension
- Middleman::CoreExtensions::FrontMatter
show all
- Defined in:
- lib/middleman-core/core_extensions/front_matter.rb
Defined Under Namespace
Modules: ResourceInstanceMethods
Constant Summary
collapse
- YAML_ERRORS =
[StandardError]
Instance Attribute Summary
Attributes inherited from Extension
#app, #options
Instance Method Summary
collapse
Methods inherited from Extension
activate, activated_extension, after_extension_activated, clear_after_extension_callbacks, config, extension_name, helpers, option, register
Constructor Details
#initialize(app, options_hash = {}, &block) ⇒ FrontMatter
Returns a new instance of FrontMatter.
20
21
22
23
24
|
# File 'lib/middleman-core/core_extensions/front_matter.rb', line 20
def initialize(app, options_hash={}, &block)
super
@cache = {}
end
|
Instance Method Details
#after_configuration ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/middleman-core/core_extensions/front_matter.rb', line 32
def after_configuration
app.extensions[:frontmatter] = self
app.ignore %r{\.frontmatter$}
::Middleman::Sitemap::Resource.send :include, ResourceInstanceMethods
app.sitemap.provides_metadata do |path|
fmdata = data(path).first
data = {}
[:layout, :layout_engine].each do |opt|
data[opt] = fmdata[opt] unless fmdata[opt].nil?
end
{ options: data, page: ::Middleman::Util.recursively_enhance(fmdata).freeze }
end
end
|
#before_configuration ⇒ Object
26
27
28
29
30
|
# File 'lib/middleman-core/core_extensions/front_matter.rb', line 26
def before_configuration
ext = self
app.files.changed { |file| ext.clear_data(file) }
app.files.deleted { |file| ext.clear_data(file) }
end
|
#clear_data(file) ⇒ Object
112
113
114
115
116
117
118
119
120
121
|
# File 'lib/middleman-core/core_extensions/front_matter.rb', line 112
def clear_data(file)
file = File.join(app.root, file)
prefix = app.source_dir.sub(/\/$/, '') + '/'
return unless file.include?(prefix)
path = file.sub(prefix, '').sub(/\.frontmatter$/, '')
@cache.delete(path)
end
|
#data(path) ⇒ Object
98
99
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/middleman-core/core_extensions/front_matter.rb', line 98
def data(path)
p = normalize_path(path)
@cache[p] ||= begin
data, content = frontmatter_and_content(p)
if app.files.exists?("#{path}.frontmatter")
external_data, = frontmatter_and_content("#{p}.frontmatter")
data = external_data.deep_merge(data)
end
[data, content]
end
end
|