middleman-core 3.0.14 → 3.1.0.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- data/features/clean_build.feature +4 -5
- data/features/content_type.feature +43 -0
- data/features/data.feature +9 -4
- data/features/front-matter-neighbor.feature +151 -0
- data/features/queryable.feature +31 -0
- data/features/step_definitions/queryable_steps.rb +123 -0
- data/fixtures/content-type-app/config.rb +1 -0
- data/fixtures/content-type-app/source/.htaccess +1 -0
- data/fixtures/content-type-app/source/README +1 -0
- data/fixtures/content-type-app/source/images/blank.gif +0 -0
- data/fixtures/content-type-app/source/index.html +1 -0
- data/fixtures/content-type-app/source/javascripts/app.js +1 -0
- data/fixtures/content-type-app/source/override.html +5 -0
- data/fixtures/content-type-app/source/stylesheets/site.css +1 -0
- data/fixtures/frontmatter-neighbor-app/config.rb +0 -0
- data/fixtures/frontmatter-neighbor-app/source/front-matter-2.php.erb +2 -0
- data/fixtures/frontmatter-neighbor-app/source/front-matter-2.php.erb.frontmatter +4 -0
- data/fixtures/frontmatter-neighbor-app/source/front-matter-auto.erb +1 -0
- data/fixtures/frontmatter-neighbor-app/source/front-matter-auto.erb.frontmatter +4 -0
- data/fixtures/frontmatter-neighbor-app/source/front-matter-change.html.erb +1 -0
- data/fixtures/frontmatter-neighbor-app/source/front-matter-change.html.erb.frontmatter +4 -0
- data/fixtures/frontmatter-neighbor-app/source/front-matter-encoding.html.erb +1 -0
- data/fixtures/frontmatter-neighbor-app/source/front-matter-encoding.html.erb.frontmatter +5 -0
- data/fixtures/frontmatter-neighbor-app/source/json-front-matter-2.php.erb +2 -0
- data/fixtures/frontmatter-neighbor-app/source/json-front-matter-2.php.erb.frontmatter +4 -0
- data/fixtures/frontmatter-neighbor-app/source/json-front-matter-auto.erb +1 -0
- data/fixtures/frontmatter-neighbor-app/source/json-front-matter-auto.erb.frontmatter +4 -0
- data/fixtures/frontmatter-neighbor-app/source/json-front-matter.html.erb +1 -0
- data/fixtures/frontmatter-neighbor-app/source/json-front-matter.html.erb.frontmatter +4 -0
- data/fixtures/frontmatter-neighbor-app/source/raw-front-matter.html +1 -0
- data/fixtures/frontmatter-neighbor-app/source/raw-front-matter.html.frontmatter +4 -0
- data/fixtures/frontmatter-neighbor-app/source/raw-front-matter.php +1 -0
- data/fixtures/frontmatter-neighbor-app/source/raw-front-matter.php.frontmatter +4 -0
- data/fixtures/frontmatter-settings-neighbor-app/config.rb +4 -0
- data/fixtures/frontmatter-settings-neighbor-app/source/alternate_layout.html.erb +1 -0
- data/fixtures/frontmatter-settings-neighbor-app/source/alternate_layout.html.erb.frontmatter +3 -0
- data/fixtures/frontmatter-settings-neighbor-app/source/ignored.html.erb +1 -0
- data/fixtures/frontmatter-settings-neighbor-app/source/ignored.html.erb.frontmatter +3 -0
- data/fixtures/frontmatter-settings-neighbor-app/source/layouts/alternate.erb +3 -0
- data/fixtures/frontmatter-settings-neighbor-app/source/layouts/override.erb +2 -0
- data/fixtures/frontmatter-settings-neighbor-app/source/override_layout.html.erb +1 -0
- data/fixtures/frontmatter-settings-neighbor-app/source/override_layout.html.erb.frontmatter +3 -0
- data/fixtures/frontmatter-settings-neighbor-app/source/page_mentioned.html.erb +1 -0
- data/fixtures/frontmatter-settings-neighbor-app/source/page_mentioned.html.erb.frontmatter +3 -0
- data/fixtures/nested-data-app/config.rb +1 -0
- data/fixtures/nested-data-app/data/examples/test.yml +1 -0
- data/fixtures/nested-data-app/source/test.html.erb +1 -0
- data/fixtures/queryable-app/config.rb +0 -0
- data/fixtures/queryable-app/source/2010-08-08-test-document-file.html.markdown +8 -0
- data/fixtures/queryable-app/source/2010-08-09-another-test-document.html.markdown +10 -0
- data/fixtures/queryable-app/source/2011-12-26-some-test-document.html.markdown +6 -0
- data/fixtures/queryable-app/source/document_with_date_in_yaml.html.markdown +7 -0
- data/fixtures/queryable-app/source/document_without_date.html.markdown +7 -0
- data/lib/middleman-core/application.rb +52 -84
- data/lib/middleman-core/cli.rb +3 -2
- data/lib/middleman-core/cli/build.rb +5 -7
- data/lib/middleman-core/cli/bundler.rb +1 -1
- data/lib/middleman-core/cli/console.rb +46 -0
- data/lib/middleman-core/configuration.rb +235 -0
- data/lib/middleman-core/core_extensions.rb +0 -6
- data/lib/middleman-core/core_extensions/data.rb +34 -11
- data/lib/middleman-core/core_extensions/extensions.rb +31 -35
- data/lib/middleman-core/core_extensions/external_helpers.rb +7 -7
- data/lib/middleman-core/core_extensions/file_watcher.rb +1 -1
- data/lib/middleman-core/core_extensions/front_matter.rb +44 -38
- data/lib/middleman-core/core_extensions/rendering.rb +27 -21
- data/lib/middleman-core/core_extensions/request.rb +41 -73
- data/lib/middleman-core/core_extensions/routing.rb +7 -24
- data/lib/middleman-core/core_extensions/show_exceptions.rb +6 -8
- data/lib/middleman-core/extensions.rb +35 -0
- data/lib/middleman-core/logger.rb +9 -0
- data/lib/middleman-core/meta_pages.rb +93 -0
- data/lib/middleman-core/meta_pages/assets/config.css +36 -0
- data/lib/middleman-core/meta_pages/assets/glyphicons-halflings.png +0 -0
- data/lib/middleman-core/meta_pages/assets/jquery-1.8.2.min.js +2 -0
- data/lib/middleman-core/meta_pages/assets/jquery.details-1.6.min.js +6 -0
- data/lib/middleman-core/meta_pages/assets/meta.css +368 -0
- data/lib/middleman-core/meta_pages/assets/sitemap.css +635 -0
- data/lib/middleman-core/meta_pages/assets/sitemap.js +0 -0
- data/lib/middleman-core/meta_pages/config_setting.rb +39 -0
- data/lib/middleman-core/meta_pages/sitemap_resource.rb +52 -0
- data/lib/middleman-core/meta_pages/sitemap_tree.rb +73 -0
- data/lib/middleman-core/meta_pages/templates/config.html.erb +59 -0
- data/lib/middleman-core/meta_pages/templates/index.html.erb +21 -0
- data/lib/middleman-core/meta_pages/templates/sitemap.html.erb +31 -0
- data/lib/middleman-core/preview_server.rb +18 -7
- data/lib/middleman-core/profiling.rb +1 -1
- data/lib/middleman-core/renderers/erb.rb +5 -5
- data/lib/middleman-core/renderers/less.rb +3 -3
- data/lib/middleman-core/renderers/markdown.rb +10 -9
- data/lib/middleman-core/renderers/redcarpet.rb +16 -21
- data/lib/middleman-core/renderers/sass.rb +4 -5
- data/lib/middleman-core/renderers/slim.rb +4 -1
- data/lib/middleman-core/sitemap.rb +3 -3
- data/lib/middleman-core/sitemap/extensions/content_type.rb +16 -0
- data/lib/middleman-core/sitemap/extensions/on_disk.rb +2 -2
- data/lib/middleman-core/sitemap/extensions/proxies.rb +26 -16
- data/lib/middleman-core/sitemap/queryable.rb +148 -0
- data/lib/middleman-core/sitemap/resource.rb +14 -2
- data/lib/middleman-core/sitemap/store.rb +8 -7
- data/lib/middleman-core/step_definitions/builder_steps.rb +3 -0
- data/lib/middleman-core/step_definitions/server_steps.rb +6 -1
- data/lib/middleman-core/templates/default/source/layouts/layout.erb +1 -1
- data/lib/middleman-core/templates/extension/lib/lib.rb +17 -26
- data/lib/middleman-core/templates/html5/source/layouts/layout.erb +1 -1
- data/lib/middleman-core/templates/shared/Gemfile.tt +6 -1
- data/lib/middleman-core/util.rb +7 -5
- data/lib/middleman-core/version.rb +1 -1
- data/middleman-core.gemspec +1 -1
- metadata +126 -28
- data/lib/middleman-core/core_extensions/builder.rb +0 -17
- data/lib/middleman-core/core_extensions/ruby_encoding.rb +0 -25
- data/middleman-core-x86-mingw32.gemspec +0 -38
@@ -4,15 +4,6 @@ module Middleman
|
|
4
4
|
module Renderers
|
5
5
|
|
6
6
|
class RedcarpetTemplate < ::Tilt::RedcarpetTemplate::Redcarpet2
|
7
|
-
|
8
|
-
def initialize(*args, &block)
|
9
|
-
super
|
10
|
-
|
11
|
-
if @options.has_key?(:context)
|
12
|
-
@context = @options[:context]
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
7
|
# Overwrite built-in Tilt version.
|
17
8
|
# Don't overload :renderer option with smartypants
|
18
9
|
# Support renderer-level options
|
@@ -39,27 +30,31 @@ module Middleman
|
|
39
30
|
|
40
31
|
renderer.new(render_options)
|
41
32
|
end
|
42
|
-
|
43
|
-
def evaluate(context, locals, &block)
|
44
|
-
@context ||= context
|
45
|
-
|
46
|
-
if @engine.renderer.respond_to? :middleman_app=
|
47
|
-
@engine.renderer.middleman_app = @context
|
48
|
-
end
|
49
|
-
super
|
50
|
-
end
|
51
33
|
end
|
52
34
|
|
53
35
|
# Custom Redcarpet renderer that uses our helpers for images and links
|
54
36
|
class MiddlemanRedcarpetHTML < ::Redcarpet::Render::HTML
|
55
|
-
|
37
|
+
cattr_accessor :middleman_app
|
56
38
|
|
57
39
|
def image(link, title, alt_text)
|
58
|
-
middleman_app.
|
40
|
+
if middleman_app && middleman_app.respond_to?(:image_tag)
|
41
|
+
middleman_app.image_tag(link, :title => title, :alt => alt_text)
|
42
|
+
else
|
43
|
+
img = "<img src=\"#{link}\""
|
44
|
+
img << " title=\"#{title}\"" if title
|
45
|
+
img << " alt=\"#{alt_text}\"" if alt_text
|
46
|
+
img << ">"
|
47
|
+
end
|
59
48
|
end
|
60
49
|
|
61
50
|
def link(link, title, content)
|
62
|
-
middleman_app.
|
51
|
+
if middleman_app && middleman_app.respond_to?(:link_to)
|
52
|
+
middleman_app.link_to(content, link, :title => title)
|
53
|
+
else
|
54
|
+
a = "<a href=\"#{link}\""
|
55
|
+
a << " title=\"#{title}\"" if title
|
56
|
+
a << ">#{content}</a>"
|
57
|
+
end
|
63
58
|
end
|
64
59
|
end
|
65
60
|
|
@@ -12,12 +12,11 @@ module Middleman
|
|
12
12
|
# Once registered
|
13
13
|
def registered(app)
|
14
14
|
# Default sass options
|
15
|
-
app.
|
15
|
+
app.config.define_setting :sass, {}, 'Sass engine options'
|
16
16
|
|
17
17
|
# Location of SASS .sass-cache directory.
|
18
18
|
# @return [String]
|
19
|
-
|
20
|
-
app.set(:sass_cache_path) { File.join(app.root_path, '.sass-cache') } # runtime compile of path
|
19
|
+
app.config.define_setting :sass_cache_path, File.join(app.root_path, '.sass-cache'), 'Location of sass cache' # runtime compile of path
|
21
20
|
|
22
21
|
app.before_configuration do
|
23
22
|
template_extensions :scss => :css,
|
@@ -76,11 +75,11 @@ module Middleman
|
|
76
75
|
more_opts = { :filename => eval_file, :line => line, :syntax => syntax }
|
77
76
|
|
78
77
|
if @context.is_a?(::Middleman::Application) && file
|
79
|
-
location_of_sass_file =
|
78
|
+
location_of_sass_file = @context.source_dir
|
80
79
|
|
81
80
|
parts = basename.split('.')
|
82
81
|
parts.pop
|
83
|
-
more_opts[:css_filename] = File.join(location_of_sass_file, @context.css_dir, parts.join("."))
|
82
|
+
more_opts[:css_filename] = File.join(location_of_sass_file, @context.config[:css_dir], parts.join("."))
|
84
83
|
end
|
85
84
|
|
86
85
|
options.merge(more_opts)
|
@@ -26,8 +26,11 @@ module Middleman
|
|
26
26
|
context_hack = {
|
27
27
|
:context => self
|
28
28
|
}
|
29
|
+
|
30
|
+
slim_embedded = defined?(::Slim::Embedded) ? ::Slim::Embedded : ::Slim::EmbeddedEngine
|
31
|
+
|
29
32
|
%w(sass scss markdown).each do |engine|
|
30
|
-
|
33
|
+
slim_embedded.default_options[engine.to_sym] = context_hack
|
31
34
|
end
|
32
35
|
end
|
33
36
|
end
|
@@ -20,10 +20,10 @@ module Middleman
|
|
20
20
|
app.register Middleman::Sitemap::Extensions::Ignores
|
21
21
|
|
22
22
|
# Set to automatically convert some characters into a directory
|
23
|
-
app.
|
23
|
+
app.config.define_setting :automatic_directory_matcher, nil, 'Set to automatically convert some characters into a directory'
|
24
24
|
|
25
25
|
# Setup callbacks which can exclude paths from the sitemap
|
26
|
-
app.
|
26
|
+
app.config.define_setting :ignored_sitemap_matchers, {
|
27
27
|
# dotfiles and folders in the root
|
28
28
|
:root_dotfiles => proc { |file| file.start_with?('.') },
|
29
29
|
|
@@ -38,7 +38,7 @@ module Middleman
|
|
38
38
|
:layout => proc { |file|
|
39
39
|
file.start_with?('source/layout.') || file.start_with?('source/layouts/')
|
40
40
|
}
|
41
|
-
}
|
41
|
+
}, 'Callbacks that can exclude paths from the sitemap'
|
42
42
|
|
43
43
|
# Include instance methods
|
44
44
|
app.send :include, InstanceMethods
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rack'
|
2
|
+
|
3
|
+
module Middleman::Sitemap::Extensions
|
4
|
+
# Content type is implemented as a module so it can be overridden by other sitemap extensions
|
5
|
+
module ContentType
|
6
|
+
# The preferred MIME content type for this resource
|
7
|
+
def content_type
|
8
|
+
# Allow explcitly setting content type from page/proxy options
|
9
|
+
meta_type = metadata[:options][:content_type]
|
10
|
+
return meta_type if meta_type
|
11
|
+
|
12
|
+
# Look up mime type based on extension
|
13
|
+
::Rack::Mime.mime_type(ext, nil)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -45,7 +45,7 @@ module Middleman
|
|
45
45
|
path = @sitemap.file_to_path(file)
|
46
46
|
return false unless path
|
47
47
|
|
48
|
-
ignored = @app.ignored_sitemap_matchers.any? do |name, callback|
|
48
|
+
ignored = @app.config[:ignored_sitemap_matchers].any? do |name, callback|
|
49
49
|
callback.call(file)
|
50
50
|
end
|
51
51
|
|
@@ -85,7 +85,7 @@ module Middleman
|
|
85
85
|
::Middleman::Sitemap::Resource.new(
|
86
86
|
@sitemap,
|
87
87
|
@sitemap.file_to_path(file),
|
88
|
-
File.
|
88
|
+
File.join(@app.root, file)
|
89
89
|
)
|
90
90
|
end
|
91
91
|
end
|
@@ -42,29 +42,39 @@ module Middleman
|
|
42
42
|
@proxied_to
|
43
43
|
end
|
44
44
|
|
45
|
-
#
|
46
|
-
#
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
45
|
+
# The resource for the page this page is proxied to. Throws an exception
|
46
|
+
# if there is no resource.
|
47
|
+
# @return [Sitemap::Resource]
|
48
|
+
def proxied_to_resource
|
49
|
+
proxy_resource = store.find_resource_by_path(proxied_to)
|
50
|
+
|
51
|
+
unless proxy_resource
|
52
|
+
raise "Path #{path} proxies to unknown file #{proxied_to}:#{store.resources.map(&:path)}"
|
52
53
|
end
|
54
|
+
|
55
|
+
if proxy_resource.proxy?
|
56
|
+
raise "You can't proxy #{path} to #{proxied_to} which is itself a proxy."
|
57
|
+
end
|
58
|
+
|
59
|
+
proxy_resource
|
53
60
|
end
|
54
61
|
|
55
62
|
def get_source_file
|
56
63
|
if proxy?
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
64
|
+
proxied_to_resource.source_file
|
65
|
+
else
|
66
|
+
super
|
67
|
+
end
|
68
|
+
end
|
62
69
|
|
63
|
-
|
64
|
-
|
65
|
-
|
70
|
+
def content_type
|
71
|
+
mime_type = super
|
72
|
+
return mime_type if mime_type
|
66
73
|
|
67
|
-
|
74
|
+
if proxy?
|
75
|
+
proxied_to_resource.content_type
|
76
|
+
else
|
77
|
+
nil
|
68
78
|
end
|
69
79
|
end
|
70
80
|
end
|
@@ -0,0 +1,148 @@
|
|
1
|
+
require "active_support/core_ext/object/inclusion"
|
2
|
+
|
3
|
+
module Middleman
|
4
|
+
module Sitemap
|
5
|
+
|
6
|
+
# Code adapted from https://github.com/ralph/document_mapper/
|
7
|
+
module Queryable
|
8
|
+
OPERATOR_MAPPING = {
|
9
|
+
'equal' => :==,
|
10
|
+
'gt' => :>,
|
11
|
+
'gte' => :>=,
|
12
|
+
'in' => :in?,
|
13
|
+
'include' => :include?,
|
14
|
+
'lt' => :<,
|
15
|
+
'lte' => :<=
|
16
|
+
}
|
17
|
+
|
18
|
+
VALID_OPERATORS = OPERATOR_MAPPING.keys
|
19
|
+
|
20
|
+
FileNotFoundError = Class.new StandardError
|
21
|
+
OperatorNotSupportedError = Class.new StandardError
|
22
|
+
|
23
|
+
module API
|
24
|
+
def select(options = {})
|
25
|
+
documents = resources.select { |r| !r.raw_data.empty? }
|
26
|
+
options[:where].each do |selector, selector_value|
|
27
|
+
documents = documents.select do |document|
|
28
|
+
next unless document.raw_data.has_key? selector.attribute
|
29
|
+
document_value = document.raw_data[selector.attribute]
|
30
|
+
operator = OPERATOR_MAPPING[selector.operator]
|
31
|
+
document_value.send operator, selector_value
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
if options[:order_by].present?
|
36
|
+
order_attribute = options[:order_by].keys.first
|
37
|
+
asc_or_desc = options[:order_by].values.first
|
38
|
+
documents = documents.select do |document|
|
39
|
+
document.raw_data.include? order_attribute
|
40
|
+
end
|
41
|
+
documents = documents.sort_by do |document|
|
42
|
+
document.raw_data[order_attribute]
|
43
|
+
end
|
44
|
+
documents.reverse! if asc_or_desc == :desc
|
45
|
+
end
|
46
|
+
|
47
|
+
documents
|
48
|
+
end
|
49
|
+
|
50
|
+
def where(hash)
|
51
|
+
Query.new(self).where(hash)
|
52
|
+
end
|
53
|
+
|
54
|
+
def order_by(field)
|
55
|
+
Query.new(self).order_by(field)
|
56
|
+
end
|
57
|
+
|
58
|
+
def offset(number)
|
59
|
+
Query.new(self).offset(number)
|
60
|
+
end
|
61
|
+
|
62
|
+
def limit(number)
|
63
|
+
Query.new(self).limit(number)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
class Query
|
68
|
+
def initialize(model)
|
69
|
+
@model = model
|
70
|
+
@where = {}
|
71
|
+
end
|
72
|
+
|
73
|
+
def where(constraints_hash)
|
74
|
+
selector_hash = constraints_hash.reject { |key, value| !key.is_a? Selector }
|
75
|
+
symbol_hash = constraints_hash.reject { |key, value| key.is_a? Selector }
|
76
|
+
symbol_hash.each do |attribute, value|
|
77
|
+
selector = Selector.new(:attribute => attribute, :operator => 'equal')
|
78
|
+
selector_hash.update({ selector => value })
|
79
|
+
end
|
80
|
+
@where.merge! selector_hash
|
81
|
+
self
|
82
|
+
end
|
83
|
+
|
84
|
+
def order_by(field)
|
85
|
+
@order_by = field.is_a?(Symbol) ? {field => :asc} : field
|
86
|
+
self
|
87
|
+
end
|
88
|
+
|
89
|
+
def offset(number)
|
90
|
+
@offset = number
|
91
|
+
self
|
92
|
+
end
|
93
|
+
|
94
|
+
def limit(number)
|
95
|
+
@limit = number
|
96
|
+
self
|
97
|
+
end
|
98
|
+
|
99
|
+
def first
|
100
|
+
self.all.first
|
101
|
+
end
|
102
|
+
|
103
|
+
def last
|
104
|
+
self.all.last
|
105
|
+
end
|
106
|
+
|
107
|
+
def all
|
108
|
+
result = @model.select(:where => @where, :order_by => @order_by)
|
109
|
+
if @offset.present?
|
110
|
+
result = result.last([result.size - @offset, 0].max)
|
111
|
+
end
|
112
|
+
if @limit.present?
|
113
|
+
result = result.first(@limit)
|
114
|
+
end
|
115
|
+
result
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
class Selector
|
120
|
+
attr_reader :attribute, :operator
|
121
|
+
|
122
|
+
def initialize(opts = {})
|
123
|
+
unless VALID_OPERATORS.include? opts[:operator]
|
124
|
+
raise OperatorNotSupportedError
|
125
|
+
end
|
126
|
+
@attribute, @operator = opts[:attribute], opts[:operator]
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
# Add operators to symbol objects
|
134
|
+
class Symbol
|
135
|
+
Middleman::Sitemap::Queryable::VALID_OPERATORS.each do |operator|
|
136
|
+
class_eval <<-OPERATORS
|
137
|
+
def #{operator}
|
138
|
+
Middleman::Sitemap::Queryable::Selector.new(:attribute => self, :operator => '#{operator}')
|
139
|
+
end
|
140
|
+
OPERATORS
|
141
|
+
end
|
142
|
+
|
143
|
+
unless method_defined?(:"<=>")
|
144
|
+
def <=>(other)
|
145
|
+
self.to_s <=> other.to_s
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require "middleman-core/sitemap/extensions/traversal"
|
2
|
+
require "middleman-core/sitemap/extensions/content_type"
|
2
3
|
|
3
4
|
module Middleman
|
4
5
|
|
@@ -8,6 +9,7 @@ module Middleman
|
|
8
9
|
# Sitemap Resource class
|
9
10
|
class Resource
|
10
11
|
include Middleman::Sitemap::Extensions::Traversal
|
12
|
+
include Middleman::Sitemap::Extensions::ContentType
|
11
13
|
|
12
14
|
# @return [Middleman::Application]
|
13
15
|
attr_reader :app
|
@@ -76,6 +78,7 @@ module Middleman
|
|
76
78
|
# Merge in new metadata specific to this resource.
|
77
79
|
# @param [Hash] metadata A metadata block like provides_metadata_for_path takes
|
78
80
|
def add_metadata(metadata={}, &block)
|
81
|
+
metadata = metadata.dup
|
79
82
|
if metadata.has_key?(:blocks)
|
80
83
|
@local_metadata[:blocks] << metadata.delete(:blocks)
|
81
84
|
end
|
@@ -114,6 +117,15 @@ module Middleman
|
|
114
117
|
instrument "render.resource", :path => relative_source do
|
115
118
|
md = metadata.dup
|
116
119
|
opts = md[:options].deep_merge(opts)
|
120
|
+
|
121
|
+
# Pass "renderer_options" hash from frontmatter along to renderer
|
122
|
+
if md[:page]["renderer_options"]
|
123
|
+
opts[:renderer_options] = {}
|
124
|
+
md[:page]["renderer_options"].each do |k, v|
|
125
|
+
opts[:renderer_options][k.to_sym] = v
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
117
129
|
locs = md[:locals].deep_merge(locs)
|
118
130
|
|
119
131
|
# Forward remaining data to helpers
|
@@ -121,7 +133,7 @@ module Middleman
|
|
121
133
|
app.data.store("page", md[:page])
|
122
134
|
end
|
123
135
|
|
124
|
-
blocks = md[:blocks].dup
|
136
|
+
blocks = Array(md[:blocks]).dup
|
125
137
|
blocks << block if block_given?
|
126
138
|
|
127
139
|
app.current_path ||= self.destination_path
|
@@ -143,7 +155,7 @@ module Middleman
|
|
143
155
|
|
144
156
|
# Whether the source file is binary.
|
145
157
|
#
|
146
|
-
# @
|
158
|
+
# @return [Boolean]
|
147
159
|
def binary?
|
148
160
|
::Middleman::Util.binary?(source_file)
|
149
161
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# Used for merging results of metadata callbacks
|
2
2
|
require "active_support/core_ext/hash/deep_merge"
|
3
3
|
require 'monitor'
|
4
|
+
require "middleman-core/sitemap/queryable"
|
4
5
|
|
5
6
|
module Middleman
|
6
7
|
|
@@ -18,6 +19,8 @@ module Middleman
|
|
18
19
|
# @return [Middleman::Application]
|
19
20
|
attr_accessor :app
|
20
21
|
|
22
|
+
include ::Middleman::Sitemap::Queryable::API
|
23
|
+
|
21
24
|
# Initialize with parent app
|
22
25
|
# @param [Middleman::Application] app
|
23
26
|
def initialize(app)
|
@@ -110,7 +113,7 @@ module Middleman
|
|
110
113
|
provides_metadata.inject(blank_metadata) do |result, (callback, matcher)|
|
111
114
|
next result if matcher && !source_file.match(matcher)
|
112
115
|
|
113
|
-
metadata = callback.call(source_file)
|
116
|
+
metadata = callback.call(source_file).dup
|
114
117
|
|
115
118
|
if metadata.has_key?(:blocks)
|
116
119
|
result[:blocks] << metadata[:blocks]
|
@@ -123,8 +126,6 @@ module Middleman
|
|
123
126
|
|
124
127
|
# Register a handler to provide metadata on a url path
|
125
128
|
# @param [Regexp] matcher
|
126
|
-
# @param [Symbol] origin an indicator of where this metadata came from - only one
|
127
|
-
# block per [matcher, origin] pair may exist.
|
128
129
|
# @return [Array<Array<Proc, Regexp>>]
|
129
130
|
def provides_metadata_for_path(matcher=nil, &block)
|
130
131
|
@_provides_metadata_for_path ||= []
|
@@ -151,7 +152,7 @@ module Middleman
|
|
151
152
|
next result unless File.fnmatch("/" + Util.strip_leading_slash(matcher), "/#{request_path}")
|
152
153
|
end
|
153
154
|
|
154
|
-
metadata = callback.call(request_path)
|
155
|
+
metadata = callback.call(request_path).dup
|
155
156
|
|
156
157
|
result[:blocks] += Array(metadata.delete(:blocks))
|
157
158
|
|
@@ -163,7 +164,7 @@ module Middleman
|
|
163
164
|
# @param [String] file
|
164
165
|
# @return [String]
|
165
166
|
def file_to_path(file)
|
166
|
-
file = File.
|
167
|
+
file = File.join(@app.root, file)
|
167
168
|
|
168
169
|
prefix = @app.source_dir.sub(/\/$/, "") + "/"
|
169
170
|
return false unless file.start_with?(prefix)
|
@@ -171,8 +172,8 @@ module Middleman
|
|
171
172
|
path = file.sub(prefix, "")
|
172
173
|
|
173
174
|
# Replace a file name containing automatic_directory_matcher with a folder
|
174
|
-
unless @app.automatic_directory_matcher.nil?
|
175
|
-
path = path.gsub(@app.automatic_directory_matcher, "/")
|
175
|
+
unless @app.config[:automatic_directory_matcher].nil?
|
176
|
+
path = path.gsub(@app.config[:automatic_directory_matcher], "/")
|
176
177
|
end
|
177
178
|
|
178
179
|
extensionless_path(path)
|