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
@@ -37,19 +37,13 @@ module Middleman
|
|
37
37
|
class << self
|
38
38
|
# @private
|
39
39
|
def registered(app)
|
40
|
-
# Using for version parsing
|
41
|
-
require "rubygems"
|
42
|
-
|
43
40
|
app.define_hook :after_configuration
|
44
41
|
app.define_hook :before_configuration
|
45
42
|
app.define_hook :build_config
|
46
43
|
app.define_hook :development_config
|
47
44
|
|
48
|
-
|
49
|
-
|
50
|
-
else
|
51
|
-
app.set :autoload_sprockets, true
|
52
|
-
end
|
45
|
+
app.config.define_setting :autoload_sprockets, true, 'Automatically load sprockets at startup?'
|
46
|
+
app.config[:autoload_sprockets] = (ENV["AUTOLOAD_SPROCKETS"] == "true") if ENV["AUTOLOAD_SPROCKETS"]
|
53
47
|
|
54
48
|
app.extend ClassMethods
|
55
49
|
app.send :include, InstanceMethods
|
@@ -68,29 +62,24 @@ module Middleman
|
|
68
62
|
send("#{env}_config", &block)
|
69
63
|
end
|
70
64
|
|
71
|
-
# Alias `extensions` to access registered extensions
|
72
|
-
#
|
73
|
-
# @return [Array<Module>]
|
74
|
-
def extensions
|
75
|
-
@extensions ||= []
|
76
|
-
end
|
77
|
-
|
78
65
|
# Register a new extension
|
79
66
|
#
|
80
67
|
# @param [Module] extension Extension modules to register
|
81
68
|
# @param [Hash] options Per-extension options hash
|
82
69
|
# @return [void]
|
83
70
|
def register(extension, options={}, &block)
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
extension.registered(self, options, &block)
|
71
|
+
if extension.instance_of? Module
|
72
|
+
extend extension
|
73
|
+
if extension.respond_to?(:registered)
|
74
|
+
if extension.method(:registered).arity === 1
|
75
|
+
extension.registered(self, &block)
|
76
|
+
else
|
77
|
+
extension.registered(self, options, &block)
|
78
|
+
end
|
93
79
|
end
|
80
|
+
extension
|
81
|
+
elsif extension.instance_of?(Class) && extension.ancestors.include?(::Middleman::Extension)
|
82
|
+
extension.new(self, options, &block)
|
94
83
|
end
|
95
84
|
end
|
96
85
|
end
|
@@ -109,17 +98,24 @@ module Middleman
|
|
109
98
|
ext_module = if ext.is_a?(Module)
|
110
99
|
ext
|
111
100
|
else
|
112
|
-
::Middleman::Extensions.load(ext
|
101
|
+
::Middleman::Extensions.load(ext)
|
113
102
|
end
|
114
103
|
|
115
104
|
if ext_module.nil?
|
116
105
|
logger.error "== Unknown Extension: #{ext}"
|
117
106
|
else
|
118
107
|
logger.debug "== Activating: #{ext}"
|
119
|
-
self.class.register(ext_module, options, &block)
|
108
|
+
extensions[ext] = self.class.register(ext_module, options, &block)
|
120
109
|
end
|
121
110
|
end
|
122
111
|
|
112
|
+
# Access activated extensions
|
113
|
+
#
|
114
|
+
# @return [Hash<Symbol,Middleman::Extension|Module>]
|
115
|
+
def extensions
|
116
|
+
@extensions ||= {}
|
117
|
+
end
|
118
|
+
|
123
119
|
# Load features before starting server
|
124
120
|
def initialize
|
125
121
|
super
|
@@ -130,14 +126,7 @@ module Middleman
|
|
130
126
|
# Search the root of the project for required files
|
131
127
|
$LOAD_PATH.unshift(root)
|
132
128
|
|
133
|
-
|
134
|
-
local_config = File.join(root, "config.rb")
|
135
|
-
if File.exists? local_config
|
136
|
-
logger.debug "== Reading: Local config"
|
137
|
-
instance_eval File.read(local_config), local_config, 1
|
138
|
-
end
|
139
|
-
|
140
|
-
if autoload_sprockets
|
129
|
+
if config[:autoload_sprockets]
|
141
130
|
begin
|
142
131
|
require "middleman-sprockets"
|
143
132
|
activate(:sprockets)
|
@@ -145,13 +134,20 @@ module Middleman
|
|
145
134
|
end
|
146
135
|
end
|
147
136
|
|
137
|
+
# Check for and evaluate local configuration
|
138
|
+
local_config = File.join(root, "config.rb")
|
139
|
+
if File.exists? local_config
|
140
|
+
logger.debug "== Reading: Local config"
|
141
|
+
instance_eval File.read(local_config), local_config, 1
|
142
|
+
end
|
143
|
+
|
148
144
|
run_hook :build_config if build?
|
149
145
|
run_hook :development_config if development?
|
150
146
|
|
151
147
|
run_hook :after_configuration
|
152
148
|
|
153
149
|
logger.debug "Loaded extensions:"
|
154
|
-
self.
|
150
|
+
self.extensions.each do |ext,_|
|
155
151
|
logger.debug "== Extension: #{ext}"
|
156
152
|
end
|
157
153
|
end
|
@@ -9,20 +9,20 @@ module Middleman
|
|
9
9
|
# once registered
|
10
10
|
def registered(app)
|
11
11
|
# Setup a default helpers paths
|
12
|
-
app.
|
13
|
-
app.
|
14
|
-
app.
|
12
|
+
app.config.define_setting :helpers_dir, "helpers", 'Directory to autoload helper modules from'
|
13
|
+
app.config.define_setting :helpers_filename_glob, "**.rb", 'Glob pattern for matching helper ruby files'
|
14
|
+
app.config.define_setting :helpers_filename_to_module_name_proc, Proc.new { |filename|
|
15
15
|
basename = File.basename(filename, File.extname(filename))
|
16
16
|
basename.camelcase
|
17
|
-
}
|
17
|
+
}, 'Proc implementing the conversion from helper filename to module name'
|
18
18
|
|
19
19
|
# After config
|
20
20
|
app.after_configuration do
|
21
|
-
helpers_path = File.
|
21
|
+
helpers_path = File.join(root, config[:helpers_dir])
|
22
22
|
next unless File.exists?(helpers_path)
|
23
23
|
|
24
|
-
Dir[File.join(helpers_path, helpers_filename_glob)].each do |filename|
|
25
|
-
module_name = helpers_filename_to_module_name_proc.call(filename)
|
24
|
+
Dir[File.join(helpers_path, config[:helpers_filename_glob])].each do |filename|
|
25
|
+
module_name = config[:helpers_filename_to_module_name_proc].call(filename)
|
26
26
|
next unless module_name
|
27
27
|
|
28
28
|
require filename
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require "active_support/core_ext/hash/keys"
|
1
2
|
require 'pathname'
|
2
3
|
|
3
4
|
# Extensions namespace
|
@@ -27,20 +28,17 @@ module Middleman::CoreExtensions
|
|
27
28
|
app.after_configuration do
|
28
29
|
::Middleman::Sitemap::Resource.send :include, ResourceInstanceMethods
|
29
30
|
|
30
|
-
|
31
|
-
:frontmatter,
|
32
|
-
frontmatter_manager
|
33
|
-
)
|
31
|
+
ignore %r{\.frontmatter$}
|
34
32
|
|
35
33
|
sitemap.provides_metadata do |path|
|
36
34
|
fmdata = frontmatter_manager.data(path).first || {}
|
37
35
|
|
38
36
|
data = {}
|
39
|
-
|
40
|
-
data[opt
|
37
|
+
[:layout, :layout_engine].each do |opt|
|
38
|
+
data[opt] = fmdata[opt] unless fmdata[opt].nil?
|
41
39
|
end
|
42
40
|
|
43
|
-
{ :options => data, :page => fmdata }
|
41
|
+
{ :options => data, :page => ::Middleman::Util.recursively_enhance(fmdata).freeze }
|
44
42
|
end
|
45
43
|
end
|
46
44
|
end
|
@@ -58,16 +56,27 @@ module Middleman::CoreExtensions
|
|
58
56
|
|
59
57
|
def data(path)
|
60
58
|
p = normalize_path(path)
|
61
|
-
@cache[p] ||=
|
59
|
+
@cache[p] ||= begin
|
60
|
+
in_file = frontmatter_and_content(p)
|
61
|
+
|
62
|
+
external_file = frontmatter_and_content("#{p}.frontmatter")
|
63
|
+
|
64
|
+
return in_file if external_file.nil?
|
65
|
+
|
66
|
+
[
|
67
|
+
external_file[0].deep_merge(in_file[0]),
|
68
|
+
in_file[1]
|
69
|
+
]
|
70
|
+
end
|
62
71
|
end
|
63
72
|
|
64
73
|
def clear_data(file)
|
65
74
|
# Copied from Sitemap::Store#file_to_path, but without
|
66
75
|
# removing the file extension
|
67
|
-
file = File.
|
76
|
+
file = File.join(@app.root, file)
|
68
77
|
prefix = @app.source_dir.sub(/\/$/, "") + "/"
|
69
78
|
return unless file.include?(prefix)
|
70
|
-
path = file.sub(prefix, "")
|
79
|
+
path = file.sub(prefix, "").sub(/\.frontmatter$/, "")
|
71
80
|
|
72
81
|
@cache.delete(path)
|
73
82
|
end
|
@@ -88,12 +97,12 @@ module Middleman::CoreExtensions
|
|
88
97
|
content = content.sub(yaml_regex, "")
|
89
98
|
|
90
99
|
begin
|
91
|
-
data = YAML.load($1)
|
100
|
+
data = YAML.load($1) || {}
|
101
|
+
data = data.symbolize_keys
|
92
102
|
rescue *YAML_ERRORS => e
|
93
103
|
logger.error "YAML Exception: #{e.message}"
|
94
104
|
return false
|
95
105
|
end
|
96
|
-
|
97
106
|
else
|
98
107
|
return false
|
99
108
|
end
|
@@ -111,7 +120,7 @@ module Middleman::CoreExtensions
|
|
111
120
|
|
112
121
|
begin
|
113
122
|
json = ($1+$2).sub(";;;", "{").sub(";;;", "}")
|
114
|
-
data = ActiveSupport::JSON.decode(json)
|
123
|
+
data = ActiveSupport::JSON.decode(json).symbolize_keys
|
115
124
|
rescue => e
|
116
125
|
logger.error "JSON Exception: #{e.message}"
|
117
126
|
return false
|
@@ -135,6 +144,8 @@ module Middleman::CoreExtensions
|
|
135
144
|
else
|
136
145
|
path
|
137
146
|
end
|
147
|
+
|
148
|
+
return nil unless File.exists?(full_path)
|
138
149
|
|
139
150
|
data = {}
|
140
151
|
content = nil
|
@@ -154,55 +165,51 @@ module Middleman::CoreExtensions
|
|
154
165
|
elsif result = parse_json_front_matter(content)
|
155
166
|
data, content = result
|
156
167
|
end
|
157
|
-
rescue
|
168
|
+
rescue
|
158
169
|
# Probably a binary file, move on
|
159
170
|
end
|
160
171
|
end
|
161
172
|
|
162
|
-
[
|
173
|
+
[data, content]
|
163
174
|
end
|
164
175
|
|
165
176
|
def normalize_path(path)
|
166
177
|
path.sub(%r{^#{@app.source_dir}\/}, "")
|
167
178
|
end
|
168
|
-
|
169
|
-
# Update the main sitemap resource list
|
170
|
-
# @return [void]
|
171
|
-
def manipulate_resource_list(resources)
|
172
|
-
resources.each do |r|
|
173
|
-
if !r.proxy? && !r.data.nil? && r.data["ignored"] == true
|
174
|
-
r.frontmatter_ignored = true
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
resources
|
179
|
-
end
|
180
179
|
end
|
181
180
|
|
182
181
|
module ResourceInstanceMethods
|
183
182
|
|
184
|
-
def frontmatter_ignored?
|
185
|
-
@_frontmatter_ignored || false
|
186
|
-
end
|
187
|
-
|
188
|
-
def frontmatter_ignored=(v)
|
189
|
-
@_frontmatter_ignored = v
|
190
|
-
end
|
191
|
-
|
192
183
|
def ignored?
|
193
|
-
if
|
184
|
+
if !proxy? && data["ignored"] == true
|
194
185
|
true
|
195
186
|
else
|
196
187
|
super
|
197
188
|
end
|
198
189
|
end
|
199
190
|
|
191
|
+
# This page's frontmatter without being enhanced for access by either symbols or strings.
|
192
|
+
# Used internally
|
193
|
+
# @private
|
194
|
+
# @return [Hash]
|
195
|
+
def raw_data
|
196
|
+
app.frontmatter_manager.data(source_file).first
|
197
|
+
end
|
198
|
+
|
200
199
|
# This page's frontmatter
|
201
200
|
# @return [Hash]
|
202
201
|
def data
|
203
|
-
|
202
|
+
::Middleman::Util.recursively_enhance(raw_data).freeze
|
204
203
|
end
|
205
204
|
|
205
|
+
# Override Resource#content_type to take into account frontmatter
|
206
|
+
def content_type
|
207
|
+
# Allow setting content type in frontmatter too
|
208
|
+
fm_type = data[:content_type]
|
209
|
+
return fm_type if fm_type
|
210
|
+
|
211
|
+
super
|
212
|
+
end
|
206
213
|
end
|
207
214
|
|
208
215
|
module InstanceMethods
|
@@ -218,7 +225,6 @@ module Middleman::CoreExtensions
|
|
218
225
|
def template_data_for_file(path)
|
219
226
|
frontmatter_manager.data(path).last
|
220
227
|
end
|
221
|
-
|
222
228
|
end
|
223
229
|
end
|
224
230
|
end
|
@@ -23,6 +23,7 @@ module Middleman
|
|
23
23
|
app.define_hook :after_render
|
24
24
|
|
25
25
|
::Tilt.mappings.delete('html') # WTF, Tilt?
|
26
|
+
::Tilt.mappings.delete('csv')
|
26
27
|
|
27
28
|
# Activate custom renderers
|
28
29
|
require "middleman-core/renderers/erb"
|
@@ -86,9 +87,7 @@ module Middleman
|
|
86
87
|
Tilt.mappings.each do |key, klasses|
|
87
88
|
begin
|
88
89
|
Tilt[".#{key}"]
|
89
|
-
rescue LoadError
|
90
|
-
Tilt.mappings.delete(key)
|
91
|
-
rescue NameError
|
90
|
+
rescue LoadError, NameError
|
92
91
|
Tilt.mappings.delete(key)
|
93
92
|
end
|
94
93
|
end
|
@@ -128,6 +127,9 @@ module Middleman
|
|
128
127
|
|
129
128
|
# Store last engine for later (could be inside nested renders)
|
130
129
|
@current_engine, engine_was = engine, @current_engine
|
130
|
+
old_locale = ::I18n.locale
|
131
|
+
|
132
|
+
I18n.locale = opts[:lang] if opts[:lang]
|
131
133
|
|
132
134
|
# Use a dup of self as a context so that instance variables set within
|
133
135
|
# the template don't persist for other templates.
|
@@ -147,7 +149,7 @@ module Middleman
|
|
147
149
|
opts[:template_body] = content if content
|
148
150
|
content = render_individual_file(path, locs, opts, context)
|
149
151
|
path = File.basename(path, File.extname(path))
|
150
|
-
rescue LocalJumpError
|
152
|
+
rescue LocalJumpError
|
151
153
|
raise "Tried to render a layout (calls yield) at #{path} like it was a template. Non-default layouts need to be in #{source}/layouts."
|
152
154
|
end
|
153
155
|
end
|
@@ -165,6 +167,7 @@ module Middleman
|
|
165
167
|
ensure
|
166
168
|
# Pop all the saved variables from earlier as we may be returning to a
|
167
169
|
# previous render (layouts, partials, nested layouts).
|
170
|
+
::I18n.locale = old_locale
|
168
171
|
@current_engine = engine_was
|
169
172
|
@content_blocks = nil
|
170
173
|
@current_locs = nil
|
@@ -192,27 +195,26 @@ module Middleman
|
|
192
195
|
engine = File.extname(resource.source_file)[1..-1].to_sym
|
193
196
|
|
194
197
|
# Look for partials relative to the current path
|
195
|
-
|
196
|
-
relative_dir = File.join(current_dir.sub("#{self.source_dir}/", ""), data)
|
198
|
+
relative_dir = File.join(current_dir.sub(%r{^#{self.source_dir}/?}, ""), data)
|
197
199
|
|
198
|
-
|
199
|
-
|
200
|
+
# Try to use the current engine first
|
201
|
+
found_partial, found_engine = resolve_template(relative_dir, :preferred_engine => engine, :try_without_underscore => true)
|
200
202
|
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
end
|
203
|
+
# Fall back to any engine available
|
204
|
+
if !found_partial
|
205
|
+
found_partial, found_engine = resolve_template(relative_dir, :try_without_underscore => true)
|
205
206
|
end
|
206
207
|
end
|
207
208
|
|
208
|
-
# Look in the
|
209
|
+
# Look in the partials_dir for the partial with the current engine
|
210
|
+
partials_path = File.join(config[:partials_dir], data)
|
209
211
|
if !found_partial && !engine.nil?
|
210
|
-
found_partial, found_engine = resolve_template(
|
212
|
+
found_partial, found_engine = resolve_template(partials_path, :preferred_engine => engine, :try_without_underscore => true)
|
211
213
|
end
|
212
214
|
|
213
215
|
# Look in the root with any engine
|
214
216
|
if !found_partial
|
215
|
-
found_partial, found_engine = resolve_template(
|
217
|
+
found_partial, found_engine = resolve_template(partials_path, :try_without_underscore => true)
|
216
218
|
end
|
217
219
|
|
218
220
|
# Render the partial if found, otherwide throw exception
|
@@ -245,8 +247,12 @@ module Middleman
|
|
245
247
|
|
246
248
|
# Merge per-extension options from config
|
247
249
|
extension = File.extname(path)
|
248
|
-
options = opts.merge(options_for_ext(extension))
|
250
|
+
options = opts.dup.merge(options_for_ext(extension))
|
249
251
|
options[:outvar] ||= '@_out_buf'
|
252
|
+
options.delete(:layout)
|
253
|
+
|
254
|
+
# Overwrite with frontmatter options
|
255
|
+
options = options.deep_merge(options[:renderer_options]) if options[:renderer_options]
|
250
256
|
|
251
257
|
template_class = Tilt[path]
|
252
258
|
# Allow hooks to manipulate the template before render
|
@@ -256,8 +262,8 @@ module Middleman
|
|
256
262
|
end
|
257
263
|
|
258
264
|
# Read compiled template from disk or cache
|
259
|
-
template = cache.fetch(:compiled_template, options, body) do
|
260
|
-
|
265
|
+
template = cache.fetch(:compiled_template, extension, options, body) do
|
266
|
+
::Tilt.new(path, 1, options) { body }
|
261
267
|
end
|
262
268
|
|
263
269
|
# Render using Tilt
|
@@ -294,9 +300,9 @@ module Middleman
|
|
294
300
|
# Find all the engines which handle this extension in tilt. Look for
|
295
301
|
# config variables of that name and merge it
|
296
302
|
extension_class = ::Tilt[ext]
|
297
|
-
::Tilt.mappings.each do |
|
303
|
+
::Tilt.mappings.each do |mapping_ext, engines|
|
298
304
|
next unless engines.include? extension_class
|
299
|
-
engine_options =
|
305
|
+
engine_options = config[mapping_ext.to_sym] || {}
|
300
306
|
options.merge!(engine_options)
|
301
307
|
end
|
302
308
|
|
@@ -311,7 +317,7 @@ module Middleman
|
|
311
317
|
# @return [String]
|
312
318
|
def fetch_layout(engine, opts)
|
313
319
|
# The layout name comes from either the system default or the options
|
314
|
-
local_layout = opts.has_key?(:layout) ? opts[:layout] : layout
|
320
|
+
local_layout = opts.has_key?(:layout) ? opts[:layout] : config[:layout]
|
315
321
|
return false unless local_layout
|
316
322
|
|
317
323
|
# Look for engine-specific options
|