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.
- checksums.yaml +4 -4
- data/cucumber.yml +2 -2
- data/features/builder.feature +1 -1
- data/features/chained_templates.feature +0 -7
- data/features/coffee-script.feature +1 -1
- data/features/collections.feature +2 -2
- data/features/console.feature +1 -1
- data/features/data.feature +31 -0
- data/features/extension_api_deprecations.feature +3 -1
- data/features/extension_hooks.feature +3 -1
- data/features/helpers_external.feature +1 -17
- data/features/i18n_link_to.feature +0 -23
- data/features/i18n_mixed_sources.feature +0 -8
- data/features/i18n_preview.feature +1 -30
- data/features/ignore.feature +11 -67
- data/features/ignore_already_minified.feature +1 -1
- data/features/markdown.feature +1 -0
- data/features/minify_javascript.feature +35 -35
- data/features/mount_rack.feature +0 -1
- data/features/page-id.feature +2 -2
- data/features/partials.feature +1 -1
- data/features/relative_assets_helpers_only.feature +6 -4
- data/features/scss-support.feature +6 -1
- data/features/support/env.rb +5 -5
- data/features/tilde_directories.feature +2 -0
- data/features/unicode_filenames.feature +1 -1
- data/fixtures/asset-hash-app/config.rb +1 -0
- data/fixtures/asset-hash-app/lib/middleware.rb +2 -2
- data/fixtures/asset-hash-app/source/stylesheets/_partial.sass +1 -1
- data/fixtures/asset-hash-minified-app/config.rb +1 -1
- data/fixtures/asset-hash-prefix/config.rb +2 -1
- data/fixtures/asset-hash-prefix/lib/middleware.rb +2 -2
- data/fixtures/asset-hash-source-map/config.rb +1 -0
- data/fixtures/asset-hash-source-map/lib/middleware.rb +2 -2
- data/fixtures/asset-host-app/config.rb +1 -1
- data/fixtures/auto-css-app/config.rb +2 -2
- data/fixtures/auto-js-app/config.rb +2 -2
- data/fixtures/auto-js-directory-index-app/config.rb +1 -1
- data/fixtures/automatic-directory-matcher-app/config.rb +1 -1
- data/fixtures/basic-data-app/config.rb +2 -2
- data/fixtures/capture-html-app/config.rb +4 -4
- data/fixtures/clean-app/config-complications.rb +6 -6
- data/fixtures/clean-app/config-hidden-dir-after.rb +4 -4
- data/fixtures/clean-app/config-hidden-dir-before.rb +1 -1
- data/fixtures/clean-app/config.rb +6 -6
- data/fixtures/clean-dir-app/config.rb +1 -0
- data/fixtures/clean-nested-app/config.rb +1 -1
- data/fixtures/collections-app/source/blog1/2011-01-01-new-article.html.markdown +1 -1
- data/fixtures/collections-app/source/blog1/2011-01-02-another-article.html.markdown +1 -1
- data/fixtures/collections-app/source/blog2/2011-01-01-new-article.html.markdown +1 -1
- data/fixtures/collections-app/source/blog2/2011-01-02-another-article.html.markdown +1 -1
- data/fixtures/content-for-app/config.rb +4 -4
- data/fixtures/dynamic-pages-app/config.rb +26 -25
- data/fixtures/ember-cli-app/config.rb +4 -4
- data/fixtures/env-app/environments/development.rb +1 -1
- data/fixtures/env-app/environments/production.rb +1 -1
- data/fixtures/env-app/source/stylesheets/site.css.scss +1 -1
- data/fixtures/extension-hooks-app/config.rb +8 -8
- data/fixtures/external-helpers/config.rb +2 -2
- data/fixtures/external-helpers/helpers/derp.rb +1 -3
- data/fixtures/external-helpers/helpers/four_helpers.rb +1 -3
- data/fixtures/external-helpers/helpers/one_helper.rb +1 -3
- data/fixtures/external-helpers/helpers/yet_another_thingy.rb +1 -3
- data/fixtures/external-helpers/lib/hello_helper.rb +1 -1
- data/fixtures/external-pipeline-error/config.rb +4 -4
- data/fixtures/feature-params-app/config.rb +1 -1
- data/fixtures/frontmatter-app/config.rb +1 -1
- data/fixtures/generator-test/config.rb +15 -1
- data/fixtures/glob-app/config.rb +1 -1
- data/fixtures/i-8859-1-app/config.rb +1 -1
- data/fixtures/i18n-force-locale/config.rb +4 -4
- data/fixtures/i18n-mixed-sources/config.rb +1 -1
- data/fixtures/i18n-test-app/locales/en.yml +1 -7
- data/fixtures/i18n-test-app/locales/es.yml +1 -2
- data/fixtures/import-app/config.rb +3 -3
- data/fixtures/indexable-app/config.rb +3 -3
- data/fixtures/large-build-app/config.rb +1 -1
- data/fixtures/manual-layout-override/config.rb +1 -1
- data/fixtures/missing-tilt-library-app/config.rb +2 -2
- data/fixtures/more-traversal-app/config.rb +4 -4
- data/fixtures/multiple-data-sources-app/config.rb +1 -1
- data/fixtures/multiple-sources-app/config.rb +1 -1
- data/fixtures/multiple-sources-with-duplicate-file-names-app/config.rb +1 -1
- data/fixtures/nested-layout-app/source/another.html.markdown +1 -1
- data/fixtures/nested-layout-app/source/haml-test.html.markdown +1 -1
- data/fixtures/nested-layout-app/source/slim-test.html.markdown +1 -1
- data/fixtures/padrino-helpers-app/config.rb +1 -1
- data/fixtures/page-classes-app/config.rb +2 -2
- data/fixtures/page-helper-layout-block-app/config.rb +1 -1
- data/fixtures/page-id-app/config-proc.rb +4 -4
- data/fixtures/page-id-app/config.rb +3 -3
- data/fixtures/page-id-app/source/{forty-two.html.erb → fourty-two.html.erb} +0 -0
- data/fixtures/paginate-app/source/blog/2011-01-01-test-article.html.markdown +1 -1
- data/fixtures/paginate-app/source/blog/2011-01-02-test-article.html.markdown +1 -1
- data/fixtures/paginate-app/source/blog/2011-01-03-test-article.html.markdown +1 -1
- data/fixtures/paginate-app/source/blog/2011-01-04-test-article.html.markdown +1 -1
- data/fixtures/paginate-app/source/blog/2011-01-05-test-article.html.markdown +1 -1
- data/fixtures/paginate-app/source/blog/2011-02-01-test-article.html.markdown +1 -1
- data/fixtures/paginate-app/source/blog/2011-02-02-test-article.html.markdown +1 -1
- data/fixtures/partials-app/source/_locals.erb +1 -1
- data/fixtures/partials-app/source/locals.html.erb +1 -1
- data/fixtures/proxy-pages-app/config.rb +14 -13
- data/fixtures/sass-assets-path-app/config.rb +2 -2
- data/fixtures/scss-app/source/stylesheets/error.css.sass +1 -0
- data/fixtures/sinatra-app/config.rb +6 -6
- data/fixtures/traversal-app/config.rb +4 -4
- data/fixtures/v4-extension-callbacks/config.rb +2 -2
- data/fixtures/wildcard-app/config.rb +1 -1
- data/fixtures/wildcard-directory-index-app/config.rb +1 -1
- data/lib/middleman/rack.rb +7 -0
- data/lib/middleman-core/application.rb +9 -10
- data/lib/middleman-core/builder.rb +21 -50
- data/lib/middleman-core/callback_manager.rb +1 -1
- data/lib/middleman-core/config_context.rb +2 -2
- data/lib/middleman-core/configuration.rb +5 -5
- data/lib/middleman-core/contracts.rb +2 -2
- data/lib/middleman-core/core_extensions/collections/lazy_root.rb +1 -1
- data/lib/middleman-core/core_extensions/collections/lazy_step.rb +9 -9
- data/lib/middleman-core/core_extensions/collections/pagination.rb +6 -6
- data/lib/middleman-core/core_extensions/collections.rb +1 -1
- data/lib/middleman-core/core_extensions/data.rb +11 -11
- data/lib/middleman-core/core_extensions/default_helpers.rb +29 -26
- data/lib/middleman-core/core_extensions/external_helpers.rb +1 -1
- data/lib/middleman-core/core_extensions/file_watcher.rb +1 -1
- data/lib/middleman-core/core_extensions/front_matter.rb +3 -3
- data/lib/middleman-core/core_extensions/i18n.rb +23 -44
- data/lib/middleman-core/core_extensions/inline_url_rewriter.rb +7 -10
- data/lib/middleman-core/core_extensions/routing.rb +1 -1
- data/lib/middleman-core/core_extensions.rb +2 -2
- data/lib/middleman-core/dns_resolver/basic_network_resolver.rb +3 -3
- data/lib/middleman-core/dns_resolver/hosts_resolver.rb +1 -1
- data/lib/middleman-core/dns_resolver/local_link_resolver.rb +1 -1
- data/lib/middleman-core/dns_resolver/network_resolver.rb +1 -1
- data/lib/middleman-core/dns_resolver.rb +1 -1
- data/lib/middleman-core/extension.rb +32 -34
- data/lib/middleman-core/extension_manager.rb +2 -6
- data/lib/middleman-core/extensions/asset_hash.rb +22 -24
- data/lib/middleman-core/extensions/asset_host.rb +10 -10
- data/lib/middleman-core/extensions/automatic_alt_tags.rb +1 -1
- data/lib/middleman-core/extensions/automatic_image_sizes.rb +3 -3
- data/lib/middleman-core/extensions/cache_buster.rb +2 -2
- data/lib/middleman-core/extensions/directory_indexes.rb +1 -1
- data/lib/middleman-core/extensions/external_pipeline.rb +9 -14
- data/lib/middleman-core/extensions/gzip.rb +6 -8
- data/lib/middleman-core/extensions/lorem.rb +9 -9
- data/lib/middleman-core/extensions/minify_css.rb +16 -14
- data/lib/middleman-core/extensions/minify_javascript.rb +13 -13
- data/lib/middleman-core/extensions/relative_assets.rb +8 -8
- data/lib/middleman-core/extensions.rb +7 -8
- data/lib/middleman-core/file_renderer.rb +6 -7
- data/lib/middleman-core/load_paths.rb +10 -13
- data/lib/middleman-core/logger.rb +4 -3
- data/lib/middleman-core/meta_pages/sitemap_resource.rb +2 -0
- data/lib/middleman-core/meta_pages/sitemap_tree.rb +1 -1
- data/lib/middleman-core/meta_pages.rb +1 -1
- data/lib/middleman-core/preview_server/checks.rb +1 -1
- data/lib/middleman-core/preview_server/information.rb +13 -13
- data/lib/middleman-core/preview_server/network_interface_inventory.rb +3 -3
- data/lib/middleman-core/preview_server/server_information.rb +1 -1
- data/lib/middleman-core/preview_server/server_information_callback_proxy.rb +1 -1
- data/lib/middleman-core/preview_server/server_url.rb +1 -1
- data/lib/middleman-core/preview_server/tcp_port_prober.rb +1 -1
- data/lib/middleman-core/preview_server.rb +25 -25
- data/lib/middleman-core/rack.rb +1 -1
- data/lib/middleman-core/renderers/coffee_script.rb +2 -2
- data/lib/middleman-core/renderers/haml.rb +4 -8
- data/lib/middleman-core/renderers/less.rb +1 -1
- data/lib/middleman-core/renderers/liquid.rb +2 -3
- data/lib/middleman-core/renderers/markdown.rb +7 -7
- data/lib/middleman-core/renderers/redcarpet.rb +2 -2
- data/lib/middleman-core/renderers/sass.rb +23 -26
- data/lib/middleman-core/renderers/sass_functions.rb +14 -17
- data/lib/middleman-core/renderers/slim.rb +2 -2
- data/lib/middleman-core/sitemap/extensions/ignores.rb +4 -2
- data/lib/middleman-core/sitemap/extensions/import.rb +1 -1
- data/lib/middleman-core/sitemap/extensions/on_disk.rb +1 -1
- data/lib/middleman-core/sitemap/extensions/proxies.rb +1 -2
- data/lib/middleman-core/sitemap/extensions/redirects.rb +1 -1
- data/lib/middleman-core/sitemap/extensions/request_endpoints.rb +1 -1
- data/lib/middleman-core/sitemap/extensions/traversal.rb +25 -80
- data/lib/middleman-core/sitemap/resource.rb +20 -21
- data/lib/middleman-core/sitemap/store.rb +6 -6
- data/lib/middleman-core/sources/source_watcher.rb +11 -17
- data/lib/middleman-core/sources.rb +12 -12
- data/lib/middleman-core/step_definitions/builder_steps.rb +12 -38
- data/lib/middleman-core/step_definitions/commandline_steps.rb +6 -6
- data/lib/middleman-core/step_definitions/middleman_steps.rb +14 -13
- data/lib/middleman-core/step_definitions/server_steps.rb +16 -18
- data/lib/middleman-core/template_context.rb +10 -17
- data/lib/middleman-core/template_renderer.rb +33 -35
- data/lib/middleman-core/util/binary.rb +1 -3
- data/lib/middleman-core/util/data.rb +22 -12
- data/lib/middleman-core/util/files.rb +3 -3
- data/lib/middleman-core/util/paths.rb +44 -47
- data/lib/middleman-core/util/rack.rb +3 -3
- data/lib/middleman-core/util/uri_templates.rb +0 -1
- data/lib/middleman-core/util.rb +2 -2
- data/lib/middleman-core/version.rb +1 -1
- data/lib/middleman-core.rb +3 -3
- data/middleman-core.gemspec +13 -12
- data/spec/middleman-core/callbacks_spec.rb +14 -15
- data/spec/middleman-core/core_extensions/data_spec.rb +74 -70
- data/spec/middleman-core/dns_resolver_spec.rb +6 -6
- data/spec/middleman-core/util_spec.rb +86 -81
- data/spec/spec_helper.rb +6 -1
- data/spec/support/given.rb +15 -11
- metadata +59 -76
- data/features/multiple-sources-reload.feature +0 -40
- data/fixtures/chained-app/source/stylesheets/main.css.scss.erb +0 -3
- data/fixtures/chained-app/source/stylesheets/sub.scss +0 -1
- data/fixtures/destination-dir-different-from-source-dir-name/external/page.html.erb +0 -1
- data/fixtures/destination-dir-different-from-source-dir-name/my-app/config.rb +0 -2
- data/fixtures/destination-dir-different-from-source-dir-name/my-app/source/index.html.erb +0 -1
- data/fixtures/i18n-default-app/source/name.html.erb +0 -1
- data/fixtures/i18n-mixed-sources/source/c/d/index.html.erb +0 -9
- data/fixtures/i18n-mixed-sources/source/localizable/c/d/index.html.erb +0 -9
- data/fixtures/i18n-test-app/source/localizable/tac.html.erb +0 -1
- data/fixtures/multiple-sources-with-destination-dir/config.rb +0 -2
- data/fixtures/multiple-sources-with-destination-dir/external/page.html.erb +0 -1
- data/fixtures/multiple-sources-with-destination-dir/source/index.html.erb +0 -1
- data/fixtures/multiple-sources-without-destination-dir/config.rb +0 -1
- data/fixtures/multiple-sources-without-destination-dir/external/page.html.erb +0 -1
- 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
|
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
|
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
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
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
|
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) &&
|
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
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
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.
|
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
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
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
|
-
|
228
|
-
|
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
|
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
|
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 =
|
113
|
-
::
|
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 =
|
128
|
-
::
|
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
|
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
|
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
|
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
|
-
|
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
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
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 =
|
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
|
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)
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
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
|
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
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
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
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
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 =
|
31
|
-
asset_path =
|
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
|
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)
|
data/lib/middleman-core/util.rb
CHANGED
@@ -16,8 +16,8 @@ module Middleman
|
|
16
16
|
module_function
|
17
17
|
|
18
18
|
# Facade for ActiveSupport/Notification
|
19
|
-
def instrument(name, payload
|
20
|
-
suffixed_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
|
data/lib/middleman-core.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
+
# rubocop:disable FileName
|
2
|
+
|
1
3
|
# Setup our load paths
|
2
|
-
libdir =
|
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'
|
data/middleman-core.gemspec
CHANGED
@@ -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.
|
19
|
+
s.required_ruby_version = '>= 2.2.0'
|
20
20
|
|
21
21
|
# Core
|
22
|
-
s.add_dependency('bundler'
|
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.
|
32
|
+
s.add_dependency('activesupport', ['>= 4.2', '< 5.1'])
|
32
33
|
s.add_dependency('padrino-helpers', ['~> 0.13.0'])
|
33
|
-
s.add_dependency(
|
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.
|
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('
|
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.
|
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
|
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
|
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
|
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(
|
49
|
+
m.add([:test1, :a]) { |n| counters[:test1a] += n }
|
50
50
|
m.add(:test1) { counters[:test1] += 1 }
|
51
51
|
|
52
|
-
m.execute(
|
53
|
-
m.execute(
|
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
|
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
|
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(
|
91
|
+
instance.execute_callbacks([:ready, :two], [20])
|
92
92
|
expect(counter).to eq 2
|
93
93
|
end
|
94
94
|
|
95
|
-
it
|
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
|
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
|
-
|
131
|
+
|
132
|
+
end
|