Rename ActionView::Template::Path ActionView::Resolver

上级 7ac9f290
...@@ -37,7 +37,7 @@ def self.load_all! ...@@ -37,7 +37,7 @@ def self.load_all!
autoload :Helpers, 'action_view/helpers' autoload :Helpers, 'action_view/helpers'
autoload :InlineTemplate, 'action_view/template/inline' autoload :InlineTemplate, 'action_view/template/inline'
autoload :Partials, 'action_view/render/partials' autoload :Partials, 'action_view/render/partials'
autoload :Path, 'action_view/template/path' autoload :Resolver, 'action_view/template/path'
autoload :PathSet, 'action_view/paths' autoload :PathSet, 'action_view/paths'
autoload :Rendering, 'action_view/render/rendering' autoload :Rendering, 'action_view/render/rendering'
autoload :Renderable, 'action_view/template/renderable' autoload :Renderable, 'action_view/template/renderable'
......
...@@ -3,7 +3,7 @@ class PathSet < Array #:nodoc: ...@@ -3,7 +3,7 @@ class PathSet < Array #:nodoc:
def self.type_cast(obj) def self.type_cast(obj)
if obj.is_a?(String) if obj.is_a?(String)
cache = !defined?(Rails) || !Rails.respond_to?(:configuration) || Rails.configuration.cache_classes cache = !defined?(Rails) || !Rails.respond_to?(:configuration) || Rails.configuration.cache_classes
Template::FileSystemPathWithFallback.new(obj, :cache => cache) FileSystemResolverWithFallback.new(obj, :cache => cache)
else else
obj obj
end end
......
require "pathname" require "pathname"
require "action_view/template/template"
module ActionView module ActionView
class Template # Abstract superclass
# Abstract super class class Resolver
class Path
def initialize(options) def initialize(options)
@cache = options[:cache] @cache = options[:cache]
@cached = {} @cached = {}
...@@ -23,7 +23,7 @@ def find_all_by_parts(name, details = {}, prefix = nil, partial = nil) ...@@ -23,7 +23,7 @@ def find_all_by_parts(name, details = {}, prefix = nil, partial = nil)
private private
# This is what child classes implement. No defaults are needed # This is what child classes implement. No defaults are needed
# because Path guarentees that the arguments are present and # because Resolver guarantees that the arguments are present and
# normalized. # normalized.
def find_templates(name, details, prefix, partial) def find_templates(name, details, prefix, partial)
raise NotImplementedError raise NotImplementedError
...@@ -58,10 +58,10 @@ def cached(key) ...@@ -58,10 +58,10 @@ def cached(key)
end end
end end
class FileSystemPath < Path class FileSystemResolver < Resolver
def initialize(path, options = {}) def initialize(path, options = {})
raise ArgumentError, "path already is a Path class" if path.is_a?(Path) raise ArgumentError, "path already is a Resolver class" if path.is_a?(Resolver)
super(options) super(options)
@path = Pathname.new(path).expand_path @path = Pathname.new(path).expand_path
end end
...@@ -138,7 +138,7 @@ def path_to_details(path) ...@@ -138,7 +138,7 @@ def path_to_details(path)
end end
end end
class FileSystemPathWithFallback < FileSystemPath class FileSystemResolverWithFallback < FileSystemResolver
def find_templates(name, details, prefix, partial) def find_templates(name, details, prefix, partial)
templates = super templates = super
...@@ -147,5 +147,4 @@ def find_templates(name, details, prefix, partial) ...@@ -147,5 +147,4 @@ def find_templates(name, details, prefix, partial)
end end
end end
end
end end
\ No newline at end of file
...@@ -9,7 +9,7 @@ class Base < AbstractController::Base ...@@ -9,7 +9,7 @@ class Base < AbstractController::Base
include AbstractController::Renderer include AbstractController::Renderer
include AbstractController::Layouts include AbstractController::Layouts
self.view_paths = [ActionView::Template::FixturePath.new( self.view_paths = [ActionView::FixtureResolver.new(
"layouts/hello.erb" => "With String <%= yield %>", "layouts/hello.erb" => "With String <%= yield %>",
"layouts/hello_override.erb" => "With Override <%= yield %>", "layouts/hello_override.erb" => "With Override <%= yield %>",
"layouts/abstract_controller_tests/layouts/with_string_implied_child.erb" => "layouts/abstract_controller_tests/layouts/with_string_implied_child.erb" =>
......
module ActionView #:nodoc: module ActionView #:nodoc:
class Template class FixtureResolver < Resolver
class FixturePath < Path
def initialize(hash = {}, options = {}) def initialize(hash = {}, options = {})
super(options) super(options)
@hash = hash @hash = hash
...@@ -65,40 +64,4 @@ def path_to_details(path) ...@@ -65,40 +64,4 @@ def path_to_details(path)
end end
end end
end end
# class FixtureTemplate < Template
# class FixturePath < Template::Path
# def initialize(hash = {})
# @hash = {}
#
# hash.each do |k, v|
# @hash[k.sub(/\.\w+$/, '')] = FixtureTemplate.new(v, k.split("/").last, self)
# end
#
# super("fixtures://root")
# end
#
# def find_template(path)
# @hash[path]
# end
# end
#
# def initialize(body, *args)
# @body = body
# super(*args)
# end
#
# def source
# @body
# end
#
# private
#
# def find_full_path(path, load_paths)
# return '/', path
# end
#
# end
end
end end
\ No newline at end of file
...@@ -19,7 +19,7 @@ def set_on_render ...@@ -19,7 +19,7 @@ def set_on_render
class ImpliedController < ActionController::Base class ImpliedController < ActionController::Base
# Template's mime type is used if no content_type is specified # Template's mime type is used if no content_type is specified
self.view_paths = [ActionView::Template::FixturePath.new( self.view_paths = [ActionView::FixtureResolver.new(
"content_type/implied/i_am_html_erb.html.erb" => "Hello world!", "content_type/implied/i_am_html_erb.html.erb" => "Hello world!",
"content_type/implied/i_am_xml_erb.xml.erb" => "<xml>Hello world!</xml>", "content_type/implied/i_am_xml_erb.xml.erb" => "<xml>Hello world!</xml>",
"content_type/implied/i_am_html_builder.html.builder" => "xml.p 'Hello'", "content_type/implied/i_am_html_builder.html.builder" => "xml.p 'Hello'",
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
module Etags module Etags
class BasicController < ActionController::Base class BasicController < ActionController::Base
self.view_paths = [ActionView::Template::FixturePath.new( self.view_paths = [ActionView::FixtureResolver.new(
"etags/basic/base.html.erb" => "Hello from without_layout.html.erb", "etags/basic/base.html.erb" => "Hello from without_layout.html.erb",
"layouts/etags.html.erb" => "teh <%= yield %> tagz" "layouts/etags.html.erb" => "teh <%= yield %> tagz"
)] )]
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
module RenderAction module RenderAction
# This has no layout and it works # This has no layout and it works
class BasicController < ActionController::Base class BasicController < ActionController::Base
self.view_paths = [ActionView::Template::FixturePath.new( self.view_paths = [ActionView::FixtureResolver.new(
"render_action/basic/hello_world.html.erb" => "Hello world!" "render_action/basic/hello_world.html.erb" => "Hello world!"
)] )]
...@@ -117,7 +117,7 @@ module RenderActionWithApplicationLayout ...@@ -117,7 +117,7 @@ module RenderActionWithApplicationLayout
# # ==== Render actions with layouts ==== # # ==== Render actions with layouts ====
class BasicController < ::ApplicationController class BasicController < ::ApplicationController
# Set the view path to an application view structure with layouts # Set the view path to an application view structure with layouts
self.view_paths = self.view_paths = [ActionView::Template::FixturePath.new( self.view_paths = self.view_paths = [ActionView::FixtureResolver.new(
"render_action_with_application_layout/basic/hello_world.html.erb" => "Hello World!", "render_action_with_application_layout/basic/hello_world.html.erb" => "Hello World!",
"render_action_with_application_layout/basic/hello.html.builder" => "xml.p 'Omg'", "render_action_with_application_layout/basic/hello.html.builder" => "xml.p 'Omg'",
"layouts/application.html.erb" => "OHAI <%= yield %> KTHXBAI", "layouts/application.html.erb" => "OHAI <%= yield %> KTHXBAI",
...@@ -202,7 +202,7 @@ class TestLayout < SimpleRouteCase ...@@ -202,7 +202,7 @@ class TestLayout < SimpleRouteCase
module RenderActionWithControllerLayout module RenderActionWithControllerLayout
class BasicController < ActionController::Base class BasicController < ActionController::Base
self.view_paths = self.view_paths = [ActionView::Template::FixturePath.new( self.view_paths = self.view_paths = [ActionView::FixtureResolver.new(
"render_action_with_controller_layout/basic/hello_world.html.erb" => "Hello World!", "render_action_with_controller_layout/basic/hello_world.html.erb" => "Hello World!",
"layouts/render_action_with_controller_layout/basic.html.erb" => "With Controller Layout! <%= yield %> KTHXBAI" "layouts/render_action_with_controller_layout/basic.html.erb" => "With Controller Layout! <%= yield %> KTHXBAI"
)] )]
...@@ -263,7 +263,7 @@ class ControllerLayoutTest < SimpleRouteCase ...@@ -263,7 +263,7 @@ class ControllerLayoutTest < SimpleRouteCase
module RenderActionWithBothLayouts module RenderActionWithBothLayouts
class BasicController < ActionController::Base class BasicController < ActionController::Base
self.view_paths = [ActionView::Template::FixturePath.new({ self.view_paths = [ActionView::FixtureResolver.new({
"render_action_with_both_layouts/basic/hello_world.html.erb" => "Hello World!", "render_action_with_both_layouts/basic/hello_world.html.erb" => "Hello World!",
"layouts/application.html.erb" => "OHAI <%= yield %> KTHXBAI", "layouts/application.html.erb" => "OHAI <%= yield %> KTHXBAI",
"layouts/render_action_with_both_layouts/basic.html.erb" => "With Controller Layout! <%= yield %> KTHXBAI" "layouts/render_action_with_both_layouts/basic.html.erb" => "With Controller Layout! <%= yield %> KTHXBAI"
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
module RenderImplicitAction module RenderImplicitAction
class SimpleController < ::ApplicationController class SimpleController < ::ApplicationController
self.view_paths = [ActionView::Template::FixturePath.new( self.view_paths = [ActionView::FixtureResolver.new(
"render_implicit_action/simple/hello_world.html.erb" => "Hello world!", "render_implicit_action/simple/hello_world.html.erb" => "Hello world!",
"render_implicit_action/simple/hyphen-ated.html.erb" => "Hello hyphen-ated!" "render_implicit_action/simple/hyphen-ated.html.erb" => "Hello hyphen-ated!"
)] )]
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
module ControllerLayouts module ControllerLayouts
class ImplicitController < ::ApplicationController class ImplicitController < ::ApplicationController
self.view_paths = [ActionView::Template::FixturePath.new( self.view_paths = [ActionView::FixtureResolver.new(
"layouts/application.html.erb" => "OMG <%= yield %> KTHXBAI", "layouts/application.html.erb" => "OMG <%= yield %> KTHXBAI",
"layouts/override.html.erb" => "Override! <%= yield %>", "layouts/override.html.erb" => "Override! <%= yield %>",
"basic.html.erb" => "Hello world!", "basic.html.erb" => "Hello world!",
...@@ -26,7 +26,7 @@ def builder_override ...@@ -26,7 +26,7 @@ def builder_override
end end
class ImplicitNameController < ::ApplicationController class ImplicitNameController < ::ApplicationController
self.view_paths = [ActionView::Template::FixturePath.new( self.view_paths = [ActionView::FixtureResolver.new(
"layouts/controller_layouts/implicit_name.html.erb" => "OMGIMPLICIT <%= yield %> KTHXBAI", "layouts/controller_layouts/implicit_name.html.erb" => "OMGIMPLICIT <%= yield %> KTHXBAI",
"basic.html.erb" => "Hello world!" "basic.html.erb" => "Hello world!"
)] )]
...@@ -68,7 +68,7 @@ class LayoutOptionsTest < SimpleRouteCase ...@@ -68,7 +68,7 @@ class LayoutOptionsTest < SimpleRouteCase
end end
class MismatchFormatController < ::ApplicationController class MismatchFormatController < ::ApplicationController
self.view_paths = [ActionView::Template::FixturePath.new( self.view_paths = [ActionView::FixtureResolver.new(
"layouts/application.html.erb" => "<html><%= yield %></html>", "layouts/application.html.erb" => "<html><%= yield %></html>",
"controller_layouts/mismatch_format/index.js.rjs" => "page[:test].omg", "controller_layouts/mismatch_format/index.js.rjs" => "page[:test].omg",
"controller_layouts/mismatch_format/implicit.rjs" => "page[:test].omg" "controller_layouts/mismatch_format/implicit.rjs" => "page[:test].omg"
......
...@@ -4,7 +4,7 @@ module RenderPartial ...@@ -4,7 +4,7 @@ module RenderPartial
class BasicController < ActionController::Base class BasicController < ActionController::Base
self.view_paths = [ActionView::Template::FixturePath.new( self.view_paths = [ActionView::FixtureResolver.new(
"render_partial/basic/_basic.html.erb" => "OMG!", "render_partial/basic/_basic.html.erb" => "OMG!",
"render_partial/basic/basic.html.erb" => "<%= @test_unchanged = 'goodbye' %><%= render :partial => 'basic' %><%= @test_unchanged %>" "render_partial/basic/basic.html.erb" => "<%= @test_unchanged = 'goodbye' %><%= render :partial => 'basic' %><%= @test_unchanged %>"
)] )]
......
...@@ -4,7 +4,7 @@ module RenderRjs ...@@ -4,7 +4,7 @@ module RenderRjs
class BasicController < ActionController::Base class BasicController < ActionController::Base
self.view_paths = [ActionView::Template::FixturePath.new( self.view_paths = [ActionView::FixtureResolver.new(
"render_rjs/basic/index.js.rjs" => "page[:customer].replace_html render(:partial => 'customer')", "render_rjs/basic/index.js.rjs" => "page[:customer].replace_html render(:partial => 'customer')",
"render_rjs/basic/index_html.js.rjs" => "page[:customer].replace_html :partial => 'customer'", "render_rjs/basic/index_html.js.rjs" => "page[:customer].replace_html :partial => 'customer'",
"render_rjs/basic/_customer.js.erb" => "JS Partial", "render_rjs/basic/_customer.js.erb" => "JS Partial",
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
module RenderTemplate module RenderTemplate
class WithoutLayoutController < ActionController::Base class WithoutLayoutController < ActionController::Base
self.view_paths = [ActionView::Template::FixturePath.new( self.view_paths = [ActionView::FixtureResolver.new(
"test/basic.html.erb" => "Hello from basic.html.erb", "test/basic.html.erb" => "Hello from basic.html.erb",
"shared.html.erb" => "Elastica", "shared.html.erb" => "Elastica",
"locals.html.erb" => "The secret is <%= secret %>", "locals.html.erb" => "The secret is <%= secret %>",
...@@ -79,7 +79,7 @@ class TestWithoutLayout < SimpleRouteCase ...@@ -79,7 +79,7 @@ class TestWithoutLayout < SimpleRouteCase
end end
class WithLayoutController < ::ApplicationController class WithLayoutController < ::ApplicationController
self.view_paths = [ActionView::Template::FixturePath.new( self.view_paths = [ActionView::FixtureResolver.new(
"test/basic.html.erb" => "Hello from basic.html.erb", "test/basic.html.erb" => "Hello from basic.html.erb",
"shared.html.erb" => "Elastica", "shared.html.erb" => "Elastica",
"layouts/application.html.erb" => "<%= yield %>, I'm here!", "layouts/application.html.erb" => "<%= yield %>, I'm here!",
...@@ -148,7 +148,7 @@ class TestWithLayout < SimpleRouteCase ...@@ -148,7 +148,7 @@ class TestWithLayout < SimpleRouteCase
module Compatibility module Compatibility
class WithoutLayoutController < ActionController::Base class WithoutLayoutController < ActionController::Base
self.view_paths = [ActionView::Template::FixturePath.new( self.view_paths = [ActionView::FixtureResolver.new(
"test/basic.html.erb" => "Hello from basic.html.erb", "test/basic.html.erb" => "Hello from basic.html.erb",
"shared.html.erb" => "Elastica" "shared.html.erb" => "Elastica"
)] )]
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
module Render module Render
class BlankRenderController < ActionController::Base class BlankRenderController < ActionController::Base
self.view_paths = [ActionView::Template::FixturePath.new( self.view_paths = [ActionView::FixtureResolver.new(
"render/blank_render/index.html.erb" => "Hello world!", "render/blank_render/index.html.erb" => "Hello world!",
"render/blank_render/access_request.html.erb" => "The request: <%= request.method.to_s.upcase %>", "render/blank_render/access_request.html.erb" => "The request: <%= request.method.to_s.upcase %>",
"render/blank_render/access_action_name.html.erb" => "Action Name: <%= action_name %>", "render/blank_render/access_action_name.html.erb" => "Action Name: <%= action_name %>",
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
module RenderText module RenderText
class SimpleController < ActionController::Base class SimpleController < ActionController::Base
self.view_paths = [ActionView::Template::FixturePath.new] self.view_paths = [ActionView::FixtureResolver.new]
def index def index
render :text => "hello david" render :text => "hello david"
...@@ -10,7 +10,7 @@ def index ...@@ -10,7 +10,7 @@ def index
end end
class WithLayoutController < ::ApplicationController class WithLayoutController < ::ApplicationController
self.view_paths = [ActionView::Template::FixturePath.new( self.view_paths = [ActionView::FixtureResolver.new(
"layouts/application.html.erb" => "<%= yield %>, I'm here!", "layouts/application.html.erb" => "<%= yield %>, I'm here!",
"layouts/greetings.html.erb" => "<%= yield %>, I wish thee well.", "layouts/greetings.html.erb" => "<%= yield %>, I wish thee well.",
"layouts/ivar.html.erb" => "<%= yield %>, <%= @ivar %>" "layouts/ivar.html.erb" => "<%= yield %>, <%= @ivar %>"
......
...@@ -4,7 +4,7 @@ module RenderXml ...@@ -4,7 +4,7 @@ module RenderXml
# This has no layout and it works # This has no layout and it works
class BasicController < ActionController::Base class BasicController < ActionController::Base
self.view_paths = [ActionView::Template::FixturePath.new( self.view_paths = [ActionView::FixtureResolver.new(
"render_xml/basic/with_render_erb" => "Hello world!" "render_xml/basic/with_render_erb" => "Hello world!"
)] )]
end end
......
...@@ -41,7 +41,7 @@ def render_with_cache(*args) ...@@ -41,7 +41,7 @@ def render_with_cache(*args)
end end
def render_without_cache(*args) def render_without_cache(*args)
path = ActionView::Template::FileSystemPathWithFallback.new(FIXTURE_LOAD_PATH) path = ActionView::FileSystemResolverWithFallback.new(FIXTURE_LOAD_PATH)
view_paths = ActionView::Base.process_view_paths(path) view_paths = ActionView::Base.process_view_paths(path)
ActionView::Base.new(view_paths, {}).render(*args) ActionView::Base.new(view_paths, {}).render(*args)
end end
......
...@@ -255,7 +255,7 @@ class CachedViewRenderTest < ActiveSupport::TestCase ...@@ -255,7 +255,7 @@ class CachedViewRenderTest < ActiveSupport::TestCase
# Ensure view path cache is primed # Ensure view path cache is primed
def setup def setup
view_paths = ActionController::Base.view_paths view_paths = ActionController::Base.view_paths
assert_equal ActionView::Template::FileSystemPathWithFallback, view_paths.first.class assert_equal ActionView::FileSystemResolverWithFallback, view_paths.first.class
setup_view(view_paths) setup_view(view_paths)
end end
end end
...@@ -266,9 +266,9 @@ class LazyViewRenderTest < ActiveSupport::TestCase ...@@ -266,9 +266,9 @@ class LazyViewRenderTest < ActiveSupport::TestCase
# Test the same thing as above, but make sure the view path # Test the same thing as above, but make sure the view path
# is not eager loaded # is not eager loaded
def setup def setup
path = ActionView::Template::FileSystemPathWithFallback.new(FIXTURE_LOAD_PATH) path = ActionView::FileSystemResolverWithFallback.new(FIXTURE_LOAD_PATH)
view_paths = ActionView::Base.process_view_paths(path) view_paths = ActionView::Base.process_view_paths(path)
assert_equal ActionView::Template::FileSystemPathWithFallback, view_paths.first.class assert_equal ActionView::FileSystemResolverWithFallback, view_paths.first.class
setup_view(view_paths) setup_view(view_paths)
end end
end end
...@@ -401,7 +401,7 @@ def load_observers ...@@ -401,7 +401,7 @@ def load_observers
def load_view_paths def load_view_paths
if configuration.frameworks.include?(:action_view) if configuration.frameworks.include?(:action_view)
if configuration.cache_classes if configuration.cache_classes
view_path = ActionView::Template::FileSystemPath.new(configuration.view_path) view_path = ActionView::FileSystemResolverWithFallback.new(configuration.view_path)
ActionController::Base.view_paths = view_path if configuration.frameworks.include?(:action_controller) ActionController::Base.view_paths = view_path if configuration.frameworks.include?(:action_controller)
ActionMailer::Base.template_root = view_path if configuration.frameworks.include?(:action_mailer) ActionMailer::Base.template_root = view_path if configuration.frameworks.include?(:action_mailer)
end end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册