devise-foundation-views 0.1.0 → 1.0.1

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.
Files changed (67) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/ci.yml +76 -0
  3. data/.gitignore +32 -3
  4. data/.rspec +1 -0
  5. data/.rubocop.yml +44 -0
  6. data/CHANGELOG.md +76 -0
  7. data/CODE_OF_CONDUCT.md +9 -0
  8. data/Gemfile +9 -2
  9. data/README.md +102 -25
  10. data/Rakefile +6 -2
  11. data/UPGRADE_GUIDE.md +87 -0
  12. data/app/assets/stylesheets/devise_foundation_layout.css +49 -0
  13. data/app/assets/stylesheets/devise_foundation_views.css +53 -0
  14. data/app/assets/stylesheets/devise_foundation_views_less.less +47 -8
  15. data/app/assets/stylesheets/devise_foundation_views_scss.scss +48 -8
  16. data/app/views/devise/confirmations/new.html.erb +15 -19
  17. data/app/views/devise/mailer/confirmation_instructions.html.erb +3 -4
  18. data/app/views/devise/mailer/reset_password_instructions.html.erb +5 -5
  19. data/app/views/devise/mailer/unlock_instructions.html.erb +4 -4
  20. data/app/views/devise/passwords/edit.html.erb +23 -21
  21. data/app/views/devise/passwords/new.html.erb +15 -18
  22. data/app/views/devise/registrations/edit.html.erb +47 -25
  23. data/app/views/devise/registrations/new.html.erb +26 -22
  24. data/app/views/devise/sessions/new.html.erb +29 -23
  25. data/app/views/devise/shared/_error_messages.html.erb +17 -0
  26. data/app/views/devise/shared/_foundation_layout.html.erb +12 -0
  27. data/app/views/devise/shared/_links.html.erb +22 -20
  28. data/app/views/devise/unlocks/new.html.erb +15 -18
  29. data/app/views/devise_haml/confirmations/new.html.haml +10 -13
  30. data/app/views/devise_haml/mailer/confirmation_instructions.html.haml +3 -3
  31. data/app/views/devise_haml/mailer/reset_password_instructions.html.haml +5 -5
  32. data/app/views/devise_haml/mailer/unlock_instructions.html.haml +4 -4
  33. data/app/views/devise_haml/passwords/edit.html.haml +16 -16
  34. data/app/views/devise_haml/passwords/new.html.haml +10 -13
  35. data/app/views/devise_haml/registrations/edit.html.haml +32 -22
  36. data/app/views/devise_haml/registrations/new.html.haml +18 -17
  37. data/app/views/devise_haml/sessions/new.html.haml +18 -17
  38. data/app/views/devise_haml/shared/_error_messages.html.haml +9 -0
  39. data/app/views/devise_haml/shared/_foundation_layout.html.haml +7 -0
  40. data/app/views/devise_haml/shared/_links.html.haml +20 -19
  41. data/app/views/devise_haml/unlocks/new.html.haml +10 -13
  42. data/app/views/devise_slim/confirmations/new.html.slim +10 -13
  43. data/app/views/devise_slim/mailer/confirmation_instructions.html.slim +3 -4
  44. data/app/views/devise_slim/mailer/reset_password_instructions.html.slim +5 -6
  45. data/app/views/devise_slim/mailer/unlock_instructions.html.slim +4 -4
  46. data/app/views/devise_slim/passwords/edit.html.slim +16 -17
  47. data/app/views/devise_slim/passwords/new.html.slim +10 -13
  48. data/app/views/devise_slim/registrations/edit.html.slim +32 -23
  49. data/app/views/devise_slim/registrations/new.html.slim +18 -18
  50. data/app/views/devise_slim/sessions/new.html.slim +18 -17
  51. data/app/views/devise_slim/shared/_error_messages.html.slim +9 -0
  52. data/app/views/devise_slim/shared/_foundation_layout.html.slim +7 -0
  53. data/app/views/devise_slim/shared/_links.html.slim +20 -19
  54. data/app/views/devise_slim/unlocks/new.html.slim +10 -14
  55. data/bin/console +8 -0
  56. data/bin/setup +5 -0
  57. data/devise-foundation-views.gemspec +28 -17
  58. data/lib/devise-foundation-views.rb +16 -19
  59. data/lib/devise_foundation_views_helper.rb +3 -17
  60. data/lib/devise_layout_helper.rb +18 -0
  61. data/lib/generators/devise/views/foundation_layout/foundation_layout_generator.rb +34 -0
  62. data/lib/generators/devise/views/foundation_layout/templates/layouts/devise.html.erb +37 -0
  63. data/lib/generators/devise/views/foundation_templates/foundation_templates_generator.rb +19 -15
  64. data/lib/version.rb +3 -1
  65. data/locales/uk.yml +1 -1
  66. metadata +108 -19
  67. data/.travis.yml +0 -8
@@ -1,19 +1,20 @@
1
- = foundation_devise_error_messages!
2
- .large-3.large-centered.columns
3
- .login-box
4
- .row
5
- .large-12.columns
6
- = form_for(resource, as: resource_name, url: session_path(resource_name)) do |f|
7
- .row
8
- h5.text-center= t('.sign_in', :default => "Sign in")
9
- .row
10
- = f.email_field :email, autofocus: true, class: "large-12 columns", placeholder: "Email"
11
- .row
12
- = f.password_field :password, autocomplete: "off", class: "large-12 columns", placeholder: "Password"
13
- - if devise_mapping.rememberable?
14
- .row
1
+ = render layout: "devise/shared/foundation_layout", locals: { title: t(".sign_in", default: "Log in") } do
2
+ = form_for(resource, as: resource_name, url: session_path(resource_name)) do |f|
3
+ = render "devise/shared/error_messages", resource: resource
4
+ .grid-x.grid-padding-x
5
+ .cell
6
+ = f.label :email
7
+ = f.email_field :email, autofocus: true, autocomplete: "email"
8
+ .cell
9
+ = f.label :password
10
+ = f.password_field :password, autocomplete: "current-password"
11
+ - if devise_mapping.rememberable?
12
+ .cell
13
+ .grid-x.align-middle
14
+ .cell.shrink
15
15
  = f.check_box :remember_me
16
+ .cell.auto
16
17
  = f.label :remember_me
17
- .row
18
- = f.submit t('.sign_in', :default => "Sign in"), class: "button expand large-12 large-centered columns"
19
- = render "devise/shared/links"
18
+ .cell
19
+ = f.submit t(".sign_in", default: "Log in"), class: "button expanded"
20
+ = render "devise/shared/links"
@@ -0,0 +1,9 @@
1
+ - if resource.errors.any?
2
+ #error_explanation.callout.alert data-closable=true role="alert"
3
+ h2
4
+ = I18n.t("errors.messages.not_saved", count: resource.errors.count, resource: resource.class.model_name.human.downcase)
5
+ ul.no-bullet
6
+ - resource.errors.full_messages.each do |message|
7
+ li= message
8
+ button.close-button aria-label=t("devise.shared.error_messages.close", default: "Dismiss alert") type="button" data-close=true
9
+ span aria-hidden="true" ×
@@ -0,0 +1,7 @@
1
+ .grid-container.devise-foundation-views
2
+ .grid-x.grid-padding-x.align-center
3
+ .medium-10.large-7.cell
4
+ .devise-form-card
5
+ - if local_assigns[:title].present?
6
+ h2.text-center.devise-form-card__title= title
7
+ = yield
@@ -1,19 +1,20 @@
1
- - if controller_name != 'sessions'
2
- = link_to t(".sign_in", :default => "Sign in"), new_session_path(resource_name)
3
- br/
4
- - if devise_mapping.registerable? && controller_name != 'registrations'
5
- = link_to t(".sign_up", :default => "Sign up"), new_registration_path(resource_name)
6
- br/
7
- - if devise_mapping.recoverable? && controller_name != 'passwords'
8
- = link_to t(".forgot_your_password", :default => "Forgot your password?"), new_password_path(resource_name)
9
- br/
10
- - if devise_mapping.confirmable? && controller_name != 'confirmations'
11
- = link_to t('.didn_t_receive_confirmation_instructions', :default => "Didn't receive confirmation instructions?"), new_confirmation_path(resource_name)
12
- br/
13
- - if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks'
14
- = link_to t('.didn_t_receive_unlock_instructions', :default => "Didn't receive unlock instructions?"), new_unlock_path(resource_name)
15
- br/
16
- - if devise_mapping.omniauthable?
17
- - resource_class.omniauth_providers.each do |provider|
18
- = link_to t('.sign_in_with_provider', :provider => provider.to_s.titleize, :default => "Sign in with #{provider.to_s.titleize}"), omniauth_authorize_path(resource_name, provider)
19
- br/
1
+ .devise-links.text-center
2
+ - if controller_name != 'sessions'
3
+ = link_to t(".sign_in", default: "Log in"), new_session_path(resource_name)
4
+ br
5
+ - if devise_mapping.registerable? && controller_name != 'registrations'
6
+ = link_to t(".sign_up", default: "Sign up"), new_registration_path(resource_name)
7
+ br
8
+ - if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations'
9
+ = link_to t(".forgot_your_password", default: "Forgot your password?"), new_password_path(resource_name)
10
+ br
11
+ - if devise_mapping.confirmable? && controller_name != 'confirmations'
12
+ = link_to t(".didn_t_receive_confirmation_instructions", default: "Didn't receive confirmation instructions?"), new_confirmation_path(resource_name)
13
+ br
14
+ - if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks'
15
+ = link_to t(".didn_t_receive_unlock_instructions", default: "Didn't receive unlock instructions?"), new_unlock_path(resource_name)
16
+ br
17
+ - if devise_mapping.omniauthable?
18
+ - resource_class.omniauth_providers.each do |provider|
19
+ = button_to t(".sign_in_with_provider", provider: OmniAuth::Utils.camelize(provider), default: "Sign in with #{OmniAuth::Utils.camelize(provider)}"), omniauth_authorize_path(resource_name, provider), data: { turbo: false }, class: "button hollow expanded"
20
+ br
@@ -1,14 +1,10 @@
1
- = foundation_devise_error_messages!
2
- .large-3.large-centered.columns
3
- .login-box
4
- .row
5
- .large-12.columns
6
- = form_for(resource, :as => resource_name, :url => unlock_path(resource_name), :html => { :method => :post}) do |f|
7
- .row
8
- h5.text-center= t('.resend_unlock_instructions', :default => "Resend unlock instructions")
9
- .row
10
- = f.email_field :email, autofocus: true, class: "large-12 columns", placeholder: "Email"
11
- .row
12
- = f.submit t('.resend_unlock_instructions', :default => "Resend unlock instructions"), class: "button expand large-12 large-centered columns"
13
- = render "devise/shared/links"
14
-
1
+ = render layout: "devise/shared/foundation_layout", locals: { title: t(".resend_unlock_instructions", default: "Resend unlock instructions") } do
2
+ = form_for(resource, as: resource_name, url: unlock_path(resource_name), html: { method: :post }) do |f|
3
+ = render "devise/shared/error_messages", resource: resource
4
+ .grid-x.grid-padding-x
5
+ .cell
6
+ = f.label :email
7
+ = f.email_field :email, autofocus: true, autocomplete: "email"
8
+ .cell
9
+ = f.submit t(".resend_unlock_instructions", default: "Resend unlock instructions"), class: "button expanded"
10
+ = render "devise/shared/links"
data/bin/console ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "devise-foundation-views"
6
+
7
+ require "irb"
8
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,5 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
@@ -1,7 +1,6 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'version'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/version"
5
4
 
6
5
  Gem::Specification.new do |spec|
7
6
  spec.name = "devise-foundation-views"
@@ -9,25 +8,37 @@ Gem::Specification.new do |spec|
9
8
  spec.authors = ["ethi"]
10
9
  spec.email = ["ethirajsrinivasan@gmail.com"]
11
10
 
12
- spec.summary = "Devise views based on foundation framework"
13
- spec.description = "Devise views based on foundation framework"
11
+ spec.summary = "Devise views based on Foundation 6"
12
+ spec.description = "A Rails engine providing Foundation 6 styled Devise views (aligned with current Devise templates) in ERB, HAML, and Slim"
14
13
  spec.homepage = "https://github.com/ethirajsrinivasan/devise-foundation-views"
15
14
  spec.license = "MIT"
16
15
 
17
- # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
- # delete this section to allow pushing this gem to any host.
19
- if spec.respond_to?(:metadata)
20
- spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
- else
22
- raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
16
+ spec.metadata = {
17
+ "allowed_push_host" => "https://rubygems.org",
18
+ "homepage_uri" => spec.homepage,
19
+ "source_code_uri" => "https://github.com/ethirajsrinivasan/devise-foundation-views",
20
+ "bug_tracker_uri" => "https://github.com/ethirajsrinivasan/devise-foundation-views/issues",
21
+ "changelog_uri" => "https://github.com/ethirajsrinivasan/devise-foundation-views/blob/master/CHANGELOG.md",
22
+ "documentation_uri" => "https://github.com/ethirajsrinivasan/devise-foundation-views/blob/master/README.md",
23
+ "rubygems_mfa_required" => "true"
24
+ }
25
+
26
+ spec.files = Dir.chdir(__dir__) do
27
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
28
  end
24
29
 
25
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
30
  spec.bindir = "exe"
27
31
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
32
  spec.require_paths = ["lib"]
29
- spec.required_ruby_version = '>= 1.9.3'
30
- spec.add_development_dependency "bundler", "~> 1.10"
31
- spec.add_development_dependency "rake", "~> 10.0"
32
- spec.add_development_dependency 'rspec'
33
+
34
+ spec.required_ruby_version = ">= 3.0"
35
+
36
+ spec.add_runtime_dependency "devise", ">= 4.9", "< 6.0"
37
+ spec.add_runtime_dependency "railties", ">= 6.0", "< 9.0"
38
+
39
+ spec.add_development_dependency "bundler", "~> 2.4"
40
+ spec.add_development_dependency "bundler-audit", "~> 0.9"
41
+ spec.add_development_dependency "rake", "~> 13.0"
42
+ spec.add_development_dependency "rspec", "~> 3.12"
43
+ spec.add_development_dependency "rubocop", "~> 1.50"
33
44
  end
@@ -1,28 +1,25 @@
1
- require 'rails'
2
- require 'devise_foundation_views_helper'
3
- module DeviseFoundationViews
4
- class Engine < ::Rails::Engine
5
- end
1
+ # frozen_string_literal: true
6
2
 
7
- class Railtie < ::Rails::Railtie
8
- initializer 'rails-devise-foundation-views' do |app|
9
- DeviseFoundationViews::Railtie.instance_eval do
10
- pattern = pattern_from app.config.i18n.available_locales
3
+ require "rails"
4
+ require "devise_foundation_views_helper"
5
+ require "devise_layout_helper"
11
6
 
12
- files = Dir[File.join(File.dirname(__FILE__), '../locales', "#{pattern}.yml")]
13
- I18n.load_path.concat(files)
7
+ module DeviseFoundationViews
8
+ class Engine < Rails::Engine
9
+ end
14
10
 
15
- ActionView::Base.send :include, DeviseFoundationViewsHelper
16
- end
11
+ class Railtie < Rails::Railtie
12
+ initializer "devise-foundation-views" do |app|
13
+ pattern = DeviseFoundationViews::Railtie.pattern_from(app.config.i18n.available_locales)
14
+ files = Dir[File.join(__dir__, "../locales", "#{pattern}.yml")]
15
+ I18n.load_path.concat(files)
16
+ ActionView::Base.include DeviseFoundationViewsHelper
17
+ ActionView::Base.include DeviseLayoutHelper
17
18
  end
18
19
 
19
- protected
20
-
21
20
  def self.pattern_from(args)
22
- array = Array(args || [])
23
- array.blank? ? '*' : "{#{array.join ','}}"
21
+ array = Array(args)
22
+ array.blank? ? "*" : "{#{array.join(',')}}"
24
23
  end
25
24
  end
26
25
  end
27
-
28
-
@@ -1,22 +1,8 @@
1
- # -*- encoding : utf-8 -*-
1
+ # frozen_string_literal: true
2
2
 
3
3
  module DeviseFoundationViewsHelper
4
+ # Deprecated: use <%= render "devise/shared/error_messages", resource: resource %> in views.
4
5
  def foundation_devise_error_messages!
5
- return '' if resource.errors.empty?
6
-
7
- messages = resource.errors.full_messages.map { |msg| content_tag(:li, msg) }.join
8
- sentence = I18n.t('errors.messages.not_saved',
9
- count: resource.errors.count,
10
- resource: resource.class.model_name.human.downcase)
11
-
12
- html = <<-HTML
13
- <div data-alert class="alert-box alert radius">
14
- <h5>#{sentence}</h5>
15
- <ul>#{messages}</ul>
16
- <a href="#" class="close">&times;</a>
17
- </div>
18
- HTML
19
-
20
- html.html_safe
6
+ render_to_string(partial: "devise/shared/error_messages", locals: { resource: resource })
21
7
  end
22
8
  end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DeviseLayoutHelper
4
+ def devise_page_title
5
+ return content_for(:title) if content_for?(:title)
6
+
7
+ case [controller_name, action_name]
8
+ when %w[sessions new] then "Sign in"
9
+ when %w[registrations new] then "Sign up"
10
+ when %w[registrations edit] then "Edit account"
11
+ when %w[passwords new] then "Forgot password"
12
+ when %w[passwords edit] then "Change password"
13
+ when %w[confirmations new] then "Resend confirmation"
14
+ when %w[unlocks new] then "Resend unlock"
15
+ else "Account"
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Devise
4
+ module Views
5
+ class FoundationLayoutGenerator < Rails::Generators::Base
6
+ source_root File.expand_path("templates", __dir__)
7
+
8
+ desc "Copy a centered Devise-only layout and hook it up in ApplicationController"
9
+
10
+ def copy_layout
11
+ template "layouts/devise.html.erb", "app/views/layouts/devise.html.erb"
12
+ end
13
+
14
+ def show_application_controller_note
15
+ say "\nAdd to ApplicationController:\n", :yellow
16
+ say <<~RUBY, :green
17
+ layout :layout_for_controller
18
+
19
+ private
20
+
21
+ def layout_for_controller
22
+ devise_controller? ? "devise" : "application"
23
+ end
24
+ RUBY
25
+ say "\nIn application.css (Sprockets, no Sass required):\n", :yellow
26
+ say <<~CSS, :green
27
+ *= require devise_foundation_views
28
+ *= require devise_foundation_layout
29
+ CSS
30
+ say "\nEnsure Foundation 6 CSS is loaded in the devise layout.\n", :yellow
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,37 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en" class="devise-layout-root">
3
+ <head>
4
+ <title><%%= devise_page_title %></title>
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <%%= csrf_meta_tags %>
7
+ <%%= csp_meta_tag %>
8
+ <!-- Load Foundation 6 in your app (CDN, npm, or foundation-rails) -->
9
+ <%%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
10
+ <%%= stylesheet_link_tag "devise_foundation_views", "data-turbo-track": "reload" %>
11
+ <%%= stylesheet_link_tag "devise_foundation_layout", "data-turbo-track": "reload" %>
12
+ </head>
13
+ <body class="devise-layout">
14
+ <%% if notice.present? %>
15
+ <div class="grid-container" style="padding-top: 1rem;">
16
+ <div class="callout success" data-closable>
17
+ <%%= notice %>
18
+ <button class="close-button" type="button" data-close aria-label="Dismiss">&times;</button>
19
+ </div>
20
+ </div>
21
+ <%% end %>
22
+ <%% if alert.present? %>
23
+ <div class="grid-container" style="padding-top: 1rem;">
24
+ <div class="callout alert" data-closable>
25
+ <%%= alert %>
26
+ <button class="close-button" type="button" data-close aria-label="Dismiss">&times;</button>
27
+ </div>
28
+ </div>
29
+ <%% end %>
30
+
31
+ <main class="devise-layout__main<%%= " devise-layout__main--tall" if controller_name == "registrations" && action_name == "edit" %>">
32
+ <%%= yield %>
33
+ </main>
34
+
35
+ <%%= javascript_include_tag "application", "data-turbo-track": "reload" %>
36
+ </body>
37
+ </html>
@@ -1,25 +1,29 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Devise
2
4
  module Views
3
5
  class FoundationTemplatesGenerator < Rails::Generators::Base
4
- source_root File.expand_path('../../../../../../app/views', __FILE__)
5
- argument :template_name, :type => :string, :default => "devise"
6
+ source_root File.expand_path("../../../../../app/views", __dir__)
7
+ argument :template_name, type: :string, default: "devise"
8
+
6
9
  def copy_views
7
- directory(template, Rails.root.join("app", "views", "devise"))
10
+ directory(template, Rails.root.join("app", "views", "devise"))
8
11
  end
9
12
 
10
13
  private
14
+
11
15
  def template
12
- case template_name
13
- when "devise"
14
- "devise"
15
- when "slim"
16
- "devise_slim"
17
- when "haml"
18
- "devise_haml"
19
- else
20
- raise "Template not available for #{template_name}"
21
- end
22
- end
23
- end
16
+ case template_name
17
+ when "devise"
18
+ "devise"
19
+ when "slim"
20
+ "devise_slim"
21
+ when "haml"
22
+ "devise_haml"
23
+ else
24
+ raise "Template not available for #{template_name}. Use: devise, slim, or haml."
25
+ end
26
+ end
27
+ end
24
28
  end
25
29
  end
data/lib/version.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module DeviseFoundationViews
2
- VERSION = "0.1.0"
4
+ VERSION = "1.0.1"
3
5
  end
data/locales/uk.yml CHANGED
@@ -20,7 +20,7 @@ uk:
20
20
  action: "Розблокувати обліковий запис"
21
21
  greeting: "Привіт \"%{recipient}!\""
22
22
  instruction: "Натисніть на посилання для активації облікового запису:"
23
- message: "Ваш обліковий запис був заблокований у зв\'язку з перевищенням ліміту невдалих спроб входу."
23
+ message: "Ваш обліковий запис був заблокований у зв'язку з перевищенням ліміту невдалих спроб входу."
24
24
  subject: "Інструкції для розблокування облікового запису"
25
25
  passwords:
26
26
  new: