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
@@ -16,11 +16,11 @@ module Middleman::CoreExtensions
|
|
16
16
|
|
17
17
|
# Set textual delimiters that denote the start and end of frontmatter
|
18
18
|
define_setting :frontmatter_delims, {
|
19
|
-
json: [%w
|
20
|
-
yaml: [%w
|
19
|
+
json: [%w[;;; ;;;]],
|
20
|
+
yaml: [%w[--- ---], %w[--- ...]]
|
21
21
|
}, 'Allowed frontmatter delimiters'
|
22
22
|
|
23
|
-
def initialize(app, options_hash={}, &block)
|
23
|
+
def initialize(app, options_hash = {}, &block)
|
24
24
|
super
|
25
25
|
|
26
26
|
@cache = {}
|
@@ -29,11 +29,11 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
|
|
29
29
|
# don't completely reload middleman, I18n.load_path can get
|
30
30
|
# polluted with paths from other test app directories that don't
|
31
31
|
# exist anymore.
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
32
|
+
return unless ENV['TEST']
|
33
|
+
|
34
|
+
app.after_configuration_eval do
|
35
|
+
::I18n.load_path.delete_if { |path| path =~ %r{tmp/aruba} }
|
36
|
+
::I18n.reload!
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
@@ -68,7 +68,7 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
|
|
68
68
|
::I18n.t(*args)
|
69
69
|
end
|
70
70
|
|
71
|
-
def url_for(path_or_resource, options={})
|
71
|
+
def url_for(path_or_resource, options = {})
|
72
72
|
locale = options.delete(:locale) || ::I18n.locale
|
73
73
|
|
74
74
|
opts = options.dup
|
@@ -79,12 +79,9 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
|
|
79
79
|
|
80
80
|
href = super(path_or_resource, opts)
|
81
81
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
# Should we log the missing file?
|
86
|
-
href
|
87
|
-
end
|
82
|
+
result = extensions[:i18n].localized_path(href, locale)
|
83
|
+
|
84
|
+
final_path = result || href
|
88
85
|
|
89
86
|
opts[:relative] = should_relativize
|
90
87
|
|
@@ -95,7 +92,7 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
|
|
95
92
|
end
|
96
93
|
end
|
97
94
|
|
98
|
-
def locate_partial(partial_name, try_static=false)
|
95
|
+
def locate_partial(partial_name, try_static = false)
|
99
96
|
locals_dir = extensions[:i18n].options[:templates_dir]
|
100
97
|
|
101
98
|
# Try /localizable
|
@@ -106,10 +103,10 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
|
|
106
103
|
extname = File.extname(partial_name)
|
107
104
|
maybe_static = !extname.empty?
|
108
105
|
suffixed_partial_name = if maybe_static
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
106
|
+
partial_name.sub(extname, ".#{locale_suffix}#{extname}")
|
107
|
+
else
|
108
|
+
"#{partial_name}.#{locale_suffix}"
|
109
|
+
end
|
113
110
|
|
114
111
|
if locale_suffix
|
115
112
|
super(suffixed_partial_name, maybe_static) ||
|
@@ -190,7 +187,7 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
|
|
190
187
|
|
191
188
|
# Process templates with locale suffix
|
192
189
|
locales.each do |locale|
|
193
|
-
abs_path = abs_path.sub(".#{locale}.",
|
190
|
+
abs_path = abs_path.sub(".#{locale}.", '.')
|
194
191
|
end
|
195
192
|
|
196
193
|
sum[abs_path] ||= {}
|
@@ -204,13 +201,15 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
|
|
204
201
|
|
205
202
|
Contract String, Symbol => Maybe[String]
|
206
203
|
def localized_path(path, locale)
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
204
|
+
lookup = ::Middleman::Util.parse_uri(path)
|
205
|
+
lookup.path << app.config[:index_file] if lookup.path&.end_with?('/')
|
206
|
+
|
207
|
+
if @lookup[lookup.path] && @lookup[lookup.path][locale]
|
208
|
+
lookup.path = @lookup[lookup.path][locale]
|
209
|
+
lookup.to_s
|
213
210
|
end
|
211
|
+
rescue ::Addressable::URI::InvalidURIError
|
212
|
+
nil
|
214
213
|
end
|
215
214
|
|
216
215
|
Contract Symbol => String
|
@@ -291,6 +290,7 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
|
|
291
290
|
|
292
291
|
File.dirname(path).split('/').each do |path_sub|
|
293
292
|
next if path_sub == ''
|
293
|
+
|
294
294
|
partially_localized_path = "#{partially_localized_path}/#{::I18n.t("paths.#{path_sub}", default: path_sub)}"
|
295
295
|
end
|
296
296
|
|
@@ -20,7 +20,7 @@ module Middleman
|
|
20
20
|
after: Maybe[Symbol]
|
21
21
|
}.freeze
|
22
22
|
|
23
|
-
def initialize(app, options_hash={}, &block)
|
23
|
+
def initialize(app, options_hash = {}, &block)
|
24
24
|
super
|
25
25
|
|
26
26
|
@rewriters = {}
|
@@ -53,7 +53,7 @@ module Middleman
|
|
53
53
|
middleman_app: IsA['Middleman::Application'],
|
54
54
|
rewriters: ArrayOf[REWRITER_DESCRIPTOR]
|
55
55
|
} => Any
|
56
|
-
def initialize(app, options={})
|
56
|
+
def initialize(app, options = {})
|
57
57
|
@rack_app = app
|
58
58
|
@middleman_app = options.fetch(:middleman_app)
|
59
59
|
@rewriters = options.fetch(:rewriters)
|
@@ -79,7 +79,10 @@ module Middleman
|
|
79
79
|
path = ::Middleman::Util.full_path(env['PATH_INFO'], @middleman_app)
|
80
80
|
|
81
81
|
return [status, headers, response] unless path =~ /(^\/$)|(#{@source_exts_regex_text}$)/
|
82
|
-
|
82
|
+
|
83
|
+
body = ::Middleman::Util.extract_response_text(response)
|
84
|
+
|
85
|
+
return [status, headers, response] unless body
|
83
86
|
|
84
87
|
dirpath = ::Pathname.new(File.dirname(path))
|
85
88
|
|
@@ -90,10 +93,10 @@ module Middleman
|
|
90
93
|
relative_path = uri.host.nil?
|
91
94
|
|
92
95
|
full_asset_path = if relative_path
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
96
|
+
dirpath.join(asset_path).to_s
|
97
|
+
else
|
98
|
+
asset_path
|
99
|
+
end
|
97
100
|
|
98
101
|
@rewriters.each do |rewriter|
|
99
102
|
uid = rewriter.fetch(:id)
|
@@ -49,7 +49,7 @@ module Middleman
|
|
49
49
|
# @option opts [Hash] data Extra metadata to add to the page. This is the same as frontmatter, though frontmatter will take precedence over metadata defined here. Available via {Resource#data}.
|
50
50
|
# @return [void]
|
51
51
|
Contract Or[String, Regexp], Hash => PageDescriptor
|
52
|
-
def page(path, opts={})
|
52
|
+
def page(path, opts = {})
|
53
53
|
options = opts.dup
|
54
54
|
|
55
55
|
page_data = options.delete(:data) || {}
|
@@ -27,7 +27,7 @@ module Middleman
|
|
27
27
|
#
|
28
28
|
# First the local resolver is queried. If this raises an error or returns
|
29
29
|
# nil or [] the network resolver is queried.
|
30
|
-
def initialize(opts={})
|
30
|
+
def initialize(opts = {})
|
31
31
|
@resolvers = []
|
32
32
|
@resolvers << opts.fetch(:hosts_resolver, HostsResolver.new)
|
33
33
|
|
@@ -8,7 +8,7 @@ module Middleman
|
|
8
8
|
|
9
9
|
public
|
10
10
|
|
11
|
-
def initialize(opts={})
|
11
|
+
def initialize(opts = {})
|
12
12
|
@timeouts = opts.fetch(:timeouts, 2)
|
13
13
|
end
|
14
14
|
|
@@ -21,7 +21,7 @@ module Middleman
|
|
21
21
|
# Array of Names
|
22
22
|
def getnames(ip)
|
23
23
|
resolver.getnames(ip.to_s).map(&:to_s)
|
24
|
-
rescue Resolv::ResolvError, Errno::EADDRNOTAVAIL
|
24
|
+
rescue Resolv::ResolvError, Errno::EADDRNOTAVAIL, Errno::ENETUNREACH
|
25
25
|
[]
|
26
26
|
end
|
27
27
|
|
@@ -34,7 +34,7 @@ module Middleman
|
|
34
34
|
# Array of ipaddresses
|
35
35
|
def getaddresses(name)
|
36
36
|
resolver.getaddresses(name.to_s).map(&:to_s)
|
37
|
-
rescue Resolv::ResolvError, Errno::EADDRNOTAVAIL
|
37
|
+
rescue Resolv::ResolvError, Errno::EADDRNOTAVAIL, Errno::ENETUNREACH
|
38
38
|
[]
|
39
39
|
end
|
40
40
|
|
@@ -4,7 +4,7 @@ module Middleman
|
|
4
4
|
class DnsResolver
|
5
5
|
# Use network name server to resolve ips and names
|
6
6
|
class NetworkResolver < BasicNetworkResolver
|
7
|
-
def initialize(opts={})
|
7
|
+
def initialize(opts = {})
|
8
8
|
super
|
9
9
|
|
10
10
|
@resolver = opts.fetch(:resolver, Resolv::DNS.new(nameserver_config))
|
@@ -135,7 +135,7 @@ module Middleman
|
|
135
135
|
# @param [Symbol] key The name of the option
|
136
136
|
# @param [Object] default The default value for the option
|
137
137
|
# @param [String] description A human-readable description of what the option does
|
138
|
-
def option(key, default=nil, description=nil, options={})
|
138
|
+
def option(key, default = nil, description = nil, options = {})
|
139
139
|
config.define_setting(key, default, description, options)
|
140
140
|
end
|
141
141
|
|
@@ -152,7 +152,7 @@ module Middleman
|
|
152
152
|
# @param [Symbol] key The name of the option
|
153
153
|
# @param [Object] default The default value for the option
|
154
154
|
# @param [String] description A human-readable description of what the option does
|
155
|
-
def define_setting(key, default=nil, description=nil, options={})
|
155
|
+
def define_setting(key, default = nil, description = nil, options = {})
|
156
156
|
global_config.define_setting(key, default, description, options)
|
157
157
|
end
|
158
158
|
|
@@ -209,7 +209,7 @@ module Middleman
|
|
209
209
|
def expose_to_application(*symbols)
|
210
210
|
self.exposed_to_application ||= {}
|
211
211
|
|
212
|
-
if symbols.first
|
212
|
+
if symbols.first&.is_a?(Hash)
|
213
213
|
self.exposed_to_application.merge!(symbols.first)
|
214
214
|
elsif symbols.is_a? Array
|
215
215
|
symbols.each do |sym|
|
@@ -229,7 +229,7 @@ module Middleman
|
|
229
229
|
def expose_to_config(*symbols)
|
230
230
|
self.exposed_to_config ||= {}
|
231
231
|
|
232
|
-
if symbols.first
|
232
|
+
if symbols.first&.is_a?(Hash)
|
233
233
|
self.exposed_to_config.merge!(symbols.first)
|
234
234
|
elsif symbols.is_a? Array
|
235
235
|
symbols.each do |sym|
|
@@ -249,7 +249,7 @@ module Middleman
|
|
249
249
|
def expose_to_template(*symbols)
|
250
250
|
self.exposed_to_template ||= {}
|
251
251
|
|
252
|
-
if symbols.first
|
252
|
+
if symbols.first&.is_a?(Hash)
|
253
253
|
self.exposed_to_template.merge!(symbols.first)
|
254
254
|
elsif symbols.is_a? Array
|
255
255
|
symbols.each do |sym|
|
@@ -282,7 +282,8 @@ module Middleman
|
|
282
282
|
# @return [void]
|
283
283
|
def activated_extension(instance)
|
284
284
|
name = instance.class.ext_name
|
285
|
-
return unless @_extension_activation_callbacks
|
285
|
+
return unless @_extension_activation_callbacks&.key?(name)
|
286
|
+
|
286
287
|
@_extension_activation_callbacks[name].each do |block|
|
287
288
|
block.arity == 1 ? block.call(instance) : block.call
|
288
289
|
end
|
@@ -307,7 +308,7 @@ module Middleman
|
|
307
308
|
# @param [Hash] options_hash The raw options hash. Subclasses should not manipulate this directly - it will be turned into {#options}.
|
308
309
|
# @yield An optional block that can be used to customize options before the extension is activated.
|
309
310
|
# @yieldparam [Middleman::Configuration::ConfigurationManager] options Extension options
|
310
|
-
def initialize(app, options_hash={}, &block)
|
311
|
+
def initialize(app, options_hash = {}, &block)
|
311
312
|
@_helpers = []
|
312
313
|
@app = app
|
313
314
|
|
@@ -423,18 +424,18 @@ module Middleman
|
|
423
424
|
def generate_resources(resources)
|
424
425
|
generator_defs = self.class.resources_generators.reduce({}) do |sum, g|
|
425
426
|
resource_definitions = if g.is_a? Hash
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
427
|
+
g
|
428
|
+
elsif g.is_a? Symbol
|
429
|
+
definition = method(g)
|
430
|
+
|
431
|
+
if definition.arity.zero?
|
432
|
+
send(g)
|
433
|
+
else
|
434
|
+
send(g, resources)
|
435
|
+
end
|
436
|
+
else
|
437
|
+
{}
|
438
|
+
end
|
438
439
|
|
439
440
|
sum.merge!(resource_definitions)
|
440
441
|
end
|
@@ -443,11 +444,11 @@ module Middleman
|
|
443
444
|
if g.is_a? Symbol
|
444
445
|
definition = method(g)
|
445
446
|
|
446
|
-
g = if definition.arity
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
447
|
+
g = if definition.arity.zero?
|
448
|
+
send(g)
|
449
|
+
else
|
450
|
+
send(g, resources)
|
451
|
+
end
|
451
452
|
end
|
452
453
|
|
453
454
|
::Middleman::Sitemap::StringResource.new(
|
@@ -492,7 +493,7 @@ module Middleman
|
|
492
493
|
end
|
493
494
|
|
494
495
|
class ConfigExtension < Extension
|
495
|
-
def initialize(app, config={}, &block)
|
496
|
+
def initialize(app, config = {}, &block)
|
496
497
|
@descriptors = {}
|
497
498
|
@ready = false
|
498
499
|
|
@@ -50,7 +50,7 @@ module Middleman
|
|
50
50
|
# @param [Hash] options Options to pass to the extension
|
51
51
|
# @yield [Middleman::Configuration::ConfigurationManager] Extension options that can be modified before the extension is initialized.
|
52
52
|
# @return [void]
|
53
|
-
def activate(ext_name, options={}, &block)
|
53
|
+
def activate(ext_name, options = {}, &block)
|
54
54
|
begin
|
55
55
|
extension = ::Middleman::Extensions.load(ext_name)
|
56
56
|
rescue LoadError => e
|
@@ -49,8 +49,9 @@ module Middleman
|
|
49
49
|
# you the ability to require other files only when the
|
50
50
|
# extension is first activated.
|
51
51
|
# @return [void]
|
52
|
-
def register(name, extension_class=nil, options={}, &block)
|
52
|
+
def register(name, extension_class = nil, options = {}, &block)
|
53
53
|
raise 'Extension name must be a symbol' unless name.is_a?(Symbol)
|
54
|
+
|
54
55
|
# If we've already got an extension registered under this name, bail out
|
55
56
|
# raise "There is a already an extension registered with the name '#{name}'" if registered.key?(name)
|
56
57
|
|
@@ -61,12 +62,12 @@ module Middleman
|
|
61
62
|
end
|
62
63
|
|
63
64
|
registered[name] = if block_given?
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
65
|
+
block
|
66
|
+
elsif extension_class && extension_class.ancestors && extension_class.ancestors.include?(::Middleman::Extension)
|
67
|
+
extension_class
|
68
|
+
else
|
69
|
+
raise 'You must provide a Middleman::Extension or a block that returns a Middleman::Extension'
|
70
|
+
end
|
70
71
|
|
71
72
|
return unless options[:auto_activate]
|
72
73
|
|
@@ -2,13 +2,13 @@ require 'middleman-core/util'
|
|
2
2
|
require 'middleman-core/rack'
|
3
3
|
|
4
4
|
class Middleman::Extensions::AssetHash < ::Middleman::Extension
|
5
|
-
option :sources, %w
|
5
|
+
option :sources, %w[.css .htm .html .js .php .xhtml], 'List of extensions that are searched for hashable assets.'
|
6
6
|
option :exts, nil, 'List of extensions that get asset hashes appended to them.'
|
7
7
|
option :ignore, [], 'Regexes of filenames to skip adding asset hashes to'
|
8
8
|
option :rewrite_ignore, [], 'Regexes of filenames to skip processing for path rewrites'
|
9
9
|
option :prefix, '', 'Prefix for hash'
|
10
10
|
|
11
|
-
def initialize(app, options_hash={}, &block)
|
11
|
+
def initialize(app, options_hash = {}, &block)
|
12
12
|
super
|
13
13
|
|
14
14
|
require 'addressable/uri'
|
@@ -20,7 +20,7 @@ class Middleman::Extensions::AssetHash < ::Middleman::Extension
|
|
20
20
|
|
21
21
|
# Exclude .ico from the default list because browsers expect it
|
22
22
|
# to be named "favicon.ico"
|
23
|
-
@exts = options.exts || (app.config[:asset_extensions] - %w
|
23
|
+
@exts = options.exts || (app.config[:asset_extensions] - %w[.ico])
|
24
24
|
|
25
25
|
app.rewrite_inline_urls id: :asset_hash,
|
26
26
|
url_extensions: @exts.sort.reverse,
|
@@ -37,12 +37,14 @@ class Middleman::Extensions::AssetHash < ::Middleman::Extension
|
|
37
37
|
relative_path = !uri.path.start_with?('/')
|
38
38
|
|
39
39
|
full_asset_path = if relative_path
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
40
|
+
dirpath.join(asset_path).to_s
|
41
|
+
else
|
42
|
+
asset_path
|
43
|
+
end
|
44
|
+
|
45
|
+
asset_page = app.sitemap.find_resource_by_destination_path(full_asset_path) || app.sitemap.find_resource_by_path(full_asset_path)
|
44
46
|
|
45
|
-
return unless asset_page
|
47
|
+
return unless asset_page
|
46
48
|
|
47
49
|
replacement_path = "/#{asset_page.destination_path}"
|
48
50
|
replacement_path = Pathname.new(replacement_path).relative_path_from(dirpath).to_s if relative_path
|
@@ -63,9 +65,9 @@ class Middleman::Extensions::AssetHash < ::Middleman::Extension
|
|
63
65
|
# This is so by the time we get around to the text files (which may reference
|
64
66
|
# images and fonts) the static assets' hashes are already calculated.
|
65
67
|
resources.sort_by do |a|
|
66
|
-
if %w
|
68
|
+
if %w[.svg .svgz].include? a.ext
|
67
69
|
0
|
68
|
-
elsif %w
|
70
|
+
elsif %w[.js .css].include? a.ext
|
69
71
|
1
|
70
72
|
else
|
71
73
|
-1
|
@@ -80,18 +82,18 @@ class Middleman::Extensions::AssetHash < ::Middleman::Extension
|
|
80
82
|
return if resource.ignored?
|
81
83
|
|
82
84
|
digest = if resource.binary?
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
85
|
+
::Digest::SHA1.file(resource.source_file).hexdigest[0..7]
|
86
|
+
else
|
87
|
+
# Render through the Rack interface so middleware and mounted apps get a shot
|
88
|
+
response = @rack_client.get(
|
89
|
+
::URI.escape(resource.destination_path),
|
90
|
+
'bypass_inline_url_rewriter_asset_hash' => 'true'
|
91
|
+
)
|
92
|
+
|
93
|
+
raise "#{resource.path} should be in the sitemap!" unless response.status == 200
|
94
|
+
|
95
|
+
::Digest::SHA1.hexdigest(response.body)[0..7]
|
96
|
+
end
|
95
97
|
|
96
98
|
resource.destination_path = resource.destination_path.sub(/\.(\w+)$/) { |ext| "-#{options.prefix}#{digest}#{ext}" }
|
97
99
|
resource
|