Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Ruby code style #60

Merged
merged 2 commits into from

2 participants

@akzhan
Owner

Code polished.

@alexdunae alexdunae merged commit d8bda95 into premailer:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 14, 2011
  1. @akzhan

    code style

    akzhan authored
  2. @akzhan

    code style

    akzhan authored
This page is out of date. Refresh to see the latest.
Showing with 17 additions and 23 deletions.
  1. +5 −3 lib/premailer.rb
  2. +12 −20 lib/premailer/premailer.rb
View
8 lib/premailer.rb
@@ -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'
+
View
32 lib/premailer/premailer.rb
@@ -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.
@@ -207,7 +205,7 @@ def load_css_from_options! # :nodoc:
def load_css_from_html! # :nodoc:
if tags = @doc.search("link[@rel='stylesheet'], style")
tags.each do |tag|
- if tag.to_s.strip =~ /^\<link/i and tag.attributes['href'] and media_type_ok?(tag.attributes['media'])
+ if tag.to_s.strip =~ /^\<link/i && tag.attributes['href'] && media_type_ok?(tag.attributes['media'])
link_uri = Premailer.resolve_link(tag.attributes['href'].to_s, @html_file)
if Premailer.local_data?(link_uri)
@@ -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,17 +359,16 @@ 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
@@ -380,13 +376,9 @@ def self.resolve_link(path, base_path) # :nodoc:
#
# 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 = []
Something went wrong with that request. Please try again.