Merge pull request #1318 from bhollis/partials_dir
Remove partials_dir functionality
This commit is contained in:
commit
52dcf37f24
|
@ -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.
|
||||
|
|
|
@ -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"
|
||||
|
|
@ -1 +0,0 @@
|
|||
contents of the partial
|
|
@ -1,2 +0,0 @@
|
|||
<%= partial 'partial' %>
|
||||
|
|
@ -1,3 +1,3 @@
|
|||
<%= partial "shared/header" %>
|
||||
<%= partial "local" %>
|
||||
<%= partial "shared/footer" %>
|
||||
<%= partial "../shared/footer" %>
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
<%= partial 'partial' %>
|
||||
|
|
@ -1 +0,0 @@
|
|||
contents of the nested partial
|
|
@ -1 +0,0 @@
|
|||
contents of the partial
|
|
@ -113,10 +113,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'
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue