draft_generators 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +7 -0
  2. data/.codeclimate.yml +6 -0
  3. data/.document +5 -0
  4. data/.rspec +1 -0
  5. data/.rubocop.yml +637 -0
  6. data/Gemfile +16 -0
  7. data/LICENSE.txt +20 -0
  8. data/README.markdown +24 -0
  9. data/Rakefile +51 -0
  10. data/VERSION +1 -0
  11. data/draft_generators.gemspec +120 -0
  12. data/lib/devise_customization_service.rb +95 -0
  13. data/lib/draft_generators.rb +8 -0
  14. data/lib/generators/draft/devise/devise_generator.rb +92 -0
  15. data/lib/generators/draft/devise/views/templates/confirmations/new.html.erb +49 -0
  16. data/lib/generators/draft/devise/views/templates/mailer/confirmation_instructions.html.erb +5 -0
  17. data/lib/generators/draft/devise/views/templates/mailer/email_changed.html.erb +7 -0
  18. data/lib/generators/draft/devise/views/templates/mailer/password_change.html.erb +3 -0
  19. data/lib/generators/draft/devise/views/templates/mailer/reset_password_instructions.html.erb +8 -0
  20. data/lib/generators/draft/devise/views/templates/mailer/unlock_instructions.html.erb +7 -0
  21. data/lib/generators/draft/devise/views/templates/passwords/edit.html.erb +83 -0
  22. data/lib/generators/draft/devise/views/templates/passwords/new.html.erb +49 -0
  23. data/lib/generators/draft/devise/views/templates/registrations/edit.html.erb +159 -0
  24. data/lib/generators/draft/devise/views/templates/registrations/new.html.erb +113 -0
  25. data/lib/generators/draft/devise/views/templates/registrations_with_sentinels/edit.html.erb +160 -0
  26. data/lib/generators/draft/devise/views/templates/registrations_with_sentinels/new.html.erb +102 -0
  27. data/lib/generators/draft/devise/views/templates/sessions/new.html.erb +51 -0
  28. data/lib/generators/draft/devise/views/templates/shared/_links.html.erb +25 -0
  29. data/lib/generators/draft/devise/views/templates/unlocks/new.html.erb +49 -0
  30. data/lib/generators/draft/devise/views/views_generator.rb +41 -0
  31. data/lib/generators/draft/layout/USAGE +49 -0
  32. data/lib/generators/draft/layout/layout_generator.rb +66 -0
  33. data/lib/generators/draft/layout/templates/_bootstrapcdn_assets.html.erb +10 -0
  34. data/lib/generators/draft/layout/templates/_flashes.html.erb +23 -0
  35. data/lib/generators/draft/layout/templates/_navbar.html.erb +75 -0
  36. data/lib/generators/draft/layout/templates/layout.html.erb +40 -0
  37. data/lib/generators/draft/model/USAGE +14 -0
  38. data/lib/generators/draft/model/model_generator.rb +42 -0
  39. data/lib/generators/draft/resource/USAGE +11 -0
  40. data/lib/generators/draft/resource/resource_generator.rb +172 -0
  41. data/lib/generators/draft/resource/templates/controllers/controller.rb +97 -0
  42. data/lib/generators/draft/resource/templates/controllers/read_only_controller.rb +13 -0
  43. data/lib/generators/draft/resource/templates/specs/crud_spec.rb +300 -0
  44. data/lib/generators/draft/resource/templates/specs/factories.rb +32 -0
  45. data/lib/generators/draft/resource/templates/views/association_new_form.html.erb +67 -0
  46. data/lib/generators/draft/resource/templates/views/create_row.html.erb +13 -0
  47. data/lib/generators/draft/resource/templates/views/destroy_row.html.erb +13 -0
  48. data/lib/generators/draft/resource/templates/views/edit_form.html.erb +72 -0
  49. data/lib/generators/draft/resource/templates/views/edit_form_with_errors.html.erb +85 -0
  50. data/lib/generators/draft/resource/templates/views/index.html.erb +102 -0
  51. data/lib/generators/draft/resource/templates/views/new_form.html.erb +73 -0
  52. data/lib/generators/draft/resource/templates/views/new_form_with_errors.html.erb +86 -0
  53. data/lib/generators/draft/resource/templates/views/show.html.erb +90 -0
  54. data/lib/generators/draft/resource/templates/views/update_row.html.erb +9 -0
  55. data/lib/generators/draft/scaffold/scaffold_controller_generator.rb +16 -0
  56. data/lib/generators/draft/scaffold/scaffold_erb_generator.rb +25 -0
  57. data/lib/generators/draft/scaffold/scaffold_generator.rb +15 -0
  58. data/lib/generators/draft/scaffold/templates/_card.html.erb +37 -0
  59. data/lib/generators/draft/scaffold/templates/_form.html.erb +44 -0
  60. data/lib/generators/draft/scaffold/templates/_list_item.html.erb +13 -0
  61. data/lib/generators/draft/scaffold/templates/_table_row.html.erb +23 -0
  62. data/lib/generators/draft/scaffold/templates/edit.html.erb +17 -0
  63. data/lib/generators/draft/scaffold/templates/index.html.erb +71 -0
  64. data/lib/generators/draft/scaffold/templates/new.html.erb +17 -0
  65. data/lib/generators/draft/scaffold/templates/show.html.erb +5 -0
  66. data/lib/rails_tag_service.rb +47 -0
  67. metadata +197 -0
@@ -0,0 +1,160 @@
1
+ <div class="row">
2
+ <div class="offset-md-3 col-md-6">
3
+ <div class="card mb-3">
4
+ <h5 class="card-header">
5
+ Edit <%= resource_name.to_s.titleize %>
6
+ </h5>
7
+
8
+ <div class="card-body">
9
+ <% was_validated = resource.errors.any? %>
10
+ <!-- Form html options start -->
11
+ <% form_html_options = { method: :put, novalidate: true, class: "mb-3" } %>
12
+ <!-- Form html options end -->
13
+ <%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: form_html_options) do |f| %>
14
+
15
+ <% if flash[:notice].present? %>
16
+ <div class="alert alert-info" role="alert">
17
+ <%= flash[:notice] %>
18
+ </div>
19
+ <% end %>
20
+
21
+ <% if flash[:alert].present? %>
22
+ <div class="alert alert-danger" role="alert">
23
+ <%= flash[:alert] %>
24
+ </div>
25
+ <% end %>
26
+
27
+ <div class="form-group">
28
+ <% email_was_invalid = resource.errors.include?(:email) %>
29
+
30
+ <% email_class = "form-control" %>
31
+
32
+ <% if was_validated %>
33
+ <% if email_was_invalid %>
34
+ <% email_class << " is-invalid" %>
35
+ <% else %>
36
+ <% email_class << " is-valid" %>
37
+ <% end %>
38
+ <% end %>
39
+
40
+ <%= f.label :email %>
41
+
42
+ <%= f.email_field :email, autofocus: true, class: email_class %>
43
+
44
+ <% if email_was_invalid %>
45
+ <% resource.errors.full_messages_for(:email).each do |message| %>
46
+ <div class="invalid-feedback d-flex">
47
+ <%= message %>
48
+ </div>
49
+ <% end %>
50
+ <% end %>
51
+
52
+ <% if devise_mapping.confirmable? && resource.pending_reconfirmation? %>
53
+ <small class="form-text text-muted">
54
+ Currently awaiting confirmation for <%= resource.unconfirmed_email %>.
55
+ </small>
56
+ <% end %>
57
+ </div>
58
+
59
+ <div class="form-group">
60
+ <% password_was_invalid = resource.errors.include?(:password) %>
61
+
62
+ <% password_class = "form-control" %>
63
+
64
+ <% if was_validated %>
65
+ <% if password_was_invalid %>
66
+ <% password_class << " is-invalid" %>
67
+ <% else %>
68
+ <% password_class << " is-valid" %>
69
+ <% end %>
70
+ <% end %>
71
+
72
+ <%= f.label :password %>
73
+
74
+ <%= f.password_field :password, class: password_class, autocomplete: "off" %>
75
+
76
+ <% if password_was_invalid %>
77
+ <% resource.errors.full_messages_for(:password).each do |message| %>
78
+ <div class="invalid-feedback d-flex">
79
+ <%= message %>
80
+ </div>
81
+ <% end %>
82
+ <% end %>
83
+
84
+ <small class="form-text text-muted">
85
+ Leave blank if you don't want to change it.
86
+
87
+ <% if @minimum_password_length %>
88
+ <%= @minimum_password_length %> characters minimum.
89
+ <% end %>
90
+ </small>
91
+ </div>
92
+
93
+ <div class="form-group">
94
+ <% password_confirmation_was_invalid = resource.errors.include?(:password_confirmation) %>
95
+
96
+ <% password_confirmation_class = "form-control" %>
97
+
98
+ <% if was_validated %>
99
+ <% if password_confirmation_was_invalid %>
100
+ <% password_confirmation_class << " is-invalid" %>
101
+ <% else %>
102
+ <% password_confirmation_class << " is-valid" %>
103
+ <% end %>
104
+ <% end %>
105
+
106
+ <%= f.label :password_confirmation %>
107
+
108
+ <%= f.password_field :password_confirmation, class: password_confirmation_class, autocomplete: "off" %>
109
+
110
+ <% if password_confirmation_was_invalid %>
111
+ <% resource.errors.full_messages_for(:password_confirmation).each do |message| %>
112
+ <div class="invalid-feedback d-flex">
113
+ <%= message %>
114
+ </div>
115
+ <% end %>
116
+ <% end %>
117
+ </div>
118
+
119
+ <div class="form-group">
120
+ <% current_password_was_invalid = resource.errors.include?(:current_password) %>
121
+
122
+ <% current_password_class = "form-control" %>
123
+
124
+ <% if was_validated %>
125
+ <% if current_password_was_invalid %>
126
+ <% current_password_class << " is-invalid" %>
127
+ <% else %>
128
+ <% current_password_class << " is-valid" %>
129
+ <% end %>
130
+ <% end %>
131
+
132
+ <%= f.label :current_password %>
133
+
134
+ <%= f.password_field :current_password, class: current_password_class, autocomplete: "off" %>
135
+
136
+ <% if current_password_was_invalid %>
137
+ <% resource.errors.full_messages_for(:current_password).each do |message| %>
138
+ <div class="invalid-feedback d-flex">
139
+ <%= message %>
140
+ </div>
141
+ <% end %>
142
+ <% end %>
143
+
144
+ <small class="form-text text-muted">
145
+ We need your current password to confirm your changes.
146
+ </small>
147
+ </div>
148
+
149
+ <%= f.submit "Update", class: "btn btn-block btn-outline-primary" %>
150
+ <% end %>
151
+
152
+ <%= link_to "Back", :back, class: "btn btn-block btn-outline-secondary" %>
153
+ </div>
154
+
155
+ <div class="card-footer">
156
+ <%= link_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?" }, class: "btn btn-block btn-link", method: :delete %>
157
+ </div>
158
+ </div>
159
+ </div>
160
+ </div>
@@ -0,0 +1,102 @@
1
+ <div class="row">
2
+ <div class="offset-md-3 col-md-6">
3
+ <div class="card mb-3">
4
+ <h5 class="card-header">
5
+ <%= resource_name != "user" ? resource_name.to_s.titleize : "" %> Sign Up
6
+ </h5>
7
+
8
+ <div class="card-body">
9
+ <% was_validated = resource.errors.any? %>
10
+ <!-- Form html options start -->
11
+ <% form_html_options = { novalidate: true, class: "mb-3" } %>
12
+ <!-- Form html options end -->
13
+ <%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: form_html_options) do |f| %>
14
+
15
+ <div class="form-group">
16
+ <% email_was_invalid = resource.errors.include?(:email) %>
17
+
18
+ <% email_class = "form-control" %>
19
+
20
+ <% if was_validated %>
21
+ <% if email_was_invalid %>
22
+ <% email_class << " is-invalid" %>
23
+ <% else %>
24
+ <% email_class << " is-valid" %>
25
+ <% end %>
26
+ <% end %>
27
+
28
+ <%= f.label :email %>
29
+
30
+ <%= f.email_field :email, class: email_class, autofocus: true %>
31
+
32
+ <% if email_was_invalid %>
33
+ <% resource.errors.full_messages_for(:email).each do |message| %>
34
+ <div class="invalid-feedback d-flex">
35
+ <%= message %>
36
+ </div>
37
+ <% end %>
38
+ <% end %>
39
+ </div>
40
+
41
+ <div class="form-group">
42
+ <% password_was_invalid = resource.errors.include?(:password) %>
43
+
44
+ <% password_class = "form-control" %>
45
+
46
+ <% if was_validated %>
47
+ <% if password_was_invalid %>
48
+ <% password_class << " is-invalid" %>
49
+ <% else %>
50
+ <% password_class << " is-valid" %>
51
+ <% end %>
52
+ <% end %>
53
+
54
+ <%= f.label :password %>
55
+
56
+ <%= f.password_field :password, class: password_class %>
57
+
58
+ <% if password_was_invalid %>
59
+ <% resource.errors.full_messages_for(:password).each do |message| %>
60
+ <div class="invalid-feedback d-flex">
61
+ <%= message %>
62
+ </div>
63
+ <% end %>
64
+ <% end %>
65
+ </div>
66
+
67
+ <div class="form-group">
68
+ <% password_confirmation_was_invalid = resource.errors.include?(:password_confirmation) %>
69
+
70
+ <% password_confirmation_class = "form-control" %>
71
+
72
+ <% if was_validated %>
73
+ <% if password_confirmation_was_invalid %>
74
+ <% password_confirmation_class << " is-invalid" %>
75
+ <% else %>
76
+ <% password_confirmation_class << " is-valid" %>
77
+ <% end %>
78
+ <% end %>
79
+
80
+ <%= f.label :password_confirmation %>
81
+
82
+ <%= f.password_field :password_confirmation, class: password_confirmation_class %>
83
+
84
+ <% if password_confirmation_was_invalid %>
85
+ <% resource.errors.full_messages_for(:password_confirmation).each do |message| %>
86
+ <div class="invalid-feedback d-flex">
87
+ <%= message %>
88
+ </div>
89
+ <% end %>
90
+ <% end %>
91
+ </div>
92
+
93
+ <%= f.button class: "btn btn-outline-primary btn-block" %>
94
+
95
+ <hr>
96
+
97
+ <%= render "devise/shared/links" %>
98
+ <% end %>
99
+ </div>
100
+ </div>
101
+ </div>
102
+ </div>
@@ -0,0 +1,51 @@
1
+ <div class="row">
2
+ <div class="offset-md-3 col-md-6">
3
+ <div class="card mb-3">
4
+ <h5 class="card-header">
5
+ <%= resource_name != "user" ? resource_name.to_s.titleize : "" %> Sign In
6
+ </h5>
7
+
8
+ <div class="card-body">
9
+ <% if flash[:notice].present? %>
10
+ <div class="alert alert-info" role="alert">
11
+ <%= flash[:notice] %>
12
+ </div>
13
+ <% end %>
14
+
15
+ <% if flash[:alert].present? %>
16
+ <div class="alert alert-danger" role="alert">
17
+ <%= flash[:alert] %>
18
+ </div>
19
+ <% end %>
20
+
21
+ <% form_html_options = { novalidate: true, class: "mb-3" } %>
22
+
23
+ <%= form_for(resource, as: resource_name, url: session_path(resource_name), html: form_html_options) do |f| %>
24
+ <div class="form-group">
25
+ <%= f.label :email %>
26
+ <%= f.email_field :email, autofocus: true, class: "form-control" %>
27
+ </div>
28
+
29
+ <div class="form-group">
30
+ <%= f.label :password %>
31
+ <%= f.password_field :password, autocomplete: "off", class: "form-control" %>
32
+ </div>
33
+
34
+ <% if devise_mapping.rememberable? -%>
35
+ <div class="form-check mb-3">
36
+ <%= f.label :remember_me, class: "form-check-label" do %>
37
+ <%= f.check_box :remember_me, class: "form-check-input" %> Remember me
38
+ <% end %>
39
+ </div>
40
+ <% end -%>
41
+
42
+ <%= f.submit "Sign in", class: "btn btn-outline-primary btn-block" %>
43
+
44
+ <hr>
45
+
46
+ <%= render "devise/shared/links" %>
47
+ <% end %>
48
+ </div>
49
+ </div>
50
+ </div>
51
+ </div>
@@ -0,0 +1,25 @@
1
+ <%- if devise_mapping.omniauthable? %>
2
+ <%- resource_class.omniauth_providers.each do |provider| %>
3
+ <%= link_to "Sign in with #{OmniAuth::Utils.camelize(provider)}", omniauth_authorize_path(resource_name, provider), class: "btn btn-block btn-outline-secondary" %>
4
+ <% end -%>
5
+ <% end -%>
6
+
7
+ <%- if controller_name != "sessions" %>
8
+ <%= link_to "Sign in", new_session_path(resource_name), class: "btn btn-block btn-outline-secondary" %>
9
+ <% end -%>
10
+
11
+ <%- if devise_mapping.registerable? && controller_name != "registrations" %>
12
+ <%= link_to "Sign up", new_registration_path(resource_name), class: "btn btn-block btn-outline-secondary" %>
13
+ <% end -%>
14
+
15
+ <%- if devise_mapping.recoverable? && controller_name != "passwords" && controller_name != "registrations" %>
16
+ <%= link_to "Forgot your password?", new_password_path(resource_name), class: "btn btn-block btn-sm btn-link" %>
17
+ <% end -%>
18
+
19
+ <%- if devise_mapping.confirmable? && controller_name != "confirmations" %>
20
+ <%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name), class: "btn btn-block btn-sm btn-link" %>
21
+ <% end -%>
22
+
23
+ <%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != "unlocks" %>
24
+ <%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name), class: "btn btn-block btn-sm btn-link" %>
25
+ <% end -%>
@@ -0,0 +1,49 @@
1
+ <div class="row">
2
+ <div class="offset-md-3 col-md-6">
3
+ <div class="card mb-3">
4
+ <h5 class="card-header">
5
+ Resend unlock instructions
6
+ </h5>
7
+
8
+ <div class="card-body">
9
+ <% was_validated = resource.errors.any? %>
10
+
11
+ <% form_html_options = { method: :post, novalidate: true, class: "mb-3" } %>
12
+
13
+ <%= form_for(resource, as: resource_name, url: unlock_path(resource_name), html: form_html_options) do |f| %>
14
+ <div class="form-group">
15
+ <% email_was_invalid = resource.errors.include?(:email) %>
16
+
17
+ <% email_class = "form-control" %>
18
+
19
+ <% if was_validated %>
20
+ <% if email_was_invalid %>
21
+ <% email_class << " is-invalid" %>
22
+ <% else %>
23
+ <% email_class << " is-valid" %>
24
+ <% end %>
25
+ <% end %>
26
+
27
+ <%= f.label :email %>
28
+
29
+ <%= f.email_field :email, class: email_class, autofocus: true %>
30
+
31
+ <% if email_was_invalid %>
32
+ <% resource.errors.full_messages_for(:email).each do |message| %>
33
+ <div class="invalid-feedback d-flex">
34
+ <%= message %>
35
+ </div>
36
+ <% end %>
37
+ <% end %>
38
+ </div>
39
+
40
+ <%= f.submit "Resend unlock instructions", class: "btn btn-outline-primary btn-block" %>
41
+
42
+ <hr>
43
+
44
+ <%= render "devise/shared/links" %>
45
+ <% end %>
46
+ </div>
47
+ </div>
48
+ </div>
49
+ </div>
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "generators/devise/views_generator"
4
+
5
+ module Draft
6
+ module Devise
7
+ class FormForGenerator < ::Devise::Generators::FormForGenerator
8
+ source_root File.expand_path("../templates", __FILE__)
9
+ class_option :with_sentinels, type: :boolean, default: false, desc: "Skip adding comments to generated files"
10
+
11
+ def generate_registrations
12
+ if with_sentinels?
13
+ view_directory :registrations_with_sentinels, "app/views/#{plural_scope}/registrations"
14
+ view_directory :mailer, "app/views/#{plural_scope}/mailer"
15
+ else
16
+ view_directory :registrations
17
+ end
18
+ end
19
+
20
+ def with_sentinels?
21
+ options[:with_sentinels]
22
+ end
23
+ end
24
+
25
+ class ViewsGenerator < ::Devise::Generators::ViewsGenerator
26
+ desc "Copies Draft Devise views to your application."
27
+ class_option :with_sentinels, type: :boolean, default: false, desc: "Skip adding comments to generated files"
28
+ class_option :views, aliases: "-v", type: :array, desc: "Select specific view directories to generate (confirmations, passwords, registrations, sessions, unlocks, mailer)"
29
+
30
+ remove_hook_for :form_builder
31
+
32
+ def form_builder
33
+ invoke Draft::Devise::FormForGenerator
34
+ end
35
+
36
+ def with_sentinels?
37
+ options[:with_sentinels]
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,49 @@
1
+ Description:
2
+
3
+ Generates a layout file with some handy utilities:
4
+
5
+ - Bootstrap (or a Bootswatch)
6
+ - Font Awesome
7
+ - A navbar with
8
+ - links to all detected index pages
9
+ - links to all detected registration and sign in forms
10
+ - Components to display flash notices and alerts
11
+ - A sticky footer
12
+
13
+ Specify "none" as the THEME_NAME to use vanilla Bootstrap; or, choose a
14
+ Bootswatch. As of this writing, available Bootswatches are:
15
+
16
+ - cerulean
17
+ - cosmo
18
+ - cyborg
19
+ - darkly
20
+ - flatly
21
+ - journal
22
+ - lumen
23
+ - none
24
+ - paper
25
+ - readable
26
+ - sandstone
27
+ - simplex
28
+ - slate
29
+ - spacelab
30
+ - superhero
31
+ - united
32
+ - yeti
33
+
34
+ WARNING: You will lose any modifications you've made to your current layout
35
+ if you choose to overwrite it. You can also specify a different filename
36
+ other than "application" with the --layout-file option.
37
+
38
+ Examples:
39
+
40
+ rails generate draft:layout
41
+
42
+ rails generate draft:layout --theme=paper
43
+
44
+ rails generate draft:layout --layout-file=some_other_filename
45
+
46
+ rails generate draft:layout --skip-cdn
47
+
48
+ (The last one omits links to CDN-hosted Bootstrap CSS, JS, and Font Awesome,
49
+ in case you are e.g. bundling them yourself using gems.)