class Emcee::Processors::ScriptProcessor
ScriptProcessor
scans a document for external script references and inlines them into the current document.
Public Class Methods
new(resolver)
click to toggle source
# File lib/emcee/processors/script_processor.rb, line 6 def initialize(resolver) @resolver = resolver end
Public Instance Methods
process(doc)
click to toggle source
# File lib/emcee/processors/script_processor.rb, line 10 def process(doc) inline_scripts(doc) doc end
Private Instance Methods
escape_with_slash(script)
click to toggle source
# File lib/emcee/processors/script_processor.rb, line 27 def escape_with_slash(script) script = script.sub('<!--', '<!\\--') script.gsub!(/<\/\s*script/i) do |match| match.sub '</', '<\\/' end script end
inline_scripts(doc)
click to toggle source
# File lib/emcee/processors/script_processor.rb, line 17 def inline_scripts(doc) doc.script_references.each do |node| path = @resolver.absolute_path(node.path) return unless @resolver.should_inline?(path) script = @resolver.evaluate(path) node.replace("script", escape_with_slash(script)) @resolver.depend_on_asset(path) end end