Class: ActionView::DependencyTracker::ERBTracker
Do not use. This class is for internal use only.
Relationships & Source Files | |
Inherits: | Object |
Defined in: | actionview/lib/action_view/dependency_tracker/erb_tracker.rb |
Constant Summary
-
EXPLICIT_DEPENDENCY =
# File 'actionview/lib/action_view/dependency_tracker/erb_tracker.rb', line 6/# Template Dependency: (\S+)/
-
IDENTIFIER =
A valid ruby identifier - suitable for class, method and specially variable names
/ [[:alpha:]_] # at least one uppercase letter, lowercase letter or underscore [[:word:]]* # followed by optional letters, numbers or underscores /x
-
LAYOUT_DEPENDENCY =
# File 'actionview/lib/action_view/dependency_tracker/erb_tracker.rb', line 58/\A (?:\s*\(?\s*) # optional opening paren surrounded by spaces (?:.*?#{LAYOUT_HASH_KEY}) # check if the line has layout key declaration (?:#{STRING}|#{VARIABLE_OR_METHOD_CHAIN}) # finally, the dependency name of interest /xm
-
LAYOUT_HASH_KEY =
Part of any hash containing the
:layout
key/ (?:\blayout:|:layout\s*=>) # layout key in either old or new style hash syntax \s* # followed by optional spaces /x
-
PARTIAL_HASH_KEY =
Part of any hash containing the
:partial
key/ (?:\bpartial:|:partial\s*=>) # partial key in either old or new style hash syntax \s* # followed by optional spaces /x
-
RENDER_ARGUMENTS =
Matches:
partial: "comments/comment", collection: @all_comments => "comments/comment" (object: @single_comment, partial: "comments/comment") => "comments/comment" "comments/comments" 'comments/comments' ('comments/comments') (@topic) => "topics/topic" topics => "topics/topic" ( .topics) => "topics/topic"
/\A (?:\s*\(?\s*) # optional opening paren surrounded by spaces (?:.*?#{PARTIAL_HASH_KEY}|#{LAYOUT_HASH_KEY})? # optional hash, up to the partial or layout key declaration (?:#{STRING}|#{VARIABLE_OR_METHOD_CHAIN}) # finally, the dependency name of interest /xm
-
STRING =
A simple string literal. e.g. “School’s out!”
/ (?<quote>['"]) # an opening quote (?<static>.*?) # with anything inside, captured as STATIC \k<quote> # and a matching closing quote /x
-
VARIABLE_OR_METHOD_CHAIN =
Any kind of variable name. e.g. @instance, @@class, $global or local. Possibly following a method call chain
/ (?:\$|@{1,2})? # optional global, instance or class variable indicator (?:#{IDENTIFIER}\.)* # followed by an optional chain of zero-argument method calls (?<dynamic>#{IDENTIFIER}) # and a final valid identifier, captured as DYNAMIC /x
Class Attribute Summary
- .supports_view_paths? ⇒ Boolean readonly
Class Method Summary
Instance Attribute Summary
Instance Method Summary
- #dependencies
- #add_dependencies(render_dependencies, arguments, pattern) private
- #add_dynamic_dependency(dependencies, dependency) private
- #add_static_dependency(dependencies, dependency, quote_type) private
- #directory private
- #explicit_dependencies private
- #render_dependencies private
- #source private
Constructor Details
.new(name, template, view_paths = nil) ⇒ ERBTracker
Class Attribute Details
.supports_view_paths? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'actionview/lib/action_view/dependency_tracker/erb_tracker.rb', line 64
def self.supports_view_paths? # :nodoc: true end
Class Method Details
.call(name, template, view_paths = nil)
[ GitHub ]Instance Attribute Details
#name (readonly, private)
[ GitHub ]# File 'actionview/lib/action_view/dependency_tracker/erb_tracker.rb', line 80
attr_reader :name, :template
#template (readonly, private)
[ GitHub ]# File 'actionview/lib/action_view/dependency_tracker/erb_tracker.rb', line 80
attr_reader :name, :template
Instance Method Details
#add_dependencies(render_dependencies, arguments, pattern) (private)
[ GitHub ]# File 'actionview/lib/action_view/dependency_tracker/erb_tracker.rb', line 104
def add_dependencies(render_dependencies, arguments, pattern) arguments.scan(pattern) do match = Regexp.last_match add_dynamic_dependency(render_dependencies, match[:dynamic]) add_static_dependency(render_dependencies, match[:static], match[:quote]) end end
#add_dynamic_dependency(dependencies, dependency) (private)
[ GitHub ]# File 'actionview/lib/action_view/dependency_tracker/erb_tracker.rb', line 112
def add_dynamic_dependency(dependencies, dependency) if dependency dependencies << "#{dependency.pluralize}/#{dependency.singularize}" end end
#add_static_dependency(dependencies, dependency, quote_type) (private)
[ GitHub ]# File 'actionview/lib/action_view/dependency_tracker/erb_tracker.rb', line 118
def add_static_dependency(dependencies, dependency, quote_type) if quote_type == '"' && dependency.include?('#{') scanner = StringScanner.new(dependency) wildcard_dependency = +"" while !scanner.eos? if scanner.scan_until(/\#{/) unmatched_brackets = 1 wildcard_dependency << scanner.pre_match while unmatched_brackets > 0 && !scanner.eos? found = scanner.scan_until(/[{}]/) return unless found case scanner.matched when "{" unmatched_brackets += 1 when "}" unmatched_brackets -= 1 end end wildcard_dependency << "*" else wildcard_dependency << scanner.rest scanner.terminate end end dependencies << wildcard_dependency elsif dependency if dependency.include?("/") dependencies << dependency else dependencies << "#{directory}/#{dependency}" end end end
#dependencies
[ GitHub ]# File 'actionview/lib/action_view/dependency_tracker/erb_tracker.rb', line 76
def dependencies WildcardResolver.new(@view_paths, render_dependencies + explicit_dependencies).resolve end
#directory (private)
[ GitHub ]# File 'actionview/lib/action_view/dependency_tracker/erb_tracker.rb', line 88
def directory name.split("/")[0..-2].join("/") end
#explicit_dependencies (private)
[ GitHub ]# File 'actionview/lib/action_view/dependency_tracker/erb_tracker.rb', line 158
def explicit_dependencies source.scan(EXPLICIT_DEPENDENCY).flatten.uniq end
#render_dependencies (private)
[ GitHub ]# File 'actionview/lib/action_view/dependency_tracker/erb_tracker.rb', line 92
def render_dependencies dependencies = [] render_calls = source.split(/\brender\b/).drop(1) render_calls.each do |arguments| add_dependencies(dependencies, arguments, LAYOUT_DEPENDENCY) add_dependencies(dependencies, arguments, RENDER_ARGUMENTS) end dependencies end
#source (private)
[ GitHub ]# File 'actionview/lib/action_view/dependency_tracker/erb_tracker.rb', line 84
def source template.source end