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.
- checksums.yaml +5 -5
- data/Rakefile +0 -1
- data/cucumber.yml +2 -2
- data/features/asset_hash.feature +2 -2
- data/features/collections.feature +2 -2
- data/features/i18n_mixed_sources.feature +8 -0
- data/features/markdown.feature +0 -1
- data/features/multiple-sources-reload.feature +40 -0
- data/features/partials.feature +1 -1
- data/features/support/env.rb +4 -1
- data/features/tilde_directories.feature +0 -2
- data/features/unicode_filenames.feature +1 -1
- data/fixtures/asset-hash-app/config.rb +0 -1
- 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-prefix/config.rb +1 -2
- data/fixtures/asset-hash-prefix/lib/middleware.rb +2 -2
- data/fixtures/asset-hash-source-map/config.rb +0 -1
- 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 +0 -1
- 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/destination-dir-different-from-source-dir-name/external/page.html.erb +1 -0
- data/fixtures/destination-dir-different-from-source-dir-name/my-app/config.rb +2 -0
- data/fixtures/destination-dir-different-from-source-dir-name/my-app/source/index.html.erb +1 -0
- data/fixtures/dynamic-pages-app/config.rb +25 -26
- 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/extension-hooks-app/config.rb +8 -8
- data/fixtures/external-helpers/config.rb +2 -2
- data/fixtures/external-helpers/helpers/derp.rb +3 -1
- data/fixtures/external-helpers/helpers/four_helpers.rb +3 -1
- data/fixtures/external-helpers/helpers/one_helper.rb +3 -1
- data/fixtures/external-helpers/helpers/yet_another_thingy.rb +3 -1
- 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/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-mixed-sources/source/c/d/index.html.erb +9 -0
- data/fixtures/i18n-mixed-sources/source/localizable/c/d/index.html.erb +9 -0
- 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-destination-dir/config.rb +2 -0
- data/fixtures/multiple-sources-with-destination-dir/external/page.html.erb +1 -0
- data/fixtures/multiple-sources-with-destination-dir/source/index.html.erb +1 -0
- data/fixtures/multiple-sources-with-duplicate-file-names-app/config.rb +1 -1
- data/fixtures/multiple-sources-without-destination-dir/config.rb +1 -0
- data/fixtures/multiple-sources-without-destination-dir/external/page.html.erb +1 -0
- data/fixtures/multiple-sources-without-destination-dir/source/index.html.erb +1 -0
- 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/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 +13 -14
- data/fixtures/sass-assets-path-app/config.rb +2 -2
- 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-core.rb +3 -3
- data/lib/middleman-core/application.rb +5 -5
- data/lib/middleman-core/builder.rb +20 -20
- 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.rb +1 -1
- 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/data.rb +10 -10
- data/lib/middleman-core/core_extensions/default_helpers.rb +26 -22
- 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 +24 -24
- data/lib/middleman-core/core_extensions/inline_url_rewriter.rb +10 -7
- data/lib/middleman-core/core_extensions/routing.rb +1 -1
- data/lib/middleman-core/dns_resolver.rb +1 -1
- 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/extension.rb +26 -25
- data/lib/middleman-core/extension_manager.rb +1 -1
- data/lib/middleman-core/extensions.rb +8 -7
- data/lib/middleman-core/extensions/asset_hash.rb +24 -22
- 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 +14 -9
- data/lib/middleman-core/extensions/gzip.rb +7 -5
- data/lib/middleman-core/extensions/lorem.rb +9 -9
- data/lib/middleman-core/extensions/minify_css.rb +9 -9
- data/lib/middleman-core/extensions/minify_javascript.rb +10 -10
- data/lib/middleman-core/extensions/relative_assets.rb +8 -8
- data/lib/middleman-core/file_renderer.rb +6 -5
- data/lib/middleman-core/load_paths.rb +10 -10
- data/lib/middleman-core/logger.rb +2 -3
- data/lib/middleman-core/meta_pages.rb +1 -1
- data/lib/middleman-core/preview_server.rb +21 -22
- 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_url.rb +1 -1
- data/lib/middleman-core/preview_server/tcp_port_prober.rb +1 -1
- 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 +1 -4
- data/lib/middleman-core/renderers/less.rb +1 -1
- data/lib/middleman-core/renderers/liquid.rb +2 -1
- 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 +5 -5
- data/lib/middleman-core/renderers/sass_functions.rb +5 -5
- data/lib/middleman-core/renderers/slim.rb +2 -2
- data/lib/middleman-core/sitemap/extensions/ignores.rb +2 -4
- 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 +2 -1
- 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 +80 -25
- data/lib/middleman-core/sitemap/resource.rb +21 -20
- data/lib/middleman-core/sitemap/store.rb +3 -3
- data/lib/middleman-core/sources.rb +12 -12
- data/lib/middleman-core/sources/source_watcher.rb +16 -10
- data/lib/middleman-core/step_definitions/builder_steps.rb +23 -23
- data/lib/middleman-core/step_definitions/commandline_steps.rb +5 -5
- data/lib/middleman-core/step_definitions/middleman_steps.rb +13 -14
- data/lib/middleman-core/step_definitions/server_steps.rb +14 -16
- data/lib/middleman-core/template_context.rb +17 -10
- data/lib/middleman-core/template_renderer.rb +34 -32
- data/lib/middleman-core/util.rb +2 -2
- data/lib/middleman-core/util/binary.rb +3 -1
- data/lib/middleman-core/util/data.rb +2 -2
- data/lib/middleman-core/util/files.rb +2 -2
- data/lib/middleman-core/util/paths.rb +47 -44
- data/lib/middleman-core/util/rack.rb +3 -3
- data/lib/middleman-core/util/uri_templates.rb +1 -0
- data/lib/middleman-core/version.rb +1 -1
- data/middleman-core.gemspec +3 -2
- data/spec/middleman-core/callbacks_spec.rb +15 -14
- data/spec/middleman-core/core_extensions/data_spec.rb +70 -74
- data/spec/middleman-core/dns_resolver_spec.rb +6 -6
- data/spec/middleman-core/util_spec.rb +81 -86
- data/spec/support/given.rb +11 -15
- metadata +44 -6
@@ -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
|
44
|
+
layout_file ||= resolve_template(app, name, resolve_opts)
|
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={}, 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) &&
|
135
|
+
next unless context.respond_to?(k) && !%i[current_path paginate page_articles blog_controller lang locale data].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,16 +149,19 @@ 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
|
+
|
152
153
|
if layout_file
|
153
|
-
|
154
|
-
layout_renderer = ::Middleman::FileRenderer.new(@app, layout_file[:relative_path].to_s)
|
154
|
+
layout_file = fetch_layout(engine, options)
|
155
155
|
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
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
|
162
165
|
end
|
163
166
|
|
164
167
|
# Return result
|
@@ -209,25 +212,24 @@ module Middleman
|
|
209
212
|
# The engine for the layout can be set in options, engine_options or passed
|
210
213
|
# into this method
|
211
214
|
layout_engine = if opts.key?(:layout_engine)
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
215
|
+
opts[:layout_engine]
|
216
|
+
elsif engine_options.key?(:layout_engine)
|
217
|
+
engine_options[:layout_engine]
|
218
|
+
else
|
219
|
+
engine
|
220
|
+
end
|
218
221
|
|
219
222
|
# Automatic mode
|
220
223
|
if local_layout == :_auto_layout
|
221
224
|
# Look for :layout of any extension
|
222
225
|
# If found, use it. If not, continue
|
223
226
|
locate_layout(:layout, layout_engine)
|
224
|
-
|
225
|
-
|
226
|
-
|
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
|
227
231
|
|
228
232
|
layout_file
|
229
|
-
else
|
230
|
-
raise ::Middleman::TemplateRenderer::TemplateNotFound, "Could not locate layout: #{local_layout}"
|
231
233
|
end
|
232
234
|
end
|
233
235
|
|
@@ -236,7 +238,7 @@ module Middleman
|
|
236
238
|
# @param [Symbol] preferred_engine
|
237
239
|
# @return [String]
|
238
240
|
Contract Or[String, Symbol], Symbol => Maybe[IsA['Middleman::SourceFile']]
|
239
|
-
def locate_layout(name, preferred_engine=nil)
|
241
|
+
def locate_layout(name, preferred_engine = nil)
|
240
242
|
self.class.locate_layout(@app, name, preferred_engine)
|
241
243
|
end
|
242
244
|
|
@@ -245,7 +247,7 @@ module Middleman
|
|
245
247
|
# @param [Hash] options
|
246
248
|
# @return [Array<String, Symbol>, Boolean]
|
247
249
|
Contract String, Hash => ArrayOf[Or[String, Symbol]]
|
248
|
-
def resolve_template(request_path, options={})
|
250
|
+
def resolve_template(request_path, options = {})
|
249
251
|
self.class.resolve_template(@app, request_path, options)
|
250
252
|
end
|
251
253
|
end
|
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={}, &block)
|
20
|
-
suffixed_name =
|
19
|
+
def instrument(name, payload = {}, &block)
|
20
|
+
suffixed_name = /\.middleman$/.match?(name) ? name.dup : "#{name}.middleman"
|
21
21
|
::ActiveSupport::Notifications.instrument(suffixed_name, payload, &block)
|
22
22
|
end
|
23
23
|
end
|
@@ -32,7 +32,9 @@ module Middleman
|
|
32
32
|
else
|
33
33
|
dot_ext = ext.to_s[0] == '.' ? ext.dup : ".#{ext}"
|
34
34
|
|
35
|
-
|
35
|
+
mime = ::Rack::Mime.mime_type(dot_ext, nil)
|
36
|
+
|
37
|
+
if mime
|
36
38
|
!nonbinary_mime?(mime)
|
37
39
|
else
|
38
40
|
file_contents_include_binary_bytes?(path.to_s)
|
@@ -45,7 +45,7 @@ module Middleman
|
|
45
45
|
# @param [String] path
|
46
46
|
# @return [Array<Hash, String>]
|
47
47
|
Contract IsA['Middleman::SourceFile'], Maybe[Symbol] => [Hash, Maybe[String]]
|
48
|
-
def parse(file, frontmatter_delims, known_type=nil)
|
48
|
+
def parse(file, frontmatter_delims, known_type = nil)
|
49
49
|
full_path = file[:full_path]
|
50
50
|
return [{}, nil] if ::Middleman::Util.binary?(full_path) || file[:types].include?(:binary)
|
51
51
|
|
@@ -110,7 +110,7 @@ module Middleman
|
|
110
110
|
Contract String, Pathname => Hash
|
111
111
|
def parse_yaml(content, full_path)
|
112
112
|
c = ::Middleman::Util.instrument 'parse.yaml' do
|
113
|
-
::YAML.
|
113
|
+
::YAML.safe_load(content)
|
114
114
|
end
|
115
115
|
c ? symbolize_recursive(c) : {}
|
116
116
|
rescue StandardError, ::Psych::SyntaxError => error
|
@@ -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 do |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
|
+
end.map(&:file_descriptor)
|
135
135
|
end
|
136
136
|
end
|
137
137
|
end
|
@@ -7,7 +7,6 @@ require 'tilt'
|
|
7
7
|
|
8
8
|
require 'middleman-core/contracts'
|
9
9
|
|
10
|
-
# rubocop:disable ModuleLength
|
11
10
|
module Middleman
|
12
11
|
module Util
|
13
12
|
extend Memoist
|
@@ -72,24 +71,24 @@ module Middleman
|
|
72
71
|
# @param [Hash] options Data to pass through.
|
73
72
|
# @return [String]
|
74
73
|
Contract ::Middleman::Application, Symbol, Or[String, Symbol], Hash => String
|
75
|
-
def asset_path(app, kind, source, options={})
|
74
|
+
def asset_path(app, kind, source, options = {})
|
76
75
|
return source if source.to_s.include?('//') || source.to_s.start_with?('data:')
|
77
76
|
|
78
77
|
asset_folder = case kind
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
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
|
90
89
|
|
91
90
|
source = source.to_s.tr(' ', '')
|
92
|
-
ignore_extension =
|
91
|
+
ignore_extension = %i[images fonts].include? kind # don't append extension
|
93
92
|
source << ".#{kind}" unless ignore_extension || source.end_with?(".#{kind}")
|
94
93
|
asset_folder = '' if source.start_with?('/') # absolute path
|
95
94
|
|
@@ -103,7 +102,7 @@ module Middleman
|
|
103
102
|
# @param [Hash] options Data to pass through.
|
104
103
|
# @return [String] The fully qualified asset url
|
105
104
|
Contract ::Middleman::Application, String, String, Hash => String
|
106
|
-
def asset_url(app, path, prefix='', options={})
|
105
|
+
def asset_url(app, path, prefix = '', options = {})
|
107
106
|
# Don't touch assets which already have a full path
|
108
107
|
return path if path.include?('//') || path.start_with?('data:')
|
109
108
|
|
@@ -118,18 +117,20 @@ module Middleman
|
|
118
117
|
# relative path, since it only takes absolute url paths.
|
119
118
|
dest_path = url_for(app, path, options.merge(relative: false))
|
120
119
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
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
|
133
134
|
|
134
135
|
final_result = ::Addressable::URI.encode(
|
135
136
|
relative_path_from_resource(
|
@@ -149,19 +150,19 @@ module Middleman
|
|
149
150
|
# or a Resource, this will produce the nice URL configured for that
|
150
151
|
# path, respecting :relative_links, directory indexes, etc.
|
151
152
|
Contract ::Middleman::Application, Or[String, Symbol, ::Middleman::Sitemap::Resource], Hash => String
|
152
|
-
def url_for(app, path_or_resource, options={})
|
153
|
+
def url_for(app, path_or_resource, options = {})
|
153
154
|
if path_or_resource.is_a?(String) || path_or_resource.is_a?(Symbol)
|
154
155
|
r = app.sitemap.find_resource_by_page_id(path_or_resource)
|
155
156
|
|
156
|
-
path_or_resource = r
|
157
|
+
path_or_resource = r || path_or_resource.to_s
|
157
158
|
end
|
158
159
|
|
159
160
|
# Handle Resources and other things which define their own url method
|
160
161
|
url = if path_or_resource.respond_to?(:url)
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
162
|
+
path_or_resource.url
|
163
|
+
else
|
164
|
+
path_or_resource.dup
|
165
|
+
end
|
165
166
|
|
166
167
|
# Try to parse URL
|
167
168
|
begin
|
@@ -209,20 +210,22 @@ module Middleman
|
|
209
210
|
|
210
211
|
if resource
|
211
212
|
uri.path = if this_resource
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
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
|
222
223
|
end
|
223
224
|
|
224
225
|
# Support a :query option that can be a string or hash
|
225
|
-
|
226
|
+
query = options[:query]
|
227
|
+
|
228
|
+
if query
|
226
229
|
uri.query = query.respond_to?(:to_param) ? query.to_param : query.to_s
|
227
230
|
end
|
228
231
|
|
@@ -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 = Regexp.last_match(1)
|
31
|
+
asset_path = Regexp.last_match(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? &&
|
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/middleman-core.gemspec
CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
|
|
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.3.0'
|
20
20
|
|
21
21
|
# Core
|
22
22
|
s.add_dependency('bundler', ['~> 1.1'])
|
@@ -32,6 +32,7 @@ Gem::Specification.new do |s|
|
|
32
32
|
s.add_dependency('padrino-helpers', ['~> 0.13.0'])
|
33
33
|
s.add_dependency('addressable', ['~> 2.3'])
|
34
34
|
s.add_dependency('memoist', ['~> 0.14'])
|
35
|
+
s.add_dependency('backports', ['~> 3.11'])
|
35
36
|
|
36
37
|
# Watcher
|
37
38
|
s.add_dependency('listen', ['~> 3.0'])
|
@@ -53,7 +54,7 @@ Gem::Specification.new do |s|
|
|
53
54
|
s.add_dependency('execjs', ['~> 2.0'])
|
54
55
|
|
55
56
|
# Testing
|
56
|
-
s.add_dependency('contracts', ['~> 0.
|
57
|
+
s.add_dependency('contracts', ['~> 0.16.0'])
|
57
58
|
|
58
59
|
# Hash stuff
|
59
60
|
s.add_dependency('hashie', ['~> 3.4'])
|
@@ -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(%i[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(%i[test1 a], [2])
|
53
|
+
m.execute(%i[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(%i[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,10 +104,12 @@ describe ::Middleman::CallbackManager do
|
|
104
104
|
|
105
105
|
instance.execute_callbacks(:ready)
|
106
106
|
|
107
|
+
# rubocop:disable Style/CaseEquality
|
107
108
|
expect(internal_self) === instance
|
109
|
+
# rubocop:enable Style/CaseEquality
|
108
110
|
end
|
109
111
|
|
110
|
-
it
|
112
|
+
it 'executes in custom scope' do
|
111
113
|
instance = Class.new(Object).new
|
112
114
|
m = ::Middleman::CallbackManager.new
|
113
115
|
m.install_methods!(instance, [:ready])
|
@@ -124,9 +126,8 @@ describe ::Middleman::CallbackManager do
|
|
124
126
|
instance.ready(&external_instance.method(:when_ready))
|
125
127
|
|
126
128
|
instance.execute_callbacks(:ready, [5])
|
127
|
-
|
129
|
+
|
128
130
|
expect(external_instance[:scope]).to eq external_instance
|
129
131
|
expect(external_instance[:counter]).to eq 5
|
130
132
|
end
|
131
|
-
|
132
|
-
end
|
133
|
+
end
|