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
@@ -53,16 +53,15 @@ module Middleman
|
|
53
53
|
#
|
54
54
|
# Common lifecycle events can be handled by extensions simply by implementing an appropriately-named method:
|
55
55
|
#
|
56
|
-
# * {#before_configuration}
|
57
56
|
# * {#after_configuration}
|
58
|
-
# * {#before_build}
|
59
57
|
# * {#after_build}
|
60
|
-
# * {#
|
58
|
+
# * {#before_build}
|
61
59
|
#
|
62
60
|
# There are also some less common hooks that can be listened to from within an extension's `initialize` method:
|
63
61
|
#
|
64
|
-
# * `app.before_render {
|
65
|
-
# * `app.after_render {
|
62
|
+
# * `app.before_render {|body, path, locs, template_class| ... }` - Manipulate template sources before they are rendered.
|
63
|
+
# * `app.after_render {|content, path, locs, template_class| ... }` - Manipulate output text after a template has been rendered. It is also common to install a Rack middleware to do this instead.
|
64
|
+
# * `app.ready { ... }` - Run code once Middleman is ready to serve or build files (after `after_configuration`).
|
66
65
|
|
67
66
|
#
|
68
67
|
# @see http://middlemanapp.com/advanced/custom/ Middleman Custom Extensions Documentation
|
@@ -135,7 +134,7 @@ module Middleman
|
|
135
134
|
# @param [Symbol] key The name of the option
|
136
135
|
# @param [Object] default The default value for the option
|
137
136
|
# @param [String] description A human-readable description of what the option does
|
138
|
-
def option(key, default
|
137
|
+
def option(key, default=nil, description=nil, options={})
|
139
138
|
config.define_setting(key, default, description, options)
|
140
139
|
end
|
141
140
|
|
@@ -152,7 +151,7 @@ module Middleman
|
|
152
151
|
# @param [Symbol] key The name of the option
|
153
152
|
# @param [Object] default The default value for the option
|
154
153
|
# @param [String] description A human-readable description of what the option does
|
155
|
-
def define_setting(key, default
|
154
|
+
def define_setting(key, default=nil, description=nil, options={})
|
156
155
|
global_config.define_setting(key, default, description, options)
|
157
156
|
end
|
158
157
|
|
@@ -204,12 +203,12 @@ module Middleman
|
|
204
203
|
# expose_to_application global_name: :local_name
|
205
204
|
# @example with Array:
|
206
205
|
# expose_to_application :method1, :method2
|
207
|
-
# @param [Array<
|
206
|
+
# @param [Array<Sumbol>, Hash<Symbol, Symbol>] symbols An optional list of symbols representing instance methods to exposed.
|
208
207
|
# @return [void]
|
209
208
|
def expose_to_application(*symbols)
|
210
209
|
self.exposed_to_application ||= {}
|
211
210
|
|
212
|
-
if symbols.first
|
211
|
+
if symbols.first && symbols.first.is_a?(Hash)
|
213
212
|
self.exposed_to_application.merge!(symbols.first)
|
214
213
|
elsif symbols.is_a? Array
|
215
214
|
symbols.each do |sym|
|
@@ -224,12 +223,12 @@ module Middleman
|
|
224
223
|
# expose_to_config global_name: :local_name
|
225
224
|
# @example with Array:
|
226
225
|
# expose_to_config :method1, :method2
|
227
|
-
# @param [Array<
|
226
|
+
# @param [Array<Sumbol>, Hash<Symbol, Symbol>] symbols An optional list of symbols representing instance methods to exposed.
|
228
227
|
# @return [void]
|
229
228
|
def expose_to_config(*symbols)
|
230
229
|
self.exposed_to_config ||= {}
|
231
230
|
|
232
|
-
if symbols.first
|
231
|
+
if symbols.first && symbols.first.is_a?(Hash)
|
233
232
|
self.exposed_to_config.merge!(symbols.first)
|
234
233
|
elsif symbols.is_a? Array
|
235
234
|
symbols.each do |sym|
|
@@ -244,12 +243,12 @@ module Middleman
|
|
244
243
|
# expose_to_template global_name: :local_name
|
245
244
|
# @example with Array:
|
246
245
|
# expose_to_template :method1, :method2
|
247
|
-
# @param [Array<
|
246
|
+
# @param [Array<Sumbol>, Hash<Symbol, Symbol>] symbols An optional list of symbols representing instance methods to exposed.
|
248
247
|
# @return [void]
|
249
248
|
def expose_to_template(*symbols)
|
250
249
|
self.exposed_to_template ||= {}
|
251
250
|
|
252
|
-
if symbols.first
|
251
|
+
if symbols.first && symbols.first.is_a?(Hash)
|
253
252
|
self.exposed_to_template.merge!(symbols.first)
|
254
253
|
elsif symbols.is_a? Array
|
255
254
|
symbols.each do |sym|
|
@@ -282,8 +281,7 @@ module Middleman
|
|
282
281
|
# @return [void]
|
283
282
|
def activated_extension(instance)
|
284
283
|
name = instance.class.ext_name
|
285
|
-
return unless @_extension_activation_callbacks
|
286
|
-
|
284
|
+
return unless @_extension_activation_callbacks && @_extension_activation_callbacks.key?(name)
|
287
285
|
@_extension_activation_callbacks[name].each do |block|
|
288
286
|
block.arity == 1 ? block.call(instance) : block.call
|
289
287
|
end
|
@@ -308,7 +306,7 @@ module Middleman
|
|
308
306
|
# @param [Hash] options_hash The raw options hash. Subclasses should not manipulate this directly - it will be turned into {#options}.
|
309
307
|
# @yield An optional block that can be used to customize options before the extension is activated.
|
310
308
|
# @yieldparam [Middleman::Configuration::ConfigurationManager] options Extension options
|
311
|
-
def initialize(app, options_hash
|
309
|
+
def initialize(app, options_hash={}, &block)
|
312
310
|
@_helpers = []
|
313
311
|
@app = app
|
314
312
|
|
@@ -424,18 +422,18 @@ module Middleman
|
|
424
422
|
def generate_resources(resources)
|
425
423
|
generator_defs = self.class.resources_generators.reduce({}) do |sum, g|
|
426
424
|
resource_definitions = if g.is_a? Hash
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
425
|
+
g
|
426
|
+
elsif g.is_a? Symbol
|
427
|
+
definition = method(g)
|
428
|
+
|
429
|
+
if definition.arity == 0
|
430
|
+
send(g)
|
431
|
+
else
|
432
|
+
send(g, resources)
|
433
|
+
end
|
434
|
+
else
|
435
|
+
{}
|
436
|
+
end
|
439
437
|
|
440
438
|
sum.merge!(resource_definitions)
|
441
439
|
end
|
@@ -444,11 +442,11 @@ module Middleman
|
|
444
442
|
if g.is_a? Symbol
|
445
443
|
definition = method(g)
|
446
444
|
|
447
|
-
g = if definition.arity
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
445
|
+
g = if definition.arity == 0
|
446
|
+
send(g)
|
447
|
+
else
|
448
|
+
send(g, resources)
|
449
|
+
end
|
452
450
|
end
|
453
451
|
|
454
452
|
::Middleman::Sitemap::StringResource.new(
|
@@ -493,7 +491,7 @@ module Middleman
|
|
493
491
|
end
|
494
492
|
|
495
493
|
class ConfigExtension < Extension
|
496
|
-
def initialize(app, config
|
494
|
+
def initialize(app, config={}, &block)
|
497
495
|
@descriptors = {}
|
498
496
|
@ready = false
|
499
497
|
|
@@ -24,10 +24,6 @@ module Middleman
|
|
24
24
|
@app.after_configuration_eval(&method(:activate_all))
|
25
25
|
end
|
26
26
|
|
27
|
-
def active?(key)
|
28
|
-
@activated.key?(key)
|
29
|
-
end
|
30
|
-
|
31
27
|
def auto_activate(key)
|
32
28
|
::Middleman::Extensions.auto_activate(key, @app)
|
33
29
|
end
|
@@ -50,7 +46,7 @@ module Middleman
|
|
50
46
|
# @param [Hash] options Options to pass to the extension
|
51
47
|
# @yield [Middleman::Configuration::ConfigurationManager] Extension options that can be modified before the extension is initialized.
|
52
48
|
# @return [void]
|
53
|
-
def activate(ext_name, options
|
49
|
+
def activate(ext_name, options={}, &block)
|
54
50
|
begin
|
55
51
|
extension = ::Middleman::Extensions.load(ext_name)
|
56
52
|
rescue LoadError => e
|
@@ -64,7 +60,7 @@ module Middleman
|
|
64
60
|
@activated[ext_name] ||= {}
|
65
61
|
key = "instance_#{@activated[ext_name].keys.length}"
|
66
62
|
@activated[ext_name][key] = extension.new(@app, options, &block)
|
67
|
-
elsif
|
63
|
+
elsif @activated.key?(ext_name)
|
68
64
|
raise "#{ext_name} has already been activated and cannot be re-activated."
|
69
65
|
else
|
70
66
|
@activated[ext_name] = extension.new(@app, options, &block)
|
@@ -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
|
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,14 +37,12 @@ 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
|
-
|
44
|
-
|
45
|
-
asset_page = app.sitemap.find_resource_by_destination_path(full_asset_path) || app.sitemap.find_resource_by_path(full_asset_path)
|
40
|
+
dirpath.join(asset_path).to_s
|
41
|
+
else
|
42
|
+
asset_path
|
43
|
+
end
|
46
44
|
|
47
|
-
return unless asset_page
|
45
|
+
return unless asset_page = app.sitemap.find_resource_by_destination_path(full_asset_path) || app.sitemap.find_resource_by_path(full_asset_path)
|
48
46
|
|
49
47
|
replacement_path = "/#{asset_page.destination_path}"
|
50
48
|
replacement_path = Pathname.new(replacement_path).relative_path_from(dirpath).to_s if relative_path
|
@@ -65,9 +63,9 @@ class Middleman::Extensions::AssetHash < ::Middleman::Extension
|
|
65
63
|
# This is so by the time we get around to the text files (which may reference
|
66
64
|
# images and fonts) the static assets' hashes are already calculated.
|
67
65
|
resources.sort_by do |a|
|
68
|
-
if %w
|
66
|
+
if %w(.svg .svgz).include? a.ext
|
69
67
|
0
|
70
|
-
elsif %w
|
68
|
+
elsif %w(.js .css).include? a.ext
|
71
69
|
1
|
72
70
|
else
|
73
71
|
-1
|
@@ -82,18 +80,18 @@ class Middleman::Extensions::AssetHash < ::Middleman::Extension
|
|
82
80
|
return if resource.ignored?
|
83
81
|
|
84
82
|
digest = if resource.binary?
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
83
|
+
::Digest::SHA1.file(resource.source_file).hexdigest[0..7]
|
84
|
+
else
|
85
|
+
# Render through the Rack interface so middleware and mounted apps get a shot
|
86
|
+
response = @rack_client.get(
|
87
|
+
::URI.escape(resource.destination_path),
|
88
|
+
'bypass_inline_url_rewriter_asset_hash' => 'true'
|
89
|
+
)
|
90
|
+
|
91
|
+
raise "#{resource.path} should be in the sitemap!" unless response.status == 200
|
92
|
+
|
93
|
+
::Digest::SHA1.hexdigest(response.body)[0..7]
|
94
|
+
end
|
97
95
|
|
98
96
|
resource.destination_path = resource.destination_path.sub(/\.(\w+)$/) { |ext| "-#{options.prefix}#{digest}#{ext}" }
|
99
97
|
resource
|
@@ -3,11 +3,11 @@ require 'addressable/uri'
|
|
3
3
|
class Middleman::Extensions::AssetHost < ::Middleman::Extension
|
4
4
|
option :host, nil, 'The asset host to use or a Proc to determine asset host', required: true
|
5
5
|
option :exts, nil, 'List of extensions that get cache busters strings appended to them.'
|
6
|
-
option :sources, %w
|
6
|
+
option :sources, %w(.css .htm .html .js .php .xhtml), 'List of extensions that are searched for bustable assets.'
|
7
7
|
option :ignore, [], 'Regexes of filenames to skip adding query strings to'
|
8
8
|
option :rewrite_ignore, [], 'Regexes of filenames to skip processing for host rewrites'
|
9
9
|
|
10
|
-
def initialize(app, options_hash
|
10
|
+
def initialize(app, options_hash={}, &block)
|
11
11
|
super
|
12
12
|
|
13
13
|
app.rewrite_inline_urls id: :asset_host,
|
@@ -24,16 +24,16 @@ class Middleman::Extensions::AssetHost < ::Middleman::Extension
|
|
24
24
|
relative_path = uri.path[0..0] != '/'
|
25
25
|
|
26
26
|
full_asset_path = if relative_path
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
dirpath.join(asset_path).to_s
|
28
|
+
else
|
29
|
+
asset_path
|
30
|
+
end
|
31
31
|
|
32
32
|
asset_prefix = if options[:host].is_a?(Proc)
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
33
|
+
options[:host].call(full_asset_path)
|
34
|
+
elsif options[:host].is_a?(String)
|
35
|
+
options[:host]
|
36
|
+
end
|
37
37
|
|
38
38
|
File.join(asset_prefix, full_asset_path)
|
39
39
|
end
|
@@ -4,7 +4,7 @@ class Middleman::Extensions::AutomaticAltTags < ::Middleman::Extension
|
|
4
4
|
# Override default image_tag helper to automatically insert alt tag
|
5
5
|
# containing image name.
|
6
6
|
|
7
|
-
def image_tag(path, params
|
7
|
+
def image_tag(path, params={})
|
8
8
|
unless path.include?('://')
|
9
9
|
params[:alt] ||= ''
|
10
10
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# Automatic Image Sizes extension
|
2
2
|
class Middleman::Extensions::AutomaticImageSizes < ::Middleman::Extension
|
3
|
-
def initialize(app, options_hash
|
3
|
+
def initialize(app, options_hash={}, &block)
|
4
4
|
super
|
5
5
|
|
6
6
|
# Include 3rd-party fastimage library
|
@@ -14,7 +14,7 @@ class Middleman::Extensions::AutomaticImageSizes < ::Middleman::Extension
|
|
14
14
|
# @param [String] path
|
15
15
|
# @param [Hash] params
|
16
16
|
# @return [String]
|
17
|
-
def image_tag(path, params
|
17
|
+
def image_tag(path, params={})
|
18
18
|
if !params.key?(:width) && !params.key?(:height) && !path.include?('://')
|
19
19
|
real_path = path.dup
|
20
20
|
real_path = File.join(config[:images_dir], real_path) unless real_path.start_with?('/')
|
@@ -36,7 +36,7 @@ class Middleman::Extensions::AutomaticImageSizes < ::Middleman::Extension
|
|
36
36
|
params[:height] = height
|
37
37
|
rescue FastImage::UnknownImageType
|
38
38
|
# No message, it's just not supported
|
39
|
-
rescue
|
39
|
+
rescue
|
40
40
|
warn "Couldn't determine dimensions for image #{path}: #{$ERROR_INFO.message}"
|
41
41
|
end
|
42
42
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
# The Cache Buster extension
|
2
2
|
class Middleman::Extensions::CacheBuster < ::Middleman::Extension
|
3
3
|
option :exts, nil, 'List of extensions that get cache busters strings appended to them.'
|
4
|
-
option :sources, %w
|
4
|
+
option :sources, %w(.css .htm .html .js .php .xhtml), 'List of extensions that are searched for bustable assets.'
|
5
5
|
option :ignore, [], 'Regexes of filenames to skip adding query strings to'
|
6
6
|
option :rewrite_ignore, [], 'Regexes of filenames to skip processing for path rewrites'
|
7
7
|
|
8
|
-
def initialize(app, options_hash
|
8
|
+
def initialize(app, options_hash={}, &block)
|
9
9
|
super
|
10
10
|
|
11
11
|
app.rewrite_inline_urls id: :cache_buster,
|
@@ -11,7 +11,7 @@ class Middleman::Extensions::DirectoryIndexes < ::Middleman::Extension
|
|
11
11
|
index_file = app.config[:index_file]
|
12
12
|
new_index_path = "/#{index_file}"
|
13
13
|
|
14
|
-
extensions = %w
|
14
|
+
extensions = %w(.htm .html .php .xhtml)
|
15
15
|
|
16
16
|
resources.each do |resource|
|
17
17
|
# Check if it would be pointless to reroute
|
@@ -7,12 +7,13 @@ class Middleman::Extensions::ExternalPipeline < ::Middleman::Extension
|
|
7
7
|
option :latency, 0.25, 'Latency between refreshes of source'
|
8
8
|
option :disable_background_execution, false, "Don't run the command in a separate background thread"
|
9
9
|
|
10
|
-
def initialize(app, config
|
10
|
+
def initialize(app, config={}, &block)
|
11
11
|
super
|
12
12
|
|
13
13
|
return if app.mode?(:config)
|
14
14
|
|
15
15
|
require 'servolux'
|
16
|
+
require 'thread'
|
16
17
|
require 'fileutils'
|
17
18
|
|
18
19
|
source_path = File.expand_path(options[:source], app.root)
|
@@ -40,12 +41,12 @@ class Middleman::Extensions::ExternalPipeline < ::Middleman::Extension
|
|
40
41
|
end
|
41
42
|
|
42
43
|
def reload!
|
43
|
-
|
44
|
+
if @current_thread
|
45
|
+
logger.info "== Stopping: `#{options[:command]}`"
|
44
46
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
@current_thread = nil
|
47
|
+
@current_thread.stop
|
48
|
+
@current_thread = nil
|
49
|
+
end
|
49
50
|
end
|
50
51
|
|
51
52
|
def watch_command!(async)
|
@@ -57,12 +58,9 @@ class Middleman::Extensions::ExternalPipeline < ::Middleman::Extension
|
|
57
58
|
@current_thread.start
|
58
59
|
|
59
60
|
watch_thread = Thread.new do
|
60
|
-
buf = @current_thread.io.gets
|
61
|
-
|
62
|
-
while buf
|
61
|
+
while buf = @current_thread.io.gets
|
63
62
|
without_newline = buf.sub(/\n$/, '')
|
64
63
|
logger.info "== External: #{without_newline}" unless without_newline.empty?
|
65
|
-
buf = @current_thread.io.gets
|
66
64
|
end
|
67
65
|
|
68
66
|
@current_thread.wait
|
@@ -82,12 +80,9 @@ class Middleman::Extensions::ExternalPipeline < ::Middleman::Extension
|
|
82
80
|
private
|
83
81
|
|
84
82
|
def print_command(stdout)
|
85
|
-
buf = stdout.gets
|
86
|
-
|
87
|
-
while buf
|
83
|
+
while buf = stdout.gets
|
88
84
|
without_newline = buf.sub(/\n$/, '')
|
89
85
|
logger.info "== External: #{without_newline}" unless without_newline.empty?
|
90
|
-
buf = stdout.gets
|
91
86
|
end
|
92
87
|
end
|
93
88
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# This extension Gzips assets and pages when building.
|
2
2
|
# Gzipped assets and pages can be served directly by Apache or
|
3
3
|
# Nginx with the proper configuration, and pre-zipping means that we
|
4
|
-
# can use a more
|
4
|
+
# can use a more agressive compression level at no CPU cost per request.
|
5
5
|
#
|
6
6
|
# Use Nginx's gzip_static directive, or AddEncoding and mod_rewrite in Apache
|
7
7
|
# to serve your Gzipped files whenever the normal (non-.gz) filename is requested.
|
@@ -10,7 +10,7 @@
|
|
10
10
|
# to .css, .htm, .html, .js, and .xhtml
|
11
11
|
#
|
12
12
|
class Middleman::Extensions::Gzip < ::Middleman::Extension
|
13
|
-
option :exts, %w
|
13
|
+
option :exts, %w(.css .htm .html .js .svg .xhtml), 'File extensions to Gzip when building.'
|
14
14
|
option :ignore, [], 'Patterns to avoid gzipping'
|
15
15
|
option :overwrite, false, 'Overwrite original files instead of adding .gz extension.'
|
16
16
|
|
@@ -18,12 +18,13 @@ class Middleman::Extensions::Gzip < ::Middleman::Extension
|
|
18
18
|
include ::Padrino::Helpers::NumberHelpers
|
19
19
|
end
|
20
20
|
|
21
|
-
def initialize(app, options_hash
|
21
|
+
def initialize(app, options_hash={})
|
22
22
|
super
|
23
23
|
|
24
24
|
require 'zlib'
|
25
25
|
require 'stringio'
|
26
26
|
require 'find'
|
27
|
+
require 'thread'
|
27
28
|
end
|
28
29
|
|
29
30
|
def after_build(builder)
|
@@ -42,11 +43,8 @@ class Middleman::Extensions::Gzip < ::Middleman::Extension
|
|
42
43
|
out_queue = Queue.new
|
43
44
|
num_threads.times.each do
|
44
45
|
Thread.new do
|
45
|
-
path = in_queue.pop
|
46
|
-
|
47
|
-
while path
|
46
|
+
while path = in_queue.pop
|
48
47
|
out_queue << gzip_file(path.to_s)
|
49
|
-
path = in_queue.pop
|
50
48
|
end
|
51
49
|
end
|
52
50
|
end
|
@@ -65,7 +63,7 @@ class Middleman::Extensions::Gzip < ::Middleman::Extension
|
|
65
63
|
next unless output_filename
|
66
64
|
|
67
65
|
total_savings += (old_size - new_size)
|
68
|
-
size_change_word = (old_size - new_size)
|
66
|
+
size_change_word = (old_size - new_size) > 0 ? 'smaller' : 'larger'
|
69
67
|
builder.trigger :created, "#{output_filename} (#{NumberHelpers.new.number_to_human_size((old_size - new_size).abs)} #{size_change_word})"
|
70
68
|
end
|
71
69
|
|
@@ -11,7 +11,7 @@ class Middleman::Extensions::Lorem < ::Middleman::Extension
|
|
11
11
|
# @param [String] size
|
12
12
|
# @param [Hash] options
|
13
13
|
# @return [String]
|
14
|
-
def placekitten(size, options
|
14
|
+
def placekitten(size, options={})
|
15
15
|
options[:domain] = 'http://placekitten.com'
|
16
16
|
lorem.image(size, options)
|
17
17
|
end
|
@@ -44,7 +44,7 @@ class Middleman::Extensions::Lorem < ::Middleman::Extension
|
|
44
44
|
module LoremObject
|
45
45
|
class << self
|
46
46
|
# Words for use in lorem text
|
47
|
-
WORDS = %w
|
47
|
+
WORDS = %w(alias consequatur aut perferendis sit voluptatem accusantium doloremque aperiam eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo aspernatur aut odit aut fugit sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt neque dolorem ipsum quia dolor sit amet consectetur adipisci velit sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem ut enim ad minima veniam quis nostrum exercitationem ullam corporis nemo enim ipsam voluptatem quia voluptas sit suscipit laboriosam nisi ut aliquid ex ea commodi consequatur quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae et iusto odio dignissimos ducimus qui blanditiis praesentium laudantium totam rem voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident sed ut perspiciatis unde omnis iste natus error similique sunt in culpa qui officia deserunt mollitia animi id est laborum et dolorum fuga et harum quidem rerum facilis est et expedita distinctio nam libero tempore cum soluta nobis est eligendi optio cumque nihil impedit quo porro quisquam est qui minus id quod maxime placeat facere possimus omnis voluptas assumenda est omnis dolor repellendus temporibus autem quibusdam et aut consequatur vel illum qui dolorem eum fugiat quo voluptas nulla pariatur at vero eos et accusamus officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae itaque earum rerum hic tenetur a sapiente delectus ut aut reiciendis voluptatibus maiores doloribus asperiores repellat).freeze
|
48
48
|
|
49
49
|
# Get one placeholder word
|
50
50
|
# @return [String]
|
@@ -94,10 +94,10 @@ class Middleman::Extensions::Lorem < ::Middleman::Extension
|
|
94
94
|
# Get a placeholder date
|
95
95
|
# @param [String] fmt
|
96
96
|
# @return [String]
|
97
|
-
def date(fmt
|
98
|
-
y = rand(1990
|
99
|
-
m = rand(
|
100
|
-
d = rand(
|
97
|
+
def date(fmt='%a %b %d, %Y')
|
98
|
+
y = rand(20) + 1990
|
99
|
+
m = rand(12) + 1
|
100
|
+
d = rand(31) + 1
|
101
101
|
Time.local(y, m, d).strftime(fmt)
|
102
102
|
end
|
103
103
|
|
@@ -135,7 +135,7 @@ class Middleman::Extensions::Lorem < ::Middleman::Extension
|
|
135
135
|
# @return [String]
|
136
136
|
def email
|
137
137
|
delimiters = ['_', '-', '']
|
138
|
-
domains = %w
|
138
|
+
domains = %w(gmail.com yahoo.com hotmail.com email.com live.com me.com mac.com aol.com fastmail.com mail.com)
|
139
139
|
username = name.gsub(/[^\w]/, delimiters[rand(delimiters.size)])
|
140
140
|
"#{username}@#{domains[rand(domains.size)]}".downcase
|
141
141
|
end
|
@@ -144,10 +144,10 @@ class Middleman::Extensions::Lorem < ::Middleman::Extension
|
|
144
144
|
# @param [String] size
|
145
145
|
# @param [Hash] options
|
146
146
|
# @return [String]
|
147
|
-
def image(size, options
|
147
|
+
def image(size, options={})
|
148
148
|
domain = options[:domain] || 'http://placehold.it'
|
149
149
|
src = "#{domain}/#{size}"
|
150
|
-
hex = %w
|
150
|
+
hex = %w(a b c d e f 0 1 2 3 4 5 6 7 8 9)
|
151
151
|
background_color = options[:background_color]
|
152
152
|
color = options[:color]
|
153
153
|
|
@@ -1,17 +1,17 @@
|
|
1
1
|
require 'active_support/core_ext/object/try'
|
2
2
|
require 'memoist'
|
3
3
|
require 'middleman-core/contracts'
|
4
|
+
require 'sassc'
|
4
5
|
|
5
6
|
# Minify CSS Extension
|
6
7
|
class Middleman::Extensions::MinifyCss < ::Middleman::Extension
|
7
8
|
option :inline, false, 'Whether to minify CSS inline within HTML files'
|
8
9
|
option :ignore, [], 'Patterns to avoid minifying'
|
9
10
|
option :compressor, proc {
|
10
|
-
require 'sass'
|
11
11
|
SassCompressor
|
12
12
|
}, 'Set the CSS compressor to use.'
|
13
|
-
option :content_types, %w
|
14
|
-
option :inline_content_types, %w
|
13
|
+
option :content_types, %w(text/css), 'Content types of resources that contain CSS'
|
14
|
+
option :inline_content_types, %w(text/html text/php), 'Content types of resources that contain inline CSS'
|
15
15
|
|
16
16
|
def ready
|
17
17
|
# Setup Rack middleware to minify CSS
|
@@ -23,10 +23,12 @@ class Middleman::Extensions::MinifyCss < ::Middleman::Extension
|
|
23
23
|
end
|
24
24
|
|
25
25
|
class SassCompressor
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
COMPRESSED_OPTIONS = { style: :compressed }.freeze
|
27
|
+
|
28
|
+
def self.compress(style, options={})
|
29
|
+
options = options.merge(COMPRESSED_OPTIONS)
|
30
|
+
|
31
|
+
::SassC::Engine.new(style, options).render.strip
|
30
32
|
end
|
31
33
|
end
|
32
34
|
|
@@ -44,7 +46,7 @@ class Middleman::Extensions::MinifyCss < ::Middleman::Extension
|
|
44
46
|
inline: Bool,
|
45
47
|
compressor: Or[Proc, RespondTo[:to_proc], RespondTo[:compress]]
|
46
48
|
} => Any
|
47
|
-
def initialize(app, options
|
49
|
+
def initialize(app, options={})
|
48
50
|
@app = app
|
49
51
|
@ignore = options.fetch(:ignore)
|
50
52
|
@inline = options.fetch(:inline)
|
@@ -57,7 +59,7 @@ class Middleman::Extensions::MinifyCss < ::Middleman::Extension
|
|
57
59
|
end
|
58
60
|
|
59
61
|
# Rack interface
|
60
|
-
# @param [Rack::
|
62
|
+
# @param [Rack::Environmemt] env
|
61
63
|
# @return [Array]
|
62
64
|
def call(env)
|
63
65
|
status, headers, response = @app.call(env)
|
@@ -66,10 +68,10 @@ class Middleman::Extensions::MinifyCss < ::Middleman::Extension
|
|
66
68
|
path = env['PATH_INFO']
|
67
69
|
|
68
70
|
minified = if @inline && minifiable_inline?(content_type)
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
71
|
+
minify_inline(::Middleman::Util.extract_response_text(response))
|
72
|
+
elsif minifiable?(content_type) && !ignore?(path)
|
73
|
+
minify(::Middleman::Util.extract_response_text(response))
|
74
|
+
end
|
73
75
|
|
74
76
|
if minified
|
75
77
|
headers['Content-Length'] = minified.bytesize.to_s
|
@@ -118,7 +120,7 @@ class Middleman::Extensions::MinifyCss < ::Middleman::Extension
|
|
118
120
|
# @return [String]
|
119
121
|
def minify_inline(content)
|
120
122
|
content.gsub(INLINE_CSS_REGEX) do
|
121
|
-
|
123
|
+
$1 + minify($2) + $3
|
122
124
|
end
|
123
125
|
end
|
124
126
|
memoize :minify_inline
|