Class: Middleman::CoreExtensions::FrontMatter
- Inherits:
-
Extension
- Object
- Extension
- Middleman::CoreExtensions::FrontMatter
show all
- Defined in:
- lib/middleman-core/core_extensions/front_matter.rb
Constant Summary
Constants included
from Contracts
Contracts::PATH_MATCHER
Instance Attribute Summary
Attributes inherited from Extension
#app, #options
Instance Method Summary
collapse
Methods inherited from Extension
activated_extension, #add_exposed_to_context, #after_build, #after_configuration, after_extension_activated, #after_extension_activated, #before_build, clear_after_extension_callbacks, config, expose_to_application, expose_to_config, expose_to_template, helpers, option, #ready, resources
Methods included from Contracts
#Contract
Constructor Details
#initialize(app, options_hash = {}, &block) ⇒ FrontMatter
Returns a new instance of FrontMatter.
17
18
19
20
21
|
# File 'lib/middleman-core/core_extensions/front_matter.rb', line 17
def initialize(app, options_hash={}, &block)
super
@cache = {}
end
|
Instance Method Details
#before_configuration ⇒ Object
23
24
25
|
# File 'lib/middleman-core/core_extensions/front_matter.rb', line 23
def before_configuration
app.files.on_change(:source, &method(:clear_data))
end
|
#clear_data(updated_files, removed_files) ⇒ Object
75
76
77
78
79
|
# File 'lib/middleman-core/core_extensions/front_matter.rb', line 75
def clear_data(updated_files, removed_files)
(updated_files + removed_files).each do |file|
@cache.delete(file[:full_path])
end
end
|
#data(path) ⇒ Object
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/middleman-core/core_extensions/front_matter.rb', line 63
def data(path)
file = app.files.find(:source, path)
return [{}, nil] unless file
@cache[file[:full_path]] ||= ::Middleman::Util::Data.parse(
file[:full_path],
app.config[:frontmatter_delims]
)
end
|
#manipulate_resource_list(resources) ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/middleman-core/core_extensions/front_matter.rb', line 29
def manipulate_resource_list(resources)
resources.each do |resource|
next if resource.file_descriptor.nil?
fmdata = data(resource.file_descriptor[:full_path].to_s).first.dup
opts = fmdata.(:layout, :layout_engine, :renderer_options, :directory_index, :content_type)
opts[:renderer_options].symbolize_keys! if opts.key?(:renderer_options)
ignored = fmdata.delete(:ignored)
resource.add_metadata options: opts, page: fmdata
resource.ignore! if ignored == true && !resource.is_a?(::Middleman::Sitemap::ProxyResource)
end
end
|
#template_data_for_file(path) ⇒ Object
58
59
60
|
# File 'lib/middleman-core/core_extensions/front_matter.rb', line 58
def template_data_for_file(path)
data(path).last
end
|