Class: Getinline::Transformer
- Inherits:
-
Object
- Object
- Getinline::Transformer
- Defined in:
- lib/getinline/transformer.rb
Instance Method Summary collapse
-
#initialize(raw_text, options = {}, premailer_options = {}) ⇒ Transformer
constructor
A new instance of Transformer.
- #transform ⇒ Object
Constructor Details
#initialize(raw_text, options = {}, premailer_options = {}) ⇒ Transformer
Returns a new instance of Transformer.
9 10 11 12 13 |
# File 'lib/getinline/transformer.rb', line 9 def initialize(raw_text, = {}, = {}) @raw_text = raw_text @options = @premailer_options = end |
Instance Method Details
#transform ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/getinline/transformer.rb', line 15 def transform matches = @raw_text.scan(/<%.+?%>/) tokenized_text = @raw_text.dup matches.each do |match| tokenized_text.sub!(match, TOKEN) end File.write(TOKENIZED_ERB_FILE_NAME, tokenized_text) @premailer = Premailer.new(TOKENIZED_ERB_FILE_NAME, @premailer_options) premailed_tokenized_text = @options[:mode] == :txt ? @premailer.to_plain_text : Nokogiri::HTML(@premailer.to_inline_css).to_html(encoding:'US-ASCII') premailed_text = premailed_tokenized_text.dup matches.each do |match| premailed_text.sub!(TOKEN, match) end premailed_text end |