middleman-core 4.3.0.rc.4 → 4.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (223) hide show
  1. checksums.yaml +4 -4
  2. data/cucumber.yml +2 -2
  3. data/features/builder.feature +1 -1
  4. data/features/chained_templates.feature +0 -7
  5. data/features/coffee-script.feature +1 -1
  6. data/features/collections.feature +2 -2
  7. data/features/console.feature +1 -1
  8. data/features/data.feature +31 -0
  9. data/features/extension_api_deprecations.feature +3 -1
  10. data/features/extension_hooks.feature +3 -1
  11. data/features/helpers_external.feature +1 -17
  12. data/features/i18n_link_to.feature +0 -23
  13. data/features/i18n_mixed_sources.feature +0 -8
  14. data/features/i18n_preview.feature +1 -30
  15. data/features/ignore.feature +11 -67
  16. data/features/ignore_already_minified.feature +1 -1
  17. data/features/markdown.feature +1 -0
  18. data/features/minify_javascript.feature +35 -35
  19. data/features/mount_rack.feature +0 -1
  20. data/features/page-id.feature +2 -2
  21. data/features/partials.feature +1 -1
  22. data/features/relative_assets_helpers_only.feature +6 -4
  23. data/features/scss-support.feature +6 -1
  24. data/features/support/env.rb +5 -5
  25. data/features/tilde_directories.feature +2 -0
  26. data/features/unicode_filenames.feature +1 -1
  27. data/fixtures/asset-hash-app/config.rb +1 -0
  28. data/fixtures/asset-hash-app/lib/middleware.rb +2 -2
  29. data/fixtures/asset-hash-app/source/stylesheets/_partial.sass +1 -1
  30. data/fixtures/asset-hash-minified-app/config.rb +1 -1
  31. data/fixtures/asset-hash-prefix/config.rb +2 -1
  32. data/fixtures/asset-hash-prefix/lib/middleware.rb +2 -2
  33. data/fixtures/asset-hash-source-map/config.rb +1 -0
  34. data/fixtures/asset-hash-source-map/lib/middleware.rb +2 -2
  35. data/fixtures/asset-host-app/config.rb +1 -1
  36. data/fixtures/auto-css-app/config.rb +2 -2
  37. data/fixtures/auto-js-app/config.rb +2 -2
  38. data/fixtures/auto-js-directory-index-app/config.rb +1 -1
  39. data/fixtures/automatic-directory-matcher-app/config.rb +1 -1
  40. data/fixtures/basic-data-app/config.rb +2 -2
  41. data/fixtures/capture-html-app/config.rb +4 -4
  42. data/fixtures/clean-app/config-complications.rb +6 -6
  43. data/fixtures/clean-app/config-hidden-dir-after.rb +4 -4
  44. data/fixtures/clean-app/config-hidden-dir-before.rb +1 -1
  45. data/fixtures/clean-app/config.rb +6 -6
  46. data/fixtures/clean-dir-app/config.rb +1 -0
  47. data/fixtures/clean-nested-app/config.rb +1 -1
  48. data/fixtures/collections-app/source/blog1/2011-01-01-new-article.html.markdown +1 -1
  49. data/fixtures/collections-app/source/blog1/2011-01-02-another-article.html.markdown +1 -1
  50. data/fixtures/collections-app/source/blog2/2011-01-01-new-article.html.markdown +1 -1
  51. data/fixtures/collections-app/source/blog2/2011-01-02-another-article.html.markdown +1 -1
  52. data/fixtures/content-for-app/config.rb +4 -4
  53. data/fixtures/dynamic-pages-app/config.rb +26 -25
  54. data/fixtures/ember-cli-app/config.rb +4 -4
  55. data/fixtures/env-app/environments/development.rb +1 -1
  56. data/fixtures/env-app/environments/production.rb +1 -1
  57. data/fixtures/env-app/source/stylesheets/site.css.scss +1 -1
  58. data/fixtures/extension-hooks-app/config.rb +8 -8
  59. data/fixtures/external-helpers/config.rb +2 -2
  60. data/fixtures/external-helpers/helpers/derp.rb +1 -3
  61. data/fixtures/external-helpers/helpers/four_helpers.rb +1 -3
  62. data/fixtures/external-helpers/helpers/one_helper.rb +1 -3
  63. data/fixtures/external-helpers/helpers/yet_another_thingy.rb +1 -3
  64. data/fixtures/external-helpers/lib/hello_helper.rb +1 -1
  65. data/fixtures/external-pipeline-error/config.rb +4 -4
  66. data/fixtures/feature-params-app/config.rb +1 -1
  67. data/fixtures/frontmatter-app/config.rb +1 -1
  68. data/fixtures/generator-test/config.rb +15 -1
  69. data/fixtures/glob-app/config.rb +1 -1
  70. data/fixtures/i-8859-1-app/config.rb +1 -1
  71. data/fixtures/i18n-force-locale/config.rb +4 -4
  72. data/fixtures/i18n-mixed-sources/config.rb +1 -1
  73. data/fixtures/i18n-test-app/locales/en.yml +1 -7
  74. data/fixtures/i18n-test-app/locales/es.yml +1 -2
  75. data/fixtures/import-app/config.rb +3 -3
  76. data/fixtures/indexable-app/config.rb +3 -3
  77. data/fixtures/large-build-app/config.rb +1 -1
  78. data/fixtures/manual-layout-override/config.rb +1 -1
  79. data/fixtures/missing-tilt-library-app/config.rb +2 -2
  80. data/fixtures/more-traversal-app/config.rb +4 -4
  81. data/fixtures/multiple-data-sources-app/config.rb +1 -1
  82. data/fixtures/multiple-sources-app/config.rb +1 -1
  83. data/fixtures/multiple-sources-with-duplicate-file-names-app/config.rb +1 -1
  84. data/fixtures/nested-layout-app/source/another.html.markdown +1 -1
  85. data/fixtures/nested-layout-app/source/haml-test.html.markdown +1 -1
  86. data/fixtures/nested-layout-app/source/slim-test.html.markdown +1 -1
  87. data/fixtures/padrino-helpers-app/config.rb +1 -1
  88. data/fixtures/page-classes-app/config.rb +2 -2
  89. data/fixtures/page-helper-layout-block-app/config.rb +1 -1
  90. data/fixtures/page-id-app/config-proc.rb +4 -4
  91. data/fixtures/page-id-app/config.rb +3 -3
  92. data/fixtures/page-id-app/source/{forty-two.html.erb → fourty-two.html.erb} +0 -0
  93. data/fixtures/paginate-app/source/blog/2011-01-01-test-article.html.markdown +1 -1
  94. data/fixtures/paginate-app/source/blog/2011-01-02-test-article.html.markdown +1 -1
  95. data/fixtures/paginate-app/source/blog/2011-01-03-test-article.html.markdown +1 -1
  96. data/fixtures/paginate-app/source/blog/2011-01-04-test-article.html.markdown +1 -1
  97. data/fixtures/paginate-app/source/blog/2011-01-05-test-article.html.markdown +1 -1
  98. data/fixtures/paginate-app/source/blog/2011-02-01-test-article.html.markdown +1 -1
  99. data/fixtures/paginate-app/source/blog/2011-02-02-test-article.html.markdown +1 -1
  100. data/fixtures/partials-app/source/_locals.erb +1 -1
  101. data/fixtures/partials-app/source/locals.html.erb +1 -1
  102. data/fixtures/proxy-pages-app/config.rb +14 -13
  103. data/fixtures/sass-assets-path-app/config.rb +2 -2
  104. data/fixtures/scss-app/source/stylesheets/error.css.sass +1 -0
  105. data/fixtures/sinatra-app/config.rb +6 -6
  106. data/fixtures/traversal-app/config.rb +4 -4
  107. data/fixtures/v4-extension-callbacks/config.rb +2 -2
  108. data/fixtures/wildcard-app/config.rb +1 -1
  109. data/fixtures/wildcard-directory-index-app/config.rb +1 -1
  110. data/lib/middleman/rack.rb +7 -0
  111. data/lib/middleman-core/application.rb +9 -10
  112. data/lib/middleman-core/builder.rb +21 -50
  113. data/lib/middleman-core/callback_manager.rb +1 -1
  114. data/lib/middleman-core/config_context.rb +2 -2
  115. data/lib/middleman-core/configuration.rb +5 -5
  116. data/lib/middleman-core/contracts.rb +2 -2
  117. data/lib/middleman-core/core_extensions/collections/lazy_root.rb +1 -1
  118. data/lib/middleman-core/core_extensions/collections/lazy_step.rb +9 -9
  119. data/lib/middleman-core/core_extensions/collections/pagination.rb +6 -6
  120. data/lib/middleman-core/core_extensions/collections.rb +1 -1
  121. data/lib/middleman-core/core_extensions/data.rb +11 -11
  122. data/lib/middleman-core/core_extensions/default_helpers.rb +29 -26
  123. data/lib/middleman-core/core_extensions/external_helpers.rb +1 -1
  124. data/lib/middleman-core/core_extensions/file_watcher.rb +1 -1
  125. data/lib/middleman-core/core_extensions/front_matter.rb +3 -3
  126. data/lib/middleman-core/core_extensions/i18n.rb +23 -44
  127. data/lib/middleman-core/core_extensions/inline_url_rewriter.rb +7 -10
  128. data/lib/middleman-core/core_extensions/routing.rb +1 -1
  129. data/lib/middleman-core/core_extensions.rb +2 -2
  130. data/lib/middleman-core/dns_resolver/basic_network_resolver.rb +3 -3
  131. data/lib/middleman-core/dns_resolver/hosts_resolver.rb +1 -1
  132. data/lib/middleman-core/dns_resolver/local_link_resolver.rb +1 -1
  133. data/lib/middleman-core/dns_resolver/network_resolver.rb +1 -1
  134. data/lib/middleman-core/dns_resolver.rb +1 -1
  135. data/lib/middleman-core/extension.rb +32 -34
  136. data/lib/middleman-core/extension_manager.rb +2 -6
  137. data/lib/middleman-core/extensions/asset_hash.rb +22 -24
  138. data/lib/middleman-core/extensions/asset_host.rb +10 -10
  139. data/lib/middleman-core/extensions/automatic_alt_tags.rb +1 -1
  140. data/lib/middleman-core/extensions/automatic_image_sizes.rb +3 -3
  141. data/lib/middleman-core/extensions/cache_buster.rb +2 -2
  142. data/lib/middleman-core/extensions/directory_indexes.rb +1 -1
  143. data/lib/middleman-core/extensions/external_pipeline.rb +9 -14
  144. data/lib/middleman-core/extensions/gzip.rb +6 -8
  145. data/lib/middleman-core/extensions/lorem.rb +9 -9
  146. data/lib/middleman-core/extensions/minify_css.rb +16 -14
  147. data/lib/middleman-core/extensions/minify_javascript.rb +13 -13
  148. data/lib/middleman-core/extensions/relative_assets.rb +8 -8
  149. data/lib/middleman-core/extensions.rb +7 -8
  150. data/lib/middleman-core/file_renderer.rb +6 -7
  151. data/lib/middleman-core/load_paths.rb +10 -13
  152. data/lib/middleman-core/logger.rb +4 -3
  153. data/lib/middleman-core/meta_pages/sitemap_resource.rb +2 -0
  154. data/lib/middleman-core/meta_pages/sitemap_tree.rb +1 -1
  155. data/lib/middleman-core/meta_pages.rb +1 -1
  156. data/lib/middleman-core/preview_server/checks.rb +1 -1
  157. data/lib/middleman-core/preview_server/information.rb +13 -13
  158. data/lib/middleman-core/preview_server/network_interface_inventory.rb +3 -3
  159. data/lib/middleman-core/preview_server/server_information.rb +1 -1
  160. data/lib/middleman-core/preview_server/server_information_callback_proxy.rb +1 -1
  161. data/lib/middleman-core/preview_server/server_url.rb +1 -1
  162. data/lib/middleman-core/preview_server/tcp_port_prober.rb +1 -1
  163. data/lib/middleman-core/preview_server.rb +25 -25
  164. data/lib/middleman-core/rack.rb +1 -1
  165. data/lib/middleman-core/renderers/coffee_script.rb +2 -2
  166. data/lib/middleman-core/renderers/haml.rb +4 -8
  167. data/lib/middleman-core/renderers/less.rb +1 -1
  168. data/lib/middleman-core/renderers/liquid.rb +2 -3
  169. data/lib/middleman-core/renderers/markdown.rb +7 -7
  170. data/lib/middleman-core/renderers/redcarpet.rb +2 -2
  171. data/lib/middleman-core/renderers/sass.rb +23 -26
  172. data/lib/middleman-core/renderers/sass_functions.rb +14 -17
  173. data/lib/middleman-core/renderers/slim.rb +2 -2
  174. data/lib/middleman-core/sitemap/extensions/ignores.rb +4 -2
  175. data/lib/middleman-core/sitemap/extensions/import.rb +1 -1
  176. data/lib/middleman-core/sitemap/extensions/on_disk.rb +1 -1
  177. data/lib/middleman-core/sitemap/extensions/proxies.rb +1 -2
  178. data/lib/middleman-core/sitemap/extensions/redirects.rb +1 -1
  179. data/lib/middleman-core/sitemap/extensions/request_endpoints.rb +1 -1
  180. data/lib/middleman-core/sitemap/extensions/traversal.rb +25 -80
  181. data/lib/middleman-core/sitemap/resource.rb +20 -21
  182. data/lib/middleman-core/sitemap/store.rb +6 -6
  183. data/lib/middleman-core/sources/source_watcher.rb +11 -17
  184. data/lib/middleman-core/sources.rb +12 -12
  185. data/lib/middleman-core/step_definitions/builder_steps.rb +12 -38
  186. data/lib/middleman-core/step_definitions/commandline_steps.rb +6 -6
  187. data/lib/middleman-core/step_definitions/middleman_steps.rb +14 -13
  188. data/lib/middleman-core/step_definitions/server_steps.rb +16 -18
  189. data/lib/middleman-core/template_context.rb +10 -17
  190. data/lib/middleman-core/template_renderer.rb +33 -35
  191. data/lib/middleman-core/util/binary.rb +1 -3
  192. data/lib/middleman-core/util/data.rb +22 -12
  193. data/lib/middleman-core/util/files.rb +3 -3
  194. data/lib/middleman-core/util/paths.rb +44 -47
  195. data/lib/middleman-core/util/rack.rb +3 -3
  196. data/lib/middleman-core/util/uri_templates.rb +0 -1
  197. data/lib/middleman-core/util.rb +2 -2
  198. data/lib/middleman-core/version.rb +1 -1
  199. data/lib/middleman-core.rb +3 -3
  200. data/middleman-core.gemspec +13 -12
  201. data/spec/middleman-core/callbacks_spec.rb +14 -15
  202. data/spec/middleman-core/core_extensions/data_spec.rb +74 -70
  203. data/spec/middleman-core/dns_resolver_spec.rb +6 -6
  204. data/spec/middleman-core/util_spec.rb +86 -81
  205. data/spec/spec_helper.rb +6 -1
  206. data/spec/support/given.rb +15 -11
  207. metadata +59 -76
  208. data/features/multiple-sources-reload.feature +0 -40
  209. data/fixtures/chained-app/source/stylesheets/main.css.scss.erb +0 -3
  210. data/fixtures/chained-app/source/stylesheets/sub.scss +0 -1
  211. data/fixtures/destination-dir-different-from-source-dir-name/external/page.html.erb +0 -1
  212. data/fixtures/destination-dir-different-from-source-dir-name/my-app/config.rb +0 -2
  213. data/fixtures/destination-dir-different-from-source-dir-name/my-app/source/index.html.erb +0 -1
  214. data/fixtures/i18n-default-app/source/name.html.erb +0 -1
  215. data/fixtures/i18n-mixed-sources/source/c/d/index.html.erb +0 -9
  216. data/fixtures/i18n-mixed-sources/source/localizable/c/d/index.html.erb +0 -9
  217. data/fixtures/i18n-test-app/source/localizable/tac.html.erb +0 -1
  218. data/fixtures/multiple-sources-with-destination-dir/config.rb +0 -2
  219. data/fixtures/multiple-sources-with-destination-dir/external/page.html.erb +0 -1
  220. data/fixtures/multiple-sources-with-destination-dir/source/index.html.erb +0 -1
  221. data/fixtures/multiple-sources-without-destination-dir/config.rb +0 -1
  222. data/fixtures/multiple-sources-without-destination-dir/external/page.html.erb +0 -1
  223. data/fixtures/multiple-sources-without-destination-dir/source/index.html.erb +0 -1
@@ -33,7 +33,7 @@ module Middleman
33
33
  # @param [Symbol] preferred_engine
34
34
  # @return [String]
35
35
  Contract IsA['Middleman::Application'], Or[String, Symbol], Symbol => Maybe[IsA['Middleman::SourceFile']]
36
- def self.locate_layout(app, name, preferred_engine = nil)
36
+ def self.locate_layout(app, name, preferred_engine=nil)
37
37
  resolve_opts = {}
38
38
  resolve_opts[:preferred_engine] = preferred_engine unless preferred_engine.nil?
39
39
 
@@ -41,7 +41,7 @@ module Middleman
41
41
  layout_file = resolve_template(app, File.join(app.config[:layouts_dir], name.to_s), resolve_opts)
42
42
 
43
43
  # If we didn't find it, check root
44
- layout_file ||= resolve_template(app, name, resolve_opts)
44
+ layout_file = resolve_template(app, name, resolve_opts) unless layout_file
45
45
 
46
46
  # Return the path
47
47
  layout_file
@@ -52,7 +52,7 @@ module Middleman
52
52
  # @option options [Boolean] :preferred_engine If set, try this engine first, then fall back to any engine.
53
53
  # @return [String, Boolean] Either the path to the template, or false
54
54
  Contract IsA['Middleman::Application'], Or[Symbol, String], Maybe[Hash] => Maybe[IsA['Middleman::SourceFile']]
55
- def self.resolve_template(app, request_path, options = {})
55
+ def self.resolve_template(app, request_path, options={})
56
56
  # Find the path by searching
57
57
  relative_path = Util.strip_leading_slash(request_path.to_s)
58
58
 
@@ -80,12 +80,12 @@ module Middleman
80
80
 
81
81
  # Cache lookups in build mode only
82
82
  file = if app.build?
83
- cache.fetch(path_with_ext, preferred_engine) do
84
- app.files.find(:source, path_with_ext, globbing)
85
- end
86
- else
87
- app.files.find(:source, path_with_ext, globbing)
88
- end
83
+ cache.fetch(path_with_ext, preferred_engine) do
84
+ app.files.find(:source, path_with_ext, globbing)
85
+ end
86
+ else
87
+ app.files.find(:source, path_with_ext, globbing)
88
+ end
89
89
 
90
90
  found_template = file if file && (preferred_engine.nil? || ::Middleman::Util.tilt_class(file[:full_path].to_s))
91
91
  break if found_template
@@ -109,7 +109,7 @@ module Middleman
109
109
  # @param [Hash] opts
110
110
  # @return [String]
111
111
  Contract Hash, Hash => String
112
- def render(locs = {}, opts = {}, &block)
112
+ def render(locs={}, opts={}, &block)
113
113
  path = @path.dup
114
114
  locals = locs.dup.freeze
115
115
  options = opts.dup
@@ -132,7 +132,7 @@ module Middleman
132
132
  @app.extensions.add_exposed_to_context(context)
133
133
 
134
134
  locals.each do |k, _|
135
- next unless context.respond_to?(k) && !%i[current_path paginate page_articles blog_controller lang locale data].include?(k.to_sym)
135
+ next unless context.respond_to?(k) && ![:current_path, :paginate, :page_articles, :blog_controller, :lang, :locale].include?(k.to_sym)
136
136
 
137
137
  msg = "Template local `#{k}` tried to overwrite an existing context value. Please rename the key when passing to `locals`"
138
138
 
@@ -149,19 +149,16 @@ module Middleman
149
149
 
150
150
  # If we need a layout and have a layout, use it
151
151
  layout_file = fetch_layout(engine, options)
152
-
153
152
  if layout_file
154
- layout_file = fetch_layout(engine, options)
153
+ content = if layout_file = fetch_layout(engine, options)
154
+ layout_renderer = ::Middleman::FileRenderer.new(@app, layout_file[:relative_path].to_s)
155
155
 
156
- content = if layout_file
157
- layout_renderer = ::Middleman::FileRenderer.new(@app, layout_file[:relative_path].to_s)
158
-
159
- ::Middleman::Util.instrument 'builder.output.resource.render-layout', path: File.basename(layout_file[:relative_path].to_s) do
160
- layout_renderer.render(locals, options, context) { content }
161
- end
162
- else
163
- content
164
- end
156
+ ::Middleman::Util.instrument 'builder.output.resource.render-layout', path: File.basename(layout_file[:relative_path].to_s) do
157
+ layout_renderer.render(locals, options, context) { content }
158
+ end
159
+ else
160
+ content
161
+ end
165
162
  end
166
163
 
167
164
  # Return result
@@ -186,7 +183,7 @@ module Middleman
186
183
  content_renderer = ::Middleman::FileRenderer.new(@app, path)
187
184
  content = content_renderer.render(locs, opts, context, &block)
188
185
 
189
- path = path.sub(/\.[^.]*\z/, '')
186
+ path = File.basename(path, File.extname(path))
190
187
  rescue LocalJumpError
191
188
  raise "Tried to render a layout (calls yield) at #{path} like it was a template. Non-default layouts need to be in #{@app.config[:source]}/#{@app.config[:layouts_dir]}."
192
189
  end
@@ -212,24 +209,25 @@ module Middleman
212
209
  # The engine for the layout can be set in options, engine_options or passed
213
210
  # into this method
214
211
  layout_engine = if opts.key?(:layout_engine)
215
- opts[:layout_engine]
216
- elsif engine_options.key?(:layout_engine)
217
- engine_options[:layout_engine]
218
- else
219
- engine
220
- end
212
+ opts[:layout_engine]
213
+ elsif engine_options.key?(:layout_engine)
214
+ engine_options[:layout_engine]
215
+ else
216
+ engine
217
+ end
221
218
 
222
219
  # Automatic mode
223
220
  if local_layout == :_auto_layout
224
221
  # Look for :layout of any extension
225
222
  # If found, use it. If not, continue
226
223
  locate_layout(:layout, layout_engine)
227
- else
228
- layout_file = locate_layout(local_layout, layout_engine)
229
-
230
- raise ::Middleman::TemplateRenderer::TemplateNotFound, "Could not locate layout: #{local_layout}" unless layout_file
224
+ elsif layout_file = locate_layout(local_layout, layout_engine)
225
+ # Look for specific layout
226
+ # If found, use it. If not, error.
231
227
 
232
228
  layout_file
229
+ else
230
+ raise ::Middleman::TemplateRenderer::TemplateNotFound, "Could not locate layout: #{local_layout}"
233
231
  end
234
232
  end
235
233
 
@@ -238,7 +236,7 @@ module Middleman
238
236
  # @param [Symbol] preferred_engine
239
237
  # @return [String]
240
238
  Contract Or[String, Symbol], Symbol => Maybe[IsA['Middleman::SourceFile']]
241
- def locate_layout(name, preferred_engine = nil)
239
+ def locate_layout(name, preferred_engine=nil)
242
240
  self.class.locate_layout(@app, name, preferred_engine)
243
241
  end
244
242
 
@@ -247,7 +245,7 @@ module Middleman
247
245
  # @param [Hash] options
248
246
  # @return [Array<String, Symbol>, Boolean]
249
247
  Contract String, Hash => ArrayOf[Or[String, Symbol]]
250
- def resolve_template(request_path, options = {})
248
+ def resolve_template(request_path, options={})
251
249
  self.class.resolve_template(@app, request_path, options)
252
250
  end
253
251
  end
@@ -32,9 +32,7 @@ module Middleman
32
32
  else
33
33
  dot_ext = ext.to_s[0] == '.' ? ext.dup : ".#{ext}"
34
34
 
35
- mime = ::Rack::Mime.mime_type(dot_ext, nil)
36
-
37
- if mime
35
+ if mime = ::Rack::Mime.mime_type(dot_ext, nil)
38
36
  !nonbinary_mime?(mime)
39
37
  else
40
38
  file_contents_include_binary_bytes?(path.to_s)
@@ -1,6 +1,7 @@
1
1
  require 'yaml'
2
2
  require 'json'
3
3
  require 'pathname'
4
+ require 'backports/2.1.0/array/to_h'
4
5
  require 'hashie'
5
6
  require 'memoist'
6
7
 
@@ -45,7 +46,7 @@ module Middleman
45
46
  # @param [String] path
46
47
  # @return [Array<Hash, String>]
47
48
  Contract IsA['Middleman::SourceFile'], Maybe[Symbol] => [Hash, Maybe[String]]
48
- def parse(file, frontmatter_delims, known_type = nil)
49
+ def parse(file, frontmatter_delims, known_type=nil)
49
50
  full_path = file[:full_path]
50
51
  return [{}, nil] if ::Middleman::Util.binary?(full_path) || file[:types].include?(:binary)
51
52
 
@@ -109,13 +110,16 @@ module Middleman
109
110
  # @return [Hash]
110
111
  Contract String, Pathname => Hash
111
112
  def parse_yaml(content, full_path)
112
- c = ::Middleman::Util.instrument 'parse.yaml' do
113
- ::YAML.safe_load(content)
113
+ c = begin
114
+ ::Middleman::Util.instrument 'parse.yaml' do
115
+ ::YAML.load(content)
116
+ end
117
+ rescue StandardError, ::Psych::SyntaxError => error
118
+ warn "YAML Exception parsing #{full_path}: #{error.message}"
119
+ {}
114
120
  end
121
+
115
122
  c ? symbolize_recursive(c) : {}
116
- rescue StandardError, ::Psych::SyntaxError => error
117
- warn "YAML Exception parsing #{full_path}: #{error.message}"
118
- {}
119
123
  end
120
124
  memoize :parse_yaml
121
125
 
@@ -124,20 +128,26 @@ module Middleman
124
128
  # @return [Hash]
125
129
  Contract String, Pathname => Hash
126
130
  def parse_json(content, full_path)
127
- c = ::Middleman::Util.instrument 'parse.json' do
128
- ::JSON.parse(content)
131
+ c = begin
132
+ ::Middleman::Util.instrument 'parse.json' do
133
+ ::JSON.parse(content)
134
+ end
135
+ rescue StandardError => error
136
+ warn "JSON Exception parsing #{full_path}: #{error.message}"
137
+ {}
129
138
  end
139
+
130
140
  c ? symbolize_recursive(c) : {}
131
- rescue StandardError => error
132
- warn "JSON Exception parsing #{full_path}: #{error.message}"
133
- {}
134
141
  end
135
142
  memoize :parse_json
136
143
 
137
144
  def symbolize_recursive(value)
138
145
  case value
139
146
  when Hash
140
- value.map { |k, v| [k.to_sym, symbolize_recursive(v)] }.to_h
147
+ value.map do |k, v|
148
+ key = k.is_a?(String) ? k.to_sym : k
149
+ [key, symbolize_recursive(v)]
150
+ end.to_h
141
151
  when Array
142
152
  value.map { |v| symbolize_recursive(v) }
143
153
  else
@@ -6,7 +6,7 @@ module Middleman
6
6
 
7
7
  module_function
8
8
 
9
- # Get a recursive list of files inside a path.
9
+ # Get a recusive list of files inside a path.
10
10
  # Works with symlinks.
11
11
  #
12
12
  # @param path Some path string or Pathname
@@ -119,7 +119,7 @@ module Middleman
119
119
 
120
120
  all_extensions.uniq!
121
121
 
122
- app.sitemap.resources.select do |r|
122
+ app.sitemap.resources.select { |r|
123
123
  if r.file_descriptor
124
124
  local_extensions = collect_extensions(r.file_descriptor[:full_path].to_s)
125
125
  local_extensions |= sass_type_aliasing unless (local_extensions & sass_type_aliasing).empty?
@@ -131,7 +131,7 @@ module Middleman
131
131
  else
132
132
  false
133
133
  end
134
- end.map(&:file_descriptor)
134
+ }.map(&:file_descriptor)
135
135
  end
136
136
  end
137
137
  end
@@ -7,6 +7,7 @@ require 'tilt'
7
7
 
8
8
  require 'middleman-core/contracts'
9
9
 
10
+ # rubocop:disable ModuleLength
10
11
  module Middleman
11
12
  module Util
12
13
  extend Memoist
@@ -71,24 +72,24 @@ module Middleman
71
72
  # @param [Hash] options Data to pass through.
72
73
  # @return [String]
73
74
  Contract ::Middleman::Application, Symbol, Or[String, Symbol], Hash => String
74
- def asset_path(app, kind, source, options = {})
75
+ def asset_path(app, kind, source, options={})
75
76
  return source if source.to_s.include?('//') || source.to_s.start_with?('data:')
76
77
 
77
78
  asset_folder = case kind
78
- when :css
79
- app.config[:css_dir]
80
- when :js
81
- app.config[:js_dir]
82
- when :images
83
- app.config[:images_dir]
84
- when :fonts
85
- app.config[:fonts_dir]
86
- else
87
- kind.to_s
88
- end
79
+ when :css
80
+ app.config[:css_dir]
81
+ when :js
82
+ app.config[:js_dir]
83
+ when :images
84
+ app.config[:images_dir]
85
+ when :fonts
86
+ app.config[:fonts_dir]
87
+ else
88
+ kind.to_s
89
+ end
89
90
 
90
91
  source = source.to_s.tr(' ', '')
91
- ignore_extension = %i[images fonts].include? kind # don't append extension
92
+ ignore_extension = (kind == :images || kind == :fonts) # don't append extension
92
93
  source << ".#{kind}" unless ignore_extension || source.end_with?(".#{kind}")
93
94
  asset_folder = '' if source.start_with?('/') # absolute path
94
95
 
@@ -102,7 +103,7 @@ module Middleman
102
103
  # @param [Hash] options Data to pass through.
103
104
  # @return [String] The fully qualified asset url
104
105
  Contract ::Middleman::Application, String, String, Hash => String
105
- def asset_url(app, path, prefix = '', options = {})
106
+ def asset_url(app, path, prefix='', options={})
106
107
  # Don't touch assets which already have a full path
107
108
  return path if path.include?('//') || path.start_with?('data:')
108
109
 
@@ -117,20 +118,18 @@ module Middleman
117
118
  # relative path, since it only takes absolute url paths.
118
119
  dest_path = url_for(app, path, options.merge(relative: false))
119
120
 
120
- resource = app.sitemap.find_resource_by_path(dest_path) || app.sitemap.find_resource_by_destination_path(dest_path)
121
-
122
- result = if resource
123
- resource.url
124
- else
125
- path = ::File.join(prefix, path)
126
- resource = app.sitemap.find_resource_by_path(path)
127
-
128
- if resource
129
- resource.url
130
- else
131
- ::File.join(app.config[:http_prefix], path)
132
- end
133
- end
121
+ result = if resource = app.sitemap.find_resource_by_path(dest_path)
122
+ resource.url
123
+ elsif resource = app.sitemap.find_resource_by_destination_path(dest_path)
124
+ resource.url
125
+ else
126
+ path = ::File.join(prefix, path)
127
+ if resource = app.sitemap.find_resource_by_path(path)
128
+ resource.url
129
+ else
130
+ ::File.join(app.config[:http_prefix], path)
131
+ end
132
+ end
134
133
 
135
134
  final_result = ::Addressable::URI.encode(
136
135
  relative_path_from_resource(
@@ -150,19 +149,19 @@ module Middleman
150
149
  # or a Resource, this will produce the nice URL configured for that
151
150
  # path, respecting :relative_links, directory indexes, etc.
152
151
  Contract ::Middleman::Application, Or[String, Symbol, ::Middleman::Sitemap::Resource], Hash => String
153
- def url_for(app, path_or_resource, options = {})
152
+ def url_for(app, path_or_resource, options={})
154
153
  if path_or_resource.is_a?(String) || path_or_resource.is_a?(Symbol)
155
154
  r = app.sitemap.find_resource_by_page_id(path_or_resource)
156
155
 
157
- path_or_resource = r || path_or_resource.to_s
156
+ path_or_resource = r ? r : path_or_resource.to_s
158
157
  end
159
158
 
160
159
  # Handle Resources and other things which define their own url method
161
160
  url = if path_or_resource.respond_to?(:url)
162
- path_or_resource.url
163
- else
164
- path_or_resource.dup
165
- end
161
+ path_or_resource.url
162
+ else
163
+ path_or_resource.dup
164
+ end
166
165
 
167
166
  # Try to parse URL
168
167
  begin
@@ -210,22 +209,20 @@ module Middleman
210
209
 
211
210
  if resource
212
211
  uri.path = if this_resource
213
- ::Addressable::URI.encode(
214
- relative_path_from_resource(
215
- this_resource,
216
- resource_url,
217
- effective_relative
218
- )
219
- )
220
- else
221
- resource_url
222
- end
212
+ ::Addressable::URI.encode(
213
+ relative_path_from_resource(
214
+ this_resource,
215
+ resource_url,
216
+ effective_relative
217
+ )
218
+ )
219
+ else
220
+ resource_url
221
+ end
223
222
  end
224
223
 
225
224
  # Support a :query option that can be a string or hash
226
- query = options[:query]
227
-
228
- if query
225
+ if query = options[:query]
229
226
  uri.query = query.respond_to?(:to_param) ? query.to_param : query.to_s
230
227
  end
231
228
 
@@ -27,8 +27,8 @@ module Middleman
27
27
  url_fn_prefix = 'url('
28
28
 
29
29
  body.dup.gsub(matcher) do |match|
30
- opening_character = Regexp.last_match(1)
31
- asset_path = Regexp.last_match(2)
30
+ opening_character = $1
31
+ asset_path = $2
32
32
 
33
33
  if asset_path.start_with?(url_fn_prefix)
34
34
  opening_character << url_fn_prefix
@@ -40,7 +40,7 @@ module Middleman
40
40
  begin
41
41
  uri = ::Middleman::Util.parse_uri(asset_path)
42
42
 
43
- if uri.relative? && uri.host.nil? && asset_path !~ /^[^\/].*[a-z]+\.[a-z]+\/.*/
43
+ if uri.relative? && uri.host.nil? && !(asset_path =~ /^[^\/].*[a-z]+\.[a-z]+\/.*/)
44
44
  dest_path = ::Middleman::Util.url_for(app, asset_path, relative: false, current_resource: current_resource)
45
45
 
46
46
  resource = app.sitemap.find_resource_by_destination_path(dest_path)
@@ -54,7 +54,6 @@ module Middleman
54
54
 
55
55
  parameterized_string.chars.to_a.each_with_index do |char, i|
56
56
  next unless char == '?' && str[i].bytes.count != 1
57
-
58
57
  parameterized_string[i] = str[i]
59
58
  end
60
59
 
@@ -16,8 +16,8 @@ module Middleman
16
16
  module_function
17
17
 
18
18
  # Facade for ActiveSupport/Notification
19
- def instrument(name, payload = {}, &block)
20
- suffixed_name = /\.middleman$/.match?(name) ? name.dup : "#{name}.middleman"
19
+ def instrument(name, payload={}, &block)
20
+ suffixed_name = name =~ /\.middleman$/ ? name.dup : "#{name}.middleman"
21
21
  ::ActiveSupport::Notifications.instrument(suffixed_name, payload, &block)
22
22
  end
23
23
  end
@@ -1,5 +1,5 @@
1
1
  module Middleman
2
2
  # Current Version
3
3
  # @return [String]
4
- VERSION = '4.3.0.rc.4'.freeze unless const_defined?(:VERSION)
4
+ VERSION = '4.3.0'.freeze unless const_defined?(:VERSION)
5
5
  end
@@ -1,9 +1,9 @@
1
+ # rubocop:disable FileName
2
+
1
3
  # Setup our load paths
2
- libdir = __dir__
4
+ libdir = File.expand_path(File.dirname(__FILE__))
3
5
  $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
4
6
 
5
- require 'backports/latest'
6
-
7
7
  # Top-level Middleman namespace
8
8
  module Middleman
9
9
  autoload :Application, 'middleman-core/application'
@@ -11,49 +11,50 @@ Gem::Specification.new do |s|
11
11
  s.email = ['me@tdreyno.com', 'ben@benhollis.net', 'karlfreeman@gmail.com']
12
12
  s.homepage = 'http://middlemanapp.com'
13
13
  s.summary = 'Hand-crafted frontend development'
14
- s.description = 'A static site generator. Provides dozens of templating languages (Haml, Sass, Slim, CoffeeScript, and more). Makes minification, compression, cache busting, Yaml data (and more) an easy part of your development cycle.'
14
+ s.description = 'A static site generator. Provides dozens of templating languages (Haml, Sass, Compass, Slim, CoffeeScript, and more). Makes minification, compression, cache busting, Yaml data (and more) an easy part of your development cycle.'
15
15
 
16
16
  s.files = `git ls-files -z`.split("\0")
17
17
  s.test_files = `git ls-files -z -- {fixtures,features}/*`.split("\0")
18
18
  s.require_path = 'lib'
19
- s.required_ruby_version = '>= 2.3.0'
19
+ s.required_ruby_version = '>= 2.2.0'
20
20
 
21
21
  # Core
22
- s.add_dependency('bundler', ['~> 1.1'])
22
+ s.add_dependency('bundler')
23
23
  s.add_dependency('rack', ['>= 1.4.5', '< 3'])
24
- s.add_dependency('tilt', ['~> 2.0'])
24
+ s.add_dependency('tilt', ['~> 2.0.9'])
25
25
  s.add_dependency('erubis')
26
+ s.add_dependency('fast_blank')
26
27
  s.add_dependency('parallel')
27
28
  s.add_dependency('servolux')
28
29
  s.add_dependency('dotenv')
29
30
 
30
31
  # Helpers
31
- s.add_dependency('activesupport', ['>= 4.2', '< 5.2'])
32
+ s.add_dependency('activesupport', ['>= 4.2', '< 5.1'])
32
33
  s.add_dependency('padrino-helpers', ['~> 0.13.0'])
33
- s.add_dependency('addressable', ['~> 2.3'])
34
+ s.add_dependency("addressable", ["~> 2.3"])
34
35
  s.add_dependency('memoist', ['~> 0.14'])
35
- s.add_dependency('backports', ['~> 3.11'])
36
36
 
37
37
  # Watcher
38
- s.add_dependency('listen', ['~> 3.0'])
38
+ s.add_dependency('listen', ['~> 3.0.0'])
39
39
 
40
40
  # i18n
41
- s.add_dependency('i18n', ['~> 0.7'])
41
+ s.add_dependency('i18n', ['~> 0.9.0'])
42
42
 
43
43
  # Automatic Image Sizes
44
44
  s.add_dependency('fastimage', ['~> 2.0'])
45
45
 
46
- # Minify CSS
47
- s.add_dependency('sass', ['>= 3.4'])
46
+ # Sass and Minify CSS
47
+ s.add_dependency('sassc', ['~> 2.0'])
48
48
 
49
49
  # Minify JS
50
50
  s.add_dependency('uglifier', ['~> 3.0'])
51
51
  s.add_dependency('execjs', ['~> 2.0'])
52
52
 
53
53
  # Testing
54
- s.add_dependency('contracts', ['~> 0.16.0'])
54
+ s.add_dependency('contracts', ['~> 0.13.0'])
55
55
 
56
56
  # Hash stuff
57
57
  s.add_dependency('hashie', ['~> 3.4'])
58
58
  s.add_dependency('hamster', ['~> 3.0'])
59
+ s.add_dependency('backports', ['~> 3.6'])
59
60
  end
@@ -2,7 +2,7 @@
2
2
  require 'middleman-core/callback_manager'
3
3
 
4
4
  describe ::Middleman::CallbackManager do
5
- it 'adds a simple key' do
5
+ it "adds a simple key" do
6
6
  counters = {
7
7
  test1: 0,
8
8
  test2: 0,
@@ -26,7 +26,7 @@ describe ::Middleman::CallbackManager do
26
26
  expect(counters[:test3]).to eq 0
27
27
  end
28
28
 
29
- it 'callbacks run in order' do
29
+ it "callbacks run in order" do
30
30
  result = []
31
31
 
32
32
  m = ::Middleman::CallbackManager.new
@@ -39,24 +39,24 @@ describe ::Middleman::CallbackManager do
39
39
  expect(result.join('')).to eq '123'
40
40
  end
41
41
 
42
- it 'adds a nested key' do
42
+ it "adds a nested key" do
43
43
  counters = {
44
44
  test1: 0,
45
45
  test1a: 0
46
46
  }
47
47
 
48
48
  m = ::Middleman::CallbackManager.new
49
- m.add(%i[test1 a]) { |n| counters[:test1a] += n }
49
+ m.add([:test1, :a]) { |n| counters[:test1a] += n }
50
50
  m.add(:test1) { counters[:test1] += 1 }
51
51
 
52
- m.execute(%i[test1 a], [2])
53
- m.execute(%i[test1 b], [5])
52
+ m.execute([:test1, :a], [2])
53
+ m.execute([:test1, :b], [5])
54
54
 
55
55
  expect(counters[:test1]).to eq 0
56
56
  expect(counters[:test1a]).to eq 2
57
57
  end
58
58
 
59
- it 'works in isolation' do
59
+ it "works in isolation" do
60
60
  m1 = ::Middleman::CallbackManager.new
61
61
  m2 = ::Middleman::CallbackManager.new
62
62
 
@@ -77,7 +77,7 @@ describe ::Middleman::CallbackManager do
77
77
  expect(counters[:test2]).to eq 5
78
78
  end
79
79
 
80
- it 'installs to arbitrary instances' do
80
+ it "installs to arbitrary instances" do
81
81
  instance = Class.new(Object).new
82
82
 
83
83
  m = ::Middleman::CallbackManager.new
@@ -88,11 +88,11 @@ describe ::Middleman::CallbackManager do
88
88
  instance.execute_callbacks(:ready, [2])
89
89
  instance.execute_callbacks(:ready2, [10])
90
90
  instance.execute_callbacks([:ready], [20])
91
- instance.execute_callbacks(%i[ready two], [20])
91
+ instance.execute_callbacks([:ready, :two], [20])
92
92
  expect(counter).to eq 2
93
93
  end
94
94
 
95
- it 'executes in default scope' do
95
+ it "executes in default scope" do
96
96
  instance = Class.new(Object).new
97
97
  m = ::Middleman::CallbackManager.new
98
98
  m.install_methods!(instance, [:ready])
@@ -104,12 +104,10 @@ describe ::Middleman::CallbackManager do
104
104
 
105
105
  instance.execute_callbacks(:ready)
106
106
 
107
- # rubocop:disable Style/CaseEquality
108
107
  expect(internal_self) === instance
109
- # rubocop:enable Style/CaseEquality
110
108
  end
111
109
 
112
- it 'executes in custom scope' do
110
+ it "executes in custom scope" do
113
111
  instance = Class.new(Object).new
114
112
  m = ::Middleman::CallbackManager.new
115
113
  m.install_methods!(instance, [:ready])
@@ -126,8 +124,9 @@ describe ::Middleman::CallbackManager do
126
124
  instance.ready(&external_instance.method(:when_ready))
127
125
 
128
126
  instance.execute_callbacks(:ready, [5])
129
-
127
+
130
128
  expect(external_instance[:scope]).to eq external_instance
131
129
  expect(external_instance[:counter]).to eq 5
132
130
  end
133
- end
131
+
132
+ end