Skip to content

Commit

Permalink
Set user configs before loading HTML
Browse files Browse the repository at this point in the history
  • Loading branch information
fphilipe committed Jun 12, 2012
1 parent f610d1b commit c5f3043
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
5 changes: 5 additions & 0 deletions lib/premailer-rails3.rb
Expand Up @@ -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

Expand Down
7 changes: 2 additions & 5 deletions lib/premailer-rails3/premailer.rb
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions spec/premailer-rails3/premailer_spec.rb
Expand Up @@ -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

0 comments on commit c5f3043

Please sign in to comment.