aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/template
diff options
context:
space:
mode:
authorCarl Lerche & Yehuda Katz <wycats@gmail.com>2009-04-14 17:22:51 -0700
committerCarl Lerche & Yehuda Katz <wycats@gmail.com>2009-04-14 18:32:31 -0700
commit3c1187699a80e0c4a003f5693389595cd644390f (patch)
tree3fc026e57412f4d145d5df314b4c6ce468ab84c1 /actionpack/lib/action_view/template
parent109a3876f09cb6b51a6da4d517bd6e3ea30380da (diff)
downloadrails-3c1187699a80e0c4a003f5693389595cd644390f.tar.gz
rails-3c1187699a80e0c4a003f5693389595cd644390f.tar.bz2
rails-3c1187699a80e0c4a003f5693389595cd644390f.zip
Makes rails-dev-boost work again
Diffstat (limited to 'actionpack/lib/action_view/template')
-rw-r--r--actionpack/lib/action_view/template/path.rb87
-rw-r--r--actionpack/lib/action_view/template/renderable.rb10
-rw-r--r--actionpack/lib/action_view/template/template.rb112
3 files changed, 108 insertions, 101 deletions
diff --git a/actionpack/lib/action_view/template/path.rb b/actionpack/lib/action_view/template/path.rb
new file mode 100644
index 0000000000..9709549b70
--- /dev/null
+++ b/actionpack/lib/action_view/template/path.rb
@@ -0,0 +1,87 @@
+module ActionView
+ class Template
+ class Path
+ attr_reader :path, :paths
+ delegate :hash, :inspect, :to => :path
+
+ def initialize(options)
+ @cache = options[:cache]
+ end
+
+ def to_s
+ if defined?(RAILS_ROOT)
+ path.to_s.sub(/^#{Regexp.escape(File.expand_path(RAILS_ROOT))}\//, '')
+ else
+ path.to_s
+ end
+ end
+
+ def to_str
+ path.to_str
+ end
+
+ def ==(path)
+ to_str == path.to_str
+ end
+
+ def eql?(path)
+ to_str == path.to_str
+ end
+
+ def find_by_parts(name, extensions = nil, prefix = nil, partial = nil)
+ path = prefix ? "#{prefix}/" : ""
+
+ name = name.to_s.split("/")
+ name[-1] = "_#{name[-1]}" if partial
+
+ path << name.join("/")
+
+ template = nil
+
+ Array(extensions).each do |extension|
+ extensioned_path = extension ? "#{path}.#{extension}" : path
+ break if (template = find_template(extensioned_path))
+ end
+ template || find_template(path)
+ end
+
+ private
+ def create_template(file)
+ Template.new(file.split("#{self}/").last, self)
+ end
+ end
+
+ class FileSystemPath < Path
+ def initialize(path, options = {})
+ raise ArgumentError, "path already is a Path class" if path.is_a?(Path)
+
+ super(options)
+ @path, @paths = path, {}
+
+ # **/*/** is a hax for symlinked directories
+ load_templates("#{@path}/{**/*,**}/**") if @cache
+ end
+
+ private
+
+ def load_template(template)
+ template.load!
+ template.accessible_paths.each do |path|
+ @paths[path] = template
+ end
+ end
+
+ def find_template(path)
+ load_templates("#{@path}/#{path}{,.*}") unless @cache
+ @paths[path]
+ end
+
+ def load_templates(glob)
+ Dir[glob].each do |file|
+ load_template(create_template(file)) unless File.directory?(file)
+ end
+ end
+
+ end
+ end
+end \ No newline at end of file
diff --git a/actionpack/lib/action_view/template/renderable.rb b/actionpack/lib/action_view/template/renderable.rb
index 2da5b742aa..54857516ab 100644
--- a/actionpack/lib/action_view/template/renderable.rb
+++ b/actionpack/lib/action_view/template/renderable.rb
@@ -11,6 +11,16 @@ module ActionView
view.send(method_name(locals), locals) {|*args| yield(*args) }
end
+ def load!
+ names = Base::CompiledTemplates.instance_methods.grep(/#{method_name_without_locals}/)
+ names.each do |name|
+ Base::CompiledTemplates.class_eval do
+ remove_method(name)
+ end
+ end
+ super
+ end
+
private
def filename
diff --git a/actionpack/lib/action_view/template/template.rb b/actionpack/lib/action_view/template/template.rb
index da8bba9658..fd9cbb494d 100644
--- a/actionpack/lib/action_view/template/template.rb
+++ b/actionpack/lib/action_view/template/template.rb
@@ -1,103 +1,18 @@
+require "action_view/template/path"
+
module ActionView #:nodoc:
class Template
- class Path
- attr_reader :path, :paths
- delegate :hash, :inspect, :to => :path
-
- def initialize(path)
- raise ArgumentError, "path already is a Path class" if path.is_a?(Path)
- @path = path.freeze
- end
-
- def to_s
- if defined?(RAILS_ROOT)
- path.to_s.sub(/^#{Regexp.escape(File.expand_path(RAILS_ROOT))}\//, '')
- else
- path.to_s
- end
- end
-
- def to_str
- path.to_str
- end
-
- def ==(path)
- to_str == path.to_str
- end
-
- def eql?(path)
- to_str == path.to_str
- end
-
- # Returns a ActionView::Template object for the given path string. The
- # input path should be relative to the view path directory,
- # +hello/index.html.erb+. This method also has a special exception to
- # match partial file names without a handler extension. So
- # +hello/index.html+ will match the first template it finds with a
- # known template extension, +hello/index.html.erb+. Template extensions
- # should not be confused with format extensions +html+, +js+, +xml+,
- # etc. A format must be supplied to match a formated file. +hello/index+
- # will never match +hello/index.html.erb+.
- def find_template(path)
- templates_in_path do |template|
- if template.accessible_paths.include?(path)
- return template
- end
- end
- nil
- end
-
- def find_by_parts(name, extensions = nil, prefix = nil, partial = nil)
- path = prefix ? "#{prefix}/" : ""
-
- name = name.to_s.split("/")
- name[-1] = "_#{name[-1]}" if partial
-
- path << name.join("/")
-
- template = nil
-
- Array(extensions).each do |extension|
- extensioned_path = extension ? "#{path}.#{extension}" : path
- template = find_template(extensioned_path) || find_template(path)
- break if template
- end
- template || find_template(path)
- end
-
- private
- def templates_in_path
- (Dir.glob("#{@path}/**/*/**") | Dir.glob("#{@path}/**")).each do |file|
- yield create_template(file) unless File.directory?(file)
- end
- end
-
- def create_template(file)
- Template.new(file.split("#{self}/").last, self)
- end
- end
-
- class EagerPath < Path
- def initialize(path)
- super
-
- @paths = {}
- templates_in_path do |template|
- template.load!
- template.accessible_paths.each do |path|
- @paths[path] = template
- end
- end
- @paths.freeze
- end
-
- def find_template(path)
- @paths[path]
- end
- end
-
extend TemplateHandlers
extend ActiveSupport::Memoizable
+
+ module Loading
+ def load!
+ @cached = true
+ # freeze
+ end
+ end
+ include Loading
+
include Renderable
# Templates that are exempt from layouts
@@ -125,11 +40,6 @@ module ActionView #:nodoc:
extend RenderablePartial if @name =~ /^_/
end
- def load!
- @cached = true
- # freeze
- end
-
def accessible_paths
paths = []