Skip to content

Commit

Permalink
Merge pull request #42 from zurb/generator-fix
Browse files Browse the repository at this point in the history
ERB Template and Generator Fix
  • Loading branch information
zokioki authored Oct 28, 2016
2 parents f22a35f + 70e786c commit dde7008
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,16 @@ Run the following command to set up the required styles and mailer layout:
rails g inky:install
```

(You can specify the generated mailer layout filename like so: `rails g inky:install some_name` and also your prefered
markup language like: `rails g inky:install mailer_layout slim`)
You can specify the layout name and templating language with the following options:

```
Usage:
rails generate inky:install [layout_name] [options]
Options:
[--haml], [--no-haml] # Generate layout in Haml
[--slim], [--no-slim] # Generate layout in Slim
```

Rename your email templates to use the `.inky` file extension. Note that you'll still be able to use your default
template engine within the `.inky` templates:
Expand Down
16 changes: 12 additions & 4 deletions lib/generators/inky/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ 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'
argument :extension, type: :string, default: 'erb', banner: 'extension'

def preserve_original_mailer_layout
return unless layout_name == 'mailer'
class_option :haml, desc: "Generate layout in Haml", type: :boolean
class_option :slim, desc: "Generate layout in Slim", type: :boolean

original_mailer = File.join(layouts_base_dir, "mailer.html.#{extension}")
def preserve_original_mailer_layout
return unless layout_name == 'mailer' && extension == 'erb'
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.exist? original_mailer
end
Expand All @@ -33,6 +34,13 @@ def stylesheets_base_dir
def layouts_base_dir
File.join('app', 'views', 'layouts')
end

def extension
%w(haml slim).each do |ext|
return ext if options.send(ext)
end
'erb'
end
end
end
end
4 changes: 2 additions & 2 deletions lib/generators/inky/templates/mailer_layout.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width" />

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

<body>
<table class="body" data-made-with-foundation>
<tr>
<td class="center" align="center" valign="top">
<center>
<%= yield %>
<%%= yield %>
</center>
</td>
</tr>
Expand Down
2 changes: 1 addition & 1 deletion lib/inky/rails/version.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Inky
module Rails
VERSION = "1.3.7.1".freeze
VERSION = "1.3.7.2".freeze
end
NODE_VERSION, GEM_VERSION = Rails::VERSION.rpartition('.').map(&:freeze)
end

0 comments on commit dde7008

Please sign in to comment.