module Premailer::Rails::CSSHelper
Constants
- FileNotFound
- STRATEGIES
Public Instance Methods
css_for_doc(doc)
click to toggle source
Returns all linked CSS files concatenated as string.
# File lib/premailer/rails/css_helper.rb, line 16 def css_for_doc(doc) css_urls_in_doc(doc).map { |url| css_for_url(url) }.join("\n") end
css_for_url(url)
click to toggle source
# File lib/premailer/rails/css_helper.rb, line 20 def css_for_url(url) load_css(url).tap do |content| CSSLoaders::CacheLoader.store(url, content) end end
Private Instance Methods
css_urls_in_doc(doc)
click to toggle source
# File lib/premailer/rails/css_helper.rb, line 28 def css_urls_in_doc(doc) doc.search('link[@rel="stylesheet"]:not([@data-premailer="ignore"])').map do |link| if link.respond_to?(:remove) link.remove else link.parent.children.delete(link) end link.attributes['href'].to_s end end
load_css(url)
click to toggle source
# File lib/premailer/rails/css_helper.rb, line 39 def load_css(url) STRATEGIES.each do |strategy| css = strategy.load(url) return css.force_encoding('UTF-8') if css end raise FileNotFound, %Q{File with URL "#{url}" could not be loaded by any strategy.} end