From c5f3043eca3653702db6f4fccb22d3f8e40f5ae7 Mon Sep 17 00:00:00 2001 From: Philipe Fatio Date: Tue, 12 Jun 2012 23:35:23 +0200 Subject: [PATCH] Set user configs before loading HTML Closes #33 --- lib/premailer-rails3.rb | 5 +++++ lib/premailer-rails3/premailer.rb | 7 ++----- spec/premailer-rails3/premailer_spec.rb | 7 +++++++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/premailer-rails3.rb b/lib/premailer-rails3.rb index 61fb9a4..16b3448 100644 --- a/lib/premailer-rails3.rb +++ b/lib/premailer-rails3.rb @@ -4,9 +4,14 @@ require 'premailer-rails3/hook' module PremailerRails + @default_config = { + :with_html_string => true, + :input_encoding => 'UTF-8' + } @config = {} class << self attr_accessor :config + attr_reader :default_config end end diff --git a/lib/premailer-rails3/premailer.rb b/lib/premailer-rails3/premailer.rb index f38afeb..1f24934 100644 --- a/lib/premailer-rails3/premailer.rb +++ b/lib/premailer-rails3/premailer.rb @@ -7,14 +7,11 @@ def initialize(html) # suitable adaptor (Nokogiri or Hpricot). To make load_html work, an # adaptor needs to be included and @options[:with_html_string] needs to be # set. For further information, refer to ::Premailer#initialize. - @options = { :with_html_string => true } + @options = PremailerRails.config.merge(PremailerRails.default_config) ::Premailer.send(:include, Adapter.find(Adapter.use)) doc = load_html(html) - options = PremailerRails.config.merge( - :with_html_string => true, - :css_string => CSSHelper.css_for_doc(doc) - ) + options = @options.merge(:css_string => CSSHelper.css_for_doc(doc)) super(html, options) end end diff --git a/spec/premailer-rails3/premailer_spec.rb b/spec/premailer-rails3/premailer_spec.rb index 6b9a470..a303c87 100644 --- a/spec/premailer-rails3/premailer_spec.rb +++ b/spec/premailer-rails3/premailer_spec.rb @@ -37,5 +37,12 @@ premailer = PremailerRails::Premailer.new('some html') premailer.instance_variable_get(:'@options')[:foo].should == :bar end + + it 'should not allow to override default configs' do + PremailerRails.config = { :input_encoding => 'ASCII-8BIT' } + premailer = PremailerRails::Premailer.new('some html') + options = premailer.instance_variable_get(:'@options') + options[:input_encoding].should == 'UTF-8' + end end end