Skip to content

Commit

Permalink
Simplify load_html
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdunae committed Nov 4, 2010
1 parent d8c34b4 commit 7e41c75
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions lib/premailer/premailer.rb
Expand Up @@ -263,23 +263,20 @@ def to_inline_css
# Load the HTML file and convert it into an Nokogiri document.
#
# Returns an Nokogiri document.
def load_html(path) # :nodoc:
if @options[:with_html_string]
Nokogiri::HTML(path, nil, nil, nil)
elsif @options[:inline]
Nokogiri::HTML(path)
def load_html(input) # :nodoc:
thing = nil

# TODO: duplicate options
if @options[:with_html_string] or @options[:inline] or input.respond_to?(:read)
thing = input
elsif @is_local_file
@base_dir = File.dirname(input)
thing = File.open(input, 'r')
else
if @is_local_file
if path.is_a?(IO) || path.is_a?(StringIO)
Nokogiri::HTML(path.read)
else
@base_dir = File.dirname(path)
Nokogiri::HTML(File.open(path, "r") {|f| f.read })
end
else
Nokogiri::HTML(open(path))
end
thing = open(input)
end

thing ? Nokogiri::HTML(thing) : nil
end

def load_css_from_local_file!(path)
Expand Down

0 comments on commit 7e41c75

Please sign in to comment.