awesomemailer 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,6 @@
1
+ 0.0.3
2
+ * Added Sprockets-based loading for local files. Now your mailers
3
+ work with local assets written with something other than CSS!
1
4
  0.0.2
2
5
  * Fixed a bug left over from when declarations were split into an
3
6
  array
data/README.md CHANGED
@@ -40,7 +40,7 @@ Suppose you have the following mailer:
40
40
  </body>
41
41
  </html>
42
42
 
43
- ... and your spreadsheet (email.css) might be kinda like this:
43
+ ... and your style sheet (email.css) might be kinda like this:
44
44
 
45
45
  body {
46
46
  background: #f0f0f0;
@@ -71,7 +71,7 @@ Suppose you have the following mailer:
71
71
  }
72
72
 
73
73
  ... you might be unhappy because most mail viewers couldn't care less that you included a stylesheet. But wait!
74
- There's ActionMailer! Just change your mailer to look like this:
74
+ There's AwesomeMailer! Just change your mailer to look like this:
75
75
 
76
76
  class UserMailer < AwesomeMailer::Base
77
77
 
@@ -122,4 +122,4 @@ AwesomeMailer is copyright (c) 2011 Delightful Widgets Inc.
122
122
 
123
123
  It was built by Flip Sasser (flip@x451.com) using libraries from Alex Dunae
124
124
  ([https://github.com/alexdunae/css_parser](https://github.com/alexdunae/css_parser)) and, as far as I know, Nick Sieger
125
- ([https://github.com/hpricot/hpricot](https://github.com/hpricot/hpricot)). Those guys are AWESOME. Be their friends.
125
+ ([https://github.com/hpricot/hpricot](https://github.com/hpricot/hpricot)). Those guys are AWESOME. Be their friends.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "awesomemailer"
8
- s.version = "0.0.2"
8
+ s.version = "0.0.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Flip Sasser"]
12
- s.date = "2012-01-06"
12
+ s.date = "2012-08-27"
13
13
  s.description = "\n AwesomeMailer embeds your e-mail CSS inline, allowing you to write e-mail templates without worrying too much about stylesheets\n "
14
14
  s.email = "flip@x451.com"
15
15
  s.extra_rdoc_files = [
@@ -22,7 +22,6 @@ Gem::Specification.new do |s|
22
22
  "README.md",
23
23
  "Rakefile",
24
24
  "VERSION",
25
- "autotest/discover.rb",
26
25
  "awesomemailer.gemspec",
27
26
  "lib/awesome_mailer.rb",
28
27
  "lib/awesome_mailer/base.rb",
@@ -35,7 +34,7 @@ Gem::Specification.new do |s|
35
34
  ]
36
35
  s.homepage = "http://github.com/Plinq/awesome_mailer"
37
36
  s.require_paths = ["lib"]
38
- s.rubygems_version = "1.8.10"
37
+ s.rubygems_version = "1.8.24"
39
38
  s.summary = "An ActionMailer extension that embeds CSS inline in e-mails"
40
39
 
41
40
  if s.respond_to? :specification_version then
@@ -1 +1,4 @@
1
1
  require 'awesome_mailer/base'
2
+
3
+ module AwesomeMailer
4
+ end
@@ -6,6 +6,8 @@ require 'css_parser'
6
6
  module AwesomeMailer
7
7
  class Base < ActionMailer::Base
8
8
  abstract!
9
+ include ActionView::Helpers::AssetTagHelper::StylesheetTagHelpers
10
+ include ActionView::Helpers::AssetTagHelper::JavascriptTagHelpers
9
11
 
10
12
  def render(*arguments)
11
13
  html_string = super
@@ -42,14 +44,12 @@ module AwesomeMailer
42
44
  path_url = Addressable::URI.parse(url)
43
45
  path_url.path = File.dirname(path_url.path)
44
46
  declarations.scan(/(url\(?["']+(.[^'"]*)["']\))/i).each do |url_command, item|
45
- next if item =~ /^http(s){0,1}:\/\//
47
+ next if item =~ /^(http(s){0,1}:\/\/|\/)/
46
48
  item_url = path_url.dup
47
49
  item_url.path = File.join(item_url.path, item)
48
50
  new_url_command = url_command.gsub(item, item_url.to_s)
49
51
  declarations[url_command] = new_url_command
50
52
  end
51
- # else
52
- # declarations.reject {|item| item.match(/url\s*\(/) }
53
53
  end
54
54
  if selector =~ /(^@)/
55
55
  append_styles!(document, selector, declarations.to_s) if url
@@ -64,18 +64,35 @@ module AwesomeMailer
64
64
  def apply_stylesheet!(document, stylesheet)
65
65
  css_parser = CssParser::Parser.new
66
66
  clean_href = stylesheet['href'].split('?').shift
67
+ if self.class.default_url_options[:host]
68
+ clean_href.gsub!(/^http:\/\/#{self.class.default_url_options[:host]}/, '')
69
+ end
67
70
  url = nil
68
- case stylesheet['href']
71
+ case clean_href
69
72
  when /^\/assets/
70
- dirname = File.dirname(clean_href).split('/').reject(&:blank?)[1..-1]
71
- css_parser.load_file!(File.join(Rails.root, 'app', 'assets', 'stylesheets', dirname, File.basename(clean_href)))
73
+ if asset = Rails.application.assets[clean_href.gsub(/^\/assets\//, '')]
74
+ css_parser.add_block!(asset.to_s, :media_types => :all)
75
+ else
76
+ dirname = File.dirname(clean_href).split('/').reject(&:blank?)[1..-1]
77
+ local_file = File.join(Rails.root, 'app', 'assets', 'stylesheets', dirname, File.basename(clean_href))
78
+ if File.file?(local_file)
79
+ css_parser.load_file!(local_file)
80
+ end
81
+ end
72
82
  when /^\//
73
83
  css_parser.load_file!(File.join(Rails.root, 'public', clean_href))
84
+ when /^#{self.class.default_url_options[:host]}\/assets/
85
+ raise 'wugh oh'
74
86
  else
87
+ raise stylesheet.inspect
75
88
  css_parser.load_uri!(stylesheet['href'])
76
89
  url = clean_href
77
- end
90
+ end
78
91
  apply_rules!(document, css_parser, url)
79
92
  end
93
+
94
+ def sprockets?
95
+ Rails.application.respond_to?(:assets)
96
+ end
80
97
  end
81
98
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awesomemailer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-06 00:00:00.000000000 Z
12
+ date: 2012-08-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: css_parser
16
- requirement: &70365360837720 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: 1.2.5
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70365360837720
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 1.2.5
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: hpricot
27
- requirement: &70365360837160 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,7 +37,12 @@ dependencies:
32
37
  version: '0.8'
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *70365360837160
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0.8'
36
46
  description: ! "\n AwesomeMailer embeds your e-mail CSS inline, allowing you
37
47
  to write e-mail templates without worrying too much about stylesheets\n "
38
48
  email: flip@x451.com
@@ -47,7 +57,6 @@ files:
47
57
  - README.md
48
58
  - Rakefile
49
59
  - VERSION
50
- - autotest/discover.rb
51
60
  - awesomemailer.gemspec
52
61
  - lib/awesome_mailer.rb
53
62
  - lib/awesome_mailer/base.rb
@@ -69,9 +78,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
69
78
  - - ! '>='
70
79
  - !ruby/object:Gem::Version
71
80
  version: '0'
72
- segments:
73
- - 0
74
- hash: 1107814900927690412
75
81
  required_rubygems_version: !ruby/object:Gem::Requirement
76
82
  none: false
77
83
  requirements:
@@ -80,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
86
  version: '0'
81
87
  requirements: []
82
88
  rubyforge_project:
83
- rubygems_version: 1.8.10
89
+ rubygems_version: 1.8.24
84
90
  signing_key:
85
91
  specification_version: 3
86
92
  summary: An ActionMailer extension that embeds CSS inline in e-mails
data/autotest/discover.rb DELETED
@@ -1,4 +0,0 @@
1
- require 'autotest/fsevent'
2
- require 'autotest/growl'
3
-
4
- Autotest.add_discovery { "rspec2" }