Skip to content

Commit

Permalink
Inline method
Browse files Browse the repository at this point in the history
  • Loading branch information
mlandauer committed Jun 28, 2024
1 parent 80e8617 commit cb2e082
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 33 deletions.
14 changes: 6 additions & 8 deletions app/mailers/alert_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,15 @@ def alert(alert:, applications: [], comments: [])
# It's not sent on in the outgoing email
"X-Cuttlefish-Metadata-alert-id" => alert.id.to_s,
"X-Cuttlefish-Metadata-user-id" => T.must(alert.user).id.to_s,
# If we're on the tailwind theme then disable css inlining because we're already
# Disable css inlining because we're already
# doing it with maizzle and the inlining on cuttlefish strips out media queries for
# responsive designs and some more modern css features
"X-Cuttlefish-Disable-Css-Inlining" => T.must(alert.user).tailwind_theme.to_s
"X-Cuttlefish-Disable-Css-Inlining" => "true"
)

if T.must(alert.user).tailwind_theme
attachments.inline["pencil.png"] = Rails.root.join("app/assets/images/tailwind/pencil.png").read
attachments.inline["trash.png"] = Rails.root.join("app/assets/images/tailwind/trash.png").read
attachments.inline["footer-illustration.png"] = Rails.root.join("app/assets/images/tailwind/illustration/woman-looking-off2.png").read
end
attachments.inline["pencil.png"] = Rails.root.join("app/assets/images/tailwind/pencil.png").read
attachments.inline["trash.png"] = Rails.root.join("app/assets/images/tailwind/trash.png").read
attachments.inline["footer-illustration.png"] = Rails.root.join("app/assets/images/tailwind/illustration/woman-looking-off2.png").read

mail(
from: "PlanningAlerts <[email protected]>",
Expand All @@ -45,7 +43,7 @@ def alert(alert:, applications: [], comments: [])
partial: "subject",
locals: { applications:, comments:, alert: }
).strip,
template_path: ("_tailwind/alert_mailer" if T.must(alert.user).tailwind_theme)
template_path: "_tailwind/alert_mailer"
)
end
end
12 changes: 6 additions & 6 deletions app/mailers/devise_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,26 @@ class DeviseMailer < Devise::Mailer
# which doesn't work. See https://github.com/heartcombo/devise/issues/4842
sig { params(action: T.untyped, opts: T.untyped).returns(T.untyped) }
def headers_for(action, opts)
super.merge!(template_path: (resource.tailwind_theme ? "_tailwind/devise/mailer" : "devise/mailer"))
super.merge!(template_path: "_tailwind/devise/mailer")
end

sig { params(record: User, token: String, opts: T.untyped).returns(T.untyped) }
def confirmation_instructions(record, token, opts = {})
headers["X-Cuttlefish-Disable-Css-Inlining"] = record.tailwind_theme.to_s
attachments.inline["illustration.png"] = Rails.root.join("app/assets/images/tailwind/illustration/confirmation.png").read if record.tailwind_theme
headers["X-Cuttlefish-Disable-Css-Inlining"] = "true"
attachments.inline["illustration.png"] = Rails.root.join("app/assets/images/tailwind/illustration/confirmation.png").read
super
end

sig { params(record: User, token: String, opts: T.untyped).returns(T.untyped) }
def reset_password_instructions(record, token, opts = {})
headers["X-Cuttlefish-Disable-Css-Inlining"] = record.tailwind_theme.to_s
attachments.inline["illustration.png"] = Rails.root.join("app/assets/images/tailwind/illustration/reset-password.png").read if record.tailwind_theme
headers["X-Cuttlefish-Disable-Css-Inlining"] = "true"
attachments.inline["illustration.png"] = Rails.root.join("app/assets/images/tailwind/illustration/reset-password.png").read
super
end

sig { params(record: User, token: String, opts: T.untyped).returns(T.untyped) }
def unlock_instructions(record, token, opts = {})
headers["X-Cuttlefish-Disable-Css-Inlining"] = record.tailwind_theme.to_s
headers["X-Cuttlefish-Disable-Css-Inlining"] = "true"
super
end
end
8 changes: 4 additions & 4 deletions app/mailers/users/activation_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ def notify(user, token)
@token = T.let(token, T.nilable(String))

headers(
# If we're on the tailwind theme then disable css inlining because we're already
# Disable css inlining because we're already
# doing it with maizzle and the inlining on cuttlefish strips out media queries for
# responsive designs and some more modern css features
"X-Cuttlefish-Disable-Css-Inlining" => user.tailwind_theme.to_s
"X-Cuttlefish-Disable-Css-Inlining" => "true"
)

attachments.inline["illustration.png"] = Rails.root.join("app/assets/images/tailwind/illustration/confirmation.png").read if user.tailwind_theme
attachments.inline["illustration.png"] = Rails.root.join("app/assets/images/tailwind/illustration/confirmation.png").read

mail(
to: user.email,
template_path: ("_tailwind/users/activation_mailer" if user.tailwind_theme)
template_path: "_tailwind/users/activation_mailer"
)
end
end
Expand Down
6 changes: 0 additions & 6 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ class User < ApplicationRecord
has_many :reports, dependent: :nullify
has_many :contact_messages, dependent: :nullify

# Force the tailwind_theme on everyone.
sig { returns(T::Boolean) }
def tailwind_theme
true
end

sig { params(notification: T.untyped, args: T.untyped).void }
def send_devise_notification(notification, *args)
devise_mailer.send(notification, self, *args).deliver_later
Expand Down
9 changes: 0 additions & 9 deletions spec/features/sign_up_for_alerts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,8 @@
end

it "when via the homepage but not yet have an account" do
# rubocop:disable RSpec/AnyInstance
allow_any_instance_of(User).to receive(:tailwind_theme).and_return(true)
# rubocop:enable RSpec/AnyInstance

create(:geocoded_application, address: "26 Bruce Rd, Glenbrook NSW 2773", lat: -33.772812, lng: 150.624252, lonlat: RGeo::Geographic.spherical_factory(srid: 4326).point(150.624252, -33.772812))

user = create(:confirmed_user)
sign_in user
visit root_path
sign_out user

visit root_path
fill_in("Street address", with: "24 Bruce Rd, Glenbrook")
click_button("Search")
Expand Down

0 comments on commit cb2e082

Please sign in to comment.