Class: ActionView::DependencyTracker::ERBTracker

Inherits:
Object
  • Object
show all
Defined in:
lib/action_view/dependency_tracker.rb

Overview

:nodoc:

Constant Summary collapse

EXPLICIT_DEPENDENCY =
/# 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
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
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
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
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
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"
(message.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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, template) ⇒ ERBTracker

Returns a new instance of ERBTracker.


83
84
85
# File 'lib/action_view/dependency_tracker.rb', line 83

def initialize(name, template)
  @name, @template = name, template
end

Class Method Details

.call(name, template) ⇒ Object


79
80
81
# File 'lib/action_view/dependency_tracker.rb', line 79

def self.call(name, template)
  new(name, template).dependencies
end

Instance Method Details

#dependenciesObject


87
88
89
# File 'lib/action_view/dependency_tracker.rb', line 87

def dependencies
  render_dependencies + explicit_dependencies
end