middleman-core 4.3.0.rc.1 → 4.3.0.rc.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (190) hide show
  1. checksums.yaml +5 -5
  2. data/Rakefile +0 -1
  3. data/cucumber.yml +2 -2
  4. data/features/asset_hash.feature +2 -2
  5. data/features/collections.feature +2 -2
  6. data/features/i18n_mixed_sources.feature +8 -0
  7. data/features/markdown.feature +0 -1
  8. data/features/multiple-sources-reload.feature +40 -0
  9. data/features/partials.feature +1 -1
  10. data/features/support/env.rb +4 -1
  11. data/features/tilde_directories.feature +0 -2
  12. data/features/unicode_filenames.feature +1 -1
  13. data/fixtures/asset-hash-app/config.rb +0 -1
  14. data/fixtures/asset-hash-app/lib/middleware.rb +2 -2
  15. data/fixtures/asset-hash-app/source/stylesheets/_partial.sass +1 -1
  16. data/fixtures/asset-hash-prefix/config.rb +1 -2
  17. data/fixtures/asset-hash-prefix/lib/middleware.rb +2 -2
  18. data/fixtures/asset-hash-source-map/config.rb +0 -1
  19. data/fixtures/asset-hash-source-map/lib/middleware.rb +2 -2
  20. data/fixtures/asset-host-app/config.rb +1 -1
  21. data/fixtures/auto-css-app/config.rb +2 -2
  22. data/fixtures/auto-js-app/config.rb +2 -2
  23. data/fixtures/auto-js-directory-index-app/config.rb +1 -1
  24. data/fixtures/automatic-directory-matcher-app/config.rb +1 -1
  25. data/fixtures/basic-data-app/config.rb +2 -2
  26. data/fixtures/capture-html-app/config.rb +4 -4
  27. data/fixtures/clean-app/config-complications.rb +6 -6
  28. data/fixtures/clean-app/config-hidden-dir-after.rb +4 -4
  29. data/fixtures/clean-app/config-hidden-dir-before.rb +1 -1
  30. data/fixtures/clean-app/config.rb +6 -6
  31. data/fixtures/clean-dir-app/config.rb +0 -1
  32. data/fixtures/clean-nested-app/config.rb +1 -1
  33. data/fixtures/collections-app/source/blog1/2011-01-01-new-article.html.markdown +1 -1
  34. data/fixtures/collections-app/source/blog1/2011-01-02-another-article.html.markdown +1 -1
  35. data/fixtures/collections-app/source/blog2/2011-01-01-new-article.html.markdown +1 -1
  36. data/fixtures/collections-app/source/blog2/2011-01-02-another-article.html.markdown +1 -1
  37. data/fixtures/content-for-app/config.rb +4 -4
  38. data/fixtures/destination-dir-different-from-source-dir-name/external/page.html.erb +1 -0
  39. data/fixtures/destination-dir-different-from-source-dir-name/my-app/config.rb +2 -0
  40. data/fixtures/destination-dir-different-from-source-dir-name/my-app/source/index.html.erb +1 -0
  41. data/fixtures/dynamic-pages-app/config.rb +25 -26
  42. data/fixtures/ember-cli-app/config.rb +4 -4
  43. data/fixtures/env-app/environments/development.rb +1 -1
  44. data/fixtures/env-app/environments/production.rb +1 -1
  45. data/fixtures/extension-hooks-app/config.rb +8 -8
  46. data/fixtures/external-helpers/config.rb +2 -2
  47. data/fixtures/external-helpers/helpers/derp.rb +3 -1
  48. data/fixtures/external-helpers/helpers/four_helpers.rb +3 -1
  49. data/fixtures/external-helpers/helpers/one_helper.rb +3 -1
  50. data/fixtures/external-helpers/helpers/yet_another_thingy.rb +3 -1
  51. data/fixtures/external-helpers/lib/hello_helper.rb +1 -1
  52. data/fixtures/external-pipeline-error/config.rb +4 -4
  53. data/fixtures/feature-params-app/config.rb +1 -1
  54. data/fixtures/frontmatter-app/config.rb +1 -1
  55. data/fixtures/glob-app/config.rb +1 -1
  56. data/fixtures/i-8859-1-app/config.rb +1 -1
  57. data/fixtures/i18n-force-locale/config.rb +4 -4
  58. data/fixtures/i18n-mixed-sources/config.rb +1 -1
  59. data/fixtures/i18n-mixed-sources/source/c/d/index.html.erb +9 -0
  60. data/fixtures/i18n-mixed-sources/source/localizable/c/d/index.html.erb +9 -0
  61. data/fixtures/import-app/config.rb +3 -3
  62. data/fixtures/indexable-app/config.rb +3 -3
  63. data/fixtures/large-build-app/config.rb +1 -1
  64. data/fixtures/manual-layout-override/config.rb +1 -1
  65. data/fixtures/missing-tilt-library-app/config.rb +2 -2
  66. data/fixtures/more-traversal-app/config.rb +4 -4
  67. data/fixtures/multiple-data-sources-app/config.rb +1 -1
  68. data/fixtures/multiple-sources-app/config.rb +1 -1
  69. data/fixtures/multiple-sources-with-destination-dir/config.rb +2 -0
  70. data/fixtures/multiple-sources-with-destination-dir/external/page.html.erb +1 -0
  71. data/fixtures/multiple-sources-with-destination-dir/source/index.html.erb +1 -0
  72. data/fixtures/multiple-sources-with-duplicate-file-names-app/config.rb +1 -1
  73. data/fixtures/multiple-sources-without-destination-dir/config.rb +1 -0
  74. data/fixtures/multiple-sources-without-destination-dir/external/page.html.erb +1 -0
  75. data/fixtures/multiple-sources-without-destination-dir/source/index.html.erb +1 -0
  76. data/fixtures/nested-layout-app/source/another.html.markdown +1 -1
  77. data/fixtures/nested-layout-app/source/haml-test.html.markdown +1 -1
  78. data/fixtures/nested-layout-app/source/slim-test.html.markdown +1 -1
  79. data/fixtures/padrino-helpers-app/config.rb +1 -1
  80. data/fixtures/page-classes-app/config.rb +2 -2
  81. data/fixtures/page-helper-layout-block-app/config.rb +1 -1
  82. data/fixtures/page-id-app/config-proc.rb +4 -4
  83. data/fixtures/page-id-app/config.rb +3 -3
  84. data/fixtures/paginate-app/source/blog/2011-01-01-test-article.html.markdown +1 -1
  85. data/fixtures/paginate-app/source/blog/2011-01-02-test-article.html.markdown +1 -1
  86. data/fixtures/paginate-app/source/blog/2011-01-03-test-article.html.markdown +1 -1
  87. data/fixtures/paginate-app/source/blog/2011-01-04-test-article.html.markdown +1 -1
  88. data/fixtures/paginate-app/source/blog/2011-01-05-test-article.html.markdown +1 -1
  89. data/fixtures/paginate-app/source/blog/2011-02-01-test-article.html.markdown +1 -1
  90. data/fixtures/paginate-app/source/blog/2011-02-02-test-article.html.markdown +1 -1
  91. data/fixtures/partials-app/source/_locals.erb +1 -1
  92. data/fixtures/partials-app/source/locals.html.erb +1 -1
  93. data/fixtures/proxy-pages-app/config.rb +13 -14
  94. data/fixtures/sass-assets-path-app/config.rb +2 -2
  95. data/fixtures/sinatra-app/config.rb +6 -6
  96. data/fixtures/traversal-app/config.rb +4 -4
  97. data/fixtures/v4-extension-callbacks/config.rb +2 -2
  98. data/fixtures/wildcard-app/config.rb +1 -1
  99. data/fixtures/wildcard-directory-index-app/config.rb +1 -1
  100. data/lib/middleman-core.rb +3 -3
  101. data/lib/middleman-core/application.rb +5 -5
  102. data/lib/middleman-core/builder.rb +20 -20
  103. data/lib/middleman-core/callback_manager.rb +1 -1
  104. data/lib/middleman-core/config_context.rb +2 -2
  105. data/lib/middleman-core/configuration.rb +5 -5
  106. data/lib/middleman-core/contracts.rb +2 -2
  107. data/lib/middleman-core/core_extensions/collections.rb +1 -1
  108. data/lib/middleman-core/core_extensions/collections/lazy_root.rb +1 -1
  109. data/lib/middleman-core/core_extensions/collections/lazy_step.rb +9 -9
  110. data/lib/middleman-core/core_extensions/collections/pagination.rb +6 -6
  111. data/lib/middleman-core/core_extensions/data.rb +10 -10
  112. data/lib/middleman-core/core_extensions/default_helpers.rb +26 -22
  113. data/lib/middleman-core/core_extensions/file_watcher.rb +1 -1
  114. data/lib/middleman-core/core_extensions/front_matter.rb +3 -3
  115. data/lib/middleman-core/core_extensions/i18n.rb +24 -24
  116. data/lib/middleman-core/core_extensions/inline_url_rewriter.rb +10 -7
  117. data/lib/middleman-core/core_extensions/routing.rb +1 -1
  118. data/lib/middleman-core/dns_resolver.rb +1 -1
  119. data/lib/middleman-core/dns_resolver/basic_network_resolver.rb +3 -3
  120. data/lib/middleman-core/dns_resolver/hosts_resolver.rb +1 -1
  121. data/lib/middleman-core/dns_resolver/local_link_resolver.rb +1 -1
  122. data/lib/middleman-core/dns_resolver/network_resolver.rb +1 -1
  123. data/lib/middleman-core/extension.rb +26 -25
  124. data/lib/middleman-core/extension_manager.rb +1 -1
  125. data/lib/middleman-core/extensions.rb +8 -7
  126. data/lib/middleman-core/extensions/asset_hash.rb +24 -22
  127. data/lib/middleman-core/extensions/asset_host.rb +10 -10
  128. data/lib/middleman-core/extensions/automatic_alt_tags.rb +1 -1
  129. data/lib/middleman-core/extensions/automatic_image_sizes.rb +3 -3
  130. data/lib/middleman-core/extensions/cache_buster.rb +2 -2
  131. data/lib/middleman-core/extensions/directory_indexes.rb +1 -1
  132. data/lib/middleman-core/extensions/external_pipeline.rb +14 -9
  133. data/lib/middleman-core/extensions/gzip.rb +7 -5
  134. data/lib/middleman-core/extensions/lorem.rb +9 -9
  135. data/lib/middleman-core/extensions/minify_css.rb +9 -9
  136. data/lib/middleman-core/extensions/minify_javascript.rb +10 -10
  137. data/lib/middleman-core/extensions/relative_assets.rb +8 -8
  138. data/lib/middleman-core/file_renderer.rb +6 -5
  139. data/lib/middleman-core/load_paths.rb +10 -10
  140. data/lib/middleman-core/logger.rb +2 -3
  141. data/lib/middleman-core/meta_pages.rb +1 -1
  142. data/lib/middleman-core/preview_server.rb +21 -22
  143. data/lib/middleman-core/preview_server/checks.rb +1 -1
  144. data/lib/middleman-core/preview_server/information.rb +13 -13
  145. data/lib/middleman-core/preview_server/network_interface_inventory.rb +3 -3
  146. data/lib/middleman-core/preview_server/server_information.rb +1 -1
  147. data/lib/middleman-core/preview_server/server_url.rb +1 -1
  148. data/lib/middleman-core/preview_server/tcp_port_prober.rb +1 -1
  149. data/lib/middleman-core/rack.rb +1 -1
  150. data/lib/middleman-core/renderers/coffee_script.rb +2 -2
  151. data/lib/middleman-core/renderers/haml.rb +1 -4
  152. data/lib/middleman-core/renderers/less.rb +1 -1
  153. data/lib/middleman-core/renderers/liquid.rb +2 -1
  154. data/lib/middleman-core/renderers/markdown.rb +7 -7
  155. data/lib/middleman-core/renderers/redcarpet.rb +2 -2
  156. data/lib/middleman-core/renderers/sass.rb +5 -5
  157. data/lib/middleman-core/renderers/sass_functions.rb +5 -5
  158. data/lib/middleman-core/renderers/slim.rb +2 -2
  159. data/lib/middleman-core/sitemap/extensions/ignores.rb +2 -4
  160. data/lib/middleman-core/sitemap/extensions/import.rb +1 -1
  161. data/lib/middleman-core/sitemap/extensions/on_disk.rb +1 -1
  162. data/lib/middleman-core/sitemap/extensions/proxies.rb +2 -1
  163. data/lib/middleman-core/sitemap/extensions/redirects.rb +1 -1
  164. data/lib/middleman-core/sitemap/extensions/request_endpoints.rb +1 -1
  165. data/lib/middleman-core/sitemap/extensions/traversal.rb +80 -25
  166. data/lib/middleman-core/sitemap/resource.rb +21 -20
  167. data/lib/middleman-core/sitemap/store.rb +3 -3
  168. data/lib/middleman-core/sources.rb +12 -12
  169. data/lib/middleman-core/sources/source_watcher.rb +16 -10
  170. data/lib/middleman-core/step_definitions/builder_steps.rb +23 -23
  171. data/lib/middleman-core/step_definitions/commandline_steps.rb +5 -5
  172. data/lib/middleman-core/step_definitions/middleman_steps.rb +13 -14
  173. data/lib/middleman-core/step_definitions/server_steps.rb +14 -16
  174. data/lib/middleman-core/template_context.rb +17 -10
  175. data/lib/middleman-core/template_renderer.rb +34 -32
  176. data/lib/middleman-core/util.rb +2 -2
  177. data/lib/middleman-core/util/binary.rb +3 -1
  178. data/lib/middleman-core/util/data.rb +2 -2
  179. data/lib/middleman-core/util/files.rb +2 -2
  180. data/lib/middleman-core/util/paths.rb +47 -44
  181. data/lib/middleman-core/util/rack.rb +3 -3
  182. data/lib/middleman-core/util/uri_templates.rb +1 -0
  183. data/lib/middleman-core/version.rb +1 -1
  184. data/middleman-core.gemspec +3 -2
  185. data/spec/middleman-core/callbacks_spec.rb +15 -14
  186. data/spec/middleman-core/core_extensions/data_spec.rb +70 -74
  187. data/spec/middleman-core/dns_resolver_spec.rb +6 -6
  188. data/spec/middleman-core/util_spec.rb +81 -86
  189. data/spec/support/given.rb +11 -15
  190. metadata +44 -6
@@ -1,4 +1,4 @@
1
1
  set :sass_assets_paths, [
2
- File.join(root, "assets", "stylesheets"),
3
- File.join(root, "my-vendor", "stylesheets")
2
+ File.join(root, 'assets', 'stylesheets'),
3
+ File.join(root, 'my-vendor', 'stylesheets')
4
4
  ]
@@ -1,14 +1,14 @@
1
- require "sinatra"
1
+ require 'sinatra'
2
2
 
3
3
  class MySinatra < Sinatra::Base
4
- get "/" do
5
- "Hello World (Sinatra)"
4
+ get '/' do
5
+ 'Hello World (Sinatra)'
6
6
  end
7
- get "/derp.html" do
8
- "De doo"
7
+ get '/derp.html' do
8
+ 'De doo'
9
9
  end
10
10
  end
11
11
 
12
- map "/sinatra" do
12
+ map '/sinatra' do
13
13
  run MySinatra
14
14
  end
@@ -1,5 +1,5 @@
1
- proxy "/sub/fake.html", "/proxied.html", ignore: true
2
- proxy "/sub/fake2.html", "/proxied.html", ignore: true
1
+ proxy '/sub/fake.html', '/proxied.html', ignore: true
2
+ proxy '/sub/fake2.html', '/proxied.html', ignore: true
3
3
 
4
- proxy "/directory-indexed/fake.html", "/proxied.html", ignore: true
5
- proxy "/directory-indexed/fake2.html", "/proxied.html", ignore: true
4
+ proxy '/directory-indexed/fake.html', '/proxied.html', ignore: true
5
+ proxy '/directory-indexed/fake2.html', '/proxied.html', ignore: true
@@ -7,7 +7,7 @@ class ExtensionOne < ::Middleman::Extension
7
7
 
8
8
  attr_reader :extension_two_was_activated
9
9
 
10
- def initialize(app, options_hash={})
10
+ def initialize(app, options_hash = {})
11
11
  super
12
12
 
13
13
  after_extension_activated :extension_two do
@@ -27,7 +27,7 @@ class ExtensionTwo < ::Middleman::Extension
27
27
 
28
28
  attr_reader :extension_one_was_activated
29
29
 
30
- def initialize(app, options_hash={})
30
+ def initialize(app, options_hash = {})
31
31
  super
32
32
 
33
33
  after_extension_activated :extension_one do
@@ -1 +1 @@
1
- page "/admin/*", layout: :admin
1
+ page '/admin/*', layout: :admin
@@ -1,2 +1,2 @@
1
1
  activate :directory_indexes
2
- page "/admin/*", layout: :admin
2
+ page '/admin/*', layout: :admin
@@ -1,9 +1,9 @@
1
- # rubocop:disable FileName
2
-
3
1
  # Setup our load paths
4
- libdir = File.expand_path(File.dirname(__FILE__))
2
+ libdir = __dir__
5
3
  $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
6
4
 
5
+ require 'backports/latest'
6
+
7
7
  # Top-level Middleman namespace
8
8
  module Middleman
9
9
  autoload :Application, 'middleman-core/application'
@@ -53,7 +53,7 @@ module Middleman
53
53
  # An anonymous subclass of ::Middleman::TemplateContext
54
54
  attr_reader :template_context_class
55
55
 
56
- # An instance of the above anonymouse class.
56
+ # An instance of the above anonymous class.
57
57
  attr_reader :generic_template_context
58
58
 
59
59
  Contract ::Middleman::Configuration::ConfigurationManager
@@ -158,11 +158,11 @@ module Middleman
158
158
 
159
159
  # Which file extensions have a layout by default.
160
160
  # @return [Array.<String>]
161
- define_setting :extensions_with_layout, %w(.htm .html .xhtml .php), 'Which file extensions have a layout by default.'
161
+ define_setting :extensions_with_layout, %w[.htm .html .xhtml .php], 'Which file extensions have a layout by default.'
162
162
 
163
163
  # Which file extensions are "assets."
164
164
  # @return [Array.<String>]
165
- define_setting :asset_extensions, %w(.css .png .jpg .jpeg .webp .svg .svgz .js .gif .ttf .otf .woff .woff2 .eot .ico .map), 'Which file extensions are treated as assets.'
165
+ define_setting :asset_extensions, %w[.css .png .jpg .jpeg .webp .svg .svgz .js .gif .ttf .otf .woff .woff2 .eot .ico .map], 'Which file extensions are treated as assets.'
166
166
 
167
167
  # Default string encoding for templates and output.
168
168
  # @return [String]
@@ -182,7 +182,7 @@ module Middleman
182
182
  ignored = false
183
183
 
184
184
  file[:relative_path].ascend do |f|
185
- if f.basename.to_s =~ %r{^_[^_]}
185
+ if /^_[^_]/.match?(f.basename.to_s)
186
186
  ignored = true
187
187
  break
188
188
  end
@@ -442,7 +442,7 @@ module Middleman
442
442
  # @param [Symbol] key Name of the attribue
443
443
  # @param value Attribute value
444
444
  # @return [void]
445
- def set(key, value=nil, &block)
445
+ def set(key, value = nil, &block)
446
446
  logger.warn "Warning: `set :#{key}` is deprecated. Use `config[:#{key}] =` instead."
447
447
 
448
448
  value = block if block_given?
@@ -21,17 +21,17 @@ module Middleman
21
21
  def_delegator :@app, :logger
22
22
 
23
23
  # Sort order, images, fonts, js/css and finally everything else.
24
- SORT_ORDER = %w(.png .jpeg .jpg .gif .bmp .svg .svgz .webp .ico .woff .woff2 .otf .ttf .eot .js .css).freeze
24
+ SORT_ORDER = %w[.png .jpeg .jpg .gif .bmp .svg .svgz .webp .ico .woff .woff2 .otf .ttf .eot .js .css].freeze
25
25
 
26
26
  # Create a new Builder instance.
27
27
  # @param [Middleman::Application] app The app to build.
28
28
  # @param [Hash] opts The builder options
29
- def initialize(app, opts={})
29
+ def initialize(app, opts = {})
30
30
  @app = app
31
31
  @source_dir = Pathname(File.join(@app.root, @app.config[:source]))
32
32
  @build_dir = Pathname(@app.config[:build_dir])
33
33
 
34
- if @build_dir.expand_path.relative_path_from(@source_dir).to_s =~ /\A[.\/]+\Z/
34
+ if /\A[.\/]+\Z/.match?(@build_dir.expand_path.relative_path_from(@source_dir).to_s)
35
35
  raise ":build_dir (#{@build_dir}) cannot be a parent of :source_dir (#{@source_dir})"
36
36
  end
37
37
 
@@ -134,10 +134,10 @@ module Middleman
134
134
  Contract ResourceList => ResourceList
135
135
  def output_resources(resources)
136
136
  results = if @parallel
137
- ::Parallel.map(resources, &method(:output_resource))
138
- else
139
- resources.map(&method(:output_resource))
140
- end
137
+ ::Parallel.map(resources, &method(:output_resource))
138
+ else
139
+ resources.map(&method(:output_resource))
140
+ end
141
141
 
142
142
  @has_error = true if results.any? { |r| r == false }
143
143
 
@@ -146,11 +146,11 @@ module Middleman
146
146
  next unless p.exist?
147
147
 
148
148
  # handle UTF-8-MAC filename on MacOS
149
- cleaned_name = if RUBY_PLATFORM =~ /darwin/
150
- p.to_s.encode('UTF-8', 'UTF-8-MAC')
151
- else
152
- p
153
- end
149
+ cleaned_name = if RUBY_PLATFORM.match?(/darwin/)
150
+ p.to_s.encode('UTF-8', 'UTF-8-MAC')
151
+ else
152
+ p
153
+ end
154
154
 
155
155
  @to_clean.delete(Pathname(cleaned_name))
156
156
  end
@@ -199,14 +199,14 @@ module Middleman
199
199
  source = write_tempfile(output_file, source.to_s) if source.is_a? String
200
200
 
201
201
  method, source_path = if source.is_a? Tempfile
202
- [::FileUtils.method(:mv), source.path]
203
- else
204
- [::FileUtils.method(:cp), source.to_s]
205
- end
202
+ [::FileUtils.method(:mv), source.path]
203
+ else
204
+ [::FileUtils.method(:cp), source.to_s]
205
+ end
206
206
 
207
207
  mode = which_mode(output_file, source_path)
208
208
 
209
- if mode == :created || mode == :updated
209
+ if %i[created updated].include? mode
210
210
  ::FileUtils.mkdir_p(output_file.dirname)
211
211
  method.call(source_path, output_file.to_s)
212
212
  end
@@ -239,7 +239,7 @@ module Middleman
239
239
  return false
240
240
  end
241
241
  end
242
- rescue => e
242
+ rescue StandardError => e
243
243
  trigger(:error, output_file, "#{e}\n#{e.backtrace.join("\n")}")
244
244
  return false
245
245
  end
@@ -267,7 +267,7 @@ module Middleman
267
267
 
268
268
  # handle UTF-8-MAC filename on MacOS
269
269
  @to_clean = @to_clean.map do |path|
270
- if RUBY_PLATFORM =~ /darwin/
270
+ if RUBY_PLATFORM.match?(/darwin/)
271
271
  Pathname(path.to_s.encode('UTF-8', 'UTF-8-MAC'))
272
272
  else
273
273
  Pathname(path)
@@ -295,7 +295,7 @@ module Middleman
295
295
  end
296
296
 
297
297
  Contract Symbol, Or[String, Pathname], Maybe[String] => Any
298
- def trigger(event_type, target, extra=nil)
298
+ def trigger(event_type, target, extra = nil)
299
299
  @events[event_type] ||= []
300
300
  @events[event_type] << target
301
301
 
@@ -47,7 +47,7 @@ module Middleman
47
47
  end
48
48
 
49
49
  Contract Or[Symbol, ArrayOf[Symbol]], Maybe[ArrayOf[Any]], Maybe[RespondTo[:instance_exec]] => Any
50
- def execute(keys, args=[], scope=self)
50
+ def execute(keys, args = [], scope = self)
51
51
  callbacks = callbacks_for(keys)
52
52
  callbacks_count = callbacks.length + @subscribers.length
53
53
 
@@ -16,7 +16,7 @@ module Middleman
16
16
  @template_context_class = template_context_class
17
17
 
18
18
  @callbacks = ::Middleman::CallbackManager.new
19
- @callbacks.install_methods!(self, [:before_build, :after_build, :configure, :after_configuration, :ready])
19
+ @callbacks.install_methods!(self, %i[before_build after_build configure after_configuration ready])
20
20
 
21
21
  # Trigger internal callbacks when app level are executed.
22
22
  app.subscribe_to_callbacks(&method(:execute_callbacks))
@@ -49,7 +49,7 @@ module Middleman
49
49
  instance_eval File.read(other_config), other_config, 1
50
50
  end
51
51
 
52
- def set(key, default=nil, &block)
52
+ def set(key, default = nil, &block)
53
53
  config.define_setting(key, default) unless config.defines_setting?(key)
54
54
  @app.config[key] = block_given? ? block : default
55
55
  end
@@ -43,15 +43,15 @@ module Middleman
43
43
  if defines_setting?(method) && args.empty?
44
44
  self[method]
45
45
  elsif method.to_s =~ /^(\w+)=$/ && args.size == 1
46
- self[$1.to_sym] = args[0]
46
+ self[Regexp.last_match(1).to_sym] = args[0]
47
47
  else
48
48
  super
49
49
  end
50
50
  end
51
51
 
52
52
  # Needed so that method_missing makes sense
53
- def respond_to?(method, include_private=false)
54
- super || defines_setting?(method) || (method =~ /^(\w+)=$/ && defines_setting?($1))
53
+ def respond_to?(method, include_private = false)
54
+ super || defines_setting?(method) || (method =~ /^(\w+)=$/ && defines_setting?(Regexp.last_match(1)))
55
55
  end
56
56
 
57
57
  # Does this configuration manager know about the setting identified by key?
@@ -71,7 +71,7 @@ module Middleman
71
71
  # @param [String] description A human-readable description of what the option does
72
72
  # @param [Hash] options Additional options.
73
73
  # @return [ConfigSetting]
74
- def define_setting(key, default=nil, description=nil, options={})
74
+ def define_setting(key, default = nil, description = nil, options = {})
75
75
  raise "Setting #{key} doesn't exist" if @finalized
76
76
  raise "Setting #{key} already defined" if @settings.key?(key)
77
77
  raise 'Setting key must be a Symbol' unless key.is_a? Symbol
@@ -127,7 +127,7 @@ module Middleman
127
127
  # Additional config.
128
128
  attr_accessor :options
129
129
 
130
- def initialize(key, default, description, options={})
130
+ def initialize(key, default, description, options = {})
131
131
  @value_set = false
132
132
  self.key = key
133
133
  self.default = default
@@ -29,10 +29,10 @@ else
29
29
 
30
30
  # rubocop:disable MethodName
31
31
  def Contract(*); end
32
+ # rubocop:enable MethodName
32
33
 
33
34
  class Callable
34
- def self.[](*)
35
- end
35
+ def self.[](*); end
36
36
  end
37
37
 
38
38
  class Bool
@@ -34,7 +34,7 @@ module Middleman
34
34
  end
35
35
  end
36
36
 
37
- def initialize(app, options_hash={}, &block)
37
+ def initialize(app, options_hash = {}, &block)
38
38
  super
39
39
 
40
40
  @leaves = Set.new
@@ -13,7 +13,7 @@ module Middleman
13
13
  @data = data
14
14
  end
15
15
 
16
- def value(_ctx=nil)
16
+ def value(_ctx = nil)
17
17
  @data
18
18
  end
19
19
 
@@ -2,9 +2,9 @@ module Middleman
2
2
  module CoreExtensions
3
3
  module Collections
4
4
  class LazyCollectorStep < BasicObject
5
- DELEGATE = [:hash, :eql?].freeze
5
+ DELEGATE = %i[hash eql?].freeze
6
6
 
7
- def initialize(name, args, block, parent=nil)
7
+ def initialize(name, args, block, parent = nil)
8
8
  @name = name
9
9
  @args = args
10
10
  @block = block
@@ -19,19 +19,19 @@ module Middleman
19
19
  @parent.leaves
20
20
  end
21
21
 
22
- def value(ctx=nil)
22
+ def value(ctx = nil)
23
23
  data = @parent.value(ctx)
24
24
 
25
25
  original_block = @block
26
26
 
27
27
  if original_block
28
28
  b = if ctx
29
- ::Proc.new do |*args|
30
- ctx.instance_exec(*args, &original_block)
31
- end
32
- else
33
- original_block
34
- end
29
+ ::Proc.new do |*args|
30
+ ctx.instance_exec(*args, &original_block)
31
+ end
32
+ else
33
+ original_block
34
+ end
35
35
  end
36
36
 
37
37
  data.send(@name, *@args.deep_dup, &b)
@@ -8,12 +8,12 @@ module Middleman
8
8
  return to_enum(__method__, per_page) unless block_given?
9
9
 
10
10
  parts = if per_page.respond_to? :call
11
- per_page.call(dup)
12
- else
13
- each_slice(per_page).reduce([]) do |sum, items|
14
- sum << items
15
- end
16
- end
11
+ per_page.call(dup)
12
+ else
13
+ each_slice(per_page).reduce([]) do |sum, items|
14
+ sum << items
15
+ end
16
+ end
17
17
 
18
18
  num_pages = parts.length
19
19
  collection = self
@@ -19,7 +19,7 @@ module Middleman
19
19
  # The regex which tells Middleman which files are for data
20
20
  DATA_FILE_MATCHER = /^(.*?)[\w-]+\.(yml|yaml|json)$/
21
21
 
22
- def initialize(app, config={}, &block)
22
+ def initialize(app, config = {}, &block)
23
23
  super
24
24
 
25
25
  @data_store = DataStore.new(app, DATA_FILE_MATCHER)
@@ -68,7 +68,7 @@ module Middleman
68
68
  # @param [Hash] content The content for this data
69
69
  # @return [Hash]
70
70
  Contract Symbol, Or[Hash, Array] => Hash
71
- def store(name=nil, content=nil)
71
+ def store(name = nil, content = nil)
72
72
  @local_sources[name.to_s] = content unless name.nil? || content.nil?
73
73
  @local_sources
74
74
  end
@@ -79,7 +79,7 @@ module Middleman
79
79
  # @param [Proc] proc The callback which will return data
80
80
  # @return [Hash]
81
81
  Contract Maybe[Symbol], Maybe[Proc] => Hash
82
- def callbacks(name=nil, proc=nil)
82
+ def callbacks(name = nil, proc = nil)
83
83
  @callback_sources[name.to_s] = proc unless name.nil? || proc.nil?
84
84
  @callback_sources
85
85
  end
@@ -102,9 +102,9 @@ module Middleman
102
102
  extension = File.extname(data_path)
103
103
  basename = File.basename(data_path, extension)
104
104
 
105
- return unless %w(.yaml .yml .json).include?(extension)
105
+ return unless %w[.yaml .yml .json].include?(extension)
106
106
 
107
- if %w(.yaml .yml).include?(extension)
107
+ if %w[.yaml .yml].include?(extension)
108
108
  data, postscript = ::Middleman::Util::Data.parse(file, @app.config[:frontmatter_delims], :yaml)
109
109
  data[:postscript] = postscript if !postscript.nil? && data.is_a?(Hash)
110
110
  elsif extension == '.json'
@@ -153,10 +153,10 @@ module Middleman
153
153
  Contract Or[String, Symbol] => Maybe[Or[Array, IsA['Middleman::Util::EnhancedHash']]]
154
154
  def data_for_path(path)
155
155
  response = if store.key?(path.to_s)
156
- store[path.to_s]
157
- elsif callbacks.key?(path.to_s)
158
- callbacks[path.to_s].call
159
- end
156
+ store[path.to_s]
157
+ elsif callbacks.key?(path.to_s)
158
+ callbacks[path.to_s].call
159
+ end
160
160
 
161
161
  ::Middleman::Util.recursively_enhance(response)
162
162
  end
@@ -179,7 +179,7 @@ module Middleman
179
179
  end
180
180
 
181
181
  # Needed so that method_missing makes sense
182
- def respond_to?(method, include_private=false)
182
+ def respond_to?(method, include_private = false)
183
183
  super || key?(method)
184
184
  end
185
185
 
@@ -20,7 +20,7 @@ end
20
20
  class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension
21
21
  define_setting :relative_links, false, 'Whether to generate relative links instead of absolute ones'
22
22
 
23
- def initialize(app, options_hash={}, &block)
23
+ def initialize(app, options_hash = {}, &block)
24
24
  super
25
25
 
26
26
  require 'active_support/core_ext/object/to_query'
@@ -38,7 +38,7 @@ class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension
38
38
  # The helpers
39
39
  helpers do
40
40
  # Make all block content html_safe
41
- def content_tag(name, content=nil, options=nil, &block)
41
+ def content_tag(name, content = nil, options = nil, &block)
42
42
  # safe_content_tag(name, content, options, &block)
43
43
  if block_given?
44
44
  options = content if content.is_a?(Hash)
@@ -64,11 +64,13 @@ class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension
64
64
  end
65
65
 
66
66
  def capture_html(*args, &block)
67
- result = if handler = auto_find_proper_handler(&block)
68
- handler.capture_from_template(*args, &block)
69
- else
70
- yield(*args)
71
- end
67
+ handler = auto_find_proper_handler(&block)
68
+
69
+ result = if handler
70
+ handler.capture_from_template(*args, &block)
71
+ else
72
+ yield(*args)
73
+ end
72
74
 
73
75
  ::ActiveSupport::SafeBuffer.new.safe_concat(result)
74
76
  end
@@ -140,14 +142,14 @@ class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension
140
142
  # @param [Symbol] asset_ext The type of asset
141
143
  # @param [String] asset_dir Where to look for assets
142
144
  # @return [void]
143
- def auto_tag(asset_ext, asset_dir=nil)
145
+ def auto_tag(asset_ext, asset_dir = nil)
144
146
  if asset_dir.nil?
145
147
  asset_dir = case asset_ext
146
- when :js
147
- config[:js_dir]
148
- when :css
149
- config[:css_dir]
150
- end
148
+ when :js
149
+ config[:js_dir]
150
+ when :css
151
+ config[:css_dir]
152
+ end
151
153
  end
152
154
 
153
155
  # If the basename of the request as no extension, assume we are serving a
@@ -161,7 +163,7 @@ class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension
161
163
  # Generate body css classes based on the current path
162
164
  #
163
165
  # @return [String]
164
- def page_classes(path=current_path.dup, options={})
166
+ def page_classes(path = current_path.dup, options = {})
165
167
  if path.is_a? Hash
166
168
  options = path
167
169
  path = current_path.dup
@@ -191,7 +193,7 @@ class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension
191
193
  # @param [String] source The path to the file
192
194
  # @param [Hash] options Data to pass through.
193
195
  # @return [String]
194
- def asset_path(kind, source, options={})
196
+ def asset_path(kind, source, options = {})
195
197
  options_with_resource = {}.merge!(options).merge!(current_resource: current_resource)
196
198
  ::Middleman::Util.asset_path(app, kind, source, options_with_resource)
197
199
  end
@@ -202,7 +204,7 @@ class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension
202
204
  # @param [String] prefix The type prefix (such as "images")
203
205
  # @param [Hash] options Additional options.
204
206
  # @return [String] The fully qualified asset url
205
- def asset_url(path, prefix='', options={})
207
+ def asset_url(path, prefix = '', options = {})
206
208
  options_with_resource = {}.merge!(options).merge!(current_resource: current_resource)
207
209
  ::Middleman::Util.asset_url(app, path, prefix, options_with_resource)
208
210
  end
@@ -210,7 +212,7 @@ class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension
210
212
  # Given a source path (referenced either absolutely or relatively)
211
213
  # or a Resource, this will produce the nice URL configured for that
212
214
  # path, respecting :relative_links, directory indexes, etc.
213
- def url_for(path_or_resource, options={})
215
+ def url_for(path_or_resource, options = {})
214
216
  options_with_resource = {}.merge!(options).merge!(current_resource: current_resource)
215
217
  ::Middleman::Util.url_for(app, path_or_resource, options_with_resource)
216
218
  end
@@ -236,7 +238,9 @@ class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension
236
238
  raise ArgumentError, 'Too many arguments to link_to(url, options={}, &block)'
237
239
  end
238
240
 
239
- if url = args[url_arg_index]
241
+ url = args[url_arg_index]
242
+
243
+ if url
240
244
  options = args[options_index] || {}
241
245
  raise ArgumentError, 'Options must be a hash' unless options.is_a?(Hash)
242
246
 
@@ -252,14 +256,14 @@ class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension
252
256
 
253
257
  # Modified Padrino form_for that uses Middleman's url_for
254
258
  # to transform the URL.
255
- def form_tag(url, options={}, &block)
259
+ def form_tag(url, options = {}, &block)
256
260
  url = url_for(url, options)
257
261
  super
258
262
  end
259
263
 
260
264
  # Modified Padrino image_tag so that it finds the paths for srcset
261
265
  # using asset_path for the images listed in the srcset param
262
- def image_tag(path, params={})
266
+ def image_tag(path, params = {})
263
267
  params.symbolize_keys!
264
268
 
265
269
  if params.key?(:srcset)
@@ -278,8 +282,8 @@ class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension
278
282
  super(path, params)
279
283
  end
280
284
 
281
- def partial(template, options={}, &block)
282
- including_parent_locals = {}
285
+ def partial(template, options = {}, &block)
286
+ including_parent_locals = Middleman::Util::EnhancedHash.new
283
287
  including_parent_locals.merge!(@locs || {})
284
288
  including_parent_locals.merge!(options[:locals] || {})
285
289