diff --git a/CHANGELOG.md b/CHANGELOG.md index e75ecd71..f3884c16 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ master === +* Remove `page` template local. Use `current_resource` instead. +* Dropped support for `page` & `proxy` blocks. +* Dropped support for instance variables inside templates. +* Moved all rendering into `TemplateRenderer` and `FileRenderer` +* Placed all template evaluation inside the `TemplateContext` class * Remove deprecated `request` instance * Remove old module-style extension support * Placed all `config.rb` evaluation inside the `ConfigContext` class diff --git a/middleman-cli/lib/middleman-cli/templates/default/source/layouts/layout.erb b/middleman-cli/lib/middleman-cli/templates/default/source/layouts/layout.erb index 7bdfeb1e..365985b7 100644 --- a/middleman-cli/lib/middleman-cli/templates/default/source/layouts/layout.erb +++ b/middleman-cli/lib/middleman-cli/templates/default/source/layouts/layout.erb @@ -7,7 +7,7 @@ - <%= current_page.data.title || "The Middleman" %> + <%= data.page.title || "The Middleman" %> <%= stylesheet_link_tag "normalize", "all" %> <%= javascript_include_tag "all" %> diff --git a/middleman-core/features/instance_vars.feature b/middleman-core/features/instance_vars.feature deleted file mode 100644 index ef240c57..00000000 --- a/middleman-core/features/instance_vars.feature +++ /dev/null @@ -1,9 +0,0 @@ -Feature: Instance Variables - Scenario: A dynamic page template using instance variables - Given the Server is running at "instance-vars-app" - When I go to "/a.html" - Then I should see "A: 'set'" - Then I should see "B: ''" - When I go to "/b.html" - Then I should see "A: ''" - Then I should see "B: 'set'" diff --git a/middleman-core/features/proxy_pages.feature b/middleman-core/features/proxy_pages.feature index 522f1eb8..4a22727c 100644 --- a/middleman-core/features/proxy_pages.feature +++ b/middleman-core/features/proxy_pages.feature @@ -15,8 +15,6 @@ Feature: Proxy Pages (using proxy rather than page) | fake2/two.html | | fake3/one.html | | fake3/two.html | - | fake4/one.html | - | fake4/two.html | | target_ignore.html | | target_ignore2.html | | target_ignore3.html | @@ -35,8 +33,6 @@ Feature: Proxy Pages (using proxy rather than page) Then I should see "I am real" When I go to "/fake3.html" Then I should see "I am real" - When I go to "/fake4.html" - Then I should see "I am real" Scenario: Preview proxy with variable one Given the Server is running at "proxy-pages-app" @@ -49,9 +45,6 @@ Feature: Proxy Pages (using proxy rather than page) When I go to "/fake3/one.html" Then I should see "I am real: one" - When I go to "/fake4/one.html" - Then I should see "I am real: one" - Scenario: Preview proxy with variable two Given the Server is running at "proxy-pages-app" When I go to "/fake/two.html" @@ -62,9 +55,6 @@ Feature: Proxy Pages (using proxy rather than page) When I go to "/fake3/two.html" Then I should see "I am real: two" - - When I go to "/fake4/two.html" - Then I should see "I am real: two" Scenario: Build proxy with variable one Given a successfully built app at "proxy-pages-app" diff --git a/middleman-core/fixtures/dynamic-pages-app/config.rb b/middleman-core/fixtures/dynamic-pages-app/config.rb index 161b0761..8f62dd0a 100644 --- a/middleman-core/fixtures/dynamic-pages-app/config.rb +++ b/middleman-core/fixtures/dynamic-pages-app/config.rb @@ -15,38 +15,16 @@ page "target_ignore3.html", :proxy => "should_be_ignored7.html", :ignore => true page "/target_ignore4.html", :proxy => "should_be_ignored8.html", :ignore => true %w(one two).each do |num| - page "/fake/#{num}.html", :proxy => "/real/index.html", :ignore => true do - @num = num - end - page "fake2/#{num}.html", :proxy => "/real/index.html", :ignore => true do - @num = num - end - page "fake3/#{num}.html", :proxy => "real/index.html", :ignore => true do - @num = num - end - page "/fake4/#{num}.html", :proxy => "real/index.html", :ignore => true do - @num = num - end + page "/fake/#{num}.html", :proxy => "/real/index.html", :ignore => true, :locals => { :num => num } + page "fake2/#{num}.html", :proxy => "/real/index.html", :ignore => true, :locals => { :num => num } + page "fake3/#{num}.html", :proxy => "real/index.html", :ignore => true, :locals => { :num => num } + page "/fake4/#{num}.html", :proxy => "real/index.html", :ignore => true, :locals => { :num => num } end page "明日がある.html", :proxy => "/real.html", :layout => false -page "f*/*" do - @all_glob = "I am all glob" -end - -page "fake/*" do - @glob_var = "I am one glob" -end - -page "fake2/*" do - @glob_var = "I am two glob" -end - -page "fake3/*" do - @glob_var = "I am three glob" -end - -page "fake4/*" do - @glob_var = "I am four glob" -end +page "f*/*", :locals => { :all_glob => "I am all glob" } +page "fake/*", :locals => { :glob_var => "I am one glob" } +page "fake2/*", :locals => { :glob_var => "I am two glob" } +page "fake3/*", :locals => { :glob_var => "I am three glob" } +page "fake4/*", :locals => { :glob_var => "I am four glob" } diff --git a/middleman-core/fixtures/dynamic-pages-app/source/real/index.html.erb b/middleman-core/fixtures/dynamic-pages-app/source/real/index.html.erb index 6e24c740..df64a7cc 100644 --- a/middleman-core/fixtures/dynamic-pages-app/source/real/index.html.erb +++ b/middleman-core/fixtures/dynamic-pages-app/source/real/index.html.erb @@ -2,8 +2,8 @@ layout: false --- -I am real: <%= @num %> +I am real: <%= num %> -Global: <%= @glob_var %> +Global: <%= glob_var %> -All: <%= @all_glob %> \ No newline at end of file +All: <%= all_glob %> \ No newline at end of file diff --git a/middleman-core/fixtures/i18n-force-locale/config.rb b/middleman-core/fixtures/i18n-force-locale/config.rb index 08ee30e5..4058360e 100644 --- a/middleman-core/fixtures/i18n-force-locale/config.rb +++ b/middleman-core/fixtures/i18n-force-locale/config.rb @@ -1,7 +1,5 @@ [:en, :es].each do |locale| - proxy "/#{locale}/index.html", "index.html", :ignore => true do - ::I18n.locale = locale - end + proxy "/#{locale}/index.html", "index.html", :ignore => true, :lang => locale end proxy "/fr/index.html", "index.html", :lang => :fr diff --git a/middleman-core/fixtures/instance-vars-app/config.rb b/middleman-core/fixtures/instance-vars-app/config.rb deleted file mode 100644 index 76367d3f..00000000 --- a/middleman-core/fixtures/instance-vars-app/config.rb +++ /dev/null @@ -1,7 +0,0 @@ -page "a.html", :proxy => 'content.html', :ignore => true do - @a = "set" -end - -page "b.html", :proxy => 'content.html', :ignore => true do - @b = "set" -end diff --git a/middleman-core/fixtures/instance-vars-app/source/content.html.erb b/middleman-core/fixtures/instance-vars-app/source/content.html.erb deleted file mode 100644 index 58b6399d..00000000 --- a/middleman-core/fixtures/instance-vars-app/source/content.html.erb +++ /dev/null @@ -1,2 +0,0 @@ -A: '<%= @a %>' -B: '<%= @b %>' diff --git a/middleman-core/fixtures/instance-vars-app/source/layout.erb b/middleman-core/fixtures/instance-vars-app/source/layout.erb deleted file mode 100644 index cd9bb66d..00000000 --- a/middleman-core/fixtures/instance-vars-app/source/layout.erb +++ /dev/null @@ -1 +0,0 @@ -<%= yield %> \ No newline at end of file diff --git a/middleman-core/fixtures/proxy-pages-app/config.rb b/middleman-core/fixtures/proxy-pages-app/config.rb index 0cd260cf..26afbc7a 100644 --- a/middleman-core/fixtures/proxy-pages-app/config.rb +++ b/middleman-core/fixtures/proxy-pages-app/config.rb @@ -13,9 +13,6 @@ proxy "/target_ignore4.html", "should_be_ignored8.html", :ignore => true proxy "/fake/#{num}.html", "/real/index.html", :ignore => true, :locals => { :num => num } proxy "fake2/#{num}.html", "/real/index.html", :ignore => true, :locals => { :num => num } proxy "fake3/#{num}.html", "real/index.html", :ignore => true, :locals => { :num => num } - proxy "/fake4/#{num}.html", "real/index-ivars.html", :ignore => true do - @num = num - end end proxy "明日がある.html", "/real.html", :layout => false diff --git a/middleman-core/fixtures/proxy-pages-app/source/real/index-ivars.html.erb b/middleman-core/fixtures/proxy-pages-app/source/real/index-ivars.html.erb deleted file mode 100644 index 07563e7d..00000000 --- a/middleman-core/fixtures/proxy-pages-app/source/real/index-ivars.html.erb +++ /dev/null @@ -1,6 +0,0 @@ ---- -layout: false ---- - -I am real: <%= @num %> - diff --git a/middleman-core/fixtures/stylus-preview-app/source/content.html.erb b/middleman-core/fixtures/stylus-preview-app/source/content.html.erb index ade1f58b..375933bf 100644 --- a/middleman-core/fixtures/stylus-preview-app/source/content.html.erb +++ b/middleman-core/fixtures/stylus-preview-app/source/content.html.erb @@ -1 +1,5 @@ +--- +layout: false +--- + Hola Mundo \ No newline at end of file diff --git a/middleman-core/fixtures/stylus-preview-app/source/layout.erb b/middleman-core/fixtures/stylus-preview-app/source/layout.erb deleted file mode 100644 index cd9bb66d..00000000 --- a/middleman-core/fixtures/stylus-preview-app/source/layout.erb +++ /dev/null @@ -1 +0,0 @@ -<%= yield %> \ No newline at end of file diff --git a/middleman-core/lib/middleman-core/core_extensions/routing.rb b/middleman-core/lib/middleman-core/core_extensions/routing.rb index c4171b78..8b9a58d6 100644 --- a/middleman-core/lib/middleman-core/core_extensions/routing.rb +++ b/middleman-core/lib/middleman-core/core_extensions/routing.rb @@ -12,9 +12,9 @@ module Middleman @layout_name = layout_name end - def page(url, opts={}, &block) + def page(url, opts={}) opts[:layout] ||= @layout_name - @scope.page(url, opts, &block) + @scope.page(url, opts) end delegate :proxy, :to => :scope @@ -41,10 +41,12 @@ module Middleman # @param [String] url # @param [Hash] opts # @return [void] - def page(url, opts={}, &block) + def page(url, opts={}) + options = opts.dup + # Default layout - opts[:layout] = @app.config[:layout] if opts[:layout].nil? - metadata = { :options => opts, :blocks => Array(block) } + options[:layout] = @app.config[:layout] if options[:layout].nil? + metadata = { :options => options, :locals => options.delete(:locals) || {} } # If the url is a regexp unless url.is_a?(Regexp) || url.include?('*') @@ -55,11 +57,11 @@ module Middleman end # Setup proxy - if target = opts.delete(:proxy) + if target = options.delete(:proxy) # TODO: deprecate proxy through page? - @app.proxy(url, target, opts, &block) + @app.proxy(url, target, opts.dup) return - elsif opts.delete(:ignore) + elsif options.delete(:ignore) # TODO: deprecate ignore through page? @app.ignore(url) end diff --git a/middleman-core/lib/middleman-core/sitemap/extensions/proxies.rb b/middleman-core/lib/middleman-core/sitemap/extensions/proxies.rb index 933e7312..55a0a371 100644 --- a/middleman-core/lib/middleman-core/sitemap/extensions/proxies.rb +++ b/middleman-core/lib/middleman-core/sitemap/extensions/proxies.rb @@ -23,13 +23,14 @@ module Middleman # @param [Hash] opts options to apply to the proxy, including things like # :locals, :ignore to hide the proxy target, :layout, and :directory_indexes. # @return [void] - def create_proxy(path, target, opts={}, &block) - metadata = { :options => {}, :locals => {}, :blocks => [] } - metadata[:blocks] << block if block_given? - metadata[:locals] = opts.delete(:locals) || {} + def create_proxy(path, target, opts={}) + options = opts.dup - @app.ignore(target) if opts.delete(:ignore) - metadata[:options] = opts + metadata = { :options => {}, :locals => {} } + metadata[:locals] = options.delete(:locals) || {} + + @app.ignore(target) if options.delete(:ignore) + metadata[:options] = options @proxy_configs << ProxyConfiguration.new(:path => path, :target => target, :metadata => metadata) @@ -45,6 +46,7 @@ module Middleman config.path ) p.proxy_to(config.target) + p.add_metadata(config.metadata) p end @@ -65,7 +67,7 @@ module Middleman @target = ::Middleman::Util.normalize_path(t) end - # Additional metadata like blocks and locals to apply to the proxy + # Additional metadata like locals to apply to the proxy attr_accessor :metadata # Create a new proxy configuration from hash options diff --git a/middleman-core/lib/middleman-core/sitemap/resource.rb b/middleman-core/lib/middleman-core/sitemap/resource.rb index a02485c6..fd87a0d6 100644 --- a/middleman-core/lib/middleman-core/sitemap/resource.rb +++ b/middleman-core/lib/middleman-core/sitemap/resource.rb @@ -48,7 +48,7 @@ module Middleman @source_file = source_file @destination_path = @path - @local_metadata = { :options => {}, :locals => {}, :page => {}, :blocks => [] } + @local_metadata = { :options => {}, :locals => {}, :page => {}} end # Whether this resource has a template file @@ -64,30 +64,18 @@ module Middleman result = store.metadata_for_path(path).dup file_meta = store.metadata_for_file(source_file).dup - if file_meta.has_key?(:blocks) - result[:blocks] += file_meta.delete(:blocks) - end result.deep_merge!(file_meta) local_meta = @local_metadata.dup - if local_meta.has_key?(:blocks) - result[:blocks] += local_meta.delete(:blocks) - end result.deep_merge!(local_meta) - result[:blocks] = result[:blocks].flatten.compact result end # Merge in new metadata specific to this resource. # @param [Hash] metadata A metadata block like provides_metadata_for_path takes - def add_metadata(metadata={}, &block) - metadata = metadata.dup - if metadata.has_key?(:blocks) - @local_metadata[:blocks] += metadata.delete(:blocks) - end - @local_metadata.deep_merge!(metadata) - @local_metadata[:blocks] += [ block ] if block_given? + def add_metadata(meta={}) + @local_metadata.deep_merge!(meta.dup) end # The output/preview URL for this resource @@ -106,7 +94,7 @@ module Middleman # Render this resource # @return [String] - def render(opts={}, locs={}, &block) + def render(opts={}, locs={}) if !template? return ::Middleman::FileRenderer.new(@app, source_file).get_template_data_for_file end @@ -132,9 +120,6 @@ module Middleman app.data.store('page', md[:page]) end - blocks = Array(md[:blocks]).dup - blocks << block if block_given? - locs[:current_path] ||= self.destination_path # Certain output file types don't use layouts @@ -143,7 +128,7 @@ module Middleman end renderer = ::Middleman::TemplateRenderer.new(@app, source_file) - renderer.render(locs, opts, blocks) + renderer.render(locs, opts) end end diff --git a/middleman-core/lib/middleman-core/sitemap/store.rb b/middleman-core/lib/middleman-core/sitemap/store.rb index a8fcdd22..069c1e73 100644 --- a/middleman-core/lib/middleman-core/sitemap/store.rb +++ b/middleman-core/lib/middleman-core/sitemap/store.rb @@ -137,18 +137,12 @@ module Middleman # @param [String] source_file # @return [Hash] def metadata_for_file(source_file) - blank_metadata = { :options => {}, :locals => {}, :page => {}, :blocks => [] } + blank_metadata = { :options => {}, :locals => {}, :page => {} } provides_metadata.inject(blank_metadata) do |result, (callback, matcher)| next result if matcher && !source_file.match(matcher) metadata = callback.call(source_file).dup - - if metadata.has_key?(:blocks) - result[:blocks] << metadata[:blocks] - metadata.delete(:blocks) - end - result.deep_merge(metadata) end end @@ -171,7 +165,7 @@ module Middleman def metadata_for_path(request_path) return @_cached_metadata[request_path] if @_cached_metadata[request_path] - blank_metadata = { :options => {}, :locals => {}, :page => {}, :blocks => [] } + blank_metadata = { :options => {}, :locals => {}, :page => {} } @_cached_metadata[request_path] = provides_metadata_for_path.inject(blank_metadata) do |result, (callback, matcher)| case matcher @@ -183,8 +177,6 @@ module Middleman metadata = callback.call(request_path).dup - result[:blocks] += Array(metadata.delete(:blocks)) - result.deep_merge(metadata) end end diff --git a/middleman-core/lib/middleman-core/template_renderer.rb b/middleman-core/lib/middleman-core/template_renderer.rb index 65585c77..5a561fe9 100644 --- a/middleman-core/lib/middleman-core/template_renderer.rb +++ b/middleman-core/lib/middleman-core/template_renderer.rb @@ -26,7 +26,7 @@ module Middleman # @param [Hash] locs # @param [Hash] opts # @return [String] - def render(locs={}, opts={}, blocks=[]) + def render(locs={}, opts={}) path = @path.dup extension = File.extname(path) engine = extension[1..-1].to_sym @@ -43,10 +43,6 @@ module Middleman context.init_haml_helpers end - blocks.each do |block| - context.instance_eval(&block) - end - # Keep rendering template until we've used up all extensions. This # handles cases like `style.css.sass.erb` content = nil diff --git a/middleman-core/lib/middleman-more/core_extensions/i18n.rb b/middleman-core/lib/middleman-more/core_extensions/i18n.rb index 24787a04..8047462b 100644 --- a/middleman-core/lib/middleman-more/core_extensions/i18n.rb +++ b/middleman-core/lib/middleman-more/core_extensions/i18n.rb @@ -124,19 +124,11 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension lang = @mount_at_root end - instance_vars = Proc.new do - @lang = lang - @page_id = page_id - end - - locals = { - :lang => lang, - :page_id => page_id - } - { - :blocks => [instance_vars], - :locals => locals, + :locals => { + :lang => lang, + :page_id => page_id + }, :options => { :lang => lang } } end