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
@@ -35,7 +35,7 @@ module Middleman
|
|
35
35
|
end
|
36
36
|
|
37
37
|
# Renderer Options
|
38
|
-
possible_render_opts = [
|
38
|
+
possible_render_opts = %i[filter_html no_images no_links no_styles safe_links_only with_toc_data hard_wrap xhtml prettify link_attributes]
|
39
39
|
|
40
40
|
render_options = possible_render_opts.each_with_object({}) do |opt, sum|
|
41
41
|
sum[opt] = options.delete(opt) if options.key?(opt)
|
@@ -65,7 +65,7 @@ module Middleman
|
|
65
65
|
class MiddlemanRedcarpetHTML < ::Redcarpet::Render::HTML
|
66
66
|
cattr_accessor :scope
|
67
67
|
|
68
|
-
def initialize(options={})
|
68
|
+
def initialize(options = {})
|
69
69
|
@local_options = options.dup
|
70
70
|
|
71
71
|
super
|
@@ -16,7 +16,7 @@ module Middleman
|
|
16
16
|
define_setting :sass_source_maps, nil, 'Whether to inline sourcemap into Sass'
|
17
17
|
|
18
18
|
# Setup extension
|
19
|
-
def initialize(app, options={}, &block)
|
19
|
+
def initialize(app, options = {}, &block)
|
20
20
|
super
|
21
21
|
|
22
22
|
logger.info '== Preferring use of LibSass' if defined?(::SassC)
|
@@ -57,10 +57,10 @@ module Middleman
|
|
57
57
|
@context ||= context
|
58
58
|
|
59
59
|
sass_module = if defined?(::SassC)
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
60
|
+
::SassC
|
61
|
+
else
|
62
|
+
::Sass
|
63
|
+
end
|
64
64
|
|
65
65
|
@engine = sass_module::Engine.new(data, sass_options)
|
66
66
|
|
@@ -14,7 +14,7 @@ module Middleman
|
|
14
14
|
# background: url(image-path("image.jpg")); // background: url("/assets/image.jpg");
|
15
15
|
# background: url(image-path("image.jpg", $digest: true)); // background: url("/assets/image-27a8f1f96afd8d4c67a59eb9447f45bd.jpg");
|
16
16
|
#
|
17
|
-
def image_path(source, options={})
|
17
|
+
def image_path(source, options = {})
|
18
18
|
p = ::Middleman::Util.asset_path(middleman_context, :images, source.value, map_options(options))
|
19
19
|
::Sass::Script::String.new p.to_s, :string
|
20
20
|
end
|
@@ -28,7 +28,7 @@ module Middleman
|
|
28
28
|
# background: image-url("image.jpg"); // background: url("/assets/image.jpg");
|
29
29
|
# background: image-url("image.jpg", $digest: true); // background: url("/assets/image-27a8f1f96afd8d4c67a59eb9447f45bd.jpg");
|
30
30
|
#
|
31
|
-
def image_url(source, options={}, _cache_buster=nil)
|
31
|
+
def image_url(source, options = {}, _cache_buster = nil)
|
32
32
|
# Work with the Compass #image_url API
|
33
33
|
if options.respond_to? :value
|
34
34
|
case options.value
|
@@ -50,7 +50,7 @@ module Middleman
|
|
50
50
|
# src: url(font-path("font.ttf")); // src: url("/assets/font.ttf");
|
51
51
|
# src: url(font-path("font.ttf", $digest: true)); // src: url("/assets/font-27a8f1f96afd8d4c67a59eb9447f45bd.ttf");
|
52
52
|
#
|
53
|
-
def font_path(source, options={})
|
53
|
+
def font_path(source, options = {})
|
54
54
|
p = ::Middleman::Util.asset_path(middleman_context, :fonts, source.value, map_options(options))
|
55
55
|
::Sass::Script::String.new p.to_s, :string
|
56
56
|
end
|
@@ -64,7 +64,7 @@ module Middleman
|
|
64
64
|
# src: font-url("font.ttf"); // src: url("/assets/font.ttf");
|
65
65
|
# src: font-url("image.jpg", $digest: true); // src: url("/assets/font-27a8f1f96afd8d4c67a59eb9447f45bd.ttf");
|
66
66
|
#
|
67
|
-
def font_url(source, options={})
|
67
|
+
def font_url(source, options = {})
|
68
68
|
# Work with the Compass #font_url API
|
69
69
|
if options.respond_to? :value
|
70
70
|
case options.value
|
@@ -92,7 +92,7 @@ module Middleman
|
|
92
92
|
|
93
93
|
# Returns an options hash where the keys are symbolized
|
94
94
|
# and the values are unwrapped Sass literals.
|
95
|
-
def map_options(options={}) # :nodoc:
|
95
|
+
def map_options(options = {}) # :nodoc:
|
96
96
|
::Sass::Util.map_hash(options) do |key, value|
|
97
97
|
[key.to_sym, value.respond_to?(:value) ? value.value : value]
|
98
98
|
end
|
@@ -13,7 +13,7 @@ class ::Slim::Template
|
|
13
13
|
def initialize(file, line, opts, &block)
|
14
14
|
if opts.key?(:context)
|
15
15
|
::Slim::Embedded::SassEngine.disable_option_validator!
|
16
|
-
%w
|
16
|
+
%w[sass scss markdown].each do |engine|
|
17
17
|
(::Slim::Embedded.options[engine.to_sym] ||= {})[:context] = opts[:context]
|
18
18
|
end
|
19
19
|
end
|
@@ -31,7 +31,7 @@ module Middleman
|
|
31
31
|
# Slim renderer
|
32
32
|
class Slim < ::Middleman::Extension
|
33
33
|
# Setup extension
|
34
|
-
def initialize(_app, _options={}, &_block)
|
34
|
+
def initialize(_app, _options = {}, &_block)
|
35
35
|
super
|
36
36
|
|
37
37
|
# Setup Slim options to work with partials
|
@@ -12,7 +12,7 @@ module Middleman
|
|
12
12
|
# @param [String, Regexp] path Path glob expression, or path regex
|
13
13
|
# @return [IgnoreDescriptor]
|
14
14
|
Contract Or[String, Regexp, Proc] => RespondTo[:execute_descriptor]
|
15
|
-
def ignore(path=nil, &block)
|
15
|
+
def ignore(path = nil, &block)
|
16
16
|
@app.sitemap.invalidate_resources_not_ignored_cache!
|
17
17
|
|
18
18
|
if path.is_a? Regexp
|
@@ -34,7 +34,7 @@ module Middleman
|
|
34
34
|
|
35
35
|
IgnoreDescriptor = Struct.new(:path, :block) do
|
36
36
|
def execute_descriptor(_app, resources)
|
37
|
-
resources.
|
37
|
+
resources.each do |r|
|
38
38
|
# Ignore based on the source path (without template extensions)
|
39
39
|
if ignored?(r.normalized_path)
|
40
40
|
r.ignore!
|
@@ -42,8 +42,6 @@ module Middleman
|
|
42
42
|
# This allows files to be ignored by their source file name (with template extensions)
|
43
43
|
r.ignore!
|
44
44
|
end
|
45
|
-
|
46
|
-
r
|
47
45
|
end
|
48
46
|
end
|
49
47
|
|
@@ -12,7 +12,7 @@ module Middleman
|
|
12
12
|
|
13
13
|
ImportFileDescriptor = Struct.new(:from, :to) do
|
14
14
|
def execute_descriptor(app, resources)
|
15
|
-
source = ::Middleman::SourceFile.new(Pathname(from).relative_path_from(app.source_dir), Pathname(from), app.source_dir, Set.new([
|
15
|
+
source = ::Middleman::SourceFile.new(Pathname(from).relative_path_from(app.source_dir), Pathname(from), app.source_dir, Set.new(%i[source binary]), 0)
|
16
16
|
|
17
17
|
resources + [
|
18
18
|
::Middleman::Sitemap::Resource.new(app.sitemap, to, source)
|
@@ -22,7 +22,7 @@ module Middleman
|
|
22
22
|
# @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}.
|
23
23
|
# @return [ProxyDescriptor]
|
24
24
|
Contract String, String, Maybe[Hash] => RespondTo[:execute_descriptor]
|
25
|
-
def proxy(path, target, opts={})
|
25
|
+
def proxy(path, target, opts = {})
|
26
26
|
ProxyDescriptor.new(
|
27
27
|
::Middleman::Util.normalize_path(path),
|
28
28
|
::Middleman::Util.normalize_path(target),
|
@@ -75,6 +75,7 @@ module Middleman
|
|
75
75
|
|
76
76
|
target = ::Middleman::Util.normalize_path(target)
|
77
77
|
raise "You can't proxy #{path} to itself!" if target == path
|
78
|
+
|
78
79
|
@target = target
|
79
80
|
end
|
80
81
|
|
@@ -29,7 +29,7 @@ module Middleman
|
|
29
29
|
# @param [String] path
|
30
30
|
# @param [Hash] opts The :to value gives a target path
|
31
31
|
Contract String, { to: Or[String, ::Middleman::Sitemap::Resource] }, Maybe[Proc] => RedirectDescriptor
|
32
|
-
def redirect(path, opts={}, &block)
|
32
|
+
def redirect(path, opts = {}, &block)
|
33
33
|
RedirectDescriptor.new(path, opts[:to], block_given? ? block : nil)
|
34
34
|
end
|
35
35
|
end
|
@@ -27,7 +27,7 @@ module Middleman
|
|
27
27
|
# @param [Hash] opts The :path value gives a request path if it
|
28
28
|
# differs from the output path
|
29
29
|
Contract String, Or[{ path: String }, Proc] => EndpointDescriptor
|
30
|
-
def endpoint(path, opts={}, &block)
|
30
|
+
def endpoint(path, opts = {}, &block)
|
31
31
|
if block_given?
|
32
32
|
EndpointDescriptor.new(path, path, block)
|
33
33
|
else
|
@@ -4,39 +4,93 @@ module Middleman
|
|
4
4
|
module Traversal
|
5
5
|
def traversal_root
|
6
6
|
root = if !@app.extensions[:i18n]
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
'/'
|
8
|
+
else
|
9
|
+
@app.extensions[:i18n].path_root(::I18n.locale)
|
10
|
+
end
|
11
11
|
|
12
12
|
root.sub(/^\//, '')
|
13
13
|
end
|
14
14
|
|
15
15
|
# This resource's parent resource
|
16
16
|
# @return [Middleman::Sitemap::Resource, nil]
|
17
|
-
def parent
|
18
|
-
|
19
|
-
|
17
|
+
def parent(_recurse = false)
|
18
|
+
max_recursion = @app.config[:max_traversal_recursion] || 99
|
19
|
+
parent_helper(path, max_recursion)
|
20
|
+
end
|
21
|
+
|
22
|
+
def parent_helper(child_path, max_recursion)
|
23
|
+
# What is the configured format for index pages.
|
24
|
+
index_file = @app.config[:index_file]
|
25
|
+
parts = child_path.split('/')
|
26
|
+
# Reduce the path by the current page to get the parent level path.
|
27
|
+
current_page = parts.pop
|
28
|
+
# Does the current page has the name of an index file?
|
29
|
+
is_index = current_page == index_file
|
30
|
+
# Is the `current_page` in the traversal root?
|
31
|
+
# Note: `traversal_root` is `/` for non localised pages and `/[lang]/` for
|
32
|
+
# localised pages.
|
33
|
+
at_traversal_root = !(child_path =~ /^#{traversal_root}#{current_page}$/).nil?
|
34
|
+
|
35
|
+
# Check that we have any path parts left after the pop because if we
|
36
|
+
# don't, `current_page` is either root or another file under root.
|
37
|
+
# Also, if we are `at_traversal_root`, we consider this root.
|
38
|
+
if parts.empty? || at_traversal_root
|
39
|
+
# If this `is_index`, the `current_page` is root and there is no parent.
|
40
|
+
return nil if is_index
|
20
41
|
|
21
|
-
|
22
|
-
|
42
|
+
# `current_page` must be a page under root, let's return the root
|
43
|
+
# index page of the `traversal_root` (`/` or `/[lang]/`).
|
44
|
+
return @store.find_resource_by_path("#{traversal_root}#{index_file}")
|
45
|
+
end
|
46
|
+
|
47
|
+
# Get the index file for the parent path parts, e.g.: `/blog/index.html`
|
48
|
+
# for `/blog/`.
|
49
|
+
index_by_parts = proc do |subparts|
|
50
|
+
found = @store.find_resource_by_destination_path("#{subparts.join('/')}/#{index_file}")
|
51
|
+
return found unless found.nil?
|
52
|
+
end
|
23
53
|
|
24
|
-
|
25
|
-
|
54
|
+
# Get a file that has the name of the parent path parts e.g.:
|
55
|
+
# `/blog.html` for `/blog/`.
|
56
|
+
file_by_parts = proc do |subparts|
|
57
|
+
test_expr = Regexp.escape(subparts.join('/'))
|
58
|
+
# eponymous reverse-lookup
|
59
|
+
found = @store.resources.find do |candidate|
|
60
|
+
candidate.path =~ %r{^#{test_expr}(?:\.[a-zA-Z0-9]+|\/)$}
|
61
|
+
end
|
62
|
+
return found unless found.nil?
|
26
63
|
end
|
27
64
|
|
28
|
-
|
29
|
-
#
|
30
|
-
|
31
|
-
|
65
|
+
# Try to find a file matching the parent path name and return it.
|
66
|
+
# E.g. `parts == ['en', 'blog']`, we try to find: `/en/blog.html`
|
67
|
+
file_by_parts.call(parts)
|
68
|
+
|
69
|
+
# Try to find an non-localised parent instead if `traversal_root`
|
70
|
+
# indicates the path is localised and there are still more parts
|
71
|
+
# remaining, and return it.
|
72
|
+
# E.g. `parts == ['en', 'blog']`, we try to find: `/blog.html`
|
73
|
+
if traversal_root != '/' && parts.length > 1
|
74
|
+
file_by_parts.call(parts[1..-1])
|
32
75
|
end
|
33
76
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
77
|
+
# Now let's drop the last part of the path to try to find an index
|
78
|
+
# file in the path above `current_page`'s path and return it.
|
79
|
+
# E.g. `parts == ['en', 'blog']`, we try to find: `/en/index.html`
|
80
|
+
parts.pop if is_index
|
81
|
+
index_by_parts.call(parts)
|
82
|
+
|
83
|
+
# Lastly, check for an non-localised index index file in the path
|
84
|
+
# above `current_page`'s path and return it.
|
85
|
+
# E.g. `parts == ['en', 'blog']`, we try to find: `/index.html`
|
86
|
+
if traversal_root == "#{parts.first}/"
|
87
|
+
index_by_parts.call(parts[1..-1] || '')
|
88
|
+
end
|
89
|
+
if !parts.empty? && max_recursion.positive?
|
90
|
+
return parent_helper(parts.join('/'), max_recursion - 1)
|
39
91
|
end
|
92
|
+
|
93
|
+
nil
|
40
94
|
end
|
41
95
|
|
42
96
|
# This resource's child resources
|
@@ -45,12 +99,12 @@ module Middleman
|
|
45
99
|
return [] unless directory_index?
|
46
100
|
|
47
101
|
base_path = if eponymous_directory?
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
102
|
+
eponymous_directory_path
|
103
|
+
else
|
104
|
+
path.sub(@app.config[:index_file].to_s, '')
|
105
|
+
end
|
52
106
|
|
53
|
-
prefix =
|
107
|
+
prefix = /^#{base_path.sub("/", "\\/")}/
|
54
108
|
|
55
109
|
@store.resources.select do |sub_resource|
|
56
110
|
if sub_resource.path == path || sub_resource.path !~ prefix
|
@@ -73,6 +127,7 @@ module Middleman
|
|
73
127
|
# @return [Array<Middleman::Sitemap::Resource>]
|
74
128
|
def siblings
|
75
129
|
return [] unless parent
|
130
|
+
|
76
131
|
parent.children.reject { |p| p == self }
|
77
132
|
end
|
78
133
|
|
@@ -45,19 +45,19 @@ module Middleman
|
|
45
45
|
# @param [String] path
|
46
46
|
# @param [String] source
|
47
47
|
Contract IsA['Middleman::Sitemap::Store'], String, Maybe[Or[IsA['Middleman::SourceFile'], String]] => Any
|
48
|
-
def initialize(store, path, source=nil)
|
48
|
+
def initialize(store, path, source = nil)
|
49
49
|
@store = store
|
50
50
|
@app = @store.app
|
51
51
|
@path = path
|
52
52
|
@ignored = false
|
53
53
|
|
54
|
-
source = Pathname(source) if source
|
54
|
+
source = Pathname(source) if source&.is_a?(String)
|
55
55
|
|
56
|
-
@file_descriptor = if source
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
56
|
+
@file_descriptor = if source&.is_a?(Pathname)
|
57
|
+
::Middleman::SourceFile.new(source.relative_path_from(@app.source_dir), source, @app.source_dir, Set.new([:source]), 0)
|
58
|
+
else
|
59
|
+
source
|
60
|
+
end
|
61
61
|
|
62
62
|
@destination_path = @path
|
63
63
|
|
@@ -75,6 +75,7 @@ module Middleman
|
|
75
75
|
Contract Bool
|
76
76
|
def template?
|
77
77
|
return false if file_descriptor.nil?
|
78
|
+
|
78
79
|
!::Middleman::Util.tilt_class(file_descriptor[:full_path].to_s).nil?
|
79
80
|
end
|
80
81
|
|
@@ -97,14 +98,14 @@ module Middleman
|
|
97
98
|
# Page are data that is exposed through this resource's data member.
|
98
99
|
# Note: It is named 'page' for backwards compatibility with older MM.
|
99
100
|
Contract METADATA_HASH, Maybe[Bool] => METADATA_HASH
|
100
|
-
def add_metadata(meta={}, reverse=false)
|
101
|
+
def add_metadata(meta = {}, reverse = false)
|
101
102
|
@page_data = nil
|
102
103
|
|
103
104
|
@metadata = if reverse
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
105
|
+
meta.deep_merge(@metadata)
|
106
|
+
else
|
107
|
+
@metadata.deep_merge(meta)
|
108
|
+
end
|
108
109
|
end
|
109
110
|
|
110
111
|
# Data about this resource, populated from frontmatter or extensions.
|
@@ -139,7 +140,7 @@ module Middleman
|
|
139
140
|
# Render this resource
|
140
141
|
# @return [String]
|
141
142
|
Contract Hash, Hash => String
|
142
|
-
def render(opts={}, locs={})
|
143
|
+
def render(opts = {}, locs = {})
|
143
144
|
return ::Middleman::FileRenderer.new(@app, file_descriptor[:full_path].to_s).template_data_for_file unless template?
|
144
145
|
|
145
146
|
md = metadata
|
@@ -218,14 +219,14 @@ module Middleman
|
|
218
219
|
Contract String => String
|
219
220
|
def make_implicit_page_id(path)
|
220
221
|
@id ||= begin
|
221
|
-
|
222
|
-
|
223
|
-
|
222
|
+
prok = @app.config[:page_id_generator]
|
223
|
+
|
224
|
+
return prok.call(path) if prok
|
224
225
|
|
225
226
|
basename = if ext == '.html'
|
226
|
-
|
227
|
-
|
228
|
-
|
227
|
+
File.basename(path, ext)
|
228
|
+
else
|
229
|
+
File.basename(path)
|
229
230
|
end
|
230
231
|
|
231
232
|
# Remove leading dot or slash if present
|
@@ -235,7 +236,7 @@ module Middleman
|
|
235
236
|
end
|
236
237
|
|
237
238
|
class StringResource < Resource
|
238
|
-
def initialize(store, path, contents=nil, &block)
|
239
|
+
def initialize(store, path, contents = nil, &block)
|
239
240
|
@request_path = path
|
240
241
|
@contents = block_given? ? block : contents
|
241
242
|
super(store, path)
|
@@ -88,7 +88,7 @@ module Middleman
|
|
88
88
|
end
|
89
89
|
|
90
90
|
Contract Symbol, RespondTo[:manipulate_resource_list], Maybe[Or[Num, ArrayOf[Num]]], Maybe[Symbol] => Any
|
91
|
-
def register_resource_list_manipulators(name, manipulator, priority=50, custom_name=nil)
|
91
|
+
def register_resource_list_manipulators(name, manipulator, priority = 50, custom_name = nil)
|
92
92
|
Array(priority || 50).each do |p|
|
93
93
|
register_resource_list_manipulator(name, manipulator, p, custom_name)
|
94
94
|
end
|
@@ -103,7 +103,7 @@ module Middleman
|
|
103
103
|
# @param [Symbol] custom_name The method name to execute.
|
104
104
|
# @return [void]
|
105
105
|
Contract Symbol, RespondTo[:manipulate_resource_list], Maybe[Num, Bool], Maybe[Symbol] => Any
|
106
|
-
def register_resource_list_manipulator(name, manipulator, priority=50, custom_name=nil)
|
106
|
+
def register_resource_list_manipulator(name, manipulator, priority = 50, custom_name = nil)
|
107
107
|
# The third argument used to be a boolean - handle those who still pass one
|
108
108
|
priority = 50 unless priority.is_a? Numeric
|
109
109
|
@resource_list_manipulators = @resource_list_manipulators.push(
|
@@ -171,7 +171,7 @@ module Middleman
|
|
171
171
|
# @param [Boolean] include_ignored Whether to include ignored resources
|
172
172
|
# @return [Array<Middleman::Sitemap::Resource>]
|
173
173
|
Contract Bool => ResourceList
|
174
|
-
def resources(include_ignored=false)
|
174
|
+
def resources(include_ignored = false)
|
175
175
|
@lock.synchronize do
|
176
176
|
ensure_resource_list_updated!
|
177
177
|
if include_ignored
|