middleman-core 3.3.3 → 3.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/features/automatic_alt_tags.feature +8 -0
- data/features/gzip.feature +36 -6
- data/features/helpers_auto_javascript_include_tag.feature +5 -0
- data/features/i18n_partials.feature +23 -0
- data/features/more-implied_extensions.feature +1 -7
- data/features/more-sitemap_traversal.feature +10 -0
- data/features/partials.feature +11 -0
- data/features/sitemap_traversal.feature +10 -0
- data/features/twitter-bootstrap-compile.feature +4 -4
- data/fixtures/auto-js-directory-index-app/config.rb +1 -0
- data/fixtures/auto-js-directory-index-app/source/auto-js.html.erb +1 -0
- data/fixtures/auto-js-directory-index-app/source/javascripts/auto-js.js +1 -0
- data/fixtures/automatic-alt-tags-app/config.rb +0 -0
- data/fixtures/automatic-alt-tags-app/source/auto-image-sizes.html.erb +1 -0
- data/fixtures/automatic-alt-tags-app/source/images/blank.gif +0 -0
- data/fixtures/i18n-test-app/source/_country.en.erb +1 -0
- data/fixtures/i18n-test-app/source/_country.es.erb +1 -0
- data/fixtures/i18n-test-app/source/_site.erb +1 -0
- data/fixtures/i18n-test-app/source/images/president.en.svg +1 -0
- data/fixtures/i18n-test-app/source/images/president.es.svg +1 -0
- data/fixtures/i18n-test-app/source/localizable/_state.en.erb +1 -0
- data/fixtures/i18n-test-app/source/localizable/_state.es.erb +1 -0
- data/fixtures/i18n-test-app/source/localizable/images/flag.en.svg +1 -0
- data/fixtures/i18n-test-app/source/localizable/images/flag.es.svg +1 -0
- data/fixtures/i18n-test-app/source/localizable/partials/_greeting.en.erb +1 -0
- data/fixtures/i18n-test-app/source/localizable/partials/_greeting.es.erb +1 -0
- data/fixtures/i18n-test-app/source/localizable/partials/index.html.erb +6 -0
- data/fixtures/partials-app/source/_code_snippet.html +1 -0
- data/fixtures/partials-app/source/images/tiger.svg +725 -0
- data/fixtures/partials-app/source/static_underscore.html.erb +1 -0
- data/fixtures/partials-app/source/svg.html.erb +1 -0
- data/lib/middleman-core.rb +2 -1
- data/lib/middleman-core/cli/build.rb +12 -14
- data/lib/middleman-core/cli/bundler.rb +2 -2
- data/lib/middleman-core/cli/init.rb +3 -3
- data/lib/middleman-core/core_extensions/extensions.rb +1 -3
- data/lib/middleman-core/core_extensions/rendering.rb +56 -31
- data/lib/middleman-core/core_extensions/request.rb +1 -1
- data/lib/middleman-core/core_extensions/routing.rb +17 -17
- data/lib/middleman-core/extension.rb +19 -18
- data/lib/middleman-core/preview_server.rb +36 -42
- data/lib/middleman-core/renderers/redcarpet.rb +4 -5
- data/lib/middleman-core/sitemap/extensions/on_disk.rb +10 -13
- data/lib/middleman-core/sitemap/extensions/traversal.rb +15 -7
- data/lib/middleman-core/sitemap/store.rb +1 -1
- data/lib/middleman-core/step_definitions.rb +12 -4
- data/lib/middleman-core/step_definitions/builder_steps.rb +4 -0
- data/lib/middleman-core/step_definitions/server_steps.rb +15 -7
- data/lib/middleman-core/version.rb +1 -1
- data/lib/middleman-more/core_extensions/default_helpers.rb +1 -1
- data/lib/middleman-more/core_extensions/i18n.rb +33 -7
- data/lib/middleman-more/extensions/asset_hash.rb +1 -1
- data/lib/middleman-more/extensions/automatic_alt_tags.rb +2 -6
- data/lib/middleman-more/extensions/gzip.rb +16 -6
- data/middleman-core.gemspec +1 -1
- data/spec/middleman-core/binary_spec.rb +2 -2
- metadata +60 -8
- data/fixtures/more-implied-extensions-app/source/stylesheets/style3.less +0 -4
@@ -0,0 +1 @@
|
|
1
|
+
<%= partial "code_snippet.html" %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= partial "images/tiger.svg" %>
|
data/lib/middleman-core.rb
CHANGED
@@ -168,10 +168,10 @@ module Middleman::Cli
|
|
168
168
|
path.to_s !~ /\/\./ || path.to_s =~ /\.(htaccess|htpasswd)/
|
169
169
|
end
|
170
170
|
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
171
|
+
return unless RUBY_PLATFORM =~ /darwin/
|
172
|
+
|
173
|
+
# handle UTF-8-MAC filename on MacOS
|
174
|
+
@to_clean = @to_clean.map { |path| path.to_s.encode('UTF-8', 'UTF-8-MAC') }
|
175
175
|
end
|
176
176
|
|
177
177
|
# Actually build the app
|
@@ -220,14 +220,14 @@ module Middleman::Cli
|
|
220
220
|
|
221
221
|
output_path = render_to_file(resource)
|
222
222
|
|
223
|
-
|
224
|
-
if RUBY_PLATFORM =~ /darwin/
|
225
|
-
# handle UTF-8-MAC filename on MacOS
|
223
|
+
return unless should_clean? && output_path.exist?
|
226
224
|
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
225
|
+
if RUBY_PLATFORM =~ /darwin/
|
226
|
+
# handle UTF-8-MAC filename on MacOS
|
227
|
+
|
228
|
+
@to_clean.delete(output_path.realpath.to_s.encode('UTF-8', 'UTF-8-MAC'))
|
229
|
+
else
|
230
|
+
@to_clean.delete(output_path.realpath)
|
231
231
|
end
|
232
232
|
end
|
233
233
|
|
@@ -279,9 +279,7 @@ module Middleman::Cli
|
|
279
279
|
end
|
280
280
|
|
281
281
|
def binary_encode(string)
|
282
|
-
if string.respond_to?(:force_encoding)
|
283
|
-
string.force_encoding('ascii-8bit')
|
284
|
-
end
|
282
|
+
string.force_encoding('ascii-8bit') if string.respond_to?(:force_encoding)
|
285
283
|
string
|
286
284
|
end
|
287
285
|
end
|
@@ -11,7 +11,7 @@ module Middleman::Cli
|
|
11
11
|
|
12
12
|
# The setup task
|
13
13
|
def bundle
|
14
|
-
run('bundle install')# , :capture => true)
|
14
|
+
run('bundle install') # , :capture => true)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
@@ -27,7 +27,7 @@ module Middleman::Cli
|
|
27
27
|
# The upgrade task
|
28
28
|
def upgrade
|
29
29
|
inside(ENV['MM_ROOT']) do
|
30
|
-
run('bundle update')# , :capture => true)
|
30
|
+
run('bundle update') # , :capture => true)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
@@ -15,13 +15,13 @@ module Middleman::Cli
|
|
15
15
|
default: 'default',
|
16
16
|
desc: "Use a project template: #{available_templates}"
|
17
17
|
method_option 'css_dir',
|
18
|
-
|
18
|
+
# :default => "stylesheets",
|
19
19
|
desc: 'The path to the css files'
|
20
20
|
method_option 'js_dir',
|
21
|
-
|
21
|
+
# :default => "javascripts",
|
22
22
|
desc: 'The path to the javascript files'
|
23
23
|
method_option 'images_dir',
|
24
|
-
|
24
|
+
# :default => "images",
|
25
25
|
desc: 'The path to the image files'
|
26
26
|
method_option 'rack',
|
27
27
|
type: :boolean,
|
@@ -188,9 +188,7 @@ module Middleman
|
|
188
188
|
logger.debug "== Extension: #{ext}"
|
189
189
|
end
|
190
190
|
|
191
|
-
if klass.is_a?(::Middleman::Extension)
|
192
|
-
::Middleman::Extension.activated_extension(klass)
|
193
|
-
end
|
191
|
+
::Middleman::Extension.activated_extension(klass) if klass.is_a?(::Middleman::Extension)
|
194
192
|
end
|
195
193
|
end
|
196
194
|
end
|
@@ -183,12 +183,33 @@ module Middleman
|
|
183
183
|
# @param [Hash] options
|
184
184
|
# @return [String]
|
185
185
|
def render(_, data, options={}, &block)
|
186
|
-
|
186
|
+
partial_name = data.to_s
|
187
|
+
found_partial = locate_partial(partial_name, false) || locate_partial(partial_name, true)
|
188
|
+
|
189
|
+
# Look in the partials_dir for the partial with the current engine
|
190
|
+
unless found_partial
|
191
|
+
partials_path = File.join(config[:partials_dir], partial_name)
|
192
|
+
found_partial = locate_partial(partials_path, false) || locate_partial(partials_path, true)
|
193
|
+
end
|
194
|
+
|
195
|
+
raise ::Middleman::CoreExtensions::Rendering::TemplateNotFound, "Could not locate partial: #{data}" unless found_partial
|
187
196
|
|
188
197
|
locals = options[:locals]
|
189
198
|
|
190
|
-
found_partial
|
191
|
-
|
199
|
+
if ::Tilt[found_partial]
|
200
|
+
# Render the partial if found, otherwide throw exception
|
201
|
+
render_individual_file(found_partial, locals, options, self, &block)
|
202
|
+
else
|
203
|
+
File.read(found_partial)
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
# Partial locator.
|
208
|
+
#
|
209
|
+
# @param [String] partial_name
|
210
|
+
# @return [String]
|
211
|
+
def locate_partial(partial_name, try_static=true)
|
212
|
+
resolve_opts = { try_without_underscore: true, try_static: try_static }
|
192
213
|
|
193
214
|
# If the path is known to the sitemap
|
194
215
|
if resource = sitemap.find_resource_by_path(current_path)
|
@@ -196,21 +217,12 @@ module Middleman
|
|
196
217
|
resolve_opts[:preferred_engine] = File.extname(resource.source_file)[1..-1].to_sym
|
197
218
|
|
198
219
|
# Look for partials relative to the current path
|
199
|
-
relative_dir = File.join(current_dir.sub(%r{^#{Regexp.escape(source_dir)}/?}, ''),
|
200
|
-
|
201
|
-
found_partial = resolve_template(relative_dir, resolve_opts)
|
202
|
-
end
|
220
|
+
relative_dir = File.join(current_dir.sub(%r{^#{Regexp.escape(source_dir)}/?}, ''), partial_name)
|
203
221
|
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
found_partial = resolve_template(partials_path, resolve_opts)
|
222
|
+
resolve_template(relative_dir, resolve_opts) || resolve_template(partial_name, resolve_opts)
|
223
|
+
else
|
224
|
+
resolve_template(partial_name, resolve_opts)
|
208
225
|
end
|
209
|
-
|
210
|
-
raise ::Middleman::CoreExtensions::Rendering::TemplateNotFound, "Could not locate partial: #{data}" unless found_partial
|
211
|
-
|
212
|
-
# Render the partial if found, otherwide throw exception
|
213
|
-
render_individual_file(found_partial, locals, options, self, &block)
|
214
226
|
end
|
215
227
|
|
216
228
|
# Render an on-disk file. Used for everything, including layouts.
|
@@ -253,7 +265,7 @@ module Middleman
|
|
253
265
|
# Overwrite with frontmatter options
|
254
266
|
options = options.deep_merge(options[:renderer_options]) if options[:renderer_options]
|
255
267
|
|
256
|
-
template_class = Tilt[path]
|
268
|
+
template_class = ::Tilt[path]
|
257
269
|
# Allow hooks to manipulate the template before render
|
258
270
|
self.class.callbacks_for_hook(:before_render).each do |callback|
|
259
271
|
# Uber::Options::Value doesn't respond to call
|
@@ -428,6 +440,7 @@ module Middleman
|
|
428
440
|
# @param [String] request_path
|
429
441
|
# @option options [Boolean] :preferred_engine If set, try this engine first, then fall back to any engine.
|
430
442
|
# @option options [Boolean] :try_without_underscore
|
443
|
+
# @option options [Boolean] :try_static
|
431
444
|
# @return [Array<String, Symbol>, Boolean]
|
432
445
|
def resolve_template(request_path, options={})
|
433
446
|
# Find the path by searching or using the cache
|
@@ -436,26 +449,33 @@ module Middleman
|
|
436
449
|
relative_path = Util.strip_leading_slash(request_path)
|
437
450
|
on_disk_path = File.expand_path(relative_path, source_dir)
|
438
451
|
|
439
|
-
|
440
|
-
|
452
|
+
preferred_engines = if options[:try_static]
|
453
|
+
[nil]
|
454
|
+
else
|
455
|
+
possible_engines = ['*'] # By default, any engine will do
|
441
456
|
|
442
|
-
|
443
|
-
|
444
|
-
|
457
|
+
# If we're specifically looking for a preferred engine
|
458
|
+
if options.key?(:preferred_engine)
|
459
|
+
extension_class = ::Tilt[options[:preferred_engine]]
|
445
460
|
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
461
|
+
# Get a list of extensions for a preferred engine
|
462
|
+
matched_exts = ::Tilt.mappings.select do |_, engines|
|
463
|
+
engines.include? extension_class
|
464
|
+
end.keys
|
450
465
|
|
451
|
-
|
452
|
-
|
453
|
-
|
466
|
+
# Prefer to look for the matched extensions
|
467
|
+
unless matched_exts.empty?
|
468
|
+
possible_engines.unshift('{' + matched_exts.join(',') + '}')
|
469
|
+
end
|
454
470
|
end
|
471
|
+
|
472
|
+
possible_engines
|
455
473
|
end
|
456
474
|
|
457
475
|
search_paths = preferred_engines.flat_map do |preferred_engine|
|
458
|
-
path_with_ext = on_disk_path
|
476
|
+
path_with_ext = on_disk_path.dup
|
477
|
+
path_with_ext << ('.' + preferred_engine) unless preferred_engine.nil?
|
478
|
+
|
459
479
|
paths = [path_with_ext]
|
460
480
|
if options[:try_without_underscore]
|
461
481
|
paths << path_with_ext.sub(relative_path, relative_path.sub(/^_/, '').sub(/\/_/, '/'))
|
@@ -468,10 +488,15 @@ module Middleman
|
|
468
488
|
found_path = Dir[path_with_ext].find do |path|
|
469
489
|
::Tilt[path]
|
470
490
|
end
|
491
|
+
|
492
|
+
unless found_path
|
493
|
+
found_path = path_with_ext if File.exist?(path_with_ext)
|
494
|
+
end
|
495
|
+
|
471
496
|
break if found_path
|
472
497
|
end
|
473
498
|
|
474
|
-
# If we found one, return it
|
499
|
+
# If we found one, return it
|
475
500
|
if found_path
|
476
501
|
found_path
|
477
502
|
elsif File.exist?(on_disk_path)
|
@@ -281,7 +281,7 @@ module Middleman
|
|
281
281
|
# Halt request and return 404
|
282
282
|
def not_found(res, path)
|
283
283
|
res.status = 404
|
284
|
-
res.write "<html><body><h1>File Not Found</h1><p>#{path}</p></body>"
|
284
|
+
res.write "<html><head></head><body><h1>File Not Found</h1><p>#{path}</p></body></html>"
|
285
285
|
res.finish
|
286
286
|
end
|
287
287
|
|
@@ -2,15 +2,15 @@
|
|
2
2
|
module Middleman
|
3
3
|
module CoreExtensions
|
4
4
|
module Routing
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
5
|
+
# Takes a block which allows many pages to have the same layout
|
6
|
+
#
|
7
|
+
# with_layout :admin do
|
8
|
+
# page "/admin/"
|
9
|
+
# page "/admin/login.html"
|
10
|
+
# end
|
11
|
+
#
|
12
|
+
# @param [String, Symbol] layout_name
|
13
|
+
# @return [void]
|
14
14
|
def with_layout(layout_name, &block)
|
15
15
|
old_layout = config[:layout]
|
16
16
|
|
@@ -20,14 +20,14 @@ module Middleman
|
|
20
20
|
config[:layout] = old_layout
|
21
21
|
end
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
23
|
+
# The page method allows the layout to be set on a specific path
|
24
|
+
#
|
25
|
+
# page "/about.html", :layout => false
|
26
|
+
# page "/", :layout => :homepage_layout
|
27
|
+
#
|
28
|
+
# @param [String] url
|
29
|
+
# @param [Hash] opts
|
30
|
+
# @return [void]
|
31
31
|
def page(url, opts={}, &block)
|
32
32
|
blocks = Array(block)
|
33
33
|
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'active_support/core_ext/module/delegation'
|
2
2
|
require 'active_support/core_ext/class/attribute'
|
3
|
+
require 'middleman-core/configuration'
|
3
4
|
|
4
5
|
module Middleman
|
5
6
|
class Extension
|
@@ -117,10 +118,10 @@ module Middleman
|
|
117
118
|
|
118
119
|
def bind_before_configuration
|
119
120
|
ext = self
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
121
|
+
return unless ext.respond_to?(:before_configuration)
|
122
|
+
|
123
|
+
@klass.before_configuration do
|
124
|
+
ext.before_configuration
|
124
125
|
end
|
125
126
|
end
|
126
127
|
|
@@ -138,26 +139,26 @@ module Middleman
|
|
138
139
|
|
139
140
|
def bind_before_build
|
140
141
|
ext = self
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
142
|
+
return unless ext.respond_to?(:before_build)
|
143
|
+
|
144
|
+
@klass.before_build do |builder|
|
145
|
+
if ext.method(:before_build).arity == 1
|
146
|
+
ext.before_build(builder)
|
147
|
+
else
|
148
|
+
ext.before_build
|
148
149
|
end
|
149
150
|
end
|
150
151
|
end
|
151
152
|
|
152
153
|
def bind_after_build
|
153
154
|
ext = self
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
155
|
+
return unless ext.respond_to?(:after_build)
|
156
|
+
|
157
|
+
@klass.after_build do |builder|
|
158
|
+
if ext.method(:after_build).arity == 1
|
159
|
+
ext.after_build(builder)
|
160
|
+
else
|
161
|
+
ext.after_build
|
161
162
|
end
|
162
163
|
end
|
163
164
|
end
|
@@ -23,26 +23,25 @@ module Middleman
|
|
23
23
|
logger.info "== Inspect your site configuration at http://#{host}:#{port}/__middleman/"
|
24
24
|
|
25
25
|
@initialized ||= false
|
26
|
-
|
27
|
-
|
26
|
+
return if @initialized
|
27
|
+
@initialized = true
|
28
28
|
|
29
|
-
|
29
|
+
register_signal_handlers
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
# Save the last-used @options so it may be re-used when
|
32
|
+
# reloading later on.
|
33
|
+
::Middleman::Profiling.report('server_start')
|
34
34
|
|
35
|
-
|
36
|
-
|
35
|
+
loop do
|
36
|
+
@webrick.start
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
end
|
38
|
+
# $mm_shutdown is set by the signal handler
|
39
|
+
if $mm_shutdown
|
40
|
+
shutdown
|
41
|
+
exit
|
42
|
+
elsif $mm_reload
|
43
|
+
$mm_reload = false
|
44
|
+
reload
|
46
45
|
end
|
47
46
|
end
|
48
47
|
end
|
@@ -107,25 +106,20 @@ module Middleman
|
|
107
106
|
opts[:instrumenting] || false
|
108
107
|
)
|
109
108
|
|
110
|
-
if opts[:environment]
|
111
|
-
config[:environment] = opts[:environment].to_sym
|
112
|
-
end
|
109
|
+
config[:environment] = opts[:environment].to_sym if opts[:environment]
|
113
110
|
end
|
114
111
|
end
|
115
112
|
|
116
113
|
def start_file_watcher
|
117
|
-
return if @options[:disable_watcher]
|
114
|
+
return if @listener || @options[:disable_watcher]
|
118
115
|
|
119
|
-
|
116
|
+
# Watcher Library
|
117
|
+
require 'listen'
|
120
118
|
|
121
|
-
|
122
|
-
|
123
|
-
require 'listen'
|
124
|
-
@listener = Listen.to(Dir.pwd, relative_paths: true, force_polling: @options[:force_polling])
|
125
|
-
@listener.latency(@options[:latency])
|
126
|
-
end
|
119
|
+
options = { force_polling: @options[:force_polling] }
|
120
|
+
options[:latency] = @options[:latency] if @options[:latency]
|
127
121
|
|
128
|
-
@listener.
|
122
|
+
@listener = Listen.to(Dir.pwd, options) do |modified, added, removed|
|
129
123
|
added_and_modified = (modified + added)
|
130
124
|
|
131
125
|
# See if the changed file is config.rb or lib/*.rb
|
@@ -134,31 +128,33 @@ module Middleman
|
|
134
128
|
@webrick.stop
|
135
129
|
else
|
136
130
|
added_and_modified.each do |path|
|
137
|
-
|
138
|
-
app.files.
|
131
|
+
relative_path = Pathname(path).relative_path_from(Pathname(Dir.pwd)).to_s
|
132
|
+
next if app.files.ignored?(relative_path)
|
133
|
+
app.files.did_change(relative_path)
|
139
134
|
end
|
140
135
|
|
141
136
|
removed.each do |path|
|
142
|
-
|
143
|
-
app.files.
|
137
|
+
relative_path = Pathname(path).relative_path_from(Pathname(Dir.pwd)).to_s
|
138
|
+
next if app.files.ignored?(relative_path)
|
139
|
+
app.files.did_delete(relative_path)
|
144
140
|
end
|
145
141
|
end
|
146
142
|
end
|
147
143
|
|
148
144
|
# Don't block this thread
|
149
|
-
@listener.start
|
145
|
+
@listener.start
|
150
146
|
end
|
151
147
|
|
152
148
|
# Trap some interupt signals and shut down smoothly
|
153
149
|
# @return [void]
|
154
150
|
def register_signal_handlers
|
155
151
|
%w(INT HUP TERM QUIT).each do |sig|
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
152
|
+
next unless Signal.list[sig]
|
153
|
+
|
154
|
+
Signal.trap(sig) do
|
155
|
+
# Do as little work as possible in the signal context
|
156
|
+
$mm_shutdown = true
|
157
|
+
@webrick.stop
|
162
158
|
end
|
163
159
|
end
|
164
160
|
end
|
@@ -234,9 +230,7 @@ module Middleman
|
|
234
230
|
|
235
231
|
class FilteredWebrickLog < ::WEBrick::Log
|
236
232
|
def log(level, data)
|
237
|
-
unless data =~ %r{Could not determine content-length of response body.}
|
238
|
-
super(level, data)
|
239
|
-
end
|
233
|
+
super(level, data) unless data =~ %r{Could not determine content-length of response body.}
|
240
234
|
end
|
241
235
|
end
|
242
236
|
end
|