diff --git a/middleman-core/features/partials.feature b/middleman-core/features/partials.feature index d039bdcb..76a7e75a 100644 --- a/middleman-core/features/partials.feature +++ b/middleman-core/features/partials.feature @@ -44,3 +44,8 @@ Feature: Provide Sane Defaults for Partial Behavior When I go to "/index.html" Then I should see "ERb Header" And I should see "Str Footer" + + Scenario: Works with non-template content (svg) + Given the Server is running at "partials-app" + When I go to "/svg.html" + Then I should see " + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/middleman-core/fixtures/partials-app/source/svg.html.erb b/middleman-core/fixtures/partials-app/source/svg.html.erb new file mode 100644 index 00000000..759ab44a --- /dev/null +++ b/middleman-core/fixtures/partials-app/source/svg.html.erb @@ -0,0 +1 @@ +<%= partial "images/tiger.svg" %> \ No newline at end of file diff --git a/middleman-core/lib/middleman-core/extensions.rb b/middleman-core/lib/middleman-core/extensions.rb index 77c99a64..1c834587 100644 --- a/middleman-core/lib/middleman-core/extensions.rb +++ b/middleman-core/lib/middleman-core/extensions.rb @@ -105,7 +105,7 @@ module Middleman # A flattened list of all extensions which are automatically activated # @return [Array] A list of extension names which are automatically activated. def auto_activated - @auto_activate.values.map(&:name).flatten + @auto_activate.values.flat_map(&:name) end # @api private diff --git a/middleman-core/lib/middleman-core/sitemap/store.rb b/middleman-core/lib/middleman-core/sitemap/store.rb index 12348695..fd5b6d72 100644 --- a/middleman-core/lib/middleman-core/sitemap/store.rb +++ b/middleman-core/lib/middleman-core/sitemap/store.rb @@ -144,7 +144,7 @@ module Middleman # @return [String] Contract String => String def file_to_path(file) - file = File.join(@app.root, file) + file = File.expand_path(file, @app.root) prefix = @app.source_dir.sub(/\/$/, '') + '/' raise "'#{file}' not inside project folder '#{prefix}" unless file.start_with?(prefix) diff --git a/middleman-core/lib/middleman-core/template_context.rb b/middleman-core/lib/middleman-core/template_context.rb index 1cca89aa..39c1e9b2 100644 --- a/middleman-core/lib/middleman-core/template_context.rb +++ b/middleman-core/lib/middleman-core/template_context.rb @@ -104,10 +104,16 @@ module Middleman raise ::Middleman::TemplateRenderer::TemplateNotFound, "Could not locate partial: #{name}" unless partial_path - opts = options.dup - locs = opts.delete(:locals) + r = sitemap.find_resource_by_path(sitemap.file_to_path(partial_path)) - render_file(partial_path, locs.freeze, opts.freeze, &block) + if r && !r.template? + File.read(r.source_file) + else + opts = options.dup + locs = opts.delete(:locals) + + render_file(partial_path, locs.freeze, opts.freeze, &block) + end end protected @@ -125,16 +131,22 @@ module Middleman current_dir = File.dirname(resource.source_file) relative_dir = File.join(current_dir.sub(%r{^#{Regexp.escape(source_dir)}/?}, ''), partial_path) - partial = ::Middleman::TemplateRenderer.resolve_template( - @app, - relative_dir, - preferred_engine: File.extname(resource.source_file)[1..-1].to_sym - ) + partial_path_no_underscore = partial_path.sub(/^_/, '').sub(/\/_/, '/') + relative_dir_no_underscore = File.join(current_dir.sub(%r{^#{Regexp.escape(source_dir)}/?}, ''), partial_path_no_underscore) - return partial if partial + partial = nil - # Try to find one relative to the source dir - ::Middleman::TemplateRenderer.resolve_template(@app, File.join('', partial_path)) + [ + [relative_dir, { preferred_engine: File.extname(resource.source_file)[1..-1].to_sym }], + [File.join('', partial_path)], + [relative_dir_no_underscore, { try_static: true }], + [File.join('', partial_path_no_underscore), { try_static: true }] + ].each do |args| + partial = ::Middleman::TemplateRenderer.resolve_template(@app, *args) + break if partial + end + + partial 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 72fa9db2..87111580 100644 --- a/middleman-core/lib/middleman-core/template_renderer.rb +++ b/middleman-core/lib/middleman-core/template_renderer.rb @@ -171,6 +171,7 @@ module Middleman # By default, any engine will do preferred_engines = ['*'] + preferred_engines << nil if options[:try_static] # If we're specifically looking for a preferred engine if options.key?(:preferred_engine) @@ -188,7 +189,9 @@ module Middleman end search_paths = preferred_engines.map do |preferred_engine| - on_disk_path + '.' + preferred_engine + path_with_ext = on_disk_path.dup + path_with_ext << ('.' + preferred_engine) unless preferred_engine.nil? + path_with_ext end found_path = nil @@ -196,6 +199,11 @@ module Middleman found_path = Dir[path_with_ext].find do |path| ::Tilt[path] end + + unless found_path + found_path = path_with_ext if File.exist?(path_with_ext) + end + break if found_path end