Permalink
Browse files

code style

  • Loading branch information...
1 parent 5024c1f commit 56e56259e8cee276d3e67efcb89ea9275c949dee @akzhan akzhan committed May 14, 2011
Showing with 16 additions and 22 deletions.
  1. +5 −3 lib/premailer.rb
  2. +11 −19 lib/premailer/premailer.rb
View
@@ -3,6 +3,8 @@
require 'digest/md5'
require 'cgi'
require 'css_parser'
-require File.expand_path(File.dirname(__FILE__) + '/premailer/adapter')
-require File.expand_path(File.dirname(__FILE__) + '/premailer/html_to_plain_text')
-require File.expand_path(File.dirname(__FILE__) + '/premailer/premailer')
+
+require 'premailer/adapter'
+require 'premailer/html_to_plain_text'
+require 'premailer/premailer'
+
@@ -1,5 +1,3 @@
-#!/usr/bin/ruby
-#
# Premailer by Alex Dunae (dunae.ca, e-mail 'code' at the same domain), 2008-10
#
# Premailer processes HTML and CSS to improve e-mail deliverability.
@@ -239,9 +237,9 @@ def local_uri?(uri) # :nodoc:
def media_type_ok?(media_types) # :nodoc:
return true if media_types.nil? or media_types.empty?
- return media_types.split(/[\s]+|,/).any? { |media_type| media_type.strip =~ /screen|handheld|all/i }
+ media_types.split(/[\s]+|,/).any? { |media_type| media_type.strip =~ /screen|handheld|all/i }
rescue
- return true
+ true
end
def append_query_string(doc, qs)
@@ -295,8 +293,7 @@ def append_query_string(doc, qs)
# Check for an XHTML doctype
def is_xhtml?
intro = @doc.to_html.strip.split("\n")[0..2].join(' ')
- is_xhtml = (intro =~ /w3c\/\/[\s]*dtd[\s]+xhtml/i)
- is_xhtml = is_xhtml ? true : false
+ is_xhtml = !!(intro =~ /w3c\/\/[\s]*dtd[\s]+xhtml/i)
$stderr.puts "Is XHTML? #{is_xhtml.inspect}\nChecked:\n#{intro}" if @options[:debug]
is_xhtml
end
@@ -362,31 +359,26 @@ def self.resolve_link(path, base_path) # :nodoc:
resolved = nil
if path =~ /(http[s]?|ftp):\/\//i
resolved = path
- return Premailer.canonicalize(resolved)
+ Premailer.canonicalize(resolved)
elsif base_path.kind_of?(URI)
resolved = base_path.merge(path)
- return Premailer.canonicalize(resolved)
+ Premailer.canonicalize(resolved)
elsif base_path.kind_of?(String) and base_path =~ /^(http[s]?|ftp):\/\//i
resolved = URI.parse(base_path)
resolved = resolved.merge(path)
- return Premailer.canonicalize(resolved)
+ Premailer.canonicalize(resolved)
else
-
- return File.expand_path(path, File.dirname(base_path))
+ File.expand_path(path, File.dirname(base_path))
end
end
# Test the passed variable to see if we are in local or remote mode.
#
# IO objects return true, as do strings that look like URLs.
def self.local_data?(data)
- if data.is_a?(IO) || data.is_a?(StringIO)
- return true
- elsif data =~ /^(http|https|ftp)\:\/\//i
- return false
- else
- return true
- end
+ return true if data.is_a?(IO) || data.is_a?(StringIO)
+ return false if data =~ /^(http|https|ftp)\:\/\//i
+ true
end
# from http://www.ruby-forum.com/topic/140101
@@ -404,7 +396,7 @@ def self.canonicalize(uri) # :nodoc:
# Check <tt>CLIENT_SUPPORT_FILE</tt> for any CSS warnings
def check_client_support # :nodoc:
- @client_support = @client_support ||= YAML::load(File.open(CLIENT_SUPPORT_FILE))
+ @client_support ||= YAML::load(File.open(CLIENT_SUPPORT_FILE))
warnings = []
properties = []

0 comments on commit 56e5625

Please sign in to comment.