middleman-core 3.3.2 → 3.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/features/helpers_select_tag.feature +6 -8
  3. data/lib/middleman-core.rb +1 -2
  4. data/lib/middleman-core/application.rb +10 -9
  5. data/lib/middleman-core/cli.rb +9 -13
  6. data/lib/middleman-core/cli/build.rb +26 -27
  7. data/lib/middleman-core/cli/bundler.rb +6 -7
  8. data/lib/middleman-core/cli/console.rb +10 -13
  9. data/lib/middleman-core/cli/extension.rb +2 -4
  10. data/lib/middleman-core/cli/init.rb +27 -28
  11. data/lib/middleman-core/cli/server.rb +43 -44
  12. data/lib/middleman-core/configuration.rb +13 -11
  13. data/lib/middleman-core/core_extensions/data.rb +21 -29
  14. data/lib/middleman-core/core_extensions/extensions.rb +8 -8
  15. data/lib/middleman-core/core_extensions/external_helpers.rb +3 -5
  16. data/lib/middleman-core/core_extensions/file_watcher.rb +7 -11
  17. data/lib/middleman-core/core_extensions/front_matter.rb +5 -6
  18. data/lib/middleman-core/core_extensions/rendering.rb +40 -30
  19. data/lib/middleman-core/core_extensions/request.rb +16 -19
  20. data/lib/middleman-core/core_extensions/routing.rb +37 -36
  21. data/lib/middleman-core/core_extensions/show_exceptions.rb +1 -5
  22. data/lib/middleman-core/extension.rb +14 -16
  23. data/lib/middleman-core/extensions.rb +4 -6
  24. data/lib/middleman-core/load_paths.rb +3 -6
  25. data/lib/middleman-core/logger.rb +1 -3
  26. data/lib/middleman-core/meta_pages.rb +11 -11
  27. data/lib/middleman-core/meta_pages/config_setting.rb +4 -4
  28. data/lib/middleman-core/meta_pages/sitemap_resource.rb +2 -2
  29. data/lib/middleman-core/meta_pages/sitemap_tree.rb +4 -4
  30. data/lib/middleman-core/preview_server.rb +12 -11
  31. data/lib/middleman-core/profiling.rb +6 -8
  32. data/lib/middleman-core/renderers/asciidoc.rb +12 -13
  33. data/lib/middleman-core/renderers/coffee_script.rb +2 -4
  34. data/lib/middleman-core/renderers/erb.rb +3 -4
  35. data/lib/middleman-core/renderers/haml.rb +2 -4
  36. data/lib/middleman-core/renderers/kramdown.rb +3 -4
  37. data/lib/middleman-core/renderers/less.rb +3 -9
  38. data/lib/middleman-core/renderers/liquid.rb +4 -8
  39. data/lib/middleman-core/renderers/markdown.rb +7 -11
  40. data/lib/middleman-core/renderers/redcarpet.rb +14 -16
  41. data/lib/middleman-core/renderers/sass.rb +36 -15
  42. data/lib/middleman-core/renderers/slim.rb +7 -10
  43. data/lib/middleman-core/renderers/stylus.rb +2 -6
  44. data/lib/middleman-core/sitemap.rb +6 -13
  45. data/lib/middleman-core/sitemap/extensions/ignores.rb +4 -10
  46. data/lib/middleman-core/sitemap/extensions/on_disk.rb +3 -7
  47. data/lib/middleman-core/sitemap/extensions/proxies.rb +7 -12
  48. data/lib/middleman-core/sitemap/extensions/redirects.rb +7 -15
  49. data/lib/middleman-core/sitemap/extensions/request_endpoints.rb +7 -15
  50. data/lib/middleman-core/sitemap/extensions/traversal.rb +4 -7
  51. data/lib/middleman-core/sitemap/queryable.rb +22 -27
  52. data/lib/middleman-core/sitemap/resource.rb +13 -25
  53. data/lib/middleman-core/sitemap/store.rb +11 -15
  54. data/lib/middleman-core/templates.rb +9 -12
  55. data/lib/middleman-core/templates/default.rb +6 -7
  56. data/lib/middleman-core/templates/empty.rb +0 -1
  57. data/lib/middleman-core/templates/extension/Gemfile +1 -1
  58. data/lib/middleman-core/templates/extension/Rakefile +2 -2
  59. data/lib/middleman-core/templates/extension/lib/lib.rb +0 -1
  60. data/lib/middleman-core/templates/html5.rb +6 -7
  61. data/lib/middleman-core/templates/local.rb +1 -2
  62. data/lib/middleman-core/templates/mobile.rb +3 -4
  63. data/lib/middleman-core/templates/shared/config.ru +1 -1
  64. data/lib/middleman-core/util.rb +5 -6
  65. data/lib/middleman-core/version.rb +1 -1
  66. data/lib/middleman-more/core_extensions/compass.rb +0 -1
  67. data/lib/middleman-more/core_extensions/default_helpers.rb +25 -16
  68. data/lib/middleman-more/core_extensions/i18n.rb +24 -23
  69. data/lib/middleman-more/extensions/asset_hash.rb +4 -6
  70. data/lib/middleman-more/extensions/asset_host.rb +1 -1
  71. data/lib/middleman-more/extensions/automatic_alt_tags.rb +2 -3
  72. data/lib/middleman-more/extensions/automatic_image_sizes.rb +4 -5
  73. data/lib/middleman-more/extensions/cache_buster.rb +0 -1
  74. data/lib/middleman-more/extensions/gzip.rb +1 -1
  75. data/lib/middleman-more/extensions/lorem.rb +8 -8
  76. data/lib/middleman-more/extensions/minify_css.rb +9 -8
  77. data/lib/middleman-more/extensions/minify_javascript.rb +5 -6
  78. data/lib/middleman-more/extensions/relative_assets.rb +0 -1
  79. data/lib/middleman-more/templates/smacss.rb +6 -7
  80. data/middleman-core.gemspec +1 -1
  81. metadata +5 -5
@@ -9,10 +9,8 @@ require 'active_support/json'
9
9
 
10
10
  # Extensions namespace
11
11
  module Middleman::CoreExtensions
12
-
13
12
  class FrontMatter < ::Middleman::Extension
14
-
15
- YAML_ERRORS = [ StandardError ]
13
+ YAML_ERRORS = [StandardError]
16
14
 
17
15
  # https://github.com/tenderlove/psych/issues/23
18
16
  if defined?(Psych) && defined?(Psych::SyntaxError)
@@ -45,7 +43,7 @@ module Middleman::CoreExtensions
45
43
  data[opt] = fmdata[opt] unless fmdata[opt].nil?
46
44
  end
47
45
 
48
- { :options => data, :page => ::Middleman::Util.recursively_enhance(fmdata).freeze }
46
+ { options: data, page: ::Middleman::Util.recursively_enhance(fmdata).freeze }
49
47
  end
50
48
  end
51
49
 
@@ -115,7 +113,8 @@ module Middleman::CoreExtensions
115
113
  @cache.delete(path)
116
114
  end
117
115
 
118
- private
116
+ private
117
+
119
118
  # Parse YAML frontmatter out of a string
120
119
  # @param [String] content
121
120
  # @return [Array<Hash, String>]
@@ -147,7 +146,7 @@ module Middleman::CoreExtensions
147
146
  content = content.sub(json_regex, '')
148
147
 
149
148
  begin
150
- json = ($1+$2).sub(';;;', '{').sub(';;;', '}')
149
+ json = ($1 + $2).sub(';;;', '{').sub(';;;', '}')
151
150
  data = ActiveSupport::JSON.decode(json).symbolize_keys
152
151
  rescue => e
153
152
  app.logger.error "JSON Exception parsing #{full_path}: #{e.message}"
@@ -1,19 +1,17 @@
1
1
  # Shutup Tilt Warnings
2
2
  # @private
3
3
  class Tilt::Template
4
- def warn(*args)
5
- # Kernel.warn(*args)
4
+ def warn(*)
6
5
  end
7
6
  end
8
7
 
9
8
  # Rendering extension
9
+ # rubocop:disable UnderscorePrefixedVariableName
10
10
  module Middleman
11
11
  module CoreExtensions
12
12
  module Rendering
13
-
14
13
  # Setup extension
15
14
  class << self
16
-
17
15
  # Once registered
18
16
  def registered(app)
19
17
  # Include methods
@@ -93,7 +91,7 @@ module Middleman
93
91
 
94
92
  # Clean up missing Tilt exts
95
93
  app.after_configuration do
96
- Tilt.mappings.each do |key, klasses|
94
+ Tilt.mappings.each do |key, _|
97
95
  begin
98
96
  Tilt[".#{key}"]
99
97
  rescue LoadError, NameError
@@ -103,7 +101,7 @@ module Middleman
103
101
  end
104
102
  end
105
103
 
106
- alias :included :registered
104
+ alias_method :included, :registered
107
105
  end
108
106
 
109
107
  # Custom error class for handling
@@ -112,7 +110,6 @@ module Middleman
112
110
 
113
111
  # Rendering instance methods
114
112
  module InstanceMethods
115
-
116
113
  # Add or overwrite a default template extension
117
114
  #
118
115
  # @param [Hash] extension_map
@@ -140,13 +137,14 @@ module Middleman
140
137
 
141
138
  # Use a dup of self as a context so that instance variables set within
142
139
  # the template don't persist for other templates.
143
- context = self.dup
140
+ context = dup
144
141
  blocks.each do |block|
145
142
  context.instance_eval(&block)
146
143
  end
147
144
 
148
145
  # Store current locs/opts for later
149
- @current_locs = locs, @current_opts = opts
146
+ @current_locs = locs
147
+ @current_opts = opts
150
148
 
151
149
  # Keep rendering template until we've used up all extensions. This
152
150
  # handles cases like `style.css.sass.erb`
@@ -184,7 +182,7 @@ module Middleman
184
182
  # @param [String, Symbol] data
185
183
  # @param [Hash] options
186
184
  # @return [String]
187
- def render(engine, data, options={}, &block)
185
+ def render(_, data, options={}, &block)
188
186
  data = data.to_s
189
187
 
190
188
  locals = options[:locals]
@@ -198,13 +196,13 @@ module Middleman
198
196
  resolve_opts[:preferred_engine] = File.extname(resource.source_file)[1..-1].to_sym
199
197
 
200
198
  # Look for partials relative to the current path
201
- relative_dir = File.join(current_dir.sub(%r{^#{Regexp.escape(self.source_dir)}/?}, ''), data)
199
+ relative_dir = File.join(current_dir.sub(%r{^#{Regexp.escape(source_dir)}/?}, ''), data)
202
200
 
203
201
  found_partial = resolve_template(relative_dir, resolve_opts)
204
202
  end
205
203
 
206
204
  # Look in the partials_dir for the partial with the current engine
207
- if !found_partial
205
+ unless found_partial
208
206
  partials_path = File.join(config[:partials_dir], data)
209
207
  found_partial = resolve_template(partials_path, resolve_opts)
210
208
  end
@@ -222,9 +220,13 @@ module Middleman
222
220
  # @param [Hash] opts
223
221
  # @param [Class] context
224
222
  # @return [String]
225
- def render_individual_file(path, locs = {}, opts = {}, context = self, &block)
223
+ def render_individual_file(path, locs={}, opts={}, context=self, &block)
226
224
  path = path.to_s
227
225
 
226
+ # Mutability is FUN!
227
+ # Try to work around: https://github.com/middleman/middleman/issues/501
228
+ locs = locs.dup
229
+
228
230
  # Detect the remdering engine from the extension
229
231
  extension = File.extname(path)
230
232
  engine = extension[1..-1].to_sym
@@ -254,13 +256,18 @@ module Middleman
254
256
  template_class = Tilt[path]
255
257
  # Allow hooks to manipulate the template before render
256
258
  self.class.callbacks_for_hook(:before_render).each do |callback|
257
- newbody = callback.call(body, path, locs, template_class)
259
+ # Uber::Options::Value doesn't respond to call
260
+ newbody = if callback.respond_to?(:call)
261
+ callback.call(body, path, locs, template_class)
262
+ elsif callback.respond_to?(:evaluate)
263
+ callback.evaluate(self, body, path, locs, template_class)
264
+ end
258
265
  body = newbody if newbody # Allow the callback to return nil to skip it
259
266
  end
260
267
 
261
268
  # Read compiled template from disk or cache
262
269
  template = cache.fetch(:compiled_template, extension, options, body) do
263
- ::Tilt.new(path, 1, options) { body }
270
+ ::Tilt.new(path, 1, options) { body }
264
271
  end
265
272
 
266
273
  # Render using Tilt
@@ -268,7 +275,13 @@ module Middleman
268
275
 
269
276
  # Allow hooks to manipulate the result after render
270
277
  self.class.callbacks_for_hook(:after_render).each do |callback|
271
- content = callback.call(content, path, locs, template_class)
278
+ # Uber::Options::Value doesn't respond to call
279
+ newcontent = if callback.respond_to?(:call)
280
+ content = callback.call(content, path, locs, template_class)
281
+ elsif callback.respond_to?(:evaluate)
282
+ content = callback.evaluate(self, content, path, locs, template_class)
283
+ end
284
+ content = newcontent if newcontent # Allow the callback to return nil to skip it
272
285
  end
273
286
 
274
287
  output = ::ActiveSupport::SafeBuffer.new ''
@@ -317,7 +330,7 @@ module Middleman
317
330
  # @return [String]
318
331
  def fetch_layout(engine, opts)
319
332
  # The layout name comes from either the system default or the options
320
- local_layout = opts.has_key?(:layout) ? opts[:layout] : config[:layout]
333
+ local_layout = opts.key?(:layout) ? opts[:layout] : config[:layout]
321
334
  return false unless local_layout
322
335
 
323
336
  # Look for engine-specific options
@@ -325,9 +338,9 @@ module Middleman
325
338
 
326
339
  # The engine for the layout can be set in options, engine_options or passed
327
340
  # into this method
328
- layout_engine = if opts.has_key?(:layout_engine)
341
+ layout_engine = if opts.key?(:layout_engine)
329
342
  opts[:layout_engine]
330
- elsif engine_options.has_key?(:layout_engine)
343
+ elsif engine_options.key?(:layout_engine)
331
344
  engine_options[:layout_engine]
332
345
  else
333
346
  engine
@@ -354,11 +367,8 @@ module Middleman
354
367
  # @param [Symbol] preferred_engine
355
368
  # @return [String]
356
369
  def locate_layout(name, preferred_engine=nil)
357
- # Whether we've found the layout
358
- layout_path = false
359
-
360
370
  resolve_opts = {}
361
- resolve_opts[:preferred_engine] = preferred_engine if !preferred_engine.nil?
371
+ resolve_opts[:preferred_engine] = preferred_engine unless preferred_engine.nil?
362
372
 
363
373
  # Check layouts folder
364
374
  layout_path = resolve_template(File.join(config[:layouts_dir], name.to_s), resolve_opts)
@@ -377,13 +387,13 @@ module Middleman
377
387
  # Save current buffer for later
378
388
  @_out_buf, _buf_was = '', @_out_buf
379
389
 
380
- layout_path = locate_layout(layout_name, self.current_engine)
390
+ layout_path = locate_layout(layout_name, current_engine)
381
391
 
382
392
  extension = File.extname(layout_path)
383
393
  engine = extension[1..-1].to_sym
384
394
 
385
395
  # Store last engine for later (could be inside nested renders)
386
- self.current_engine, engine_was = engine, self.current_engine
396
+ self.current_engine, engine_was = engine, current_engine
387
397
 
388
398
  begin
389
399
  content = if block_given?
@@ -408,6 +418,7 @@ module Middleman
408
418
  end
409
419
 
410
420
  # The currently rendering engine
421
+ # rubocop:disable TrivialAccessors
411
422
  # @return [Symbol, nil]
412
423
  def current_engine=(v)
413
424
  @_current_engine = v
@@ -423,18 +434,17 @@ module Middleman
423
434
  request_path = request_path.to_s
424
435
  cache.fetch(:resolve_template, request_path, options) do
425
436
  relative_path = Util.strip_leading_slash(request_path)
426
- on_disk_path = File.expand_path(relative_path, self.source_dir)
437
+ on_disk_path = File.expand_path(relative_path, source_dir)
427
438
 
428
439
  # By default, any engine will do
429
440
  preferred_engines = ['*']
430
441
 
431
442
  # If we're specifically looking for a preferred engine
432
- if options.has_key?(:preferred_engine)
443
+ if options.key?(:preferred_engine)
433
444
  extension_class = ::Tilt[options[:preferred_engine]]
434
- matched_exts = []
435
445
 
436
446
  # Get a list of extensions for a preferred engine
437
- matched_exts = ::Tilt.mappings.select do |ext, engines|
447
+ matched_exts = ::Tilt.mappings.select do |_, engines|
438
448
  engines.include? extension_class
439
449
  end.keys
440
450
 
@@ -464,7 +474,7 @@ module Middleman
464
474
  # If we found one, return it and the found engine
465
475
  if found_path
466
476
  found_path
467
- elsif File.exists?(on_disk_path)
477
+ elsif File.exist?(on_disk_path)
468
478
  on_disk_path
469
479
  else
470
480
  false
@@ -8,15 +8,12 @@ require 'middleman-core/util'
8
8
 
9
9
  module Middleman
10
10
  module CoreExtensions
11
-
12
11
  # Base helper to manipulate asset paths
13
12
  module Request
14
-
15
13
  # Extension registered
16
14
  class << self
17
15
  # @private
18
16
  def registered(app)
19
-
20
17
  # CSSPIE HTC File
21
18
  ::Rack::Mime::MIME_TYPES['.htc'] = 'text/x-component'
22
19
 
@@ -32,7 +29,7 @@ module Middleman
32
29
  # Include instance methods
33
30
  app.send :include, InstanceMethods
34
31
  end
35
- alias :included :registered
32
+ alias_method :included, :registered
36
33
  end
37
34
 
38
35
  module ClassMethods
@@ -60,9 +57,7 @@ module Middleman
60
57
  # @private
61
58
  # @param [Middleman::Application] inst
62
59
  # @return [void]
63
- def inst=(inst)
64
- @inst = inst
65
- end
60
+ attr_writer :inst
66
61
 
67
62
  # Return built Rack app
68
63
  #
@@ -74,15 +69,15 @@ module Middleman
74
69
  app.use Rack::Lint
75
70
  app.use Rack::Head
76
71
 
77
- Array(@middleware).each do |klass, options, block|
78
- app.use(klass, *options, &block)
72
+ Array(@middleware).each do |klass, options, middleware_block|
73
+ app.use(klass, *options, &middleware_block)
79
74
  end
80
75
 
81
76
  inner_app = inst(&block)
82
77
  app.map('/') { run inner_app }
83
78
 
84
- Array(@mappings).each do |path, block|
85
- app.map(path, &block)
79
+ Array(@mappings).each do |path, map_block|
80
+ app.map(path, &map_block)
86
81
  end
87
82
 
88
83
  app
@@ -130,6 +125,7 @@ module Middleman
130
125
  # configuration can be included later without impacting
131
126
  # other classes and instances.
132
127
  #
128
+ # rubocop:disable ClassVars
133
129
  # @return [Class]
134
130
  def server(&block)
135
131
  @@servercounter ||= 0
@@ -169,20 +165,21 @@ module Middleman
169
165
  # @return [void]
170
166
  def current_path=(path)
171
167
  Thread.current[:current_path] = path
172
- Thread.current[:legacy_request] = ::Thor::CoreExt::HashWithIndifferentAccess.new({
173
- :path => path,
174
- :params => req ? ::Thor::CoreExt::HashWithIndifferentAccess.new(req.params) : {}
175
- })
168
+ Thread.current[:legacy_request] = ::Thor::CoreExt::HashWithIndifferentAccess.new(
169
+ path: path,
170
+ params: req ? ::Thor::CoreExt::HashWithIndifferentAccess.new(req.params) : {}
171
+ )
176
172
  end
177
173
 
178
- delegate :use, :to => :"self.class"
179
- delegate :map, :to => :"self.class"
174
+ delegate :use, to: :"self.class"
175
+ delegate :map, to: :"self.class"
180
176
 
181
177
  # Rack request
182
178
  # @return [Rack::Request]
183
179
  def req
184
180
  Thread.current[:req]
185
181
  end
182
+
186
183
  def req=(value)
187
184
  Thread.current[:req] = value
188
185
  end
@@ -199,7 +196,7 @@ module Middleman
199
196
  self.req = req = ::Rack::Request.new(env)
200
197
  res = ::Rack::Response.new
201
198
 
202
- logger.debug "== Request: #{env["PATH_INFO"]}"
199
+ logger.debug "== Request: #{env['PATH_INFO']}"
203
200
 
204
201
  # Catch :halt exceptions and use that response if given
205
202
  catch(:halt) do
@@ -277,7 +274,7 @@ module Middleman
277
274
  # @param [String] value Mime type
278
275
  # @return [void]
279
276
  def mime_type(type, value)
280
- type = ".#{type}" unless type.to_s[0] == ?.
277
+ type = ".#{type}" unless type.to_s[0] == '.'
281
278
  ::Rack::Mime::MIME_TYPES[type] = value
282
279
  end
283
280
 
@@ -11,14 +11,14 @@ module Middleman
11
11
  #
12
12
  # @param [String, Symbol] layout_name
13
13
  # @return [void]
14
- def with_layout(layout_name, &block)
15
- old_layout = config[:layout]
14
+ def with_layout(layout_name, &block)
15
+ old_layout = config[:layout]
16
16
 
17
- config[:layout] = layout_name
18
- instance_exec(&block) if block_given?
19
- ensure
20
- config[:layout] = old_layout
21
- end
17
+ config[:layout] = layout_name
18
+ instance_exec(&block) if block_given?
19
+ ensure
20
+ config[:layout] = old_layout
21
+ end
22
22
 
23
23
  # The page method allows the layout to be set on a specific path
24
24
  #
@@ -28,43 +28,44 @@ module Middleman
28
28
  # @param [String] url
29
29
  # @param [Hash] opts
30
30
  # @return [void]
31
- def page(url, opts={}, &block)
32
- blocks = Array(block)
33
-
34
- # Default layout
35
- opts[:layout] = config[:layout] if opts[:layout].nil?
31
+ def page(url, opts={}, &block)
32
+ blocks = Array(block)
36
33
 
37
- # If the url is a regexp
38
- if url.is_a?(Regexp) || url.include?('*')
34
+ # Default layout
35
+ opts[:layout] = config[:layout] if opts[:layout].nil?
39
36
 
40
- # Use the metadata loop for matching against paths at runtime
41
- sitemap.provides_metadata_for_path(url) do |_|
42
- { :options => opts, :blocks => blocks }
43
- end
37
+ # If the url is a regexp
38
+ if url.is_a?(Regexp) || url.include?('*')
44
39
 
45
- return
40
+ # Use the metadata loop for matching against paths at runtime
41
+ sitemap.provides_metadata_for_path(url) do |_|
42
+ { options: opts, blocks: blocks }
46
43
  end
47
44
 
48
- # Normalized path
49
- url = '/' + Middleman::Util.normalize_path(url)
50
- if url.end_with?('/') || File.directory?(File.join(source_dir, url))
51
- url = File.join(url, config[:index_file])
52
- end
45
+ return
46
+ end
53
47
 
54
- # Setup proxy
55
- if target = opts.delete(:proxy)
56
- # TODO: deprecate proxy through page?
57
- proxy(url, target, opts, &block) and return
58
- elsif opts.delete(:ignore)
59
- # TODO: deprecate ignore through page?
60
- ignore(url)
61
- end
48
+ # Normalized path
49
+ url = '/' + Middleman::Util.normalize_path(url)
50
+ if url.end_with?('/') || File.directory?(File.join(source_dir, url))
51
+ url = File.join(url, config[:index_file])
52
+ end
62
53
 
63
- # Setup a metadata matcher for rendering those options
64
- sitemap.provides_metadata_for_path(url) do |_|
65
- { :options => opts, :blocks => blocks }
66
- end
54
+ # Setup proxy
55
+ if target = opts.delete(:proxy)
56
+ # TODO: deprecate proxy through page?
57
+ proxy(url, target, opts, &block)
58
+ return
59
+ elsif opts.delete(:ignore)
60
+ # TODO: deprecate ignore through page?
61
+ ignore(url)
62
+ end
63
+
64
+ # Setup a metadata matcher for rendering those options
65
+ sitemap.provides_metadata_for_path(url) do |_|
66
+ { options: opts, blocks: blocks }
67
67
  end
68
+ end
68
69
  end
69
70
  end
70
71
  end