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,90 @@
1
+ <div class="row mb-3">
2
+ <div class="col-md-8 offset-md-2">
3
+ <h1>
4
+ <%= singular_table_name.humanize %> #<%%= @<%= singular_table_name %>.id %> details
5
+ </h1>
6
+
7
+ <div class="row mb-3">
8
+ <div class="col">
9
+ <a href="/<%= plural_table_name %>" class="btn btn-block btn-outline-secondary">
10
+ Go back
11
+ </a>
12
+ </div>
13
+
14
+ <% if with_sentinels? -%>
15
+ <!-- Edit link <%= singular_table_name %> start -->
16
+ <% end -%>
17
+ <div class="col">
18
+ <a href="/<%= plural_table_name %>/<%%= @<%= singular_table_name %>.id %>/edit" class="btn btn-block btn-outline-secondary">
19
+ Edit <%= singular_table_name.humanize.downcase %>
20
+ </a>
21
+ </div>
22
+ <% if with_sentinels? -%>
23
+ <!-- Edit link <%= singular_table_name %> end -->
24
+ <% end -%>
25
+
26
+ <% unless read_only? -%>
27
+ <% if with_sentinels? -%>
28
+ <!-- Delete link <%= singular_table_name %> start -->
29
+ <% end -%>
30
+ <div class="col">
31
+ <a href="/delete_<%= singular_table_name %>/<%%= @<%= singular_table_name %>.id %>" class="btn btn-block btn-outline-secondary">
32
+ Delete <%= singular_table_name.humanize.downcase %>
33
+ </a>
34
+ </div>
35
+ <% if with_sentinels? -%>
36
+ <!-- Delete link <%= singular_table_name %> end -->
37
+ <% end -%>
38
+ <% end -%>
39
+ </div>
40
+
41
+ <dl>
42
+ <% attributes.each do |attribute| -%>
43
+ <dt>
44
+ <%= attribute.human_name %>
45
+ </dt>
46
+ <% if with_sentinels? -%>
47
+ <!-- Display <%= attribute.column_name %> start -->
48
+ <% end -%>
49
+ <dd>
50
+ <%%= @<%= singular_table_name %>.<%= attribute.column_name %> %>
51
+ </dd>
52
+ <% if with_sentinels? -%>
53
+ <!-- Display <%= attribute.column_name %> end -->
54
+ <% end -%>
55
+
56
+ <% end -%>
57
+ <dt>
58
+ Created at
59
+ </dt>
60
+ <% if with_sentinels? -%>
61
+ <!-- Display created_at start -->
62
+ <% end -%>
63
+ <dd>
64
+ <%%= time_ago_in_words(@<%= singular_table_name %>.created_at) %> ago
65
+ </dd>
66
+ <% if with_sentinels? -%>
67
+ <!-- Display created_at end -->
68
+ <% end -%>
69
+
70
+ <dt>
71
+ Updated at
72
+ </dt>
73
+ <% if with_sentinels? -%>
74
+ <!-- Display updated_at start -->
75
+ <% end -%>
76
+ <dd>
77
+ <%%= time_ago_in_words(@<%= singular_table_name %>.updated_at) %> ago
78
+ </dd>
79
+ <% if with_sentinels? -%>
80
+ <!-- Display updated_at end -->
81
+ <% end -%>
82
+ </dl>
83
+ </div>
84
+ </div>
85
+
86
+ <% if with_sentinels? -%>
87
+ <!-- Show Page Customization starts -->
88
+
89
+ <!-- Show Page Customization end -->
90
+ <% end -%>
@@ -0,0 +1,9 @@
1
+ <h1>You updated <%= singular_table_name.humanize.downcase %> #<%%= @<%= singular_table_name %>.id %>!</h1>
2
+
3
+ <p>
4
+ <a href="/<%= plural_table_name.underscore %>/<%%= @<%= singular_table_name.underscore %>.id %>">
5
+ Click here
6
+ </a>
7
+
8
+ to check it out.
9
+ </p>
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "generators/draft/scaffold/scaffold_erb_generator"
4
+ require "rails/generators/rails/scaffold_controller/scaffold_controller_generator"
5
+
6
+ module Draft
7
+ class ScaffoldControllerGenerator < ::Rails::Generators::ScaffoldControllerGenerator
8
+ source_root Rails::Generators::ScaffoldControllerGenerator.source_root
9
+
10
+ remove_hook_for :template_engine
11
+
12
+ def generate_views
13
+ invoke Draft::ScaffoldErbGenerator
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/generators/erb/scaffold/scaffold_generator"
4
+
5
+ module Draft
6
+ class ScaffoldErbGenerator < Erb::Generators::ScaffoldGenerator
7
+ source_root File.expand_path("../templates", __FILE__)
8
+
9
+ def copy_view_files
10
+ available_views.each do |view|
11
+ template view, File.join("app/views", controller_file_path, view)
12
+ end
13
+ end
14
+
15
+ protected
16
+
17
+ def available_views
18
+ base = self.class.source_root
19
+ base_len = base.length + 1
20
+ Dir[File.join(base, "**", "*")].
21
+ select { |f| File.file?(f) }.
22
+ map { |f| f[base_len..-1] }
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "generators/draft/scaffold/scaffold_controller_generator"
4
+ require "rails/generators/rails/scaffold/scaffold_generator"
5
+
6
+ module Draft
7
+ class ScaffoldGenerator < ::Rails::Generators::ScaffoldGenerator
8
+ remove_hook_for :scaffold_controller
9
+ remove_hook_for :assets
10
+
11
+ def generate_controller
12
+ invoke Draft::ScaffoldControllerGenerator
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,37 @@
1
+ <div class="card mb-3">
2
+ <h2 class="card-header h4">
3
+ <%= singular_table_name.titlecase %> #<%%= <%= singular_table_name %>.id %>
4
+ </h2>
5
+
6
+ <div class="card-body">
7
+ <dl class="mb-1">
8
+ <% attributes.reject(&:password_digest?).each do |attribute| -%>
9
+ <dt><%= attribute.human_name %></dt>
10
+ <dd><%%= <%= singular_table_name %>.<%= attribute.name %> %></dd>
11
+
12
+ <% end -%>
13
+ </dl>
14
+
15
+ <div class="row">
16
+ <div class="col">
17
+ <%%= link_to_show_or_back <%= singular_table_name %>, '<i class="fas fa-search-plus"></i>'.html_safe, '<i class="fas fa-chevron-left"></i>'.html_safe, class: "btn btn-block btn-outline-secondary" %>
18
+ </div>
19
+
20
+ <div class="col">
21
+ <%%= link_to edit_<%= singular_table_name %>_url(<%= singular_table_name %>), class: "btn btn-block btn-outline-secondary" do %>
22
+ <i class="fas fa-edit"></i>
23
+ <%% end %>
24
+ </div>
25
+
26
+ <div class="col">
27
+ <%%= link_to <%= singular_table_name %>, method: :delete, data: { confirm: "Do you really want to delete this <%= singular_table_name %>?" }, class: "btn btn-block btn-outline-secondary" do %>
28
+ <i class="fas fa-trash-alt"></i>
29
+ <%% end %>
30
+ </div>
31
+ </div>
32
+ </div>
33
+
34
+ <div class="card-footer text-muted">
35
+ Last updated <%%= time_ago_in_words(<%= singular_table_name %>.updated_at) %> ago
36
+ </div>
37
+ </div>
@@ -0,0 +1,44 @@
1
+ <%% was_validated = <%= singular_table_name %>.errors.any? %>
2
+
3
+ <%% form_html_options = { novalidate: true, class: "mb-3" } %>
4
+
5
+ <%%= form_for(<%= singular_table_name %>, html: form_html_options) do |f| %>
6
+ <% attributes.each do |attribute| -%>
7
+ <% if attribute.field_type == :check_box -%>
8
+ <div class="form-check">
9
+ <%% <%= attribute.name %>_class = "form-check-input" %>
10
+ <% else -%>
11
+ <div class="form-group">
12
+ <%% <%= attribute.name %>_class = "form-control" %>
13
+ <% end -%>
14
+ <%% <%= attribute.name %>_was_invalid = <%= singular_table_name %>.errors.include?(:<%= attribute.name %>) %>
15
+
16
+ <%% if was_validated %>
17
+ <%% if <%= attribute.name %>_was_invalid %>
18
+ <%% <%= attribute.name %>_class << " is-invalid" %>
19
+ <%% else %>
20
+ <%% <%= attribute.name %>_class << " is-valid" %>
21
+ <%% end %>
22
+ <%% end %>
23
+
24
+ <% if attribute.field_type == :check_box -%>
25
+ <%%= f.label :<%= attribute.name %>, class: "form-check-label" do %>
26
+ <%%= f.check_box :<%= attribute.name %>, class: <%= attribute.name %>_class %> <%= attribute.name.humanize %>
27
+ <%% end %>
28
+ <% else -%>
29
+ <%%= f.label :<%= attribute.name %> %>
30
+
31
+ <%%= f.<%= attribute.field_type %> :<%= attribute.name %>, class: <%= attribute.name %>_class, placeholder: "Enter <%= attribute.name.humanize.downcase %>" %>
32
+ <% end -%>
33
+ <%% if <%= attribute.name %>_was_invalid %>
34
+ <%% <%= singular_table_name %>.errors.full_messages_for(:<%= attribute.name %>).each do |message| %>
35
+ <div class="invalid-feedback d-flex">
36
+ <%%= message %>
37
+ </div>
38
+ <%% end %>
39
+ <%% end %>
40
+ </div>
41
+
42
+ <% end -%>
43
+ <%%= f.button class: "btn btn-outline-secondary btn-block" %>
44
+ <%% end %>
@@ -0,0 +1,13 @@
1
+ <%%= link_to <%= singular_table_name %>, class: "list-group-item list-group-item-action d-flex align-items-center justify-content-between" do %>
2
+ <div>
3
+ <%= singular_table_name.titlecase %> #<%%= <%= singular_table_name %>.id %>
4
+
5
+ <small class="text-muted">
6
+ <%%= time_ago_in_words(<%= singular_table_name %>.updated_at) %> ago
7
+ </small>
8
+ </div>
9
+
10
+ <span class="btn btn-sm btn-outline-secondary">
11
+ <i class="fas fa-chevron-right fa-fw"></i>
12
+ </span>
13
+ <%% end %>
@@ -0,0 +1,23 @@
1
+ <tr>
2
+ <% attributes.reject(&:password_digest?).each do |attribute| -%>
3
+ <td>
4
+ <%%= <%= singular_table_name %>.<%= attribute.name %> %>
5
+ </td>
6
+
7
+ <% end -%>
8
+ <td>
9
+ <div class="btn-group">
10
+ <%%= link_to <%= singular_table_name %>, class: "btn btn-sm btn-outline-secondary" do %>
11
+ <i class="fas fa-search-plus fa-fw"></i>
12
+ <%% end %>
13
+
14
+ <%%= link_to edit_<%= singular_table_name %>_url(<%= singular_table_name %>), class: "btn btn-sm btn-outline-secondary" do %>
15
+ <i class="fas fa-edit fa-fw"></i>
16
+ <%% end %>
17
+
18
+ <%%= link_to <%= singular_table_name %>, method: :delete, data: { confirm: "Do you really want to delete this <%= singular_table_name %>?" }, class: "btn btn-sm btn-outline-secondary" do %>
19
+ <i class="fas fa-trash-alt fa-fw"></i>
20
+ <%% end %>
21
+ </div>
22
+ </td>
23
+ </tr>
@@ -0,0 +1,17 @@
1
+ <div class="row justify-content-center mb-3">
2
+ <div class="col-md-8">
3
+ <div class="card">
4
+ <h2 class="card-header h4">
5
+ Edit <%= singular_table_name.titlecase %> #<%%= @<%= singular_table_name %>.id %>
6
+ </h2>
7
+
8
+ <div class="card-body">
9
+ <%%= render "form", <%= singular_table_name %>: @<%= singular_table_name %> %>
10
+
11
+ <%%= link_to :back, class: "btn btn-block btn-outline-secondary" do %>
12
+ <i class="fas fa-chevron-left fa-fw"></i>
13
+ <%% end %>
14
+ </div>
15
+ </div>
16
+ </div>
17
+ </div>
@@ -0,0 +1,71 @@
1
+ <div class="row mb-3">
2
+ <div class="col-md-12">
3
+ <h1 class="display-4">
4
+ <%= plural_table_name.titlecase %>
5
+
6
+ <%%= link_to new_<%= singular_table_name %>_path, class: "btn btn-lg btn-outline-secondary" do %>
7
+ <i class="fas fa-plus fa-fw"></i>
8
+ <%% end %>
9
+ </h1>
10
+ </div>
11
+ </div>
12
+
13
+ <!-- Table example -->
14
+
15
+ <div class="row">
16
+ <div class="col-md-12">
17
+ <div class="table-responsive">
18
+ <table class="table table-striped">
19
+ <thead>
20
+ <tr>
21
+ <% attributes.reject(&:password_digest?).each do |attribute| -%>
22
+ <th>
23
+ <%= attribute.human_name %>
24
+ </th>
25
+
26
+ <% end -%>
27
+ <th>
28
+ Actions
29
+ </th>
30
+ </tr>
31
+ </thead>
32
+
33
+ <tbody>
34
+ <%%= render collection: @<%= plural_table_name %>, partial: "table_row", as: :<%= singular_table_name %> %>
35
+ </tbody>
36
+ </table>
37
+ </div>
38
+ </div>
39
+ </div>
40
+
41
+ <!-- Card deck example -->
42
+
43
+ <%% @<%= plural_table_name %>.each_slice(3) do |slice| %>
44
+ <div class="row">
45
+ <div class="col-md-12">
46
+ <div class="card-deck">
47
+ <%%= render collection: slice, partial: "card", as: :<%= singular_table_name %> %>
48
+ </div>
49
+ </div>
50
+ </div>
51
+ <%% end %>
52
+
53
+ <!-- List group example -->
54
+
55
+ <div class="row justify-content-center mb-3">
56
+ <div class="col-md-8">
57
+ <div class="card">
58
+ <h1 class="card-header h4 d-flex align-items-center justify-content-between">
59
+ <%= plural_table_name.titlecase %>
60
+
61
+ <%%= link_to new_<%= singular_table_name %>_path, class: "btn btn-sm btn-outline-secondary" do %>
62
+ <i class="fas fa-plus fa-fw"></i>
63
+ <%% end %>
64
+ </h1>
65
+
66
+ <div class="list-group list-group-flush">
67
+ <%%= render collection: @<%= plural_table_name %>, partial: "list_item", as: :<%= singular_table_name %> %>
68
+ </div>
69
+ </div>
70
+ </div>
71
+ </div>
@@ -0,0 +1,17 @@
1
+ <div class="row justify-content-center mb-3">
2
+ <div class="col-md-8">
3
+ <div class="card">
4
+ <h2 class="card-header h4">
5
+ New <%= singular_table_name.titlecase %>
6
+ </h2>
7
+
8
+ <div class="card-body">
9
+ <%%= render "form", <%= singular_table_name %>: @<%= singular_table_name %> %>
10
+
11
+ <%%= link_to :back, class: "btn btn-block btn-outline-secondary" do %>
12
+ <i class="fas fa-chevron-left fa-fw"></i>
13
+ <%% end %>
14
+ </div>
15
+ </div>
16
+ </div>
17
+ </div>
@@ -0,0 +1,5 @@
1
+ <div class="row justify-content-center mb-3">
2
+ <div class="col-md-8">
3
+ <%%= render object: @<%= singular_table_name %>, partial: "card", as: :<%= singular_table_name %> %>
4
+ </div>
5
+ </div>
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DraftGenerators
4
+ class RailsTagService
5
+ def self.text_input(field_name)
6
+ %{<%= f.text_field :#{field_name}, :class => #{field_name}_class, :placeholder => "Enter #{field_name.gsub("_", " ")}" %>}
7
+ end
8
+
9
+ def self.text_area_input(field_name)
10
+ %{<%= f.text_area :#{field_name}, :class => #{field_name}_class, :placeholder => "Enter #{field_name.gsub("_", " ")}" %>}
11
+ end
12
+
13
+ def self.number_field(field_name)
14
+ %{<%= f.number_field :#{field_name}, :class => #{field_name}_class, :placeholder => "Enter #{field_name.gsub("_", " ")}" %>}
15
+ end
16
+
17
+ def self.date_select(field_name)
18
+ %{<%= f.date_select :#{field_name}, class: "\#\{#{field_name}_class\} col-sm-2" %>}
19
+ end
20
+
21
+ def self.datetime_select(field_name)
22
+ %{<%= f.datetime_select :#{field_name}, class: "\#\{#{field_name}_class\} col-sm-2" %>}
23
+ end
24
+
25
+ def self.check_box(field_name)
26
+ %{<%= f.check_box :#{field_name}, class: "\#\{#{field_name}_class\} col-sm-2" %>}
27
+ end
28
+
29
+ def self.time_select(field_name)
30
+ %{<%= f.time_select :#{field_name}, class: "\#\{#{field_name}_class\} col-sm-2" %>}
31
+ end
32
+
33
+ def self.input_tag(column)
34
+ name = column.name
35
+ case column.type.to_s
36
+ when "datetime"; datetime_select(name)
37
+ when "date"; date_select(name)
38
+ when "time"; time_select(name)
39
+ when "boolean"; check_box(name)
40
+ when "text"; text_area_input(name)
41
+ when "decimal", "integer"; number_field(name)
42
+ else
43
+ text_input(name)
44
+ end
45
+ end
46
+ end
47
+ end