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.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/features/automatic_alt_tags.feature +8 -0
  3. data/features/gzip.feature +36 -6
  4. data/features/helpers_auto_javascript_include_tag.feature +5 -0
  5. data/features/i18n_partials.feature +23 -0
  6. data/features/more-implied_extensions.feature +1 -7
  7. data/features/more-sitemap_traversal.feature +10 -0
  8. data/features/partials.feature +11 -0
  9. data/features/sitemap_traversal.feature +10 -0
  10. data/features/twitter-bootstrap-compile.feature +4 -4
  11. data/fixtures/auto-js-directory-index-app/config.rb +1 -0
  12. data/fixtures/auto-js-directory-index-app/source/auto-js.html.erb +1 -0
  13. data/fixtures/auto-js-directory-index-app/source/javascripts/auto-js.js +1 -0
  14. data/fixtures/automatic-alt-tags-app/config.rb +0 -0
  15. data/fixtures/automatic-alt-tags-app/source/auto-image-sizes.html.erb +1 -0
  16. data/fixtures/automatic-alt-tags-app/source/images/blank.gif +0 -0
  17. data/fixtures/i18n-test-app/source/_country.en.erb +1 -0
  18. data/fixtures/i18n-test-app/source/_country.es.erb +1 -0
  19. data/fixtures/i18n-test-app/source/_site.erb +1 -0
  20. data/fixtures/i18n-test-app/source/images/president.en.svg +1 -0
  21. data/fixtures/i18n-test-app/source/images/president.es.svg +1 -0
  22. data/fixtures/i18n-test-app/source/localizable/_state.en.erb +1 -0
  23. data/fixtures/i18n-test-app/source/localizable/_state.es.erb +1 -0
  24. data/fixtures/i18n-test-app/source/localizable/images/flag.en.svg +1 -0
  25. data/fixtures/i18n-test-app/source/localizable/images/flag.es.svg +1 -0
  26. data/fixtures/i18n-test-app/source/localizable/partials/_greeting.en.erb +1 -0
  27. data/fixtures/i18n-test-app/source/localizable/partials/_greeting.es.erb +1 -0
  28. data/fixtures/i18n-test-app/source/localizable/partials/index.html.erb +6 -0
  29. data/fixtures/partials-app/source/_code_snippet.html +1 -0
  30. data/fixtures/partials-app/source/images/tiger.svg +725 -0
  31. data/fixtures/partials-app/source/static_underscore.html.erb +1 -0
  32. data/fixtures/partials-app/source/svg.html.erb +1 -0
  33. data/lib/middleman-core.rb +2 -1
  34. data/lib/middleman-core/cli/build.rb +12 -14
  35. data/lib/middleman-core/cli/bundler.rb +2 -2
  36. data/lib/middleman-core/cli/init.rb +3 -3
  37. data/lib/middleman-core/core_extensions/extensions.rb +1 -3
  38. data/lib/middleman-core/core_extensions/rendering.rb +56 -31
  39. data/lib/middleman-core/core_extensions/request.rb +1 -1
  40. data/lib/middleman-core/core_extensions/routing.rb +17 -17
  41. data/lib/middleman-core/extension.rb +19 -18
  42. data/lib/middleman-core/preview_server.rb +36 -42
  43. data/lib/middleman-core/renderers/redcarpet.rb +4 -5
  44. data/lib/middleman-core/sitemap/extensions/on_disk.rb +10 -13
  45. data/lib/middleman-core/sitemap/extensions/traversal.rb +15 -7
  46. data/lib/middleman-core/sitemap/store.rb +1 -1
  47. data/lib/middleman-core/step_definitions.rb +12 -4
  48. data/lib/middleman-core/step_definitions/builder_steps.rb +4 -0
  49. data/lib/middleman-core/step_definitions/server_steps.rb +15 -7
  50. data/lib/middleman-core/version.rb +1 -1
  51. data/lib/middleman-more/core_extensions/default_helpers.rb +1 -1
  52. data/lib/middleman-more/core_extensions/i18n.rb +33 -7
  53. data/lib/middleman-more/extensions/asset_hash.rb +1 -1
  54. data/lib/middleman-more/extensions/automatic_alt_tags.rb +2 -6
  55. data/lib/middleman-more/extensions/gzip.rb +16 -6
  56. data/middleman-core.gemspec +1 -1
  57. data/spec/middleman-core/binary_spec.rb +2 -2
  58. metadata +60 -8
  59. 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" %>
@@ -1,5 +1,6 @@
1
- # Setup our load paths
2
1
  # rubocop:disable FileName
2
+
3
+ # Setup our load paths
3
4
  libdir = File.expand_path(File.dirname(__FILE__))
4
5
  $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
5
6
 
@@ -168,10 +168,10 @@ module Middleman::Cli
168
168
  path.to_s !~ /\/\./ || path.to_s =~ /\.(htaccess|htpasswd)/
169
169
  end
170
170
 
171
- if RUBY_PLATFORM =~ /darwin/
172
- # handle UTF-8-MAC filename on MacOS
173
- @to_clean = @to_clean.map { |path| path.to_s.encode('UTF-8', 'UTF-8-MAC') }
174
- end
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
- if should_clean? && output_path.exist?
224
- if RUBY_PLATFORM =~ /darwin/
225
- # handle UTF-8-MAC filename on MacOS
223
+ return unless should_clean? && output_path.exist?
226
224
 
227
- @to_clean.delete(output_path.realpath.to_s.encode('UTF-8', 'UTF-8-MAC'))
228
- else
229
- @to_clean.delete(output_path.realpath)
230
- end
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
- # :default => "stylesheets",
18
+ # :default => "stylesheets",
19
19
  desc: 'The path to the css files'
20
20
  method_option 'js_dir',
21
- # :default => "javascripts",
21
+ # :default => "javascripts",
22
22
  desc: 'The path to the javascript files'
23
23
  method_option 'images_dir',
24
- # :default => "images",
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
- data = data.to_s
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 = false
191
- resolve_opts = { try_without_underscore: true }
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)}/?}, ''), data)
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
- # Look in the partials_dir for the partial with the current engine
205
- unless found_partial
206
- partials_path = File.join(config[:partials_dir], data)
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
- # By default, any engine will do
440
- preferred_engines = ['*']
452
+ preferred_engines = if options[:try_static]
453
+ [nil]
454
+ else
455
+ possible_engines = ['*'] # By default, any engine will do
441
456
 
442
- # If we're specifically looking for a preferred engine
443
- if options.key?(:preferred_engine)
444
- extension_class = ::Tilt[options[:preferred_engine]]
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
- # Get a list of extensions for a preferred engine
447
- matched_exts = ::Tilt.mappings.select do |_, engines|
448
- engines.include? extension_class
449
- end.keys
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
- # Prefer to look for the matched extensions
452
- unless matched_exts.empty?
453
- preferred_engines.unshift('{' + matched_exts.join(',') + '}')
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 + '.' + preferred_engine
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 and the found engine
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
- # 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]
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
- # 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]
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
- if ext.respond_to?(:before_configuration)
121
- @klass.before_configuration do
122
- ext.before_configuration
123
- end
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
- if ext.respond_to?(:before_build)
142
- @klass.before_build do |builder|
143
- if ext.method(:before_build).arity == 1
144
- ext.before_build(builder)
145
- else
146
- ext.before_build
147
- end
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
- if ext.respond_to?(:after_build)
155
- @klass.after_build do |builder|
156
- if ext.method(:after_build).arity == 1
157
- ext.after_build(builder)
158
- else
159
- ext.after_build
160
- end
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
- unless @initialized
27
- @initialized = true
26
+ return if @initialized
27
+ @initialized = true
28
28
 
29
- register_signal_handlers
29
+ register_signal_handlers
30
30
 
31
- # Save the last-used @options so it may be re-used when
32
- # reloading later on.
33
- ::Middleman::Profiling.report('server_start')
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
- loop do
36
- @webrick.start
35
+ loop do
36
+ @webrick.start
37
37
 
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
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
- first_run = !@listener
116
+ # Watcher Library
117
+ require 'listen'
120
118
 
121
- if first_run
122
- # Watcher Library
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.change do |modified, added, removed|
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
- next if app.files.ignored?(path)
138
- app.files.did_change(path)
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
- next if app.files.ignored?(path)
143
- app.files.did_delete(path)
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 if first_run
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
- if Signal.list[sig]
157
- Signal.trap(sig) do
158
- # Do as little work as possible in the signal context
159
- $mm_shutdown = true
160
- @webrick.stop
161
- end
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