From d39f5f18bbe60c13e671fc9c7a8eec8e7b4fc42b Mon Sep 17 00:00:00 2001 From: Carl Lerche & Yehuda Katz Date: Mon, 13 Apr 2009 17:33:15 -0700 Subject: Move all Templates methods not used by other class into private to define surface area of the class. --- actionpack/lib/action_view/template/template.rb | 175 ++++++++++++------------ 1 file changed, 88 insertions(+), 87 deletions(-) (limited to 'actionpack/lib/action_view') diff --git a/actionpack/lib/action_view/template/template.rb b/actionpack/lib/action_view/template/template.rb index a61c46020f..da8bba9658 100644 --- a/actionpack/lib/action_view/template/template.rb +++ b/actionpack/lib/action_view/template/template.rb @@ -124,7 +124,12 @@ module ActionView #:nodoc: # Extend with partial super powers extend RenderablePartial if @name =~ /^_/ end - + + def load! + @cached = true + # freeze + end + def accessible_paths paths = [] @@ -143,49 +148,56 @@ module ActionView #:nodoc: 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 @@ -193,11 +205,6 @@ module ActionView #:nodoc: 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 @@ module ActionView #:nodoc: !@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 -- cgit v1.2.3