whose-components 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +231 -0
- data/Rakefile +8 -0
- data/app/assets/fonts/whose_components/OFL.txt +93 -0
- data/app/assets/fonts/whose_components/leaguespartan-bold.woff2 +0 -0
- data/app/assets/tailwind/whose_components/engine.css +139 -0
- data/app/components/whose/badge_component/badge_component.html.haml +1 -0
- data/app/components/whose/badge_component.rb +23 -0
- data/app/components/whose/button_component/button_component.html.haml +6 -0
- data/app/components/whose/button_component.rb +40 -0
- data/app/components/whose/card_component/card_component.html.haml +6 -0
- data/app/components/whose/card_component.rb +24 -0
- data/app/components/whose/dialog.rb +21 -0
- data/app/components/whose/dialog_header_component/dialog_header_component.en.yml +2 -0
- data/app/components/whose/dialog_header_component/dialog_header_component.html.haml +3 -0
- data/app/components/whose/dialog_header_component.rb +8 -0
- data/app/components/whose/flash_component/flash_component.en.yml +2 -0
- data/app/components/whose/flash_component/flash_component.html.haml +14 -0
- data/app/components/whose/flash_component.rb +35 -0
- data/app/components/whose/form/field_component/field_component.html.haml +16 -0
- data/app/components/whose/form/field_component.rb +90 -0
- data/app/components/whose/link_component/link_component.html.haml +1 -0
- data/app/components/whose/link_component.rb +22 -0
- data/app/components/whose/list_component/list_component.html.haml +3 -0
- data/app/components/whose/list_component.rb +15 -0
- data/app/components/whose/list_row_component/list_row_component.html.haml +12 -0
- data/app/components/whose/list_row_component.rb +19 -0
- data/app/components/whose/modal_component/modal_component.html.haml +10 -0
- data/app/components/whose/modal_component.rb +12 -0
- data/app/components/whose/nav/item_component/item_component.html.haml +5 -0
- data/app/components/whose/nav/item_component.rb +21 -0
- data/app/components/whose/nav_component/nav_component.en.yml +4 -0
- data/app/components/whose/nav_component/nav_component.html.haml +22 -0
- data/app/components/whose/nav_component.rb +55 -0
- data/app/components/whose/offcanvas_component/offcanvas_component.html.haml +8 -0
- data/app/components/whose/offcanvas_component.rb +21 -0
- data/app/components/whose/page_header_component/page_header_component.html.haml +7 -0
- data/app/components/whose/page_header_component.rb +17 -0
- data/app/components/whose/pagination_component/pagination_component.html.haml +2 -0
- data/app/components/whose/pagination_component.rb +12 -0
- data/app/components/whose/tooltip_component/tooltip_component.html.haml +3 -0
- data/app/components/whose/tooltip_component.rb +26 -0
- data/app/controllers/concerns/whose/authentication.rb +77 -0
- data/app/controllers/whose/confirmations_controller.rb +29 -0
- data/app/controllers/whose/passwords_controller.rb +38 -0
- data/app/controllers/whose/registrations_controller.rb +29 -0
- data/app/controllers/whose/sessions_controller.rb +31 -0
- data/app/helpers/whose/component_helper.rb +18 -0
- data/app/helpers/whose/form_helper.rb +16 -0
- data/app/javascript/whose/controllers/whose_dialog_controller.js +3 -0
- data/app/javascript/whose/controllers/whose_notification_controller.js +8 -0
- data/app/javascript/whose/controllers/whose_password_visibility_controller.js +3 -0
- data/app/jobs/.keep +0 -0
- data/app/mailers/whose/auth_mailer.rb +17 -0
- data/app/models/concerns/whose/authenticatable.rb +31 -0
- data/app/models/whose/current.rb +6 -0
- data/app/models/whose/session.rb +7 -0
- data/app/views/whose/auth_mailer/account_exists.html.haml +6 -0
- data/app/views/whose/auth_mailer/account_exists.text.haml +9 -0
- data/app/views/whose/auth_mailer/confirmation.html.haml +3 -0
- data/app/views/whose/auth_mailer/confirmation.text.haml +5 -0
- data/app/views/whose/auth_mailer/password_reset.html.haml +3 -0
- data/app/views/whose/auth_mailer/password_reset.text.haml +5 -0
- data/app/views/whose/confirmations/new.html.haml +11 -0
- data/app/views/whose/confirmations/show.html.haml +6 -0
- data/app/views/whose/passwords/edit.html.haml +11 -0
- data/app/views/whose/passwords/new.html.haml +11 -0
- data/app/views/whose/registrations/new.html.haml +16 -0
- data/app/views/whose/sessions/new.html.haml +15 -0
- data/config/importmap.rb +7 -0
- data/config/locales/whose/auth.en.yml +71 -0
- data/config/locales/whose/errors.en.yml +17 -0
- data/config/locales/whose/form.en.yml +5 -0
- data/config/locales/whose/nav.en.yml +4 -0
- data/lib/generators/whose/components/install/install_generator.rb +56 -0
- data/lib/generators/whose/components/install/templates/application.html.haml +24 -0
- data/lib/generators/whose/components/install/templates/create_users.rb.tt +17 -0
- data/lib/generators/whose/components/install/templates/create_whose_sessions.rb.tt +13 -0
- data/lib/generators/whose/components/install/templates/user.rb.tt +7 -0
- data/lib/generators/whose/components/install/templates/users.rb.tt +15 -0
- data/lib/generators/whose/components/views/USAGE +12 -0
- data/lib/generators/whose/components/views/views_generator.rb +19 -0
- data/lib/templates/app/.claude/skills/asd-ste100/LICENSE +21 -0
- data/lib/templates/app/.claude/skills/asd-ste100/README.md +102 -0
- data/lib/templates/app/.claude/skills/asd-ste100/SKILL.md +139 -0
- data/lib/templates/app/.claude/skills/asd-ste100/examples/before-after.md +92 -0
- data/lib/templates/app/.claude/skills/asd-ste100/examples/linter-edge-cases.md +14 -0
- data/lib/templates/app/.claude/skills/asd-ste100/references/writing-rules.md +59 -0
- data/lib/templates/app/.claude/skills/asd-ste100/scripts/ste-lint.py +486 -0
- data/lib/templates/app/CLAUDE.md.tt +181 -0
- data/lib/templates/whose_app_template.rb +144 -0
- data/lib/whose/components/engine.rb +33 -0
- data/lib/whose/components/form_builder.rb +158 -0
- data/lib/whose/components/routes.rb +16 -0
- data/lib/whose/components/version.rb +7 -0
- data/lib/whose/components.rb +16 -0
- data/lib/whose/merge_classes.rb +17 -0
- data/vendor/javascript/@stimulus-components--dialog.js +4 -0
- data/vendor/javascript/@stimulus-components--notification.js +4 -0
- data/vendor/javascript/@stimulus-components--password-visibility.js +4 -0
- data/vendor/javascript/LICENSES +30 -0
- data/vendor/javascript/stimulus-use.js +4 -0
- metadata +272 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class Whose::SessionsController < ::ApplicationController
|
|
4
|
+
include Whose::Authentication
|
|
5
|
+
|
|
6
|
+
allow_unauthenticated_access only: %i[new create]
|
|
7
|
+
rate_limit to: 10, within: 3.minutes, only: :create,
|
|
8
|
+
with: -> { redirect_to new_session_path, alert: t("whose.rate_limited") }
|
|
9
|
+
|
|
10
|
+
def new
|
|
11
|
+
redirect_to after_sign_in_path if authenticated?
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def create
|
|
15
|
+
credentials = params.permit(:email, :password)
|
|
16
|
+
user = User.authenticate_by(email: credentials[:email], password: credentials[:password])
|
|
17
|
+
if user&.confirmed?
|
|
18
|
+
start_new_session_for user
|
|
19
|
+
redirect_to after_authentication_url
|
|
20
|
+
else
|
|
21
|
+
@unconfirmed = user.present?
|
|
22
|
+
flash.now[:alert] = t(@unconfirmed ? "whose.sessions.unconfirmed" : "whose.sessions.invalid")
|
|
23
|
+
render :new, status: :unprocessable_content
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def destroy
|
|
28
|
+
terminate_session
|
|
29
|
+
redirect_to after_sign_out_path, status: :see_other, notice: t("whose.sessions.signed_out")
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Whose::ComponentHelper
|
|
4
|
+
def button_component(*, **, &) = render(Whose::ButtonComponent.new(*, **), &)
|
|
5
|
+
def link_component(*, **, &) = render(Whose::LinkComponent.new(*, **), &)
|
|
6
|
+
def badge_component(*, **, &) = render(Whose::BadgeComponent.new(*, **), &)
|
|
7
|
+
def card_component(*, **, &) = render(Whose::CardComponent.new(*, **), &)
|
|
8
|
+
def flash_component(*, **, &) = render(Whose::FlashComponent.new(*, **), &)
|
|
9
|
+
def page_header_component(*, **, &) = render(Whose::PageHeaderComponent.new(*, **), &)
|
|
10
|
+
def list_component(*, **, &) = render(Whose::ListComponent.new(*, **), &)
|
|
11
|
+
def list_row_component(*, **, &) = render(Whose::ListRowComponent.new(*, **), &)
|
|
12
|
+
def modal_component(*, **, &) = render(Whose::ModalComponent.new(*, **), &)
|
|
13
|
+
def offcanvas_component(*, **, &) = render(Whose::OffcanvasComponent.new(*, **), &)
|
|
14
|
+
def tooltip_component(*, **, &) = render(Whose::TooltipComponent.new(*, **), &)
|
|
15
|
+
def nav_component(*, **, &) = render(Whose::NavComponent.new(*, **), &)
|
|
16
|
+
def nav_item_component(*, **, &) = render(Whose::Nav::ItemComponent.new(*, **), &)
|
|
17
|
+
def pagination_component(*, **, &) = render(Whose::PaginationComponent.new(*, **), &)
|
|
18
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Whose::FormHelper
|
|
4
|
+
LAYOUTS = %i[vertical horizontal inline].freeze
|
|
5
|
+
LABELS = %i[visible placeholder].freeze
|
|
6
|
+
ROW_CLASSES = "flex flex-col gap-4 sm:flex-row sm:items-start"
|
|
7
|
+
|
|
8
|
+
def whose_form_with(model: false, layout: :vertical, labels: :visible, **options, &block)
|
|
9
|
+
raise ArgumentError, "Unknown layout: #{layout.inspect}." unless LAYOUTS.include?(layout)
|
|
10
|
+
raise ArgumentError, "Unknown labels: #{labels.inspect}." unless LABELS.include?(labels)
|
|
11
|
+
|
|
12
|
+
form_with(model:, builder: Whose::Components::FormBuilder, layout:, labels:, **options) do |form|
|
|
13
|
+
layout == :inline ? tag.div(capture(form, &block), class: ROW_CLASSES, data: { form_row: true }) : capture(form, &block)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
data/app/jobs/.keep
ADDED
|
File without changes
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class Whose::AuthMailer < ::ApplicationMailer
|
|
4
|
+
def confirmation(user)
|
|
5
|
+
@token = user.generate_token_for(:email_confirmation)
|
|
6
|
+
mail to: user.email
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def account_exists(user)
|
|
10
|
+
mail to: user.email
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def password_reset(user)
|
|
14
|
+
@token = user.password_reset_token
|
|
15
|
+
mail to: user.email
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Whose::Authenticatable
|
|
4
|
+
extend ActiveSupport::Concern
|
|
5
|
+
|
|
6
|
+
included do
|
|
7
|
+
has_secure_password
|
|
8
|
+
has_many :sessions, class_name: "Whose::Session", dependent: :destroy
|
|
9
|
+
|
|
10
|
+
normalizes :email, with: -> { it.strip.downcase }
|
|
11
|
+
normalizes :first_name, :last_name, with: -> { it.strip.presence }
|
|
12
|
+
|
|
13
|
+
validates :email, presence: true, uniqueness: true, format: { with: URI::MailTo::EMAIL_REGEXP }
|
|
14
|
+
validates :password, length: { minimum: 8 }, allow_nil: true
|
|
15
|
+
validates :first_name, presence: true
|
|
16
|
+
|
|
17
|
+
before_save { self.name = [ first_name, last_name ].compact_blank.join(" ") }
|
|
18
|
+
|
|
19
|
+
generates_token_for :email_confirmation, expires_in: 2.days do
|
|
20
|
+
confirmed_at
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def confirmed?
|
|
25
|
+
confirmed_at.present?
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def confirm!
|
|
29
|
+
update!(confirmed_at: Time.current)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
.mx-auto.w-full.max-w-sm
|
|
2
|
+
= render Whose::CardComponent.new do |card|
|
|
3
|
+
- card.with_header do
|
|
4
|
+
%h1.text-lg= t(".title")
|
|
5
|
+
- card.with_footer do
|
|
6
|
+
= render(Whose::LinkComponent.new(href: new_session_path, class: "text-sm")) { t(".sign_in") }
|
|
7
|
+
= whose_form_with url: confirmations_path do |form|
|
|
8
|
+
.flex.flex-col.gap-4
|
|
9
|
+
= form.email_field :email, label: t(".email"), required: true, autofocus: true,
|
|
10
|
+
autocomplete: "username"
|
|
11
|
+
= form.submit t(".submit"), full: true
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
.mx-auto.w-full.max-w-sm
|
|
2
|
+
= render Whose::CardComponent.new do |card|
|
|
3
|
+
- card.with_header do
|
|
4
|
+
%h1.text-lg= t(".title")
|
|
5
|
+
= whose_form_with model: @user, url: password_path(params[:token]), method: :patch do |form|
|
|
6
|
+
.flex.flex-col.gap-4
|
|
7
|
+
= form.password_field :password, label: t(".password"), required: true, autofocus: true,
|
|
8
|
+
autocomplete: "new-password"
|
|
9
|
+
= form.password_field :password_confirmation, label: t(".password_confirmation"), required: true,
|
|
10
|
+
autocomplete: "new-password"
|
|
11
|
+
= form.submit t(".submit"), full: true
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
.mx-auto.w-full.max-w-sm
|
|
2
|
+
= render Whose::CardComponent.new do |card|
|
|
3
|
+
- card.with_header do
|
|
4
|
+
%h1.text-lg= t(".title")
|
|
5
|
+
- card.with_footer do
|
|
6
|
+
= render(Whose::LinkComponent.new(href: new_session_path, class: "text-sm")) { t(".sign_in") }
|
|
7
|
+
= whose_form_with url: passwords_path do |form|
|
|
8
|
+
.flex.flex-col.gap-4
|
|
9
|
+
= form.email_field :email, label: t(".email"), required: true, autofocus: true,
|
|
10
|
+
autocomplete: "username"
|
|
11
|
+
= form.submit t(".submit"), full: true
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
.mx-auto.w-full.max-w-sm
|
|
2
|
+
= render Whose::CardComponent.new do |card|
|
|
3
|
+
- card.with_header do
|
|
4
|
+
%h1.text-lg= t(".title")
|
|
5
|
+
- card.with_footer do
|
|
6
|
+
= render(Whose::LinkComponent.new(href: new_session_path, class: "text-sm")) { t(".sign_in") }
|
|
7
|
+
= whose_form_with model: @user, url: registration_path do |form|
|
|
8
|
+
.flex.flex-col.gap-4
|
|
9
|
+
= form.text_field :first_name, label: t(".first_name"), required: true, autofocus: true,
|
|
10
|
+
autocomplete: "given-name"
|
|
11
|
+
= form.text_field :last_name, label: t(".last_name"), autocomplete: "family-name"
|
|
12
|
+
= form.email_field :email, label: t(".email"), required: true, autocomplete: "username"
|
|
13
|
+
= form.password_field :password, label: t(".password"), required: true, autocomplete: "new-password"
|
|
14
|
+
= form.password_field :password_confirmation, label: t(".password_confirmation"), required: true,
|
|
15
|
+
autocomplete: "new-password"
|
|
16
|
+
= form.submit t(".submit"), full: true
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
.mx-auto.w-full.max-w-sm
|
|
2
|
+
= render Whose::CardComponent.new do |card|
|
|
3
|
+
- card.with_header do
|
|
4
|
+
%h1.text-lg= t(".title")
|
|
5
|
+
- card.with_footer do
|
|
6
|
+
= render(Whose::LinkComponent.new(href: new_registration_path, class: "text-sm")) { t(".sign_up") }
|
|
7
|
+
= whose_form_with url: session_path do |form|
|
|
8
|
+
.flex.flex-col.gap-4
|
|
9
|
+
- if @unconfirmed
|
|
10
|
+
= render(Whose::LinkComponent.new(href: new_confirmation_path, class: "text-sm")) { t(".resend") }
|
|
11
|
+
= form.email_field :email, label: t(".email"), value: params[:email],
|
|
12
|
+
required: true, autofocus: true, autocomplete: "username"
|
|
13
|
+
= form.password_field :password, label: t(".password"), required: true, autocomplete: "current-password"
|
|
14
|
+
= render(Whose::LinkComponent.new(href: new_password_path, class: "text-sm")) { t(".forgot_password") }
|
|
15
|
+
= form.submit t(".submit"), full: true
|
data/config/importmap.rb
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
pin_all_from Whose::Components::Engine.root.join("app/javascript/whose/controllers"), under: "whose/controllers"
|
|
4
|
+
pin "@stimulus-components/dialog", to: "@stimulus-components--dialog.js" # @1.0.1
|
|
5
|
+
pin "@stimulus-components/notification", to: "@stimulus-components--notification.js" # @3.0.0
|
|
6
|
+
pin "@stimulus-components/password-visibility", to: "@stimulus-components--password-visibility.js" # @3.0.0
|
|
7
|
+
pin "stimulus-use", to: "stimulus-use.js" # @0.52.3
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
en:
|
|
2
|
+
whose:
|
|
3
|
+
rate_limited: Too many attempts. Try again later.
|
|
4
|
+
sessions:
|
|
5
|
+
invalid: The email address or the password is not correct.
|
|
6
|
+
unconfirmed: Confirm your email address before you sign in.
|
|
7
|
+
signed_out: You signed out.
|
|
8
|
+
new:
|
|
9
|
+
title: Sign in
|
|
10
|
+
email: Email address
|
|
11
|
+
password: Password
|
|
12
|
+
submit: Sign in
|
|
13
|
+
sign_up: Create an account
|
|
14
|
+
resend: Send a new confirmation link
|
|
15
|
+
forgot_password: Forgot your password?
|
|
16
|
+
registrations:
|
|
17
|
+
created: We sent you an email. Open the link in it to confirm your email address.
|
|
18
|
+
new:
|
|
19
|
+
title: Sign up
|
|
20
|
+
first_name: First name
|
|
21
|
+
last_name: Last name
|
|
22
|
+
email: Email address
|
|
23
|
+
password: Password
|
|
24
|
+
password_confirmation: Confirm the password
|
|
25
|
+
submit: Sign up
|
|
26
|
+
sign_in: Sign in
|
|
27
|
+
confirmations:
|
|
28
|
+
confirmed: Your email address is confirmed.
|
|
29
|
+
invalid: The link is not valid or it expired. Send a new link.
|
|
30
|
+
sent: If the email address has an account that is not confirmed, we sent a new link.
|
|
31
|
+
new:
|
|
32
|
+
title: Send a new confirmation link
|
|
33
|
+
email: Email address
|
|
34
|
+
submit: Send the link
|
|
35
|
+
sign_in: Sign in
|
|
36
|
+
show:
|
|
37
|
+
title: Confirm your email address
|
|
38
|
+
submit: Confirm email address
|
|
39
|
+
passwords:
|
|
40
|
+
sent: If the email address has an account, we sent a link to reset the password.
|
|
41
|
+
updated: Your password is changed. Sign in with the new password.
|
|
42
|
+
invalid: The link is not valid or it expired. Ask for a new link.
|
|
43
|
+
new:
|
|
44
|
+
title: Reset your password
|
|
45
|
+
email: Email address
|
|
46
|
+
submit: Send the link
|
|
47
|
+
sign_in: Sign in
|
|
48
|
+
edit:
|
|
49
|
+
title: Choose a new password
|
|
50
|
+
password: New password
|
|
51
|
+
password_confirmation: Confirm the new password
|
|
52
|
+
submit: Change password
|
|
53
|
+
auth_mailer:
|
|
54
|
+
account_exists:
|
|
55
|
+
subject: You already have an account
|
|
56
|
+
instruction: Someone tried to sign up with this email address. You already have an account with this address.
|
|
57
|
+
sign_in_instruction: Open this link to sign in.
|
|
58
|
+
sign_in: Sign in
|
|
59
|
+
reset_instruction: If you forgot your password, open this link to reset it.
|
|
60
|
+
reset: Reset your password
|
|
61
|
+
ignore: If you did not try to sign up, ignore this email.
|
|
62
|
+
password_reset:
|
|
63
|
+
subject: Reset your password
|
|
64
|
+
instruction: Open this link to choose a new password.
|
|
65
|
+
link: Reset your password
|
|
66
|
+
expiry: The link expires in 15 minutes. If you did not ask for it, ignore this email.
|
|
67
|
+
confirmation:
|
|
68
|
+
subject: Confirm your email address
|
|
69
|
+
instruction: Open this link to confirm your email address.
|
|
70
|
+
link: Confirm your email address
|
|
71
|
+
expiry: The link expires in 2 days. If you did not sign up, ignore this email.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
en:
|
|
2
|
+
errors:
|
|
3
|
+
messages:
|
|
4
|
+
blank: Enter a value.
|
|
5
|
+
taken: This value is already in use.
|
|
6
|
+
invalid: Enter a valid value.
|
|
7
|
+
too_short:
|
|
8
|
+
one: Use at least %{count} character.
|
|
9
|
+
other: Use at least %{count} characters.
|
|
10
|
+
too_long:
|
|
11
|
+
one: Use at most %{count} character.
|
|
12
|
+
other: Use at most %{count} characters.
|
|
13
|
+
confirmation: Enter the same value as %{attribute}.
|
|
14
|
+
inclusion: Choose a value from the list.
|
|
15
|
+
not_a_number: Enter a number.
|
|
16
|
+
greater_than: Enter a number greater than %{count}.
|
|
17
|
+
less_than: Enter a number less than %{count}.
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "rails/generators/active_record"
|
|
4
|
+
|
|
5
|
+
module Whose
|
|
6
|
+
module Components
|
|
7
|
+
module Generators
|
|
8
|
+
class InstallGenerator < Rails::Generators::Base
|
|
9
|
+
include Rails::Generators::Migration
|
|
10
|
+
|
|
11
|
+
ENGINE_CSS_IMPORT = %(@import "../builds/tailwind/whose_components.css";)
|
|
12
|
+
STIMULUS_REGISTRATION = %(eagerLoadControllersFrom("whose/controllers", application))
|
|
13
|
+
|
|
14
|
+
source_root File.expand_path("templates", __dir__)
|
|
15
|
+
|
|
16
|
+
desc "Add the whose-components styles and Stimulus controllers to the app."
|
|
17
|
+
|
|
18
|
+
class_option :auth, type: :boolean, default: false, desc: "Install email and password sign-in"
|
|
19
|
+
|
|
20
|
+
def self.next_migration_number(dirname)
|
|
21
|
+
ActiveRecord::Generators::Base.next_migration_number(dirname)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def add_engine_css
|
|
25
|
+
insert_into_file "app/assets/tailwind/application.css", "#{ENGINE_CSS_IMPORT}\n", after: %(@import "tailwindcss";\n)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def register_stimulus_controllers
|
|
29
|
+
append_to_file "app/javascript/controllers/index.js", "#{STIMULUS_REGISTRATION}\n"
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def write_layout
|
|
33
|
+
remove_file "app/views/layouts/application.html.erb"
|
|
34
|
+
template "application.html.haml", "app/views/layouts/application.html.haml"
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def add_authentication
|
|
38
|
+
return unless options[:auth]
|
|
39
|
+
|
|
40
|
+
migration_template "create_users.rb", "db/migrate/create_users.rb"
|
|
41
|
+
migration_template "create_whose_sessions.rb", "db/migrate/create_whose_sessions.rb"
|
|
42
|
+
template "user.rb", "app/models/user.rb"
|
|
43
|
+
template "users.rb", "test/factories/users.rb"
|
|
44
|
+
inject_into_class "app/controllers/application_controller.rb", "ApplicationController", " include Whose::Authentication\n"
|
|
45
|
+
route "whose_authentication"
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
private
|
|
49
|
+
|
|
50
|
+
def app_title
|
|
51
|
+
Rails.application.class.module_parent_name.titleize
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
!!!
|
|
2
|
+
%html{ lang: "en" }
|
|
3
|
+
%head
|
|
4
|
+
%title= content_for(:title) || "<%= app_title %>"
|
|
5
|
+
%meta{ name: "viewport", content: "width=device-width,initial-scale=1" }
|
|
6
|
+
= csrf_meta_tags
|
|
7
|
+
= csp_meta_tag
|
|
8
|
+
= yield :head
|
|
9
|
+
%link{ rel: "icon", href: "/icon.png", type: "image/png" }
|
|
10
|
+
%link{ rel: "icon", href: "/icon.svg", type: "image/svg+xml" }
|
|
11
|
+
%link{ rel: "apple-touch-icon", href: "/icon.png" }
|
|
12
|
+
= stylesheet_link_tag "tailwind", data: { turbo_track: "reload" }
|
|
13
|
+
= javascript_importmap_tags
|
|
14
|
+
%body.bg-canvas.text-fg.font-sans
|
|
15
|
+
= render Whose::NavComponent.new do |nav|
|
|
16
|
+
- nav.with_brand { "<%= app_title %>" }
|
|
17
|
+
- nav.with_item(label: "Home", href: "/")
|
|
18
|
+
<%- if options[:auth] -%>
|
|
19
|
+
- if authenticated?
|
|
20
|
+
- nav.with_actions { button_to t("whose.nav.sign_out"), session_path, method: :delete }
|
|
21
|
+
<%- end -%>
|
|
22
|
+
= render Whose::FlashComponent.new(flash:)
|
|
23
|
+
%main.mx-auto.max-w-5xl.px-4.py-6
|
|
24
|
+
= yield
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class CreateUsers < ActiveRecord::Migration[<%= ActiveRecord::Migration.current_version %>]
|
|
4
|
+
def change
|
|
5
|
+
create_table :users, id: :uuid do |t|
|
|
6
|
+
t.string :email, null: false
|
|
7
|
+
t.string :password_digest, null: false
|
|
8
|
+
t.datetime :confirmed_at
|
|
9
|
+
t.string :first_name, null: false
|
|
10
|
+
t.string :last_name
|
|
11
|
+
t.string :name, null: false
|
|
12
|
+
|
|
13
|
+
t.timestamps
|
|
14
|
+
end
|
|
15
|
+
add_index :users, :email, unique: true
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class CreateWhoseSessions < ActiveRecord::Migration[<%= ActiveRecord::Migration.current_version %>]
|
|
4
|
+
def change
|
|
5
|
+
create_table :whose_sessions do |t|
|
|
6
|
+
t.references :user, null: false, foreign_key: true, type: :uuid
|
|
7
|
+
t.string :ip_address
|
|
8
|
+
t.string :user_agent
|
|
9
|
+
|
|
10
|
+
t.timestamps
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
FactoryBot.define do
|
|
4
|
+
factory :user do
|
|
5
|
+
first_name { "Ann" }
|
|
6
|
+
last_name { "Lee" }
|
|
7
|
+
sequence(:email) { "user#{it}@example.com" }
|
|
8
|
+
password { "password123" }
|
|
9
|
+
confirmed_at { Time.current }
|
|
10
|
+
|
|
11
|
+
trait :unconfirmed do
|
|
12
|
+
confirmed_at { nil }
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Description:
|
|
2
|
+
Copy the auth views into the app, so you can change them.
|
|
3
|
+
|
|
4
|
+
Example:
|
|
5
|
+
bin/rails generate whose:components:views
|
|
6
|
+
|
|
7
|
+
This will create:
|
|
8
|
+
app/views/whose/sessions
|
|
9
|
+
app/views/whose/registrations
|
|
10
|
+
app/views/whose/confirmations
|
|
11
|
+
app/views/whose/passwords
|
|
12
|
+
app/views/whose/auth_mailer
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Whose
|
|
4
|
+
module Components
|
|
5
|
+
module Generators
|
|
6
|
+
class ViewsGenerator < Rails::Generators::Base
|
|
7
|
+
source_root Whose::Components::Engine.root.join("app/views/whose")
|
|
8
|
+
|
|
9
|
+
desc "Copy the whose-components auth views into the app."
|
|
10
|
+
|
|
11
|
+
def copy_views
|
|
12
|
+
%w[sessions registrations confirmations passwords auth_mailer].each do |folder|
|
|
13
|
+
directory folder, "app/views/whose/#{folder}"
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Dustin Yuchen Teng
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|