Class: Emcee::Processors::HtmlProcessor
- Inherits:
-
Sprockets::DirectiveProcessor
- Object
- Sprockets::DirectiveProcessor
- Emcee::Processors::HtmlProcessor
- Includes:
- Includes
- Defined in:
- lib/emcee/processors/html_processor.rb
Overview
HtmlProcessor processes html files by doing 4 things:
-
Stripping out asset pipeline directives and processing the associated files.
-
Stripping out html imports and processing those files.
-
Stripping out external stylesheet includes, and inlining those sheets where they were called.
-
Stripping out external script tags, and inlining those scripts where they were called.
It inherits from Sprocket::DirectiveProcessor, which does most of the work for us.
Constant Summary collapse
- HEADER_PATTERN =
Matches the entire header/directive block. This is everything from the top of the file, enclosed in html comments.
A matches the beginning of the string (?m:s*) matches whitespace, including n (<!–(?m:.*?)–>) matches html comments and their content
/\A((?m:\s*)(<!--(?m:.*?)-->))+/- DIRECTIVE_PATTERN =
Matches the an asset pipeline directive.
*= require_tree .
^ matches the beginning of the line W* matches any non-word character, zero or more times
matches =, obviously
s* matches any whitespace character, zero or more times (w+.*?) matches a group of characters, starting with a letter or number $ matches the end of the line
/^\W*=\s*(\w+.*?)$/
Constants included from Includes
Includes::HREF_PATH_PATTERN, Includes::IMPORT_PATTERN, Includes::SCRIPT_PATTERN, Includes::SRC_PATH_PATTERN, Includes::STYLESHEET_PATTERN
Instance Method Summary collapse
-
#render(context, locals) ⇒ Object
Render takes the actual text of the file and does our processing to it.
Methods included from Includes
#process_imports, #process_scripts, #process_stylesheets, #read_file
Instance Method Details
#render(context, locals) ⇒ Object
Render takes the actual text of the file and does our processing to it. This is based on the standard render method on Sprockets’s DirectiveProcessor.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/emcee/processors/html_processor.rb', line 53 def render(context, locals) @context = context @pathname = context.pathname @directory = File.dirname(@pathname) @header = data[HEADER_PATTERN, 0] || "" @body = $' || data # Ensure body ends in a new line @body += "\n" if @body != "" && @body !~ /\n\Z/m @included_pathnames = [] @result = "" @result.force_encoding(body.encoding) @has_written_body = false process_directives @body = process_imports(@body, @context, @directory) @body = process_stylesheets(@body, @directory) @body = process_scripts(@body, @directory) process_source @result end |