diff --git a/CHANGELOG.md b/CHANGELOG.md index 08751a8e..22e2750e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ master === +* Remove the `partials_dir` setting. Partials should live next to content, or be addressed with absolute paths. +* Partials must be named with a leading underscore. `_my_snippet.html.erb`, not `my_snippet.html.erb`. * Removed the `proxy` and `ignore` options for the `page` command in `config.rb`. Use the `proxy` and `ignore` commands instead of passing these options to `page`. * The `page` command in `config.rb` can now be used to add data to the page via the `data` argument. It is accessed the same way as frontmatter data, via `current_resource.data`. * Add support for `environments` with the `-e` CLI flag. Loads additional config from `environments/envname.rb`. Removed `development?` helper in favor of `environment?(:development)`. Added `server?` helper to differentiate between build and server mode. diff --git a/middleman-core/features/partials_dir.feature b/middleman-core/features/partials_dir.feature deleted file mode 100644 index 8648c8e2..00000000 --- a/middleman-core/features/partials_dir.feature +++ /dev/null @@ -1,30 +0,0 @@ -Feature: Partials dir - Scenario: Find partials in a custom partials dir - Given a fixture app "partials-dir-app" - And a file named "config.rb" with: - """ - set :partials_dir, 'partials' - """ - And the Server is running - When I go to "/index.html" - Then I should see "contents of the partial" - - Scenario: Find partials in a nested custom partials dir - Given a fixture app "partials-dir-app" - And a file named "config.rb" with: - """ - set :partials_dir, 'nested/partials' - """ - And the Server is running - When I go to "/index.html" - Then I should see "contents of the nested partial" - - Scenario: Find partials in the default partials dir - Given a fixture app "default-partials-dir-app" - And a file named "config.rb" with: - """ - """ - And the Server is running - When I go to "/index.html" - Then I should see "contents of the partial" - diff --git a/middleman-core/fixtures/default-partials-dir-app/source/_partial.html.erb b/middleman-core/fixtures/default-partials-dir-app/source/_partial.html.erb deleted file mode 100644 index 5b50edf3..00000000 --- a/middleman-core/fixtures/default-partials-dir-app/source/_partial.html.erb +++ /dev/null @@ -1 +0,0 @@ -contents of the partial diff --git a/middleman-core/fixtures/default-partials-dir-app/source/index.html.erb b/middleman-core/fixtures/default-partials-dir-app/source/index.html.erb deleted file mode 100644 index 871728d4..00000000 --- a/middleman-core/fixtures/default-partials-dir-app/source/index.html.erb +++ /dev/null @@ -1,2 +0,0 @@ -<%= partial 'partial' %> - diff --git a/middleman-core/fixtures/partials-app/source/shared/snippet.erb b/middleman-core/fixtures/partials-app/source/shared/_snippet.html.erb similarity index 100% rename from middleman-core/fixtures/partials-app/source/shared/snippet.erb rename to middleman-core/fixtures/partials-app/source/shared/_snippet.html.erb diff --git a/middleman-core/fixtures/partials-app/source/sub/index.html.erb b/middleman-core/fixtures/partials-app/source/sub/index.html.erb index 5ce2eb35..e09e527b 100644 --- a/middleman-core/fixtures/partials-app/source/sub/index.html.erb +++ b/middleman-core/fixtures/partials-app/source/sub/index.html.erb @@ -1,3 +1,3 @@ <%= partial "shared/header" %> <%= partial "local" %> -<%= partial "shared/footer" %> \ No newline at end of file +<%= partial "../shared/footer" %> diff --git a/middleman-core/fixtures/partials-dir-app/source/index.html.erb b/middleman-core/fixtures/partials-dir-app/source/index.html.erb deleted file mode 100644 index 871728d4..00000000 --- a/middleman-core/fixtures/partials-dir-app/source/index.html.erb +++ /dev/null @@ -1,2 +0,0 @@ -<%= partial 'partial' %> - diff --git a/middleman-core/fixtures/partials-dir-app/source/nested/partials/_partial.html.erb b/middleman-core/fixtures/partials-dir-app/source/nested/partials/_partial.html.erb deleted file mode 100644 index b27433e1..00000000 --- a/middleman-core/fixtures/partials-dir-app/source/nested/partials/_partial.html.erb +++ /dev/null @@ -1 +0,0 @@ -contents of the nested partial diff --git a/middleman-core/fixtures/partials-dir-app/source/partials/_partial.html.erb b/middleman-core/fixtures/partials-dir-app/source/partials/_partial.html.erb deleted file mode 100644 index 5b50edf3..00000000 --- a/middleman-core/fixtures/partials-dir-app/source/partials/_partial.html.erb +++ /dev/null @@ -1 +0,0 @@ -contents of the partial diff --git a/middleman-core/lib/middleman-core/application.rb b/middleman-core/lib/middleman-core/application.rb index a40158e9..63db4237 100644 --- a/middleman-core/lib/middleman-core/application.rb +++ b/middleman-core/lib/middleman-core/application.rb @@ -109,10 +109,6 @@ module Middleman # @return [String] config.define_setting :fonts_dir, 'fonts', 'Location of fonts within source' - # Location of partials within source. Used by renderers. - # @return [String] - config.define_setting :partials_dir, '', 'Location of partials within source' - # Location of layouts within source. Used by renderers. # @return [String] config.define_setting :layouts_dir, 'layouts', 'Location of layouts within source' diff --git a/middleman-core/lib/middleman-core/template_context.rb b/middleman-core/lib/middleman-core/template_context.rb index 17b970fb..d80b46d3 100644 --- a/middleman-core/lib/middleman-core/template_context.rb +++ b/middleman-core/lib/middleman-core/template_context.rb @@ -91,14 +91,13 @@ module Middleman # Sinatra/Padrino compatible render method signature referenced by some view # helpers. Especially partials. # - # @param [] _ Unused parameter. # @param [String, Symbol] name The partial to render. # @param [Hash] options # @return [String] def render(_, name, options={}, &block) name = name.to_s - partial_path = locate_partial_relative(name) || locate_partial_in_partials_dir(name) + partial_path = locate_partial(name) raise ::Middleman::TemplateRenderer::TemplateNotFound, "Could not locate partial: #{name}" unless partial_path @@ -110,38 +109,28 @@ module Middleman protected - # Locate a partial reltive to the current path, given a name. + # Locate a partial relative to the current path or the source dir, given a partial's path. # # @api private - # @param [String] name + # @param [String] partial_path # @return [String] - def locate_partial_relative(name) + def locate_partial(partial_path) return unless resource = sitemap.find_resource_by_path(current_path) # Look for partials relative to the current path current_dir = File.dirname(resource.source_file) - relative_dir = File.join(current_dir.sub(%r{^#{Regexp.escape(source_dir)}/?}, ''), name) + relative_dir = File.join(current_dir.sub(%r{^#{Regexp.escape(source_dir)}/?}, ''), partial_path) - ::Middleman::TemplateRenderer.resolve_template( + partial = ::Middleman::TemplateRenderer.resolve_template( @app, relative_dir, - try_without_underscore: true, preferred_engine: File.extname(resource.source_file)[1..-1].to_sym ) - end - # Locate a partial reltive to the partials dir, given a name. - # - # @api private - # @param [String] name - # @return [String] - def locate_partial_in_partials_dir(name) - partials_path = File.join(@app.config[:partials_dir], name) - ::Middleman::TemplateRenderer.resolve_template( - @app, - partials_path, - try_without_underscore: true - ) + return partial if partial + + # Try to find one relative to the source dir + ::Middleman::TemplateRenderer.resolve_template(@app, File.join('', partial_path)) end # Render a path with locs, opts and contents block. diff --git a/middleman-core/lib/middleman-core/template_renderer.rb b/middleman-core/lib/middleman-core/template_renderer.rb index a8d1d527..27384ccf 100644 --- a/middleman-core/lib/middleman-core/template_renderer.rb +++ b/middleman-core/lib/middleman-core/template_renderer.rb @@ -150,7 +150,6 @@ module Middleman # Find a template on disk given a output path # @param [String] request_path # @option options [Boolean] :preferred_engine If set, try this engine first, then fall back to any engine. - # @option options [Boolean] :try_without_underscore # @return [String, Boolean] Either the path to the template, or false def self.resolve_template(app, request_path, options={}) # Find the path by searching or using the cache @@ -177,13 +176,8 @@ module Middleman end end - search_paths = preferred_engines.flat_map do |preferred_engine| - path_with_ext = on_disk_path + '.' + preferred_engine - paths = [path_with_ext] - if options[:try_without_underscore] - paths << path_with_ext.sub(relative_path, relative_path.sub(/^_/, '').sub(/\/_/, '/')) - end - paths + search_paths = preferred_engines.map do |preferred_engine| + on_disk_path + '.' + preferred_engine end found_path = nil