命名空间
- 类 ActionView::Digestor::Injected
- 类 ActionView::Digestor::Missing
- 类 ActionView::Digestor::Node
- 类 ActionView::Digestor::NullLogger
- 类 ActionView::Digestor::Partial
方法
类公共方法
digest(name:, format: nil, finder:, dependencies: nil) 链接
支持的选项
-
name
-Template
名称 -
format
-Template
格式 -
finder
-ActionView::LookupContext
的实例 -
dependencies
- 依赖视图的数组
来源: 显示 | 在 GitHub 上
# File actionview/lib/action_view/digestor.rb, line 16 def digest(name:, format: nil, finder:, dependencies: nil) if dependencies.nil? || dependencies.empty? cache_key = "#{name}.#{format}" else dependencies_suffix = dependencies.flatten.tap(&:compact!).join(".") cache_key = "#{name}.#{format}.#{dependencies_suffix}" end # this is a correctly done double-checked locking idiom # (Concurrent::Map's lookups have volatile semantics) finder.digest_cache[cache_key] || @@digest_mutex.synchronize do finder.digest_cache.fetch(cache_key) do # re-check under lock path = TemplatePath.parse(name) root = tree(path.to_s, finder, path.partial?) dependencies.each do |injected_dep| root.children << Injected.new(injected_dep, nil, nil) end if dependencies finder.digest_cache[cache_key] = root.digest(finder) end end end
logger() 链接
来源: 显示 | 在 GitHub 上
# File actionview/lib/action_view/digestor.rb, line 38 def logger ActionView::Base.logger || NullLogger end
tree(name, finder, partial = false, seen = {}) 链接
为名为name
的模板创建依赖树。
来源: 显示 | 在 GitHub 上
# File actionview/lib/action_view/digestor.rb, line 43 def tree(name, finder, partial = false, seen = {}) logical_name = name.gsub(%r|/_|, "/") interpolated = name.include?("#") path = TemplatePath.parse(name) if !interpolated && (template = find_template(finder, path.name, [path.prefix], partial, [])) if node = seen[template.identifier] # handle cycles in the tree node else node = seen[template.identifier] = Node.create(name, logical_name, template, partial) deps = DependencyTracker.find_dependencies(name, template, finder.view_paths) deps.uniq { |n| n.gsub(%r|/_|, "/") }.each do |dep_file| node.children << tree(dep_file, finder, true, seen) end node end else unless interpolated # Dynamic template partial names can never be tracked logger.error " Couldn't find template for digesting: #{name}" end seen[name] ||= Missing.new(name, logical_name, nil) end end