remove instance variable and page block support

i18n_v4
Thomas Reynolds 2014-01-03 15:49:54 -08:00
parent 614d69dc18
commit 98e3c8aa79
20 changed files with 54 additions and 139 deletions

View File

@ -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

View File

@ -7,7 +7,7 @@
<meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
<!-- Use title if it's in the page YAML frontmatter -->
<title><%= current_page.data.title || "The Middleman" %></title>
<title><%= data.page.title || "The Middleman" %></title>
<%= stylesheet_link_tag "normalize", "all" %>
<%= javascript_include_tag "all" %>

View File

@ -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'"

View File

@ -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"

View File

@ -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" }

View File

@ -2,8 +2,8 @@
layout: false
---
I am real: <%= @num %>
I am real: <%= num %>
Global: <%= @glob_var %>
Global: <%= glob_var %>
All: <%= @all_glob %>
All: <%= all_glob %>

View File

@ -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

View File

@ -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

View File

@ -1,2 +0,0 @@
A: '<%= @a %>'
B: '<%= @b %>'

View File

@ -1 +0,0 @@
<%= yield %>

View File

@ -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

View File

@ -1,6 +0,0 @@
---
layout: false
---
I am real: <%= @num %>

View File

@ -1 +1,5 @@
---
layout: false
---
Hola Mundo

View File

@ -1 +0,0 @@
<%= yield %>

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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