Skip to content

Commit

Permalink
Integrate helpers directly
Browse files Browse the repository at this point in the history
Takes a more straightforward path to using the email helpers in a given app.
  • Loading branch information
justalever committed Sep 29, 2024
1 parent 1db7480 commit 6956e34
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 7 deletions.
6 changes: 4 additions & 2 deletions lib/install/application_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
class ApplicationMailer < ActionMailer::Base
helper Railsui::MailHelper

default from: email_address_with_name("#{Railsui.config.support_email}", "#{Railsui.config.application_name}")

# Required to use helpers in mailers
helper ApplicationHelper

layout "mailer"
end
1 change: 1 addition & 0 deletions lib/install/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
say "✉️ Update mail sender"
update_mailer_sender
copy_sample_mailers
update_application_helper

# Migrate
rails_command "db:create"
Expand Down
24 changes: 22 additions & 2 deletions lib/install/setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ def add_devise_customizations
Devise::ConfirmationsController.layout "devise"
Devise::PasswordsController.layout "devise"
Devise::UnlocksController.layout "devise"
Devise::Mailer.helper Railsui::MailHelper
end
RUBY

Expand Down Expand Up @@ -208,9 +207,30 @@ def copy_hero_icons
end

def copy_application_mailer
copy_file "#{__dir__}/application_mailer.rb", Rails.root.join("app/mailers/application_mailer.rb"), force: true
copy_file "#{__dir__}/application_mailer.rb", Rails.root.join("app/mailers/application_mailer.rb"), force: true
end

def update_application_helper
content = <<-RUBY
def spacer(amount = 16)
render "shared/email_spacer", amount: amount
end
def email_action(action, url, options={})
align = options[:align] ||= "left"
theme = options[:theme] ||= "primary"
fullwidth = options[:fullwidth] ||= false
render "shared/email_action", align: align, theme: theme, action: action, url: url, fullwidth: fullwidth
end
def email_callout(&block)
render "shared/email_callout", block: block
end
RUBY

insert_into_file "#{Rails.root}/app/helpers/application_helper.rb", content, after: "module ApplicationHelper\n"
end

# Extend this gems helper into the client app + extend devise
def add_application_controller_code
app_controller_code = <<-RUBY
Expand Down
7 changes: 7 additions & 0 deletions lib/install/shared/_email_callout.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<table class="callout">
<tbody>
<td>
<%= capture(&block) %>
</td>
</tbody>
</table>
1 change: 0 additions & 1 deletion lib/install/shared/_email_spacer.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@
</tr>
</tbody>
</table>
x
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<table class="callout">
<tbody>
<td>
<%= capture(&block) %>
</td>
</tbody>
</table>
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@
</tr>
</tbody>
</table>
x
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<table class="callout">
<tbody>
<td>
<%= capture(&block) %>
</td>
</tbody>
</table>
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@
</tr>
</tbody>
</table>
x

0 comments on commit 6956e34

Please sign in to comment.