firstdraft_generators 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +7 -0
  2. data/.document +5 -0
  3. data/.rspec +1 -0
  4. data/.rubocop.yml +637 -0
  5. data/Gemfile +14 -0
  6. data/Gemfile.lock +83 -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/firstdraft_generators.gemspec +85 -0
  12. data/lib/firstdraft_generators.rb +2 -0
  13. data/lib/generators/draft/layout/USAGE +49 -0
  14. data/lib/generators/draft/layout/layout_generator.rb +70 -0
  15. data/lib/generators/draft/layout/templates/_bootstrapcdn_assets.html.erb +9 -0
  16. data/lib/generators/draft/layout/templates/_flashes.html.erb +17 -0
  17. data/lib/generators/draft/layout/templates/_footer.html.erb +33 -0
  18. data/lib/generators/draft/layout/templates/_navbar.html.erb +61 -0
  19. data/lib/generators/draft/layout/templates/layout.html.erb +31 -0
  20. data/lib/generators/draft/model/USAGE +14 -0
  21. data/lib/generators/draft/model/model_generator.rb +33 -0
  22. data/lib/generators/draft/resource/USAGE +11 -0
  23. data/lib/generators/draft/resource/resource_generator.rb +162 -0
  24. data/lib/generators/draft/resource/templates/controllers/controller.rb +98 -0
  25. data/lib/generators/draft/resource/templates/controllers/read_only_controller.rb +9 -0
  26. data/lib/generators/draft/resource/templates/specs/crud_spec.rb +300 -0
  27. data/lib/generators/draft/resource/templates/specs/factories.rb +34 -0
  28. data/lib/generators/draft/resource/templates/views/create_row.html.erb +13 -0
  29. data/lib/generators/draft/resource/templates/views/destroy_row.html.erb +13 -0
  30. data/lib/generators/draft/resource/templates/views/edit_form.html.erb +54 -0
  31. data/lib/generators/draft/resource/templates/views/index.html.erb +62 -0
  32. data/lib/generators/draft/resource/templates/views/new_form.html.erb +54 -0
  33. data/lib/generators/draft/resource/templates/views/show.html.erb +46 -0
  34. data/lib/generators/draft/resource/templates/views/update_row.html.erb +9 -0
  35. metadata +151 -0
@@ -0,0 +1,34 @@
1
+ # Copy this file into your spec/support folder; create one if you don't have it.
2
+ # https://github.com/firstdraft/increasing_random/blob/master/increasing_random.rb
3
+
4
+ require Rails.root.join("spec", "support", "increasing_random.rb")
5
+
6
+ FactoryGirl.define do
7
+ factory :<%= singular_table_name %> do
8
+ sequence(:id, IncreasingRandom.new) { |n| n.value }
9
+ <% attributes.each do |attribute| -%>
10
+ <% case attribute.type -%>
11
+ <% when :belongs_to, :references -%>
12
+ association :<%= attribute.name %>
13
+ <% when :boolean -%>
14
+ <%= attribute.column_name %> false
15
+ <% when :date -%>
16
+ sequence(:<%= attribute.column_name %>, Date.today)
17
+ <% when :datetime -%>
18
+ <%= attribute.column_name %> Time.now
19
+ <% when :decimal -%>
20
+ <%= attribute.column_name %> 42.42
21
+ <% when :integer, :primary_key -%>
22
+ sequence(:<%= attribute.column_name %>, IncreasingRandom.new) { |n| n.value }
23
+ <% when :string, :text -%>
24
+ sequence(:<%= attribute.column_name %>, IncreasingRandom.new) { |n| "Some fake <%= attribute.human_name.downcase %> #{n}" }
25
+ <% when :time -%>
26
+ <%= attribute.column_name %> Time.now.beginning_of_day
27
+ <% when :timestamp -%>
28
+ <%= attribute.column_name %> Time.now
29
+ <% else -%>
30
+ sequence(:<%= attribute.column_name %>, IncreasingRandom.new) { |n| "Some fake <%= attribute.human_name.downcase %> #{n}" }
31
+ <% end -%>
32
+ <% end -%>
33
+ end
34
+ end
@@ -0,0 +1,13 @@
1
+ <h1>You created <%= singular_table_name.humanize.downcase %> #<%%= @<%= singular_table_name %>.id %>!</h1>
2
+
3
+ <p>
4
+ There are now <%%= @current_count %> <%= plural_table_name.humanize.downcase %>.
5
+ </p>
6
+
7
+ <p>
8
+ <a href="/<%= @plural_table_name.underscore %>">
9
+ Click here
10
+ </a>
11
+
12
+ to go back.
13
+ </p>
@@ -0,0 +1,13 @@
1
+ <h1>You deleted <%= singular_table_name.humanize.downcase %> #<%%= @<%= singular_table_name %>.id %>!</h1>
2
+
3
+ <p>
4
+ There are now <%%= @remaining_count %> <%= plural_table_name.humanize.downcase %>.
5
+ </p>
6
+
7
+ <p>
8
+ <a href="/<%= @plural_table_name.underscore %>">
9
+ Click here
10
+ </a>
11
+
12
+ to go back.
13
+ </p>
@@ -0,0 +1,54 @@
1
+ <% unless skip_validation_alerts? -%>
2
+ <!-- Validation failure messages -->
3
+ <%% if @<%= singular_table_name %>.errors.any? %>
4
+ <%% @<%= singular_table_name %>.errors.full_messages.each do |message| %>
5
+ <div class="alert alert-dismissable alert-danger">
6
+ <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
7
+
8
+ <%%= message %>
9
+ </div>
10
+ <%% end %>
11
+ <%% end %>
12
+
13
+ <% end -%>
14
+ <h1>
15
+ Edit <%= singular_table_name.humanize.downcase %> #<%%= @<%= singular_table_name %>.id %>
16
+ </h1>
17
+
18
+ <hr>
19
+
20
+ <form action="/update_<%= singular_table_name %>/<%%= @<%= singular_table_name %>.id %>"<% unless skip_post? -%> method="post"<% end -%>>
21
+ <% attributes.each do |attribute| -%>
22
+ <!-- Label and input for <%= attribute.column_name %> -->
23
+ <% if attribute.field_type == :check_box -%>
24
+ <div class="checkbox">
25
+ <label for="<%= attribute.column_name %>">
26
+ <input type="checkbox" id="<%= attribute.column_name %>" name="<%= attribute.column_name %>" value="1" <%%= "checked" if @<%= singular_table_name %>.<%= attribute.column_name %> %>>
27
+ <%= attribute.column_name.humanize %>
28
+ </label>
29
+ </div>
30
+ <% else -%>
31
+ <div class="form-group">
32
+ <label for="<%= attribute.column_name %>" class="control-label">
33
+ <%= attribute.column_name.humanize %>
34
+ </label>
35
+
36
+ <% if attribute.field_type == :text_area -%>
37
+ <textarea id="<%= attribute.column_name %>" name="<%= attribute.column_name %>" class="form-control" rows="3"><%%= @<%= singular_table_name %>.<%= attribute.column_name %> %></textarea>
38
+ <% else -%>
39
+ <input type="text" id="<%= attribute.column_name %>" name="<%= attribute.column_name %>" class="form-control" value="<%%= @<%= singular_table_name %>.<%= attribute.column_name %> %>">
40
+ <% end -%>
41
+ </div>
42
+ <% end -%>
43
+
44
+ <% end -%>
45
+ <button class="btn btn-default">
46
+ Update <%= singular_table_name.humanize.downcase %>
47
+ </button>
48
+ </form>
49
+
50
+ <hr>
51
+
52
+ <a href="/<%= plural_table_name %>">
53
+ Go back
54
+ </a>
@@ -0,0 +1,62 @@
1
+ <h1>
2
+ All <%= plural_table_name.humanize.downcase %>
3
+ </h1>
4
+
5
+ <a href="/<%= plural_table_name %>/new">
6
+ Add a new <%= singular_table_name.humanize.downcase %>
7
+ </a>
8
+
9
+ <hr>
10
+
11
+ <table class="table">
12
+ <tr>
13
+ <th>
14
+ ID
15
+ </th>
16
+
17
+ <% attributes.each do |attribute| -%>
18
+ <th>
19
+ <%= attribute.human_name %>
20
+ </th>
21
+
22
+ <% end -%>
23
+ <th>
24
+ Created at
25
+ </th>
26
+
27
+ <th>
28
+ Updated at
29
+ </th>
30
+
31
+ <th>
32
+ </th>
33
+ </tr>
34
+
35
+ <%% @<%= plural_table_name %>.each do |<%= singular_table_name %>| %>
36
+ <tr>
37
+ <td>
38
+ <%%= <%= singular_table_name %>.id %>
39
+ </td>
40
+
41
+ <% attributes.each do |attribute| -%>
42
+ <td>
43
+ <%%= <%= singular_table_name %>.<%= attribute.column_name %> %>
44
+ </td>
45
+
46
+ <% end -%>
47
+ <td>
48
+ <%%= time_ago_in_words(<%= singular_table_name %>.created_at) %> ago
49
+ </td>
50
+
51
+ <td>
52
+ <%%= time_ago_in_words(<%= singular_table_name %>.updated_at) %> ago
53
+ </td>
54
+
55
+ <td>
56
+ <a href="/<%= plural_table_name %>/<%%= <%= singular_table_name %>.id %>">
57
+ Show details
58
+ </a>
59
+ </td>
60
+ </tr>
61
+ <%% end %>
62
+ </table>
@@ -0,0 +1,54 @@
1
+ <% unless skip_validation_alerts? -%>
2
+ <!-- Validation failure messages -->
3
+ <%% if @<%= singular_table_name %>.errors.any? %>
4
+ <%% @<%= singular_table_name %>.errors.full_messages.each do |message| %>
5
+ <div class="alert alert-dismissable alert-danger">
6
+ <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
7
+
8
+ <%%= message %>
9
+ </div>
10
+ <%% end %>
11
+ <%% end %>
12
+
13
+ <% end -%>
14
+ <h1>
15
+ Add a new <%= singular_table_name.humanize.downcase %>
16
+ </h1>
17
+
18
+ <hr>
19
+
20
+ <form action="/create_<%= singular_table_name %>"<% unless skip_post? -%> method="post"<% end -%>>
21
+ <% attributes.each do |attribute| -%>
22
+ <!-- Label and input for <%= attribute.column_name %> -->
23
+ <% if attribute.field_type == :check_box -%>
24
+ <div class="checkbox">
25
+ <label for="<%= attribute.column_name %>">
26
+ <input type="checkbox" id="<%= attribute.column_name %>" name="<%= attribute.column_name %>" <% unless skip_validation_alerts? -%><%%= "checked" if @<%= singular_table_name %>.<%= attribute.column_name %> %><% end -%>>
27
+ <%= attribute.column_name.humanize %>
28
+ </label>
29
+ </div>
30
+ <% else -%>
31
+ <div class="form-group">
32
+ <label for="<%= attribute.column_name %>" class="control-label">
33
+ <%= attribute.column_name.humanize %>
34
+ </label>
35
+
36
+ <% if attribute.field_type == :text_area -%>
37
+ <textarea id="<%= attribute.column_name %>" name="<%= attribute.column_name %>" class="form-control" rows="3"><% unless skip_validation_alerts? -%><%%= @<%= singular_table_name %>.<%= attribute.column_name %> %><% end -%></textarea>
38
+ <% else -%>
39
+ <input type="text" id="<%= attribute.column_name %>" name="<%= attribute.column_name %>" class="form-control"<% unless skip_validation_alerts? -%> value="<%%= @<%= singular_table_name %>.<%= attribute.column_name %> %>"<% end -%>>
40
+ <% end -%>
41
+ </div>
42
+ <% end -%>
43
+
44
+ <% end -%>
45
+ <button class="btn btn-default">
46
+ Create <%= singular_table_name.humanize.downcase %>
47
+ </button>
48
+ </form>
49
+
50
+ <hr>
51
+
52
+ <a href="/<%= plural_table_name %>">
53
+ Go back
54
+ </a>
@@ -0,0 +1,46 @@
1
+ <h1>
2
+ <%= singular_table_name.humanize %> #<%%= @<%= singular_table_name %>.id %> details
3
+ </h1>
4
+
5
+ <a href="/<%= plural_table_name %>/<%%= @<%= singular_table_name %>.id %>/edit">
6
+ Edit <%= singular_table_name.humanize.downcase %>
7
+ </a>
8
+
9
+ <hr>
10
+
11
+ <dl>
12
+ <% attributes.each do |attribute| -%>
13
+ <dt>
14
+ <%= attribute.human_name %>
15
+ </dt>
16
+ <dd>
17
+ <%%= @<%= singular_table_name %>.<%= attribute.column_name %> %>
18
+ </dd>
19
+
20
+ <% end -%>
21
+ <dt>
22
+ Created at
23
+ </dt>
24
+ <dd>
25
+ <%%= time_ago_in_words(@<%= singular_table_name %>.created_at) %> ago
26
+ </dd>
27
+
28
+ <dt>
29
+ Updated at
30
+ </dt>
31
+ <dd>
32
+ <%%= time_ago_in_words(@<%= singular_table_name %>.updated_at) %> ago
33
+ </dd>
34
+ </dl>
35
+
36
+ <% unless read_only? -%>
37
+ <a href="/delete_<%= singular_table_name %>/<%%= @<%= singular_table_name %>.id %>" class="btn btn-default">
38
+ Delete <%= singular_table_name.humanize.downcase %>
39
+ </a>
40
+ <% end -%>
41
+
42
+ <hr>
43
+
44
+ <a href="/<%= plural_table_name %>">
45
+ Go back
46
+ </a>
@@ -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>
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: firstdraft_generators
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Raghu Betina
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-05-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 3.5.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 3.5.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rdoc
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: juwelier
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 2.1.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 2.1.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: This is a set of generators that help beginners learn to program. Primarily,
84
+ they generate code that is more explicit and verbose and less idiomatic and “magical”
85
+ than the built-in scaffold generator, which is helpful for beginners while they
86
+ are learning how exactly things are wired together.
87
+ email: raghu@firstdraft.com
88
+ executables: []
89
+ extensions: []
90
+ extra_rdoc_files:
91
+ - LICENSE.txt
92
+ - README.markdown
93
+ files:
94
+ - ".document"
95
+ - ".rspec"
96
+ - ".rubocop.yml"
97
+ - Gemfile
98
+ - Gemfile.lock
99
+ - LICENSE.txt
100
+ - README.markdown
101
+ - Rakefile
102
+ - VERSION
103
+ - firstdraft_generators.gemspec
104
+ - lib/firstdraft_generators.rb
105
+ - lib/generators/draft/layout/USAGE
106
+ - lib/generators/draft/layout/layout_generator.rb
107
+ - lib/generators/draft/layout/templates/_bootstrapcdn_assets.html.erb
108
+ - lib/generators/draft/layout/templates/_flashes.html.erb
109
+ - lib/generators/draft/layout/templates/_footer.html.erb
110
+ - lib/generators/draft/layout/templates/_navbar.html.erb
111
+ - lib/generators/draft/layout/templates/layout.html.erb
112
+ - lib/generators/draft/model/USAGE
113
+ - lib/generators/draft/model/model_generator.rb
114
+ - lib/generators/draft/resource/USAGE
115
+ - lib/generators/draft/resource/resource_generator.rb
116
+ - lib/generators/draft/resource/templates/controllers/controller.rb
117
+ - lib/generators/draft/resource/templates/controllers/read_only_controller.rb
118
+ - lib/generators/draft/resource/templates/specs/crud_spec.rb
119
+ - lib/generators/draft/resource/templates/specs/factories.rb
120
+ - lib/generators/draft/resource/templates/views/create_row.html.erb
121
+ - lib/generators/draft/resource/templates/views/destroy_row.html.erb
122
+ - lib/generators/draft/resource/templates/views/edit_form.html.erb
123
+ - lib/generators/draft/resource/templates/views/index.html.erb
124
+ - lib/generators/draft/resource/templates/views/new_form.html.erb
125
+ - lib/generators/draft/resource/templates/views/show.html.erb
126
+ - lib/generators/draft/resource/templates/views/update_row.html.erb
127
+ homepage: http://github.com/raghubetina/firstdraft_generators
128
+ licenses:
129
+ - MIT
130
+ metadata: {}
131
+ post_install_message:
132
+ rdoc_options: []
133
+ require_paths:
134
+ - lib
135
+ required_ruby_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ required_rubygems_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ requirements: []
146
+ rubyforge_project:
147
+ rubygems_version: 2.6.11
148
+ signing_key:
149
+ specification_version: 4
150
+ summary: Generators that help beginners learn to program.
151
+ test_files: []