Permalink
Browse files

Move all Templates methods not used by other class into private to

define surface area of the class.
  • Loading branch information...
1 parent 9954494 commit d39f5f18bbe60c13e671fc9c7a8eec8e7b4fc42b @wycats wycats committed Apr 14, 2009
Showing with 88 additions and 87 deletions.
  1. +88 −87 actionpack/lib/action_view/template/template.rb
@@ -124,7 +124,12 @@ def initialize(template_path, load_paths = [])
# Extend with partial super powers
extend RenderablePartial if @name =~ /^_/
end
-
+
+ def load!
+ @cached = true
+ # freeze
+ end
+
def accessible_paths
paths = []
@@ -143,61 +148,63 @@ def accessible_paths
paths
end
-
- def format_and_extension
- (extensions = [format, extension].compact.join(".")).blank? ? nil : extensions
+
+ def relative_path
+ path = File.expand_path(filename)
+ path.sub!(/^#{Regexp.escape(File.expand_path(RAILS_ROOT))}\//, '') if defined?(RAILS_ROOT)
+ path
end
- memoize :format_and_extension
-
- def multipart?
- format && format.include?('.')
+ memoize :relative_path
+
+ def source
+ File.read(filename)
end
-
- def content_type
- format.gsub('.', '/')
+ memoize :source
+
+ def exempt_from_layout?
+ @@exempt_from_layout.any? { |exempted| path =~ exempted }
+ end
+
+ def path_without_extension
+ [base_path, [name, locale, format].compact.join('.')].compact.join('/')
end
+ memoize :path_without_extension
- def mime_type
- Mime::Type.lookup_by_extension(format) if format && defined?(::Mime)
+ def path_without_format_and_extension
+ [base_path, [name, locale].compact.join('.')].compact.join('/')
end
- memoize :mime_type
-
+ memoize :path_without_format_and_extension
+
def path
[base_path, [name, locale, format, extension].compact.join('.')].compact.join('/')
end
memoize :path
-
- def path_without_extension
- [base_path, [name, locale, format].compact.join('.')].compact.join('/')
+
+ def mime_type
+ Mime::Type.lookup_by_extension(format) if format && defined?(::Mime)
end
- memoize :path_without_extension
-
- def path_without_format_and_extension
- [base_path, [name, locale].compact.join('.')].compact.join('/')
+ memoize :mime_type
+
+ private
+
+ def format_and_extension
+ (extensions = [format, extension].compact.join(".")).blank? ? nil : extensions
end
- memoize :path_without_format_and_extension
+ memoize :format_and_extension
- def relative_path
- path = File.expand_path(filename)
- path.sub!(/^#{Regexp.escape(File.expand_path(RAILS_ROOT))}\//, '') if defined?(RAILS_ROOT)
- path
+ def multipart?
+ format && format.include?('.')
end
- memoize :relative_path
- def exempt_from_layout?
- @@exempt_from_layout.any? { |exempted| path =~ exempted }
+ def content_type
+ format.gsub('.', '/')
end
def mtime
File.mtime(filename)
end
memoize :mtime
- def source
- File.read(filename)
- end
- memoize :source
-
def method_segment
relative_path.to_s.gsub(/([^a-zA-Z0-9_])/) { $1.ord }
end
@@ -211,66 +218,60 @@ def recompile?
!@cached
end
- def load!
- @cached = true
- # freeze
+ def valid_extension?(extension)
+ !Template.registered_template_handler(extension).nil?
end
- private
- def valid_extension?(extension)
- !Template.registered_template_handler(extension).nil?
- end
+ def valid_locale?(locale)
+ I18n.available_locales.include?(locale.to_sym)
+ end
- def valid_locale?(locale)
- I18n.available_locales.include?(locale.to_sym)
+ def find_full_path(path, load_paths)
+ load_paths = Array(load_paths) + [nil]
+ load_paths.each do |load_path|
+ file = load_path ? "#{load_path.to_str}/#{path}" : path
+ return load_path, file if File.file?(file)
end
+ raise MissingTemplate.new(load_paths, path)
+ end
- def find_full_path(path, load_paths)
- load_paths = Array(load_paths) + [nil]
- load_paths.each do |load_path|
- file = load_path ? "#{load_path.to_str}/#{path}" : path
- return load_path, file if File.file?(file)
- end
- raise MissingTemplate.new(load_paths, path)
+ # Returns file split into an array
+ # [base_path, name, locale, format, extension]
+ def split(file)
+ if m = file.to_s.match(/^(.*\/)?([^\.]+)\.(.*)$/)
+ base_path = m[1]
+ name = m[2]
+ extensions = m[3]
+ else
+ return
end
- # Returns file split into an array
- # [base_path, name, locale, format, extension]
- def split(file)
- if m = file.to_s.match(/^(.*\/)?([^\.]+)\.(.*)$/)
- base_path = m[1]
- name = m[2]
- extensions = m[3]
- else
- return
+ locale = nil
+ format = nil
+ extension = nil
+
+ if m = extensions.split(".")
+ if valid_locale?(m[0]) && m[1] && valid_extension?(m[2]) # All three
+ locale = m[0]
+ format = m[1]
+ extension = m[2]
+ elsif m[0] && m[1] && valid_extension?(m[2]) # Multipart formats
+ format = "#{m[0]}.#{m[1]}"
+ extension = m[2]
+ elsif valid_locale?(m[0]) && valid_extension?(m[1]) # locale and extension
+ locale = m[0]
+ extension = m[1]
+ elsif valid_extension?(m[1]) # format and extension
+ format = m[0]
+ extension = m[1]
+ elsif valid_extension?(m[0]) # Just extension
+ extension = m[0]
+ else # No extension
+ format = m[0]
end
-
- locale = nil
- format = nil
- extension = nil
-
- if m = extensions.split(".")
- if valid_locale?(m[0]) && m[1] && valid_extension?(m[2]) # All three
- locale = m[0]
- format = m[1]
- extension = m[2]
- elsif m[0] && m[1] && valid_extension?(m[2]) # Multipart formats
- format = "#{m[0]}.#{m[1]}"
- extension = m[2]
- elsif valid_locale?(m[0]) && valid_extension?(m[1]) # locale and extension
- locale = m[0]
- extension = m[1]
- elsif valid_extension?(m[1]) # format and extension
- format = m[0]
- extension = m[1]
- elsif valid_extension?(m[0]) # Just extension
- extension = m[0]
- else # No extension
- format = m[0]
- end
- end
-
- [base_path, name, locale, format, extension]
end
+
+ [base_path, name, locale, format, extension]
+ end
end
end

0 comments on commit d39f5f1

Please sign in to comment.