aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/lib/action_view/template
diff options
context:
space:
mode:
Diffstat (limited to 'actionview/lib/action_view/template')
-rw-r--r--actionview/lib/action_view/template/error.rb8
-rw-r--r--actionview/lib/action_view/template/handlers.rb8
-rw-r--r--actionview/lib/action_view/template/handlers/builder.rb10
-rw-r--r--actionview/lib/action_view/template/handlers/erb.rb20
-rw-r--r--actionview/lib/action_view/template/html.rb4
-rw-r--r--actionview/lib/action_view/template/resolver.rb160
-rw-r--r--actionview/lib/action_view/template/text.rb4
-rw-r--r--actionview/lib/action_view/template/types.rb2
8 files changed, 108 insertions, 108 deletions
diff --git a/actionview/lib/action_view/template/error.rb b/actionview/lib/action_view/template/error.rb
index 0f1348b032..b95e5236a0 100644
--- a/actionview/lib/action_view/template/error.rb
+++ b/actionview/lib/action_view/template/error.rb
@@ -1,5 +1,5 @@
require "active_support/core_ext/enumerable"
-require 'active_support/core_ext/regexp'
+require "active_support/core_ext/regexp"
module ActionView
# = Action View Errors
@@ -37,9 +37,9 @@ module ActionView
template_type = if partial
"partial"
elsif /layouts/i.match?(path)
- 'layout'
+ "layout"
else
- 'template'
+ "template"
end
if partial && path.present?
@@ -131,7 +131,7 @@ module ActionView
if line_number
"on line ##{line_number} of "
else
- 'in '
+ "in "
end + file_name
end
diff --git a/actionview/lib/action_view/template/handlers.rb b/actionview/lib/action_view/template/handlers.rb
index ad4c353608..f4301f6f07 100644
--- a/actionview/lib/action_view/template/handlers.rb
+++ b/actionview/lib/action_view/template/handlers.rb
@@ -2,10 +2,10 @@ module ActionView #:nodoc:
# = Action View Template Handlers
class Template
module Handlers #:nodoc:
- autoload :Raw, 'action_view/template/handlers/raw'
- autoload :ERB, 'action_view/template/handlers/erb'
- autoload :Html, 'action_view/template/handlers/html'
- autoload :Builder, 'action_view/template/handlers/builder'
+ autoload :Raw, "action_view/template/handlers/raw"
+ autoload :ERB, "action_view/template/handlers/erb"
+ autoload :Html, "action_view/template/handlers/html"
+ autoload :Builder, "action_view/template/handlers/builder"
def self.extended(base)
base.register_default_template_handler :raw, Raw.new
diff --git a/actionview/lib/action_view/template/handlers/builder.rb b/actionview/lib/action_view/template/handlers/builder.rb
index d90b0c6378..e08a5b5db8 100644
--- a/actionview/lib/action_view/template/handlers/builder.rb
+++ b/actionview/lib/action_view/template/handlers/builder.rb
@@ -15,12 +15,12 @@ module ActionView
protected
- def require_engine
- @required ||= begin
- require "builder"
- true
+ def require_engine
+ @required ||= begin
+ require "builder"
+ true
+ end
end
- end
end
end
end
diff --git a/actionview/lib/action_view/template/handlers/erb.rb b/actionview/lib/action_view/template/handlers/erb.rb
index 058b590c56..6f07de1813 100644
--- a/actionview/lib/action_view/template/handlers/erb.rb
+++ b/actionview/lib/action_view/template/handlers/erb.rb
@@ -1,5 +1,5 @@
-require 'erubis'
-require 'active_support/core_ext/regexp'
+require "erubis"
+require "active_support/core_ext/regexp"
module ActionView
class Template
@@ -29,7 +29,7 @@ module ActionView
# We override to always treat <%== as escaped.
def add_expr(src, code, indicator)
case indicator
- when '=='
+ when "=="
add_expr_escaped(src, code)
else
super
@@ -41,9 +41,9 @@ module ActionView
def add_expr_literal(src, code)
flush_newline_if_pending(src)
if BLOCK_EXPR.match?(code)
- src << '@output_buffer.append= ' << code
+ src << "@output_buffer.append= " << code
else
- src << '@output_buffer.append=(' << code << ');'
+ src << "@output_buffer.append=(" << code << ");"
end
end
@@ -63,7 +63,7 @@ module ActionView
def add_postamble(src)
flush_newline_if_pending(src)
- src << '@output_buffer.to_s'
+ src << "@output_buffer.to_s"
end
def flush_newline_if_pending(src)
@@ -78,7 +78,7 @@ module ActionView
# Specify trim mode for the ERB compiler. Defaults to '-'.
# See ERB documentation for suitable values.
class_attribute :erb_trim_mode
- self.erb_trim_mode = '-'
+ self.erb_trim_mode = "-"
# Default implementation used.
class_attribute :erb_implementation
@@ -109,7 +109,7 @@ module ActionView
# expression
template_source = template.source.dup.force_encoding(Encoding::ASCII_8BIT)
- erb = template_source.gsub(ENCODING_TAG, '')
+ erb = template_source.gsub(ENCODING_TAG, "")
encoding = $2
erb.force_encoding valid_encoding(template.source.dup, encoding)
@@ -119,8 +119,8 @@ module ActionView
self.class.erb_implementation.new(
erb,
- :escape => (self.class.escape_whitelist.include? template.type),
- :trim => (self.class.erb_trim_mode == "-")
+ escape: (self.class.escape_whitelist.include? template.type),
+ trim: (self.class.erb_trim_mode == "-")
).src
end
diff --git a/actionview/lib/action_view/template/html.rb b/actionview/lib/action_view/template/html.rb
index 0321f819b5..ddbd2ea36a 100644
--- a/actionview/lib/action_view/template/html.rb
+++ b/actionview/lib/action_view/template/html.rb
@@ -11,11 +11,11 @@ module ActionView #:nodoc:
end
def identifier
- 'html template'
+ "html template"
end
def inspect
- 'html template'
+ "html template"
end
def to_str
diff --git a/actionview/lib/action_view/template/resolver.rb b/actionview/lib/action_view/template/resolver.rb
index bf68e93c58..20c2d5c782 100644
--- a/actionview/lib/action_view/template/resolver.rb
+++ b/actionview/lib/action_view/template/resolver.rb
@@ -37,15 +37,15 @@ module ActionView
class Cache #:nodoc:
class SmallCache < Concurrent::Map
def initialize(options = {})
- super(options.merge(:initial_capacity => 2))
+ super(options.merge(initial_capacity: 2))
end
end
# preallocate all the default blocks for performance/memory consumption reasons
- PARTIAL_BLOCK = lambda {|cache, partial| cache[partial] = SmallCache.new}
- PREFIX_BLOCK = lambda {|cache, prefix| cache[prefix] = SmallCache.new(&PARTIAL_BLOCK)}
- NAME_BLOCK = lambda {|cache, name| cache[name] = SmallCache.new(&PREFIX_BLOCK)}
- KEY_BLOCK = lambda {|cache, key| cache[key] = SmallCache.new(&NAME_BLOCK)}
+ PARTIAL_BLOCK = lambda { |cache, partial| cache[partial] = SmallCache.new }
+ PREFIX_BLOCK = lambda { |cache, prefix| cache[prefix] = SmallCache.new(&PARTIAL_BLOCK) }
+ NAME_BLOCK = lambda { |cache, name| cache[name] = SmallCache.new(&PREFIX_BLOCK) }
+ KEY_BLOCK = lambda { |cache, key| cache[key] = SmallCache.new(&NAME_BLOCK) }
# usually a majority of template look ups return nothing, use this canonical preallocated array to save memory
NO_TEMPLATES = [].freeze
@@ -107,22 +107,22 @@ module ActionView
private
- def canonical_no_templates(templates)
- templates.empty? ? NO_TEMPLATES : templates
- end
-
- def templates_have_changed?(cached_templates, fresh_templates)
- # if either the old or new template list is empty, we don't need to (and can't)
- # compare modification times, and instead just check whether the lists are different
- if cached_templates.blank? || fresh_templates.blank?
- return fresh_templates.blank? != cached_templates.blank?
+ def canonical_no_templates(templates)
+ templates.empty? ? NO_TEMPLATES : templates
end
- cached_templates_max_updated_at = cached_templates.map(&:updated_at).max
+ def templates_have_changed?(cached_templates, fresh_templates)
+ # if either the old or new template list is empty, we don't need to (and can't)
+ # compare modification times, and instead just check whether the lists are different
+ if cached_templates.blank? || fresh_templates.blank?
+ return fresh_templates.blank? != cached_templates.blank?
+ end
- # if a template has changed, it will be now be newer than all the cached templates
- fresh_templates.any? { |t| t.updated_at > cached_templates_max_updated_at }
- end
+ cached_templates_max_updated_at = cached_templates.map(&:updated_at).max
+
+ # if a template has changed, it will be now be newer than all the cached templates
+ fresh_templates.any? { |t| t.updated_at > cached_templates_max_updated_at }
+ end
end
cattr_accessor :caching
@@ -204,7 +204,7 @@ module ActionView
# An abstract class that implements a Resolver with path semantics.
class PathResolver < Resolver #:nodoc:
- EXTENSIONS = { :locale => ".", :formats => ".", :variants => "+", :handlers => "." }
+ EXTENSIONS = { locale: ".", formats: ".", variants: "+", handlers: "." }
DEFAULT_PATTERN = ":prefix/:action{.:locale,}{.:formats,}{+:variants,}{.:handlers,}"
def initialize(pattern=nil)
@@ -214,93 +214,93 @@ module ActionView
private
- def find_templates(name, prefix, partial, details, outside_app_allowed = false)
- path = Path.build(name, prefix, partial)
- query(path, details, details[:formats], outside_app_allowed)
- end
+ def find_templates(name, prefix, partial, details, outside_app_allowed = false)
+ path = Path.build(name, prefix, partial)
+ query(path, details, details[:formats], outside_app_allowed)
+ end
- def query(path, details, formats, outside_app_allowed)
- query = build_query(path, details)
+ def query(path, details, formats, outside_app_allowed)
+ query = build_query(path, details)
- template_paths = find_template_paths(query)
- template_paths = reject_files_external_to_app(template_paths) unless outside_app_allowed
+ template_paths = find_template_paths(query)
+ template_paths = reject_files_external_to_app(template_paths) unless outside_app_allowed
- template_paths.map do |template|
- handler, format, variant = extract_handler_and_format_and_variant(template, formats)
- contents = File.binread(template)
+ template_paths.map do |template|
+ handler, format, variant = extract_handler_and_format_and_variant(template, formats)
+ contents = File.binread(template)
- Template.new(contents, File.expand_path(template), handler,
- :virtual_path => path.virtual,
- :format => format,
- :variant => variant,
- :updated_at => mtime(template)
- )
+ Template.new(contents, File.expand_path(template), handler,
+ virtual_path: path.virtual,
+ format: format,
+ variant: variant,
+ updated_at: mtime(template)
+ )
+ end
end
- end
- def reject_files_external_to_app(files)
- files.reject { |filename| !inside_path?(@path, filename) }
- end
+ def reject_files_external_to_app(files)
+ files.reject { |filename| !inside_path?(@path, filename) }
+ end
- def find_template_paths(query)
- Dir[query].uniq.reject do |filename|
- File.directory?(filename) ||
- # deals with case-insensitive file systems.
- !File.fnmatch(query, filename, File::FNM_EXTGLOB)
+ def find_template_paths(query)
+ Dir[query].uniq.reject do |filename|
+ File.directory?(filename) ||
+ # deals with case-insensitive file systems.
+ !File.fnmatch(query, filename, File::FNM_EXTGLOB)
+ end
end
- end
- def inside_path?(path, filename)
- filename = File.expand_path(filename)
- path = File.join(path, '')
- filename.start_with?(path)
- end
+ def inside_path?(path, filename)
+ filename = File.expand_path(filename)
+ path = File.join(path, "")
+ filename.start_with?(path)
+ end
# Helper for building query glob string based on resolver's pattern.
- def build_query(path, details)
- query = @pattern.dup
+ def build_query(path, details)
+ query = @pattern.dup
- prefix = path.prefix.empty? ? '' : "#{escape_entry(path.prefix)}\\1"
- query.gsub!(/:prefix(\/)?/, prefix)
+ prefix = path.prefix.empty? ? "" : "#{escape_entry(path.prefix)}\\1"
+ query.gsub!(/:prefix(\/)?/, prefix)
- partial = escape_entry(path.partial? ? "_#{path.name}" : path.name)
- query.gsub!(/:action/, partial)
+ partial = escape_entry(path.partial? ? "_#{path.name}" : path.name)
+ query.gsub!(/:action/, partial)
- details.each do |ext, candidates|
- if ext == :variants && candidates == :any
- query.gsub!(/:#{ext}/, "*")
- else
- query.gsub!(/:#{ext}/, "{#{candidates.compact.uniq.join(',')}}")
+ details.each do |ext, candidates|
+ if ext == :variants && candidates == :any
+ query.gsub!(/:#{ext}/, "*")
+ else
+ query.gsub!(/:#{ext}/, "{#{candidates.compact.uniq.join(',')}}")
+ end
end
- end
- File.expand_path(query, @path)
- end
+ File.expand_path(query, @path)
+ end
- def escape_entry(entry)
- entry.gsub(/[*?{}\[\]]/, '\\\\\\&'.freeze)
- end
+ def escape_entry(entry)
+ entry.gsub(/[*?{}\[\]]/, '\\\\\\&'.freeze)
+ end
# Returns the file mtime from the filesystem.
- def mtime(p)
- File.mtime(p)
- end
+ def mtime(p)
+ File.mtime(p)
+ end
# Extract handler, formats and variant from path. If a format cannot be found neither
# from the path, or the handler, we should return the array of formats given
# to the resolver.
- def extract_handler_and_format_and_variant(path, default_formats)
- pieces = File.basename(path).split('.'.freeze)
- pieces.shift
+ def extract_handler_and_format_and_variant(path, default_formats)
+ pieces = File.basename(path).split(".".freeze)
+ pieces.shift
- extension = pieces.pop
+ extension = pieces.pop
- handler = Template.handler_for_extension(extension)
- format, variant = pieces.last.split(EXTENSIONS[:variants], 2) if pieces.last
- format &&= Template::Types[format]
+ handler = Template.handler_for_extension(extension)
+ format, variant = pieces.last.split(EXTENSIONS[:variants], 2) if pieces.last
+ format &&= Template::Types[format]
- [handler, format, variant]
- end
+ [handler, format, variant]
+ end
end
# A resolver that loads files from the filesystem. It allows setting your own
diff --git a/actionview/lib/action_view/template/text.rb b/actionview/lib/action_view/template/text.rb
index 04f5b8d17a..898593e702 100644
--- a/actionview/lib/action_view/template/text.rb
+++ b/actionview/lib/action_view/template/text.rb
@@ -11,11 +11,11 @@ module ActionView #:nodoc:
end
def identifier
- 'text template'
+ "text template"
end
def inspect
- 'text template'
+ "text template"
end
def to_str
diff --git a/actionview/lib/action_view/template/types.rb b/actionview/lib/action_view/template/types.rb
index b32567cd66..21959a3798 100644
--- a/actionview/lib/action_view/template/types.rb
+++ b/actionview/lib/action_view/template/types.rb
@@ -1,4 +1,4 @@
-require 'active_support/core_ext/module/attribute_accessors'
+require "active_support/core_ext/module/attribute_accessors"
module ActionView
class Template