inline_styles_mailer 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +4 -0
- data/.rspec +1 -0
- data/.rvmrc +2 -0
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/README.md +53 -0
- data/Rakefile +6 -0
- data/inline_styles_mailer.gemspec +26 -0
- data/lib/inline_styles_mailer/version.rb +3 -0
- data/lib/inline_styles_mailer.rb +70 -0
- data/spec/fixtures/assets/stylesheets/_foo_mailer.css.scss +6 -0
- data/spec/fixtures/layout.html.erb +4 -0
- data/spec/fixtures/views/foo_mailer/foo.html +1 -0
- data/spec/fixtures/views/layouts/mailer.html.erb +6 -0
- data/spec/foo_mailer.rb +10 -0
- data/spec/inline_styles_mailer/inline_styles_mailer_spec.rb +15 -0
- data/spec/spec_helper.rb +7 -0
- metadata +119 -0
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.rvmrc
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Bill Horsman
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
## Inline Styles Mailer
|
2
|
+
|
3
|
+
Using Jack Danger's excellent [Inline Styles](https://github.com/jackdanger/inline_styles) gem is even easier if you're using Rails 3.1 too.
|
4
|
+
|
5
|
+
The Inline Styles gem helps you embed CSS styles into your markup so that you can send pretty HTML emails that won't get butchered by email clients that strip out CSS. Or, more precisely, will help reduce the amount of butchering (even with inline CSS some styles, like background images, are often cut out).
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
If you're using bundler:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'inline_styles_mailer'
|
13
|
+
```
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
If you follow some conventions, then it's just one line:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
class FooMailer < ActionMailer::Base
|
21
|
+
include InlineStylesMailer
|
22
|
+
|
23
|
+
def foo(email)
|
24
|
+
mail(:to => email, :subject => "Foo foo!")
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
```
|
29
|
+
|
30
|
+
If you have a CSS file <code>app/assets/stylesheets/_foo.css.scss</code> then it will get automatically applied to the mail using the inline_styles gem. That name (<code>_foo.css.scss</code>) is based on the mailer class name.
|
31
|
+
|
32
|
+
Want to use a different file?
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
class FooMailer < ActionMailer::Base
|
36
|
+
include InlineStylesMailer
|
37
|
+
use_stylesheet '_bar'
|
38
|
+
|
39
|
+
|
40
|
+
def foo(email)
|
41
|
+
mail(:to => email, :subject => "Foo foo!")
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
```
|
46
|
+
|
47
|
+
The location of that file, and the fact that it uses [SASS](http://sass-lang.com/) is fixed at this time.
|
48
|
+
|
49
|
+
## Development
|
50
|
+
|
51
|
+
Questions or problems? Please post them on the [issue tracker](https://github.com/billhorsman/inline_styles_mailer/issues). You can contribute changes by forking the project and submitting a pull request. You can ensure the tests passing by running `bundle` and `rake`.
|
52
|
+
|
53
|
+
This gem was created by Bill Horsman and is under the MIT License.
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "inline_styles_mailer/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "inline_styles_mailer"
|
7
|
+
s.version = InlineStylesMailer::VERSION
|
8
|
+
s.authors = ["Bill Horsman"]
|
9
|
+
s.email = ["bill@logicalcobwebs.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{Convenient use of inline_styles gem with Rails 3.1}
|
12
|
+
s.description = %q{Convenient use of inline_styles gem with Rails 3.1}
|
13
|
+
|
14
|
+
s.rubyforge_project = "inline_styles_mailer"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
s.add_development_dependency "rspec"
|
23
|
+
s.add_runtime_dependency "inline_styles"
|
24
|
+
s.add_runtime_dependency "rails", "~> 3.1"
|
25
|
+
s.add_runtime_dependency "sass-rails"
|
26
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require "inline_styles"
|
2
|
+
require "inline_styles_mailer/version"
|
3
|
+
require "sass"
|
4
|
+
|
5
|
+
module InlineStylesMailer
|
6
|
+
|
7
|
+
def self.included(base)
|
8
|
+
base.extend(ClassMethods)
|
9
|
+
end
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
|
13
|
+
def use_stylesheet(*stylesheets)
|
14
|
+
@stylesheets = Array(stylesheets)
|
15
|
+
end
|
16
|
+
|
17
|
+
def locate_css_file(stylesheet)
|
18
|
+
Rails.root.join("app", "assets", "stylesheets", "#{stylesheet}.css.scss")
|
19
|
+
end
|
20
|
+
|
21
|
+
def locate_template(name)
|
22
|
+
"#{self.name.underscore}/#{name}.html"
|
23
|
+
end
|
24
|
+
|
25
|
+
def css_content
|
26
|
+
puts "#{`pwd`}"
|
27
|
+
@stylesheets ||= ["_#{self.name.underscore}"]
|
28
|
+
@css_content ||= @stylesheets.map {|stylesheet|
|
29
|
+
file = locate_css_file(stylesheet)
|
30
|
+
if File.exist?(file)
|
31
|
+
puts "Processing #{file}"
|
32
|
+
Sass::Engine.new(File.read(file), syntax: :scss).render
|
33
|
+
else
|
34
|
+
puts "Skipping #{file}"
|
35
|
+
nil
|
36
|
+
end
|
37
|
+
}.compact.join
|
38
|
+
end
|
39
|
+
|
40
|
+
def locate_layout
|
41
|
+
"mailer"
|
42
|
+
end
|
43
|
+
|
44
|
+
def page
|
45
|
+
@page ||= InlineStyles::Page.new.with_css(css_content)
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
def mail(options, &block)
|
51
|
+
if block
|
52
|
+
super(mail, &block) # We'll just let this pass through
|
53
|
+
else
|
54
|
+
super(options) do |format|
|
55
|
+
# Only format for text if an appropriate template exists
|
56
|
+
# TODO we should be finding this file using Rails
|
57
|
+
unless Dir[Rails.root.join('app', 'views', self.class.name.underscore, "#{action_name}.text.*")].empty?
|
58
|
+
format.text do
|
59
|
+
render
|
60
|
+
end
|
61
|
+
end
|
62
|
+
format.html do
|
63
|
+
html = render_to_string :file => self.class.locate_template(action_name), :layout => self.class.locate_layout
|
64
|
+
render :text => self.class.page.with_html(html).apply
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
<p>Testing foo.</p>
|
data/spec/foo_mailer.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'foo_mailer'
|
3
|
+
require 'rails/all'
|
4
|
+
|
5
|
+
describe InlineStylesMailer do
|
6
|
+
|
7
|
+
it "should instantiate FooMailer" do
|
8
|
+
FooMailer.should_receive(:locate_css_file).and_return(File.join("spec", "fixtures", "assets", "stylesheets", "_foo_mailer.css.scss"))
|
9
|
+
Rails.should_receive(:root).any_number_of_times.and_return(Pathname.new(File.join("spec", "fixtures")))
|
10
|
+
mail = FooMailer.foo
|
11
|
+
mail.body.should =~ /<p style="color: red;">Testing foo\.<\/p>/
|
12
|
+
mail.body.should =~ /<body style="background: yellow;">/
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
require 'inline_styles_mailer'
|
2
|
+
require 'rails/all'
|
3
|
+
|
4
|
+
ActionMailer::Base.delivery_method = :test
|
5
|
+
ActionMailer::Base.prepend_view_path File.join(File.dirname(__FILE__), "fixtures", "views")
|
6
|
+
|
7
|
+
Dir["#{File.dirname(__FILE__)}/fixtures/mailers/*.rb"].each { |f| require f }
|
metadata
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: inline_styles_mailer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Bill Horsman
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-12-06 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &70169775483020 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70169775483020
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: inline_styles
|
27
|
+
requirement: &70169775481920 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70169775481920
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rails
|
38
|
+
requirement: &70169775480420 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '3.1'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70169775480420
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: sass-rails
|
49
|
+
requirement: &70169775479080 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70169775479080
|
58
|
+
description: Convenient use of inline_styles gem with Rails 3.1
|
59
|
+
email:
|
60
|
+
- bill@logicalcobwebs.com
|
61
|
+
executables: []
|
62
|
+
extensions: []
|
63
|
+
extra_rdoc_files: []
|
64
|
+
files:
|
65
|
+
- .gitignore
|
66
|
+
- .rspec
|
67
|
+
- .rvmrc
|
68
|
+
- Gemfile
|
69
|
+
- LICENSE
|
70
|
+
- README.md
|
71
|
+
- Rakefile
|
72
|
+
- inline_styles_mailer.gemspec
|
73
|
+
- lib/inline_styles_mailer.rb
|
74
|
+
- lib/inline_styles_mailer/version.rb
|
75
|
+
- spec/fixtures/assets/stylesheets/_foo_mailer.css.scss
|
76
|
+
- spec/fixtures/layout.html.erb
|
77
|
+
- spec/fixtures/views/foo_mailer/foo.html
|
78
|
+
- spec/fixtures/views/layouts/mailer.html.erb
|
79
|
+
- spec/foo_mailer.rb
|
80
|
+
- spec/inline_styles_mailer/inline_styles_mailer_spec.rb
|
81
|
+
- spec/spec_helper.rb
|
82
|
+
homepage: ''
|
83
|
+
licenses: []
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
segments:
|
95
|
+
- 0
|
96
|
+
hash: 1152225782059017698
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ! '>='
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
segments:
|
104
|
+
- 0
|
105
|
+
hash: 1152225782059017698
|
106
|
+
requirements: []
|
107
|
+
rubyforge_project: inline_styles_mailer
|
108
|
+
rubygems_version: 1.8.10
|
109
|
+
signing_key:
|
110
|
+
specification_version: 3
|
111
|
+
summary: Convenient use of inline_styles gem with Rails 3.1
|
112
|
+
test_files:
|
113
|
+
- spec/fixtures/assets/stylesheets/_foo_mailer.css.scss
|
114
|
+
- spec/fixtures/layout.html.erb
|
115
|
+
- spec/fixtures/views/foo_mailer/foo.html
|
116
|
+
- spec/fixtures/views/layouts/mailer.html.erb
|
117
|
+
- spec/foo_mailer.rb
|
118
|
+
- spec/inline_styles_mailer/inline_styles_mailer_spec.rb
|
119
|
+
- spec/spec_helper.rb
|