Skip to content

Commit

Permalink
Skip views and preview flags (#276)
Browse files Browse the repository at this point in the history
* Skip views and preview flags

* Add changelog
  • Loading branch information
HenriqueMorato authored Oct 25, 2024
1 parent b78e288 commit 1f0f2b3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- `--skip-previews` and `--skip-views` flags to skip mail previews and views (#276, @HenriqueMorato)

## [0.11.0] - 2024-09-16
### Added
- Support Rails 7.2 (#270, @jbennett)
Expand Down
14 changes: 14 additions & 0 deletions lib/generators/heya/campaign/campaign_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ class Heya::CampaignGenerator < Rails::Generators::NamedBase
source_root File.expand_path("templates", __dir__)

argument :steps, type: :array, default: []
class_option :skip_previews, type: :boolean, default: false
class_option :skip_views, type: :boolean, default: false

def copy_campaign_template
application_campaign = "app/campaigns/application_campaign.rb"
Expand All @@ -14,6 +16,8 @@ def copy_campaign_template
end

def copy_view_templates
return if skip_views?

selection =
if defined?(Maildown)
puts <<~MSG
Expand Down Expand Up @@ -45,6 +49,8 @@ def copy_view_templates
end

def copy_test_templates
return if skip_previews?

if preview_path
template "preview.rb", preview_path.join("#{file_name.underscore}_campaign_preview.rb")
end
Expand Down Expand Up @@ -74,4 +80,12 @@ def preview_path
Pathname(preview_path).sub(Rails.root.to_s, ".") if preview_path
end
end

def skip_previews?
options[:skip_previews]
end

def skip_views?
options[:skip_views]
end
end
20 changes: 19 additions & 1 deletion test/lib/generators/heya/heya/campaign_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,26 @@ class Heya::CampaignGeneratorTest < Rails::Generators::TestCase

test "generator runs without errors" do
assert_nothing_raised do
run_generator ["arguments"]
run_generator %w[arguments welcome:0]
end
assert_file "test/mailers/previews/arguments_campaign_preview.rb"
assert_file "app/views/heya/campaign_mailer/arguments_campaign/welcome.html.erb"
assert_file "app/views/heya/campaign_mailer/arguments_campaign/welcome.text.erb"
end

test "supports flag --skip-previews" do
assert_nothing_raised do
run_generator %w[arguments --skip-previews]
end
assert_no_file "test/mailers/previews/arguments_campaign_preview.rb"
end

test "supports flag --skip-views" do
assert_nothing_raised do
run_generator %w[arguments welcome:0 --skip-views]
end
assert_no_file "app/views/heya/campaign_mailer/arguments_campaign/welcome.html.erb"
assert_no_file "app/views/heya/campaign_mailer/arguments_campaign/welcome.text.erb"
end
end
end

0 comments on commit 1f0f2b3

Please sign in to comment.