diff --git a/README.md b/README.md index ad1dc39..bcb899b 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/lib/generators/inky/install_generator.rb b/lib/generators/inky/install_generator.rb index b7f212e..f7ce28a 100644 --- a/lib/generators/inky/install_generator.rb +++ b/lib/generators/inky/install_generator.rb @@ -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 @@ -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 diff --git a/lib/generators/inky/templates/mailer_layout.html.erb b/lib/generators/inky/templates/mailer_layout.html.erb index 374751e..43d8b6f 100644 --- a/lib/generators/inky/templates/mailer_layout.html.erb +++ b/lib/generators/inky/templates/mailer_layout.html.erb @@ -4,7 +4,7 @@ - <%= stylesheet_link_tag "foundation_emails" %> + <%%= stylesheet_link_tag "foundation_emails" %>
@@ -12,7 +12,7 @@