el_generators 0.0.4 → 0.0.5

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.
@@ -1,3 +1,3 @@
1
1
  module ElGenerators
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate el_scaffold Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,12 @@
1
+ class ElScaffoldGenerator < Rails::Generators::Base
2
+ source_root File.expand_path('../templates', __FILE__)
3
+
4
+ def copy_templates
5
+ copy_file "erb/scaffold/_form.html.erb", "lib/templates/erb/scaffold/_form.html.erb"
6
+ copy_file "erb/scaffold/edit.html.erb", "lib/templates/erb/scaffold/edit.html.erb"
7
+ copy_file "erb/scaffold/index.html.erb", "lib/templates/erb/scaffold/index.html.erb"
8
+ copy_file "erb/scaffold/new.html.erb", "lib/templates/erb/scaffold/new.html.erb"
9
+ copy_file "erb/scaffold/show.html.erb", "lib/templates/erb/scaffold/show.html.erb"
10
+ copy_file "rails/scaffold_controller/controller.rb", "lib/templates/rails/scaffold_controller/controller.rb"
11
+ end
12
+ end
@@ -0,0 +1,23 @@
1
+ <%%= form_for(@<%= singular_table_name %>) do |f| %>
2
+ <%% if @<%= singular_table_name %>.errors.any? %>
3
+ <div id="error_explanation">
4
+ <h2><%%= pluralize(@<%= singular_table_name %>.errors.count, "error") %> prohibited this <%= singular_table_name %> from being saved:</h2>
5
+
6
+ <ul>
7
+ <%% @<%= singular_table_name %>.errors.full_messages.each do |msg| %>
8
+ <li><%%= msg %></li>
9
+ <%% end %>
10
+ </ul>
11
+ </div>
12
+ <%% end %>
13
+
14
+ <% attributes.each do |attribute| -%>
15
+ <div class="field">
16
+ <%%= f.label :<%= attribute.name %> %><br />
17
+ <%%= f.<%= attribute.field_type %> :<%= attribute.name %> %>
18
+ </div>
19
+ <% end -%>
20
+ <div class="actions">
21
+ <%%= f.submit %>
22
+ </div>
23
+ <%% end %>
@@ -0,0 +1,6 @@
1
+ <h1>Editing <%= singular_table_name %></h1>
2
+
3
+ <%%= render 'form' %>
4
+
5
+ <%%= link_to 'Show', @<%= singular_table_name %> %> |
6
+ <%%= link_to 'Back', <%= index_helper %>_path %>
@@ -0,0 +1,27 @@
1
+ <h1>Listing <%= plural_table_name %></h1>
2
+
3
+ <table>
4
+ <tr>
5
+ <% attributes.each do |attribute| -%>
6
+ <th><%= attribute.human_name %></th>
7
+ <% end -%>
8
+ <th></th>
9
+ <th></th>
10
+ <th></th>
11
+ </tr>
12
+
13
+ <%% @<%= plural_table_name %>.each do |<%= singular_table_name %>| %>
14
+ <tr>
15
+ <% attributes.each do |attribute| -%>
16
+ <td><%%= <%= singular_table_name %>.<%= attribute.name %> %></td>
17
+ <% end -%>
18
+ <td><%%= link_to 'Show', <%= singular_table_name %> %></td>
19
+ <td><%%= link_to 'Edit', edit_<%= singular_table_name %>_path(<%= singular_table_name %>) %></td>
20
+ <td><%%= link_to 'Destroy', <%= singular_table_name %>, <%= key_value :confirm, "'Are you sure?'" %>, <%= key_value :method, ":delete" %> %></td>
21
+ </tr>
22
+ <%% end %>
23
+ </table>
24
+
25
+ <br />
26
+
27
+ <%%= link_to 'New <%= human_name %>', new_<%= singular_table_name %>_path %>
@@ -0,0 +1,5 @@
1
+ <h1>New <%= singular_table_name %></h1>
2
+
3
+ <%%= render 'form' %>
4
+
5
+ <%%= link_to 'Back', <%= index_helper %>_path %>
@@ -0,0 +1,12 @@
1
+ <p id="notice"><%%= notice %></p>
2
+
3
+ <% attributes.each do |attribute| -%>
4
+ <p>
5
+ <b><%= attribute.human_name %>:</b>
6
+ <%%= @<%= singular_table_name %>.<%= attribute.name %> %>
7
+ </p>
8
+
9
+ <% end -%>
10
+
11
+ <%%= link_to 'Edit', edit_<%= singular_table_name %>_path(@<%= singular_table_name %>) %> |
12
+ <%%= link_to 'Back', <%= index_helper %>_path %>
@@ -0,0 +1,85 @@
1
+ <% module_namespacing do -%>
2
+ class <%= controller_class_name %>Controller < ApplicationController
3
+ # GET <%= route_url %>
4
+ # GET <%= route_url %>.json
5
+ def index
6
+ @<%= plural_table_name %> = <%= orm_class.all(class_name) %>
7
+
8
+ respond_to do |format|
9
+ format.html # index.html.erb
10
+ format.json { render <%= key_value :json, "@#{plural_table_name}" %> }
11
+ end
12
+ end
13
+
14
+ # GET <%= route_url %>/1
15
+ # GET <%= route_url %>/1.json
16
+ def show
17
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
18
+
19
+ respond_to do |format|
20
+ format.html # show.html.erb
21
+ format.json { render <%= key_value :json, "@#{singular_table_name}" %> }
22
+ end
23
+ end
24
+
25
+ # GET <%= route_url %>/new
26
+ # GET <%= route_url %>/new.json
27
+ def new
28
+ @<%= singular_table_name %> = <%= orm_class.build(class_name) %>
29
+
30
+ respond_to do |format|
31
+ format.html # new.html.erb
32
+ format.json { render <%= key_value :json, "@#{singular_table_name}" %> }
33
+ end
34
+ end
35
+
36
+ # GET <%= route_url %>/1/edit
37
+ def edit
38
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
39
+ end
40
+
41
+ # POST <%= route_url %>
42
+ # POST <%= route_url %>.json
43
+ def create
44
+ @<%= singular_table_name %> = <%= orm_class.build(class_name, "params[:#{singular_table_name}]") %>
45
+
46
+ respond_to do |format|
47
+ if @<%= orm_instance.save %>
48
+ format.html { redirect_to @<%= singular_table_name %>, <%= key_value :notice, "'#{human_name} was successfully created.'" %> }
49
+ format.json { render <%= key_value :json, "@#{singular_table_name}" %>, <%= key_value :status, ':created' %>, <%= key_value :location, "@#{singular_table_name}" %> }
50
+ else
51
+ format.html { render <%= key_value :action, '"new"' %> }
52
+ format.json { render <%= key_value :json, "@#{orm_instance.errors}" %>, <%= key_value :status, ':unprocessable_entity' %> }
53
+ end
54
+ end
55
+ end
56
+
57
+ # PUT <%= route_url %>/1
58
+ # PUT <%= route_url %>/1.json
59
+ def update
60
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
61
+
62
+ respond_to do |format|
63
+ if @<%= orm_instance.update_attributes("params[:#{singular_table_name}]") %>
64
+ format.html { redirect_to @<%= singular_table_name %>, <%= key_value :notice, "'#{human_name} was successfully updated.'" %> }
65
+ format.json { head :no_content }
66
+ else
67
+ format.html { render <%= key_value :action, '"edit"' %> }
68
+ format.json { render <%= key_value :json, "@#{orm_instance.errors}" %>, <%= key_value :status, ':unprocessable_entity' %> }
69
+ end
70
+ end
71
+ end
72
+
73
+ # DELETE <%= route_url %>/1
74
+ # DELETE <%= route_url %>/1.json
75
+ def destroy
76
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
77
+ @<%= orm_instance.destroy %>
78
+
79
+ respond_to do |format|
80
+ format.html { redirect_to <%= index_helper %>_url }
81
+ format.json { head :no_content }
82
+ end
83
+ end
84
+ end
85
+ <% end -%>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: el_generators
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -24,6 +24,14 @@ files:
24
24
  - el_generators.gemspec
25
25
  - lib/el_generators.rb
26
26
  - lib/el_generators/version.rb
27
+ - lib/generators/el_scaffold/USAGE
28
+ - lib/generators/el_scaffold/el_scaffold_generator.rb
29
+ - lib/generators/el_scaffold/templates/erb/scaffold/_form.html.erb
30
+ - lib/generators/el_scaffold/templates/erb/scaffold/edit.html.erb
31
+ - lib/generators/el_scaffold/templates/erb/scaffold/index.html.erb
32
+ - lib/generators/el_scaffold/templates/erb/scaffold/new.html.erb
33
+ - lib/generators/el_scaffold/templates/erb/scaffold/show.html.erb
34
+ - lib/generators/el_scaffold/templates/rails/scaffold_controller/controller.rb
27
35
  - lib/generators/messages/USAGE
28
36
  - lib/generators/messages/messages_generator.rb
29
37
  - lib/generators/messages/templates/add_human_to_active_record.rb