Class: Roadie::Inliner
- Inherits:
-
Object
- Object
- Roadie::Inliner
- Defined in:
- lib/roadie/inliner.rb
Overview
This class is the core of Roadie as it does all the actual work. You just give it the CSS rules, the HTML and the url_options for rewriting URLs and let it go on doing all the heavy lifting and building.
Constant Summary collapse
- CSS_URL_REGEXP =
Regexp matching all the url() declarations in CSS
It matches without any quotes and with both single and double quotes inside the parenthesis. There’s much room for improvement, of course.
%r{ url\( (["']?) ( [^(]* # Text leading up to before opening parens (?:\([^)]*\))* # Texts containing parens pairs [^(]+ # Texts without parens - required ) \1 # Closing quote \) }x
Instance Method Summary collapse
-
#execute ⇒ String
Start the inlining and return the final HTML output.
-
#initialize(assets, targets, html, url_options) ⇒ Inliner
constructor
Initialize a new Inliner with the given Provider, CSS targets, HTML, and ‘url_options`.
Constructor Details
#initialize(assets, targets, html, url_options) ⇒ Inliner
Initialize a new Inliner with the given Provider, CSS targets, HTML, and ‘url_options`.
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/roadie/inliner.rb', line 30 def initialize(assets, targets, html, ) @assets = assets @css = assets.all(targets) @html = html @inline_css = [] @url_options = if and [:asset_path_prefix] raise ArgumentError, "The asset_path_prefix URL option is not working anymore. You need to add the following configuration to your application.rb:\n" + " config.roadie.provider = AssetPipelineProvider.new(#{[:asset_path_prefix].inspect})\n" + "Note that the prefix \"/assets\" is the default one, so you do not need to configure anything in that case." end end |
Instance Method Details
#execute ⇒ String
Start the inlining and return the final HTML output
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/roadie/inliner.rb', line 46 def execute adjust_html do |document| @document = document add_missing_structure extract_link_elements extract_inline_style_elements inline_css_rules make_image_urls_absolute make_style_urls_absolute @document = nil end end |