module Premailer::Adapter
Manages the adapter classes. Currently supports:
-
nokogiri
-
nokogiri_fast
-
nokogumbo
Constants
- REQUIREMENT_MAP
adapter to required file mapping.
Public Class Methods
default()
click to toggle source
The default adapter based on what you currently have loaded and installed. First checks to see if any adapters are already loaded, then checks to see which are installed if none are loaded. @raise [RuntimeError] unless suitable adapter found.
# File lib/premailer/adapter.rb, line 31 def self.default return :nokogiri if defined?(::Nokogiri) return :nokogiri_fast if defined?(::NokogiriFast) return :nokogumbo if defined?(::Nokogumbo) REQUIREMENT_MAP.each do |(library, adapter)| begin require library return adapter rescue LoadError next end end raise RuntimeError.new("No suitable adapter for Premailer was found, please install nokogiri or nokogumbo") end
find(adapter)
click to toggle source
Returns an adapter. @raise [ArgumentError] unless the adapter exists.
# File lib/premailer/adapter.rb, line 56 def self.find(adapter) return adapter if adapter.is_a?(Module) Premailer::Adapter.const_get("#{adapter.to_s.split('_').map{|s| s.capitalize}.join('')}") rescue NameError raise ArgumentError, "Invalid adapter: #{adapter}" end
use()
click to toggle source
Returns the adapter to use.
# File lib/premailer/adapter.rb, line 21 def self.use return @use if @use self.use = self.default @use end
use=(new_adapter)
click to toggle source
Sets the adapter to use. @raise [ArgumentError] unless the adapter exists.
# File lib/premailer/adapter.rb, line 50 def self.use=(new_adapter) @use = find(new_adapter) end