From b6951f2729c368bc47de7e27a3247d03d7b3b5e1 Mon Sep 17 00:00:00 2001 From: Thomas Reynolds Date: Thu, 17 Jul 2014 09:32:38 -0700 Subject: [PATCH 1/2] use stable sprockets branch --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index a37adb4d..1fc15c03 100644 --- a/Gemfile +++ b/Gemfile @@ -32,4 +32,4 @@ gem 'coveralls', '~> 0.7', require: false # Middleman itself gem 'middleman', path: 'middleman' gem 'middleman-core', path: 'middleman-core' -gem 'middleman-sprockets', github: 'middleman/middleman-sprockets' +gem 'middleman-sprockets', github: 'middleman/middleman-sprockets', branch: 'v3-stable' From f0603ddf2f29b16bdf22addf50b1dfd78ad67868 Mon Sep 17 00:00:00 2001 From: Thomas Reynolds Date: Fri, 18 Jul 2014 10:54:48 -0700 Subject: [PATCH 2/2] work with static partials. Closes #1206 --- middleman-core/features/partials.feature | 5 + .../partials-app/source/images/tiger.svg | 725 ++++++++++++++++++ .../fixtures/partials-app/source/svg.html.erb | 1 + .../core_extensions/rendering.rb | 25 +- .../lib/middleman-core/preview_server.rb | 4 +- .../lib/middleman-core/sitemap/store.rb | 2 +- 6 files changed, 754 insertions(+), 8 deletions(-) create mode 100644 middleman-core/fixtures/partials-app/source/images/tiger.svg create mode 100644 middleman-core/fixtures/partials-app/source/svg.html.erb 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/core_extensions/rendering.rb b/middleman-core/lib/middleman-core/core_extensions/rendering.rb index 091a0e85..074fa017 100644 --- a/middleman-core/lib/middleman-core/core_extensions/rendering.rb +++ b/middleman-core/lib/middleman-core/core_extensions/rendering.rb @@ -188,7 +188,7 @@ module Middleman locals = options[:locals] found_partial = false - resolve_opts = { try_without_underscore: true } + resolve_opts = { try_without_underscore: true, try_static: true } # If the path is known to the sitemap if resource = sitemap.find_resource_by_path(current_path) @@ -209,8 +209,14 @@ module Middleman raise ::Middleman::CoreExtensions::Rendering::TemplateNotFound, "Could not locate partial: #{data}" unless found_partial - # Render the partial if found, otherwide throw exception - render_individual_file(found_partial, locals, options, self, &block) + r = sitemap.find_resource_by_path(sitemap.file_to_path(found_partial)) + + if r && !r.template? + File.read(r.source_file) + else + # Render the partial if found, otherwide throw exception + render_individual_file(found_partial, locals, options, self, &block) + end end # Render an on-disk file. Used for everything, including layouts. @@ -428,6 +434,7 @@ module Middleman # @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 + # @option options [Boolean] :try_static # @return [Array, Boolean] def resolve_template(request_path, options={}) # Find the path by searching or using the cache @@ -438,6 +445,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) @@ -455,7 +463,9 @@ module Middleman end search_paths = preferred_engines.flat_map do |preferred_engine| - path_with_ext = on_disk_path + '.' + preferred_engine + path_with_ext = on_disk_path.dup + path_with_ext << ('.' + preferred_engine) unless preferred_engine.nil? + paths = [path_with_ext] if options[:try_without_underscore] paths << path_with_ext.sub(relative_path, relative_path.sub(/^_/, '').sub(/\/_/, '/')) @@ -468,10 +478,15 @@ 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 - # If we found one, return it and the found engine + # If we found one, return it if found_path found_path elsif File.exist?(on_disk_path) diff --git a/middleman-core/lib/middleman-core/preview_server.rb b/middleman-core/lib/middleman-core/preview_server.rb index d848fda9..ef3cd21c 100644 --- a/middleman-core/lib/middleman-core/preview_server.rb +++ b/middleman-core/lib/middleman-core/preview_server.rb @@ -111,12 +111,12 @@ module Middleman end def start_file_watcher - return if @listener or @options[:disable_watcher] + return if @listener || @options[:disable_watcher] # Watcher Library require 'listen' - options = {force_polling: @options[:force_polling]} + options = { force_polling: @options[:force_polling] } options[:latency] = @options[:latency] if @options[:latency] @listener = Listen.to(Dir.pwd, options) do |modified, added, removed| diff --git a/middleman-core/lib/middleman-core/sitemap/store.rb b/middleman-core/lib/middleman-core/sitemap/store.rb index 6fbb8b68..18333788 100644 --- a/middleman-core/lib/middleman-core/sitemap/store.rb +++ b/middleman-core/lib/middleman-core/sitemap/store.rb @@ -174,7 +174,7 @@ module Middleman # @param [String] file # @return [String] def file_to_path(file) - file = File.join(@app.root, file) + file = File.expand_path(file, @app.root) prefix = @app.source_dir.sub(/\/$/, '') + '/' return false unless file.start_with?(prefix)