Skip to content

Commit

Permalink
Merge pull request #8 from zurb/develop
Browse files Browse the repository at this point in the history
Install Generator
  • Loading branch information
zokioki authored Jul 4, 2016
2 parents 2e3a7d6 + 943dff3 commit 9e0dd7f
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 43 deletions.
16 changes: 8 additions & 8 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
PATH
remote: .
specs:
inky-rb (0.0.3)
inky-rb (1.3.6.1)
foundation_emails (~> 2)

GEM
remote: https://rubygems.org/
specs:
diff-lcs (1.2.5)
foundation_emails (2.1.0.1)
foundation_emails (2.2.0.0)
rake (11.2.2)
rspec-core (3.4.4)
rspec-support (~> 3.4.0)
rspec-expectations (3.4.0)
rspec-core (3.5.0)
rspec-support (~> 3.5.0)
rspec-expectations (3.5.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.4.0)
rspec-support (3.4.1)
rspec-support (~> 3.5.0)
rspec-support (3.5.0)

PLATFORMS
ruby
Expand All @@ -28,4 +28,4 @@ DEPENDENCIES
rspec-expectations

BUNDLED WITH
1.12.4
1.11.2
43 changes: 9 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# Inky

[![Gem Version](https://badge.fury.io/rb/inky-rb.svg)](https://badge.fury.io/rb/inky-rb)

Inky is an HTML-based templating language that converts simple HTML into complex, responsive email-ready HTML. Designed for [Foundation for Emails](http://foundation.zurb.com/emails), a responsive email framework from [ZURB](http://zurb.com).

To include only the Foundation for Emails styles in your Asset Pipeline, without Inky, use the [**foundation_emails**](https://github.com/zurb/foundation-emails/#using-the-ruby-gem) gem.

Give Inky simple HTML like this:

```html
Expand Down Expand Up @@ -52,50 +56,21 @@ Then execute:
bundle install
```

Make sure that the stylesheet included in your email layout imports the Foundation for Emails styles:

```scss
// app/assets/stylesheets/your_emails_stylesheet.scss
Run the following command to set up the required styles and mailer layout:

@import "foundation-emails";
```bash
rails g inky:install
```

(You can specify the generated mailer layout filename like so: `rails g inky:install some_name`)

Rename your email templates to use the `.inky` file extension. Note that you'll still be able to use ERB within the `.inky` templates:

```
welcome.html => welcome.html.inky
pw_reset.html.erb => pw_reset.html.inky
```

Ensure your mailer layout has the following structure:

```html
<!-- app/views/layouts/your_mailer_layout.html.erb -->

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- Enables media queries -->
<meta name="viewport" content="width=device-width"/>
<!-- Link to the email's CSS, which will be inlined into the email -->
<link rel="stylesheet" href="assets/css/foundation-emails.css">
</head>

<body>
<table class="body" data-made-with-foundation>
<tr>
<td class="center" align="center" valign="top">
<center>
<%= yield %>
</center>
</td>
</tr>
</table>
</body>
</html>
```

You're all set!

** The majority of email clients ignore linked stylesheets. By using a CSS inliner like `premailer-rails` or `roadie`, you're able to leave your stylesheets in a separate file, keeping your markup lean.
Expand Down
37 changes: 37 additions & 0 deletions lib/generators/inky/install_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
require 'rails/generators'

module Inky
module Generators
class InstallGenerator < ::Rails::Generators::Base
desc 'Install Foundation for Emails'
source_root File.join(File.dirname(__FILE__), 'templates')
argument :layout_name, :type => :string, :default => 'mailer', :banner => 'layout_name'

def preserve_original_mailer_layout
return nil unless layout_name == 'mailer'

original_mailer = File.join(layouts_base_dir, 'mailer.html.erb')
rename_filename = File.join(layouts_base_dir, "old_mailer_#{Time.now.to_i}.html.erb")
File.rename(original_mailer, rename_filename) if File.exists? original_mailer
end

def create_mailer_stylesheet
template 'foundation_emails.scss', File.join(stylesheets_base_dir, 'foundation_emails.scss')
end

def create_mailer_layout
template 'mailer_layout.html.erb', File.join(layouts_base_dir, "#{layout_name.underscore}.html.erb")
end

private

def stylesheets_base_dir
File.join('app', 'assets', 'stylesheets')
end

def layouts_base_dir
File.join('app', 'views', 'layouts')
end
end
end
end
1 change: 1 addition & 0 deletions lib/generators/inky/templates/foundation_emails.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import "foundation-emails";
21 changes: 21 additions & 0 deletions lib/generators/inky/templates/mailer_layout.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width" />

<%%= stylesheet_link_tag "foundation_emails" %>
</head>

<body>
<table class="body" data-made-with-foundation>
<tr>
<td class="center" align="center" valign="top">
<center>
<%%= yield %>
</center>
</td>
</tr>
</table>
</body>
</html>
2 changes: 1 addition & 1 deletion lib/inky/rails/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Inky
module Rails
VERSION = "1.3.6.0"
VERSION = "1.3.6.1"
end
end

0 comments on commit 9e0dd7f

Please sign in to comment.