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
@@ -2,16 +2,16 @@ require 'active_support/core_ext/object/try'
|
|
2
2
|
require 'middleman-core/contracts'
|
3
3
|
require 'memoist'
|
4
4
|
|
5
|
-
# Minify
|
6
|
-
class Middleman::Extensions::
|
5
|
+
# Minify Javascript Extension
|
6
|
+
class Middleman::Extensions::MinifyJavascript < ::Middleman::Extension
|
7
7
|
option :inline, false, 'Whether to minify JS inline within HTML files'
|
8
8
|
option :ignore, [], 'Patterns to avoid minifying'
|
9
9
|
option :compressor, proc {
|
10
10
|
require 'uglifier'
|
11
11
|
::Uglifier.new
|
12
12
|
}, 'Set the JS compressor to use.'
|
13
|
-
option :content_types, %w
|
14
|
-
option :inline_content_types, %w
|
13
|
+
option :content_types, %w(application/javascript), 'Content types of resources that contain JS'
|
14
|
+
option :inline_content_types, %w(text/html text/php), 'Content types of resources that contain inline JS'
|
15
15
|
|
16
16
|
def ready
|
17
17
|
# Setup Rack middleware to minify JS
|
@@ -36,7 +36,7 @@ class Middleman::Extensions::MinifyJavaScript < ::Middleman::Extension
|
|
36
36
|
inline: Bool,
|
37
37
|
compressor: Or[Proc, RespondTo[:to_proc], RespondTo[:compress]]
|
38
38
|
} => Any
|
39
|
-
def initialize(app, options
|
39
|
+
def initialize(app, options={})
|
40
40
|
@app = app
|
41
41
|
@ignore = options.fetch(:ignore)
|
42
42
|
@inline = options.fetch(:inline)
|
@@ -49,7 +49,7 @@ class Middleman::Extensions::MinifyJavaScript < ::Middleman::Extension
|
|
49
49
|
end
|
50
50
|
|
51
51
|
# Rack interface
|
52
|
-
# @param [Rack::
|
52
|
+
# @param [Rack::Environmemt] env
|
53
53
|
# @return [Array]
|
54
54
|
def call(env)
|
55
55
|
status, headers, response = @app.call(env)
|
@@ -58,10 +58,10 @@ class Middleman::Extensions::MinifyJavaScript < ::Middleman::Extension
|
|
58
58
|
@path = env['PATH_INFO']
|
59
59
|
|
60
60
|
minified = if @inline && minifiable_inline?(type)
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
61
|
+
minify_inline(::Middleman::Util.extract_response_text(response))
|
62
|
+
elsif minifiable?(type) && !ignore?(@path)
|
63
|
+
minify(::Middleman::Util.extract_response_text(response))
|
64
|
+
end
|
65
65
|
|
66
66
|
if minified
|
67
67
|
headers['Content-Length'] = minified.bytesize.to_s
|
@@ -113,9 +113,9 @@ class Middleman::Extensions::MinifyJavaScript < ::Middleman::Extension
|
|
113
113
|
# @return [String]
|
114
114
|
def minify_inline(content)
|
115
115
|
content.gsub(INLINE_JS_REGEX) do |match|
|
116
|
-
first =
|
117
|
-
inline_content =
|
118
|
-
last =
|
116
|
+
first = $1
|
117
|
+
inline_content = $2
|
118
|
+
last = $3
|
119
119
|
|
120
120
|
# Only compress script tags that contain JavaScript (as opposed to
|
121
121
|
# something like jQuery templates, identified with a "text/html" type).
|
@@ -3,12 +3,12 @@ require 'addressable/uri'
|
|
3
3
|
# Relative Assets extension
|
4
4
|
class Middleman::Extensions::RelativeAssets < ::Middleman::Extension
|
5
5
|
option :exts, nil, 'List of extensions that get converted to relative paths.'
|
6
|
-
option :sources, %w
|
6
|
+
option :sources, %w(.css .htm .html .xhtml), 'List of extensions that are searched for relative assets.'
|
7
7
|
option :ignore, [], 'Regexes of filenames to skip converting to relative paths.'
|
8
8
|
option :rewrite_ignore, [], 'Regexes of filenames to skip processing for path rewrites.'
|
9
9
|
option :helpers_only, false, 'Allow only Ruby helpers to change paths.'
|
10
10
|
|
11
|
-
def initialize(app, options_hash
|
11
|
+
def initialize(app, options_hash={}, &block)
|
12
12
|
super
|
13
13
|
|
14
14
|
return if options[:helpers_only]
|
@@ -46,11 +46,11 @@ class Middleman::Extensions::RelativeAssets < ::Middleman::Extension
|
|
46
46
|
end
|
47
47
|
|
48
48
|
helpers do
|
49
|
-
def asset_url(path, prefix
|
49
|
+
def asset_url(path, prefix='', options={})
|
50
50
|
super(path, prefix, app.extensions[:relative_assets].mark_as_relative(super, options, current_resource))
|
51
51
|
end
|
52
52
|
|
53
|
-
def asset_path(kind, source, options
|
53
|
+
def asset_path(kind, source, options={})
|
54
54
|
super(kind, source, app.extensions[:relative_assets].mark_as_relative(super, options, current_resource))
|
55
55
|
end
|
56
56
|
end
|
@@ -64,10 +64,10 @@ class Middleman::Extensions::RelativeAssets < ::Middleman::Extension
|
|
64
64
|
relative_path = uri.host.nil?
|
65
65
|
|
66
66
|
full_asset_path = if relative_path
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
67
|
+
dirpath.join(asset_path).to_s
|
68
|
+
else
|
69
|
+
asset_path
|
70
|
+
end
|
71
71
|
|
72
72
|
current_dir = Pathname(request_path).dirname
|
73
73
|
result = Pathname(full_asset_path).relative_path_from(current_dir).to_s
|
@@ -49,9 +49,8 @@ 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
|
52
|
+
def register(name, extension_class=nil, options={}, &block)
|
53
53
|
raise 'Extension name must be a symbol' unless name.is_a?(Symbol)
|
54
|
-
|
55
54
|
# If we've already got an extension registered under this name, bail out
|
56
55
|
# raise "There is a already an extension registered with the name '#{name}'" if registered.key?(name)
|
57
56
|
|
@@ -62,12 +61,12 @@ module Middleman
|
|
62
61
|
end
|
63
62
|
|
64
63
|
registered[name] = if block_given?
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
64
|
+
block
|
65
|
+
elsif extension_class && extension_class.ancestors.include?(::Middleman::Extension)
|
66
|
+
extension_class
|
67
|
+
else
|
68
|
+
raise 'You must provide a Middleman::Extension or a block that returns a Middleman::Extension'
|
69
|
+
end
|
71
70
|
|
72
71
|
return unless options[:auto_activate]
|
73
72
|
|
@@ -32,23 +32,22 @@ module Middleman
|
|
32
32
|
def render(locs, opts, context, &block)
|
33
33
|
path = @path.dup
|
34
34
|
|
35
|
-
# Detect the
|
35
|
+
# Detect the remdering engine from the extension
|
36
36
|
extension = File.extname(path)
|
37
37
|
engine = extension[1..-1].to_sym
|
38
38
|
|
39
39
|
# Store last engine for later (could be inside nested renders)
|
40
|
-
engine_was = context.current_engine
|
41
|
-
context.current_engine = engine
|
40
|
+
context.current_engine, engine_was = engine, context.current_engine
|
42
41
|
|
43
42
|
# Save current buffer for later
|
44
43
|
buf_was = context.save_buffer
|
45
44
|
|
46
45
|
# Read from disk or cache the contents of the file
|
47
46
|
body = if opts[:template_body]
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
47
|
+
opts.delete(:template_body)
|
48
|
+
else
|
49
|
+
template_data_for_file
|
50
|
+
end
|
52
51
|
|
53
52
|
# Merge per-extension options from config
|
54
53
|
extension = File.extname(path)
|
@@ -5,6 +5,7 @@ module Middleman
|
|
5
5
|
class << self
|
6
6
|
def setup_load_paths
|
7
7
|
@_is_setup ||= begin
|
8
|
+
|
8
9
|
# Only look for config.rb if MM_ROOT isn't set
|
9
10
|
if !ENV['MM_ROOT'] && (found_path = findup('config.rb'))
|
10
11
|
ENV['MM_ROOT'] = found_path
|
@@ -21,31 +22,27 @@ module Middleman
|
|
21
22
|
|
22
23
|
# Set BUNDLE_GEMFILE and run Bundler setup. Raises an exception if there is no Gemfile
|
23
24
|
def setup_bundler
|
24
|
-
found_gemfile_root = findup('Gemfile', ENV['MM_ROOT'])
|
25
|
-
|
26
|
-
if found_gemfile_root
|
25
|
+
if found_gemfile_root = findup('Gemfile', ENV['MM_ROOT'])
|
27
26
|
ENV['BUNDLE_GEMFILE'] ||= File.join(found_gemfile_root, 'Gemfile')
|
28
27
|
end
|
29
28
|
|
30
29
|
unless File.exist?(ENV['BUNDLE_GEMFILE'])
|
31
|
-
ENV['BUNDLE_GEMFILE'] = File.expand_path('
|
30
|
+
ENV['BUNDLE_GEMFILE'] = File.expand_path('../../../../Gemfile', __FILE__)
|
32
31
|
end
|
33
32
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
)
|
33
|
+
if File.exist?(ENV['BUNDLE_GEMFILE'])
|
34
|
+
require 'bundler/setup'
|
35
|
+
Bundler.require
|
36
|
+
else
|
37
|
+
raise "Couldn't find your Gemfile. Middleman projects require a Gemfile for specifying dependencies."
|
38
|
+
end
|
41
39
|
end
|
42
40
|
|
43
41
|
# Recursive method to find a file in parent directories
|
44
|
-
def findup(filename, cwd
|
42
|
+
def findup(filename, cwd=Dir.pwd)
|
45
43
|
cwd = Pathname(cwd)
|
46
44
|
return cwd.to_s if (cwd + filename).exist?
|
47
45
|
return false if cwd.root?
|
48
|
-
|
49
46
|
findup(filename, cwd.parent)
|
50
47
|
end
|
51
48
|
end
|
@@ -1,11 +1,13 @@
|
|
1
1
|
# Use the Ruby/Rails logger
|
2
2
|
require 'active_support/notifications'
|
3
3
|
require 'active_support/logger'
|
4
|
+
require 'thread'
|
5
|
+
|
4
6
|
module Middleman
|
5
7
|
# The Middleman Logger
|
6
8
|
class Logger < ActiveSupport::Logger
|
7
9
|
def self.singleton(*args)
|
8
|
-
if !@_logger || !args.empty?
|
10
|
+
if !@_logger || !args || !args.empty?
|
9
11
|
if args.length == 1 && (args.first.is_a?(::String) || args.first.respond_to?(:write))
|
10
12
|
args = [0, false, args.first]
|
11
13
|
end
|
@@ -15,7 +17,7 @@ module Middleman
|
|
15
17
|
@_logger
|
16
18
|
end
|
17
19
|
|
18
|
-
def initialize(log_level
|
20
|
+
def initialize(log_level=1, is_instrumenting=false, target=$stdout)
|
19
21
|
super(target)
|
20
22
|
|
21
23
|
self.level = log_level
|
@@ -39,7 +41,6 @@ module Middleman
|
|
39
41
|
|
40
42
|
evt = ::ActiveSupport::Notifications::Event.new(message, *args)
|
41
43
|
return unless evt.duration > 30
|
42
|
-
|
43
44
|
info "== Instrument (#{evt.name.sub(/.middleman$/, '')}): #{evt.duration}ms\n#{args.last}"
|
44
45
|
end
|
45
46
|
end
|
@@ -59,7 +59,7 @@ module Middleman
|
|
59
59
|
|
60
60
|
if path_parts.size == 1
|
61
61
|
sitemap_class = SitemapResource
|
62
|
-
# Allow special sitemap resources to use custom metadata view
|
62
|
+
# Allow special sitemap resources to use custom metadata view calsses
|
63
63
|
sitemap_class = resource.meta_pages_class if resource.respond_to? :meta_pages_class
|
64
64
|
|
65
65
|
@children[first_part] = sitemap_class.new(resource)
|
@@ -93,7 +93,7 @@ module Middleman
|
|
93
93
|
private
|
94
94
|
|
95
95
|
# Render a template with the given name and locals
|
96
|
-
def template(template_name, locals
|
96
|
+
def template(template_name, locals={})
|
97
97
|
template_path = File.join(File.dirname(__FILE__), 'meta_pages', 'templates', template_name)
|
98
98
|
content = Tilt.new(template_path).render(::Object.new, locals)
|
99
99
|
response(content)
|
@@ -46,7 +46,7 @@ module Middleman
|
|
46
46
|
# @param [Information] information
|
47
47
|
# The information to be validated
|
48
48
|
def validate(information)
|
49
|
-
return if information.bind_address.blank? || information.local_network_interfaces.include?(information.bind_address.to_s) || %w
|
49
|
+
return if information.bind_address.blank? || information.local_network_interfaces.include?(information.bind_address.to_s) || %w(0.0.0.0 ::).any? { |b| information.bind_address == b } || IPAddr.new('127.0.0.0/8').include?(information.bind_address.to_s)
|
50
50
|
|
51
51
|
information.valid = false
|
52
52
|
information.reason = format('Bind address "%s" is not available on your system. Please use one of %s', information.bind_address, information.local_network_interfaces.map { |i| %("#{i}") }.join(', '))
|
@@ -27,7 +27,7 @@ module Middleman
|
|
27
27
|
#
|
28
28
|
# @param [Integer] port
|
29
29
|
# The port to listen on
|
30
|
-
def initialize(opts
|
30
|
+
def initialize(opts={})
|
31
31
|
@bind_address = ServerIpAddress.new(opts[:bind_address])
|
32
32
|
@server_name = ServerHostname.new(opts[:server_name])
|
33
33
|
@port = opts[:port]
|
@@ -56,7 +56,7 @@ module Middleman
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def resolve_me(*)
|
59
|
-
|
59
|
+
fail NoMethodError
|
60
60
|
end
|
61
61
|
|
62
62
|
# Get network information
|
@@ -100,7 +100,7 @@ module Middleman
|
|
100
100
|
after_init
|
101
101
|
end
|
102
102
|
|
103
|
-
def self.matches?(opts
|
103
|
+
def self.matches?(opts={})
|
104
104
|
opts[:bind_address].blank? && opts[:server_name].blank?
|
105
105
|
end
|
106
106
|
|
@@ -116,7 +116,7 @@ module Middleman
|
|
116
116
|
@site_addresses << hostname
|
117
117
|
|
118
118
|
network_interface = ServerIpAddress.new((local_network_interfaces & hostname_ips).first)
|
119
|
-
elsif
|
119
|
+
elsif RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
|
120
120
|
@server_name = hostname
|
121
121
|
@site_addresses << hostname
|
122
122
|
elsif !resolved_name.blank?
|
@@ -146,7 +146,7 @@ module Middleman
|
|
146
146
|
# This is used if bind address is 0.0.0.0, the server name needs to be
|
147
147
|
# blank
|
148
148
|
class AllIpv4Interfaces < AllInterfaces
|
149
|
-
def self.matches?(opts
|
149
|
+
def self.matches?(opts={})
|
150
150
|
opts[:bind_address] == '0.0.0.0' && opts[:server_name].blank?
|
151
151
|
end
|
152
152
|
|
@@ -164,7 +164,7 @@ module Middleman
|
|
164
164
|
|
165
165
|
# This is used if bind address is ::, the server name needs to be blank
|
166
166
|
class AllIpv6Interfaces < AllInterfaces
|
167
|
-
def self.matches?(opts
|
167
|
+
def self.matches?(opts={})
|
168
168
|
opts[:bind_address] == '::' && opts[:server_name].blank?
|
169
169
|
end
|
170
170
|
|
@@ -189,7 +189,7 @@ module Middleman
|
|
189
189
|
@site_addresses << bind_address
|
190
190
|
end
|
191
191
|
|
192
|
-
def self.matches?(opts
|
192
|
+
def self.matches?(opts={})
|
193
193
|
!opts[:bind_address].blank? && opts[:server_name].blank?
|
194
194
|
end
|
195
195
|
|
@@ -222,7 +222,7 @@ module Middleman
|
|
222
222
|
self
|
223
223
|
end
|
224
224
|
|
225
|
-
def self.matches?(opts
|
225
|
+
def self.matches?(opts={})
|
226
226
|
opts[:bind_address].blank? && !opts[:server_name].blank?
|
227
227
|
end
|
228
228
|
end
|
@@ -240,8 +240,8 @@ module Middleman
|
|
240
240
|
@checks << Checks::ServerNameResolvesToBindAddress.new
|
241
241
|
end
|
242
242
|
|
243
|
-
def self.matches?(opts
|
244
|
-
!opts[:bind_address].blank? && !opts[:server_name].blank? && !%w
|
243
|
+
def self.matches?(opts={})
|
244
|
+
!opts[:bind_address].blank? && !opts[:server_name].blank? && !%w(:: 0.0.0.0).include?(opts[:bind_address])
|
245
245
|
end
|
246
246
|
|
247
247
|
def resolve_me(*); end
|
@@ -250,7 +250,7 @@ module Middleman
|
|
250
250
|
# If the server name is either an ipv4 or ipv6 address, e.g. 127.0.0.1 or
|
251
251
|
# ::1, use this one
|
252
252
|
class ServerNameIsIpInformation < BasicInformation
|
253
|
-
def initialize(opts
|
253
|
+
def initialize(opts={})
|
254
254
|
super
|
255
255
|
|
256
256
|
ip = ServerIpAddress.new(server_name.to_s)
|
@@ -261,11 +261,11 @@ module Middleman
|
|
261
261
|
|
262
262
|
def resolve_me(*); end
|
263
263
|
|
264
|
-
def self.matches?(opts
|
264
|
+
def self.matches?(opts={})
|
265
265
|
ip = IPAddr.new(opts[:server_name])
|
266
266
|
|
267
267
|
ip.ipv4? || ip.ipv6?
|
268
|
-
rescue
|
268
|
+
rescue
|
269
269
|
false
|
270
270
|
end
|
271
271
|
end
|
@@ -25,7 +25,7 @@ module Middleman
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def self.match?(type)
|
28
|
-
|
28
|
+
:ipv4 == type
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -36,7 +36,7 @@ module Middleman
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def self.match?(type)
|
39
|
-
|
39
|
+
:ipv6 == type
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
@@ -57,7 +57,7 @@ module Middleman
|
|
57
57
|
#
|
58
58
|
# @param [Symbol] type
|
59
59
|
# The type of interface which should be returned
|
60
|
-
def network_interfaces(type
|
60
|
+
def network_interfaces(type=:all)
|
61
61
|
types.find { |t| t.match? type.to_sym }.new.network_interfaces
|
62
62
|
end
|
63
63
|
end
|
@@ -22,7 +22,7 @@ module Middleman
|
|
22
22
|
|
23
23
|
attr_writer :https
|
24
24
|
|
25
|
-
def initialize(opts
|
25
|
+
def initialize(opts={})
|
26
26
|
@resolver = opts.fetch(:resolver, DnsResolver.new)
|
27
27
|
@validator = opts.fetch(:validator, ServerInformationValidator.new)
|
28
28
|
@network_interface_inventory = opts.fetch(:network_interface_inventory, NetworkInterfaceInventory.new)
|
@@ -7,7 +7,7 @@ module Middleman
|
|
7
7
|
# * server name
|
8
8
|
# * site_addresses
|
9
9
|
#
|
10
|
-
# All information is "
|
10
|
+
# All information is "dupped" and the callback is not meant to be used to
|
11
11
|
# modify these information.
|
12
12
|
class ServerInformationCallbackProxy
|
13
13
|
attr_reader :server_name, :port, :site_addresses, :listeners
|
@@ -8,6 +8,7 @@ require 'middleman-core/preview_server/server_information'
|
|
8
8
|
require 'middleman-core/preview_server/server_url'
|
9
9
|
require 'middleman-core/preview_server/server_information_callback_proxy'
|
10
10
|
|
11
|
+
# rubocop:disable GlobalVars
|
11
12
|
module Middleman
|
12
13
|
class PreviewServer
|
13
14
|
class << self
|
@@ -17,7 +18,7 @@ module Middleman
|
|
17
18
|
|
18
19
|
# Start an instance of Middleman::Application
|
19
20
|
# @return [void]
|
20
|
-
def start(opts
|
21
|
+
def start(opts={}, cli_options={})
|
21
22
|
# Do not buffer output, otherwise testing of output does not work
|
22
23
|
$stdout.sync = true
|
23
24
|
$stderr.sync = true
|
@@ -34,7 +35,7 @@ module Middleman
|
|
34
35
|
|
35
36
|
# And now comes the check
|
36
37
|
unless server_information.valid?
|
37
|
-
|
38
|
+
$stderr.puts %(== Running Middleman failed: #{server_information.reason}. Please fix that and try again.)
|
38
39
|
exit 1
|
39
40
|
end
|
40
41
|
|
@@ -48,7 +49,6 @@ module Middleman
|
|
48
49
|
|
49
50
|
@initialized ||= false
|
50
51
|
return if @initialized
|
51
|
-
|
52
52
|
@initialized = true
|
53
53
|
|
54
54
|
register_signal_handlers
|
@@ -61,9 +61,7 @@ module Middleman
|
|
61
61
|
|
62
62
|
if @options[:daemon]
|
63
63
|
# To output the child PID, let's make preview server a daemon by hand
|
64
|
-
child_pid = fork
|
65
|
-
|
66
|
-
if child_pid
|
64
|
+
if child_pid = fork
|
67
65
|
app.logger.info "== Middleman preview server is running in background with PID #{child_pid}"
|
68
66
|
Process.detach child_pid
|
69
67
|
exit 0
|
@@ -93,7 +91,7 @@ module Middleman
|
|
93
91
|
def stop
|
94
92
|
begin
|
95
93
|
app.logger.info '== The Middleman is shutting down'
|
96
|
-
rescue
|
94
|
+
rescue
|
97
95
|
# if the user closed their terminal STDOUT/STDERR won't exist
|
98
96
|
end
|
99
97
|
|
@@ -109,8 +107,8 @@ module Middleman
|
|
109
107
|
|
110
108
|
begin
|
111
109
|
app = initialize_new_app
|
112
|
-
rescue
|
113
|
-
|
110
|
+
rescue => e
|
111
|
+
$stderr.puts "Error reloading Middleman: #{e}\n#{e.backtrace.join("\n")}"
|
114
112
|
app.logger.info '== The Middleman is still running the application from before the error'
|
115
113
|
return
|
116
114
|
end
|
@@ -151,7 +149,7 @@ module Middleman
|
|
151
149
|
ready do
|
152
150
|
unless config[:watcher_disable]
|
153
151
|
match_against = [
|
154
|
-
|
152
|
+
%r{^config\.rb$},
|
155
153
|
%r{^environments/[^\.](.*)\.rb$},
|
156
154
|
%r{^lib/[^\.](.*)\.rb$},
|
157
155
|
%r{^#{config[:helpers_dir]}/[^\.](.*)\.rb$}
|
@@ -201,21 +199,25 @@ module Middleman
|
|
201
199
|
|
202
200
|
# Add in the meta pages application
|
203
201
|
meta_app = Middleman::MetaPages::Application.new(app)
|
204
|
-
app.map '/__middleman' do
|
205
|
-
|
202
|
+
app.map '/__middleman' do
|
203
|
+
run meta_app
|
206
204
|
end
|
207
205
|
|
208
206
|
app
|
209
207
|
end
|
210
208
|
|
211
209
|
def possible_from_cli(key, config)
|
212
|
-
@cli_options[key]
|
210
|
+
if @cli_options[key]
|
211
|
+
@cli_options[key]
|
212
|
+
else
|
213
|
+
config[key]
|
214
|
+
end
|
213
215
|
end
|
214
216
|
|
215
|
-
# Trap some
|
217
|
+
# Trap some interupt signals and shut down smoothly
|
216
218
|
# @return [void]
|
217
219
|
def register_signal_handlers
|
218
|
-
%w
|
220
|
+
%w(INT HUP TERM QUIT).each do |sig|
|
219
221
|
next unless Signal.list[sig]
|
220
222
|
|
221
223
|
Signal.trap(sig) do
|
@@ -243,14 +245,13 @@ module Middleman
|
|
243
245
|
|
244
246
|
if ssl_certificate || ssl_private_key
|
245
247
|
raise 'You must provide both :ssl_certificate and :ssl_private_key' unless ssl_private_key && ssl_certificate
|
246
|
-
|
247
248
|
http_opts[:SSLCertificate] = OpenSSL::X509::Certificate.new ::File.read ssl_certificate
|
248
249
|
http_opts[:SSLPrivateKey] = OpenSSL::PKey::RSA.new ::File.read ssl_private_key
|
249
250
|
else
|
250
251
|
# use a generated self-signed cert
|
251
252
|
http_opts[:SSLCertName] = [
|
252
|
-
%w
|
253
|
-
|
253
|
+
%w(CN localhost),
|
254
|
+
%w(CN #{host})
|
254
255
|
].uniq
|
255
256
|
cert, key = create_self_signed_cert(1024, [['CN', server_information.server_name]], server_information.site_addresses, 'Middleman Preview Server')
|
256
257
|
http_opts[:SSLCertificate] = cert
|
@@ -259,16 +260,15 @@ module Middleman
|
|
259
260
|
end
|
260
261
|
|
261
262
|
http_opts[:Logger] = if is_logging
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
263
|
+
FilteredWebrickLog.new
|
264
|
+
else
|
265
|
+
::WEBrick::Log.new(nil, 0)
|
266
|
+
end
|
266
267
|
|
267
268
|
begin
|
268
269
|
::WEBrick::HTTPServer.new(http_opts)
|
269
270
|
rescue Errno::EADDRINUSE
|
270
|
-
|
271
|
-
warn %(== Port #{port} is already in use. This could mean another instance of middleman is already running. Please make sure port #{port} is free and start `middleman server` again, or choose another port by running `middleman server —-port=#{port + 1}` instead.)
|
271
|
+
$stderr.puts %(== Port "#{http_opts[:Port]}" is in use. This should not have happened. Please start "middleman server" again.)
|
272
272
|
end
|
273
273
|
end
|
274
274
|
|
@@ -331,7 +331,7 @@ module Middleman
|
|
331
331
|
|
332
332
|
class FilteredWebrickLog < ::WEBrick::Log
|
333
333
|
def log(level, data)
|
334
|
-
super(level, data) unless data =~
|
334
|
+
super(level, data) unless data =~ %r{Could not determine content-length of response body.}
|
335
335
|
end
|
336
336
|
end
|
337
337
|
end
|
data/lib/middleman-core/rack.rb
CHANGED
@@ -143,7 +143,7 @@ module Middleman
|
|
143
143
|
response = file.serving(env)
|
144
144
|
end
|
145
145
|
status = response[0]
|
146
|
-
response[1]['Content-Encoding'] = 'gzip' if %w
|
146
|
+
response[1]['Content-Encoding'] = 'gzip' if %w(.svgz .gz).include?(resource.ext)
|
147
147
|
# Do not set Content-Type if status is 1xx, 204, 205 or 304, otherwise
|
148
148
|
# Rack will throw an error (500)
|
149
149
|
if !(100..199).cover?(status) && ![204, 205, 304].include?(status)
|
@@ -6,7 +6,7 @@ module Middleman
|
|
6
6
|
# CoffeeScript Renderer
|
7
7
|
class CoffeeScript < ::Middleman::Extension
|
8
8
|
# Setup extension
|
9
|
-
def initialize(app, options
|
9
|
+
def initialize(app, options={}, &block)
|
10
10
|
super
|
11
11
|
|
12
12
|
# Tell Tilt to use it as well (for inline scss blocks)
|
@@ -32,7 +32,7 @@ module Middleman
|
|
32
32
|
super
|
33
33
|
rescue ::ExecJS::RuntimeError => e
|
34
34
|
e.to_s
|
35
|
-
rescue
|
35
|
+
rescue => e
|
36
36
|
e.to_s
|
37
37
|
end
|
38
38
|
end
|