custom-template 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +38 -8
- data/lib/custom-template/templates/erb/controller/view.html.erb +2 -0
- data/lib/custom-template/templates/erb/mailer/view.text.erb +3 -0
- data/lib/custom-template/templates/erb/scaffold/_form.html.erb +0 -0
- data/lib/custom-template/templates/erb/scaffold/edit.html.erb +31 -0
- data/lib/custom-template/templates/erb/scaffold/index.html.erb +33 -0
- data/lib/custom-template/templates/erb/scaffold/new.html.erb +29 -0
- data/lib/custom-template/templates/erb/scaffold/show.html.erb +9 -0
- data/lib/custom-template/templates/haml/controller/view.html.haml +2 -0
- data/lib/custom-template/templates/haml/mailer/view.text.haml +3 -0
- data/lib/custom-template/templates/haml/scaffold/_form.html.haml +0 -0
- data/lib/custom-template/templates/haml/scaffold/edit.html.haml +16 -0
- data/lib/custom-template/templates/haml/scaffold/index.html.haml +23 -0
- data/lib/custom-template/templates/haml/scaffold/new.html.haml +14 -0
- data/lib/custom-template/templates/haml/scaffold/show.html.haml +10 -0
- data/lib/custom-template/templates/rails/assets/javascript.js +2 -0
- data/lib/custom-template/templates/rails/assets/stylesheet.css +4 -0
- data/lib/custom-template/templates/rails/controller/controller.rb +12 -0
- data/lib/custom-template/templates/rails/helper/helper.rb +2 -0
- data/lib/custom-template/templates/rails/scaffold_controller/controller.rb +73 -0
- data/lib/custom-template/templates/rails/stylesheets/scaffold.css +60 -0
- data/lib/custom-template/version.rb +1 -1
- metadata +21 -1
data/README.md
CHANGED
@@ -1,24 +1,54 @@
|
|
1
1
|
# Custom::Template
|
2
2
|
|
3
|
-
|
3
|
+
Custom Template for Scaffold.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
7
|
Add this line to your application's Gemfile:
|
8
8
|
|
9
|
-
|
9
|
+
```ruby
|
10
|
+
# For Custom Template
|
11
|
+
gem 'custom-template', :group => :development
|
12
|
+
gem 'haml'
|
13
|
+
gem 'haml-rails', :group => :development
|
14
|
+
```
|
10
15
|
|
11
16
|
And then execute:
|
12
17
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
$ gem install custom-template
|
18
|
+
```
|
19
|
+
bundle install --without production
|
20
|
+
```
|
18
21
|
|
19
22
|
## Usage
|
20
23
|
|
21
|
-
|
24
|
+
```
|
25
|
+
rails g custom:template
|
26
|
+
----------
|
27
|
+
create lib/templates/erb
|
28
|
+
create lib/templates/erb/controller/view.html.erb
|
29
|
+
create lib/templates/erb/mailer/view.text.erb
|
30
|
+
create lib/templates/erb/scaffold/_form.html.erb
|
31
|
+
create lib/templates/erb/scaffold/edit.html.erb
|
32
|
+
create lib/templates/erb/scaffold/index.html.erb
|
33
|
+
create lib/templates/erb/scaffold/new.html.erb
|
34
|
+
create lib/templates/erb/scaffold/show.html.erb
|
35
|
+
create lib/templates/haml
|
36
|
+
create lib/templates/haml/controller/view.html.haml
|
37
|
+
create lib/templates/haml/mailer/view.text.haml
|
38
|
+
create lib/templates/haml/scaffold/_form.html.haml
|
39
|
+
create lib/templates/haml/scaffold/edit.html.haml
|
40
|
+
create lib/templates/haml/scaffold/index.html.haml
|
41
|
+
create lib/templates/haml/scaffold/new.html.haml
|
42
|
+
create lib/templates/haml/scaffold/show.html.haml
|
43
|
+
create lib/templates/rails
|
44
|
+
create lib/templates/rails/assets/javascript.js
|
45
|
+
create lib/templates/rails/assets/stylesheet.css
|
46
|
+
create lib/templates/rails/controller/controller.rb
|
47
|
+
create lib/templates/rails/helper/helper.rb
|
48
|
+
create lib/templates/rails/scaffold_controller/controller.rb
|
49
|
+
create lib/templates/rails/stylesheets/scaffold.css
|
50
|
+
----------
|
51
|
+
```
|
22
52
|
|
23
53
|
## Contributing
|
24
54
|
|
File without changes
|
@@ -0,0 +1,31 @@
|
|
1
|
+
|
2
|
+
<h1>Editing <%= singular_table_name %></h1>
|
3
|
+
|
4
|
+
<%%= form_for :<%= singular_table_name %>, url: { action: "update", id: @<%= singular_table_name %>.try(:id) } do |f| %>
|
5
|
+
<%% if @<%= singular_table_name %>.errors.any? %>
|
6
|
+
<div id="error_explanation">
|
7
|
+
<h2><%%= pluralize(@<%= singular_table_name %>.errors.count, "error") %> prohibited this <%= singular_table_name %> from being saved:</h2>
|
8
|
+
|
9
|
+
<ul>
|
10
|
+
<%% @<%= singular_table_name %>.errors.full_messages.each{ |msg| %>
|
11
|
+
<li><%%= msg %></li>
|
12
|
+
<%% } %>
|
13
|
+
</ul>
|
14
|
+
</div>
|
15
|
+
<%% end %>
|
16
|
+
|
17
|
+
<% attributes.each do |attribute| -%>
|
18
|
+
<div class="field">
|
19
|
+
<%%= f.label :<%= attribute.name %> %><br />
|
20
|
+
<%%= f.<%= attribute.field_type %> :<%= attribute.name %> %>
|
21
|
+
</div>
|
22
|
+
|
23
|
+
<% end -%>
|
24
|
+
<div class="actions">
|
25
|
+
<%%= f.submit t( "menu.update" ), 'data-disable-with' => t( "menu.update" ) %>
|
26
|
+
</div>
|
27
|
+
<%% end %>
|
28
|
+
|
29
|
+
|
30
|
+
<%%= link_to t( "menu.show" ), action: "show", id: @<%= singular_table_name %>.id %>
|
31
|
+
| <%%= link_to t( "menu.list" ), action: "index" %>
|
@@ -0,0 +1,33 @@
|
|
1
|
+
|
2
|
+
<h1>Listing <%= plural_table_name %></h1>
|
3
|
+
|
4
|
+
<table>
|
5
|
+
<tr>
|
6
|
+
<% attributes.each do |attribute| -%>
|
7
|
+
<th><%= attribute.human_name %></th>
|
8
|
+
<% end -%>
|
9
|
+
<th></th>
|
10
|
+
<th></th>
|
11
|
+
<th></th>
|
12
|
+
</tr>
|
13
|
+
|
14
|
+
<%% @<%= plural_table_name %>.each{ |<%= singular_table_name %>| %>
|
15
|
+
<tr>
|
16
|
+
<% attributes.each do |attribute| -%>
|
17
|
+
<td><%%= <%= singular_table_name %>.<%= attribute.name %> %></td>
|
18
|
+
<% end -%>
|
19
|
+
<td><%%= link_to t( "menu.show" ), action: "show", id: <%= singular_table_name %>.id %></td>
|
20
|
+
<td><%%= link_to t( "menu.edit" ), action: "edit", id: <%= singular_table_name %>.id %></td>
|
21
|
+
<td><%%= link_to t( "menu.destroy" ), { action: "destroy", id: <%= singular_table_name %>.id }, onclick: "return confirm('本当に削除してよろしいですか?');" %></td>
|
22
|
+
</tr>
|
23
|
+
<%% } %>
|
24
|
+
</table>
|
25
|
+
|
26
|
+
<br />
|
27
|
+
|
28
|
+
<%%= link_to t( "menu.new" ), action: "new" %>
|
29
|
+
|
30
|
+
<br />
|
31
|
+
<br />
|
32
|
+
|
33
|
+
<%%= link_to t( "menu.top" ), :root %>
|
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
<h1>New <%= singular_table_name %></h1>
|
3
|
+
|
4
|
+
<%%= form_for :<%= singular_table_name %>, url: { action: "create", id: @<%= singular_table_name %>.try(:id) } do |f| %>
|
5
|
+
<%% if @<%= singular_table_name %>.errors.any? %>
|
6
|
+
<div id="error_explanation">
|
7
|
+
<h2><%%= pluralize(@<%= singular_table_name %>.errors.count, "error") %> prohibited this <%= singular_table_name %> from being saved:</h2>
|
8
|
+
|
9
|
+
<ul>
|
10
|
+
<%% @<%= singular_table_name %>.errors.full_messages.each{ |msg| %>
|
11
|
+
<li><%%= msg %></li>
|
12
|
+
<%% } %>
|
13
|
+
</ul>
|
14
|
+
</div>
|
15
|
+
<%% end %>
|
16
|
+
|
17
|
+
<% attributes.each do |attribute| -%>
|
18
|
+
<div class="field">
|
19
|
+
<%%= f.label :<%= attribute.name %> %><br />
|
20
|
+
<%%= f.<%= attribute.field_type %> :<%= attribute.name %> %>
|
21
|
+
</div>
|
22
|
+
|
23
|
+
<% end -%>
|
24
|
+
<div class="actions">
|
25
|
+
<%%= f.submit t( "menu.create" ), 'data-disable-with' => t( "menu.create" ) %>
|
26
|
+
</div>
|
27
|
+
<%% end %>
|
28
|
+
|
29
|
+
<%%= link_to t( "menu.list" ), action: "index" %>
|
@@ -0,0 +1,9 @@
|
|
1
|
+
|
2
|
+
<% attributes.each{ |attribute| -%>
|
3
|
+
<p>
|
4
|
+
<b><%= attribute.human_name %>:</b><%%= @<%= singular_table_name %>.<%= attribute.name %> %>
|
5
|
+
</p>
|
6
|
+
|
7
|
+
<% } -%>
|
8
|
+
<%%= link_to t( "menu.edit" ), action: "edit", id: @<%= singular_table_name %>.id %>
|
9
|
+
| <%%= link_to t( "menu.list" ), action: "index" %>
|
File without changes
|
@@ -0,0 +1,16 @@
|
|
1
|
+
%h1 Editing <%= singular_table_name %>
|
2
|
+
|
3
|
+
= form_for :<%= singular_table_name %>, url: { action: "update", id: @<%= singular_table_name %>.try(:id) } do |f|
|
4
|
+
|
5
|
+
<% attributes.each{ |attribute| -%>
|
6
|
+
.field
|
7
|
+
= f.label :<%= attribute.name %>
|
8
|
+
= f.<%= attribute.field_type %> :<%= attribute.name %>
|
9
|
+
|
10
|
+
<% } -%>
|
11
|
+
.actions
|
12
|
+
= f.submit t( "menu.update" ), 'data-disable-with' => t( "menu.update" )
|
13
|
+
|
14
|
+
= link_to t( "menu.show" ), action: "show", id: @<%= singular_table_name %>.id
|
15
|
+
|
|
16
|
+
= link_to t( "menu.list" ), action: "index"
|
@@ -0,0 +1,23 @@
|
|
1
|
+
%h1 Listing <%= plural_table_name %>
|
2
|
+
|
3
|
+
%table
|
4
|
+
%tr
|
5
|
+
<% attributes.each do |attribute| -%>
|
6
|
+
%th <%= attribute.human_name %>
|
7
|
+
<% end -%>
|
8
|
+
%th
|
9
|
+
%th
|
10
|
+
%th
|
11
|
+
|
12
|
+
- @<%= plural_table_name %>.each do |<%= singular_table_name %>|
|
13
|
+
%tr
|
14
|
+
<% attributes.each do |attribute| -%>
|
15
|
+
%td= <%= singular_table_name %>.<%= attribute.name %>
|
16
|
+
<% end -%>
|
17
|
+
%td= link_to t( "menu.show" ), action: "show", id: <%= singular_table_name %>.id
|
18
|
+
%td= link_to t( "menu.edit" ), action: "edit", id: <%= singular_table_name %>.id
|
19
|
+
%td= link_to t( "menu.destroy" ), { action: "destroy", id: <%= singular_table_name %>.id }, data: { confirm: "本当に削除してよろしいですか?" }
|
20
|
+
|
21
|
+
%br
|
22
|
+
|
23
|
+
= link_to t( "menu.new" ), action: "new"
|
@@ -0,0 +1,14 @@
|
|
1
|
+
%h1 New <%= singular_table_name %>
|
2
|
+
|
3
|
+
= form_for :<%= singular_table_name %>, url: { action: "create", id: @<%= singular_table_name %>.try(:id) } do |f|
|
4
|
+
|
5
|
+
<% attributes.each{ |attribute| -%>
|
6
|
+
.field
|
7
|
+
= f.label :<%= attribute.name %>
|
8
|
+
= f.<%= attribute.field_type %> :<%= attribute.name %>
|
9
|
+
|
10
|
+
<% } -%>
|
11
|
+
.actions
|
12
|
+
= f.submit t( "menu.create" ), 'data-disable-with' => t( "menu.create" )
|
13
|
+
|
14
|
+
= link_to t( "menu.list" ), action: "index"
|
@@ -0,0 +1,10 @@
|
|
1
|
+
|
2
|
+
<% attributes.each{ |attribute| -%>
|
3
|
+
%p
|
4
|
+
%b <%= attribute.human_name %>:
|
5
|
+
= @<%= singular_table_name %>.<%= attribute.name %>
|
6
|
+
|
7
|
+
<% } -%>
|
8
|
+
= link_to t( "menu.edit" ), action: "edit", id: @<%= singular_table_name %>.id
|
9
|
+
|
|
10
|
+
= link_to t( "menu.list" ), action: "index"
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
class <%= controller_class_name %>Controller < ApplicationController
|
3
|
+
|
4
|
+
#-------#
|
5
|
+
# index #
|
6
|
+
#-------#
|
7
|
+
def index
|
8
|
+
@<%= plural_table_name %> = <%= "#{class_name}.where( user_id: session[:user_id] ).all" %>
|
9
|
+
end
|
10
|
+
|
11
|
+
#------#
|
12
|
+
# show #
|
13
|
+
#------#
|
14
|
+
def show
|
15
|
+
@<%= singular_table_name %> = <%= "#{class_name}.where( id: params[:id], user_id: session[:user_id] ).first" %>
|
16
|
+
end
|
17
|
+
|
18
|
+
#-----#
|
19
|
+
# new #
|
20
|
+
#-----#
|
21
|
+
def new
|
22
|
+
@<%= singular_table_name %> = <%= orm_class.build( class_name ) %>
|
23
|
+
|
24
|
+
@submit = "create"
|
25
|
+
end
|
26
|
+
|
27
|
+
#------#
|
28
|
+
# edit #
|
29
|
+
#------#
|
30
|
+
def edit
|
31
|
+
@<%= singular_table_name %> = <%= "#{class_name}.where( id: params[:id], user_id: session[:user_id] ).first" %>
|
32
|
+
|
33
|
+
@submit = "update"
|
34
|
+
end
|
35
|
+
|
36
|
+
#--------#
|
37
|
+
# create #
|
38
|
+
#--------#
|
39
|
+
def create
|
40
|
+
@<%= singular_table_name %> = <%= orm_class.build( class_name, " params[:#{singular_table_name}] " ) %>
|
41
|
+
@<%= "#{singular_table_name}.user_id" %> = <%= "session[:user_id]" %>
|
42
|
+
|
43
|
+
if @<%= orm_instance.save %>
|
44
|
+
redirect_to( { action: "index" }, notice: <%= "\"#{human_name} was successfully created.\"" %> )
|
45
|
+
else
|
46
|
+
render action: "new"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
#--------#
|
51
|
+
# update #
|
52
|
+
#--------#
|
53
|
+
def update
|
54
|
+
@<%= singular_table_name %> = <%= "#{class_name}.where( id: params[:id], user_id: session[:user_id] ).first" %>
|
55
|
+
|
56
|
+
if @<%= orm_instance.update_attributes(" params[:#{singular_table_name}] ") %>
|
57
|
+
redirect_to( { action: "show", id: <%= "params[:id]" %> }, notice: <%= "\"#{human_name} was successfully updated.\"" %> )
|
58
|
+
else
|
59
|
+
render action: "edit", id: <%= "params[:id]" %>
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
#---------#
|
64
|
+
# destroy #
|
65
|
+
#---------#
|
66
|
+
def destroy
|
67
|
+
@<%= singular_table_name %> = <%= "#{class_name}.where( id: params[:id], user_id: session[:user_id] ).first" %>
|
68
|
+
@<%= orm_instance.destroy %>
|
69
|
+
|
70
|
+
redirect_to action: "index"
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
body { background-color: #fff; color: #333; }
|
2
|
+
|
3
|
+
body, p, ol, ul, td {
|
4
|
+
font-family: Courier, monospace, verdana, arial, helvetica, sans-serif;
|
5
|
+
font-size: 13px;
|
6
|
+
line-height: 18px;
|
7
|
+
}
|
8
|
+
|
9
|
+
textarea, pre {
|
10
|
+
font-family: Courier;
|
11
|
+
font-size: 14px;
|
12
|
+
}
|
13
|
+
|
14
|
+
pre {
|
15
|
+
background-color: #eee;
|
16
|
+
padding: 10px;
|
17
|
+
}
|
18
|
+
|
19
|
+
a { color: #000; }
|
20
|
+
a:visited { color: #666; }
|
21
|
+
a:hover { color: #fff; background-color:#000; }
|
22
|
+
|
23
|
+
div.field, div.actions {
|
24
|
+
margin-bottom: 10px;
|
25
|
+
}
|
26
|
+
|
27
|
+
#notice {
|
28
|
+
color: green;
|
29
|
+
}
|
30
|
+
|
31
|
+
.field_with_errors {
|
32
|
+
padding: 2px;
|
33
|
+
background-color: red;
|
34
|
+
display: table;
|
35
|
+
}
|
36
|
+
|
37
|
+
#error_explanation {
|
38
|
+
width: 450px;
|
39
|
+
border: 2px solid red;
|
40
|
+
padding: 7px;
|
41
|
+
padding-bottom: 0;
|
42
|
+
margin-bottom: 20px;
|
43
|
+
background-color: #f0f0f0;
|
44
|
+
}
|
45
|
+
|
46
|
+
#error_explanation h2 {
|
47
|
+
text-align: left;
|
48
|
+
font-weight: bold;
|
49
|
+
padding: 5px 5px 5px 15px;
|
50
|
+
font-size: 12px;
|
51
|
+
margin: -7px;
|
52
|
+
margin-bottom: 0px;
|
53
|
+
background-color: #c00;
|
54
|
+
color: #fff;
|
55
|
+
}
|
56
|
+
|
57
|
+
#error_explanation ul li {
|
58
|
+
font-size: 12px;
|
59
|
+
list-style: square;
|
60
|
+
}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: custom-template
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -25,6 +25,26 @@ files:
|
|
25
25
|
- Rakefile
|
26
26
|
- custom-template.gemspec
|
27
27
|
- lib/custom-template.rb
|
28
|
+
- lib/custom-template/templates/erb/controller/view.html.erb
|
29
|
+
- lib/custom-template/templates/erb/mailer/view.text.erb
|
30
|
+
- lib/custom-template/templates/erb/scaffold/_form.html.erb
|
31
|
+
- lib/custom-template/templates/erb/scaffold/edit.html.erb
|
32
|
+
- lib/custom-template/templates/erb/scaffold/index.html.erb
|
33
|
+
- lib/custom-template/templates/erb/scaffold/new.html.erb
|
34
|
+
- lib/custom-template/templates/erb/scaffold/show.html.erb
|
35
|
+
- lib/custom-template/templates/haml/controller/view.html.haml
|
36
|
+
- lib/custom-template/templates/haml/mailer/view.text.haml
|
37
|
+
- lib/custom-template/templates/haml/scaffold/_form.html.haml
|
38
|
+
- lib/custom-template/templates/haml/scaffold/edit.html.haml
|
39
|
+
- lib/custom-template/templates/haml/scaffold/index.html.haml
|
40
|
+
- lib/custom-template/templates/haml/scaffold/new.html.haml
|
41
|
+
- lib/custom-template/templates/haml/scaffold/show.html.haml
|
42
|
+
- lib/custom-template/templates/rails/assets/javascript.js
|
43
|
+
- lib/custom-template/templates/rails/assets/stylesheet.css
|
44
|
+
- lib/custom-template/templates/rails/controller/controller.rb
|
45
|
+
- lib/custom-template/templates/rails/helper/helper.rb
|
46
|
+
- lib/custom-template/templates/rails/scaffold_controller/controller.rb
|
47
|
+
- lib/custom-template/templates/rails/stylesheets/scaffold.css
|
28
48
|
- lib/custom-template/version.rb
|
29
49
|
homepage: https://github.com/shu0115/custom-template
|
30
50
|
licenses: []
|