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.
22
23
24
25
26
|
# File 'lib/middleman-core/core_extensions/front_matter.rb', line 22
def initialize(app, options_hash={}, &block)
super
@cache = {}
end
|
Instance Method Details
#after_configuration ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/middleman-core/core_extensions/front_matter.rb', line 34
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
28
29
30
31
32
|
# File 'lib/middleman-core/core_extensions/front_matter.rb', line 28
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
107
108
109
110
111
112
113
114
115
116
|
# File 'lib/middleman-core/core_extensions/front_matter.rb', line 107
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
93
94
95
96
97
98
99
100
101
102
103
104
105
|
# File 'lib/middleman-core/core_extensions/front_matter.rb', line 93
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
|