inherited_resources_views 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +4 -7
- data/VERSION +1 -1
- data/inherited_resources_views.gemspec +8 -2
- data/lib/generators/inherited_resources_views/generators/current_generator.rb +14 -0
- data/lib/generators/inherited_resources_views/templates/app/views/inherited_resources/_collection_table.html.erb +23 -0
- data/lib/generators/inherited_resources_views/templates/app/views/inherited_resources/_edit_navigation.html.erb +2 -0
- data/lib/generators/inherited_resources_views/templates/app/views/inherited_resources/_form.html.erb +8 -4
- data/lib/generators/inherited_resources_views/templates/app/views/inherited_resources/_index_navigation.html.erb +1 -0
- data/lib/generators/inherited_resources_views/templates/app/views/inherited_resources/_new_navigation.html.erb +1 -0
- data/lib/generators/inherited_resources_views/templates/app/views/inherited_resources/_resource_detail.html.erb +9 -0
- data/lib/generators/inherited_resources_views/templates/app/views/inherited_resources/_show_navigation.html.erb +2 -0
- data/lib/generators/inherited_resources_views/templates/app/views/inherited_resources/edit.html.erb +3 -2
- data/lib/generators/inherited_resources_views/templates/app/views/inherited_resources/index.html.erb +4 -22
- data/lib/generators/inherited_resources_views/templates/app/views/inherited_resources/new.html.erb +3 -1
- data/lib/generators/inherited_resources_views/templates/app/views/inherited_resources/show.html.erb +4 -10
- metadata +10 -4
data/README.md
CHANGED
@@ -18,11 +18,6 @@ If you are confused about the difference to some other similarly named projects,
|
|
18
18
|
|
19
19
|
[Inherited Views](http://github.com/gregbell/inherited_views) tries to solve the same problem we're solving, but from a slightly different angle. It is more complex, requires [Formtastic](http://github.com/justinfrench/formtastic) and [WillPaginate](http://github.com/mislav/will_paginate), and it only generates erb templates. **Inherited Resources Views** on the other hand, is extremely simple, is library-agnostic (it only depends on [Inherited Resources](http://github.com/josevalim/inherited_resources)), and it supports both erb and [haml](http://github.com/nex3/haml) templates.
|
20
20
|
|
21
|
-
## Todo
|
22
|
-
|
23
|
-
* Add tests
|
24
|
-
* Make default views more elegant and perhaps customisable
|
25
|
-
|
26
21
|
## Dependencies
|
27
22
|
|
28
23
|
* [Inherited Resources](http://github.com/josevalim/inherited_resources)
|
@@ -37,7 +32,7 @@ As a Rails plugin:
|
|
37
32
|
|
38
33
|
# rails 3
|
39
34
|
rails plugin install git://github.com/fredwu/inherited_resources_views.git
|
40
|
-
|
35
|
+
|
41
36
|
# rails 2
|
42
37
|
script/plugin install git://github.com/fredwu/inherited_resources_views.git
|
43
38
|
|
@@ -51,10 +46,12 @@ It is *extremely* simple to use Inherited Resources Views. The only step you nee
|
|
51
46
|
|
52
47
|
# rails 3
|
53
48
|
rails generate inherited_resources_views
|
54
|
-
|
49
|
+
|
55
50
|
# rails 2
|
56
51
|
script/generate inherited_resources_views
|
57
52
|
|
53
|
+
# Please remember to restart your server!
|
54
|
+
|
58
55
|
This will generate a set of views in your `app/views/inherited_resources` folder. Edit away!
|
59
56
|
|
60
57
|
## Author
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{inherited_resources_views}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.4.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Fred Wu"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-11-04}
|
13
13
|
s.description = %q{Using Inherited Resources is an excellent way to reduce the amount of repetition in your controllers. But what about views? A lot of times resources share the same views, so why not DRY 'em up using Inherited Resources Views!}
|
14
14
|
s.email = %q{ifredwu@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -26,7 +26,13 @@ Gem::Specification.new do |s|
|
|
26
26
|
"lib/generators/inherited_resources_views/generators/current_generator.rb",
|
27
27
|
"lib/generators/inherited_resources_views/generators/legacy_generator.rb",
|
28
28
|
"lib/generators/inherited_resources_views/inherited_resources_views_generator.rb",
|
29
|
+
"lib/generators/inherited_resources_views/templates/app/views/inherited_resources/_collection_table.html.erb",
|
30
|
+
"lib/generators/inherited_resources_views/templates/app/views/inherited_resources/_edit_navigation.html.erb",
|
29
31
|
"lib/generators/inherited_resources_views/templates/app/views/inherited_resources/_form.html.erb",
|
32
|
+
"lib/generators/inherited_resources_views/templates/app/views/inherited_resources/_index_navigation.html.erb",
|
33
|
+
"lib/generators/inherited_resources_views/templates/app/views/inherited_resources/_new_navigation.html.erb",
|
34
|
+
"lib/generators/inherited_resources_views/templates/app/views/inherited_resources/_resource_detail.html.erb",
|
35
|
+
"lib/generators/inherited_resources_views/templates/app/views/inherited_resources/_show_navigation.html.erb",
|
30
36
|
"lib/generators/inherited_resources_views/templates/app/views/inherited_resources/edit.html.erb",
|
31
37
|
"lib/generators/inherited_resources_views/templates/app/views/inherited_resources/index.html.erb",
|
32
38
|
"lib/generators/inherited_resources_views/templates/app/views/inherited_resources/new.html.erb",
|
@@ -38,6 +38,20 @@ class InheritedResourcesViewsGenerator < Rails::Generators::Base
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def create_and_copy_haml_views
|
41
|
+
begin
|
42
|
+
require 'hpricot'
|
43
|
+
rescue LoadError
|
44
|
+
say "Hpricot is not installed, or it is not specified in your Gemfile."
|
45
|
+
exit
|
46
|
+
end
|
47
|
+
|
48
|
+
begin
|
49
|
+
require 'ruby_parser'
|
50
|
+
rescue LoadError
|
51
|
+
say "Ruby_parser is not installed, or it is not specified in your Gemfile."
|
52
|
+
exit
|
53
|
+
end
|
54
|
+
|
41
55
|
require 'tmpdir'
|
42
56
|
html_root = "#{self.class.source_root}/inherited_resources"
|
43
57
|
|
@@ -0,0 +1,23 @@
|
|
1
|
+
<table class="<%= collection.first.class.to_s.downcase.pluralize %> collection">
|
2
|
+
<thead>
|
3
|
+
<tr>
|
4
|
+
<% collection.first.attributes.each_pair do |field, value| %>
|
5
|
+
<% next if ['id', 'created_at', 'updated_at'].include?(field) %>
|
6
|
+
<th><%= field.titleize %></th>
|
7
|
+
<% end %>
|
8
|
+
</tr>
|
9
|
+
</thead>
|
10
|
+
<tbody>
|
11
|
+
<% collection.each do |r| %>
|
12
|
+
<tr>
|
13
|
+
<% r.attributes.each_pair do |field, value| %>
|
14
|
+
<% next if ['id', 'created_at', 'updated_at'].include?(field) %>
|
15
|
+
<td><%= value %></td>
|
16
|
+
<% end %>
|
17
|
+
<td><%= link_to "Show", resource_url(r) %></td>
|
18
|
+
<td><%= link_to "Edit", edit_resource_url(r) %></td>
|
19
|
+
<td><%= link_to "Destroy", resource_url(r), :confirm => 'Are you sure?', :method => :delete %></td>
|
20
|
+
</tr>
|
21
|
+
<% end %>
|
22
|
+
</tbody>
|
23
|
+
</table>
|
data/lib/generators/inherited_resources_views/templates/app/views/inherited_resources/_form.html.erb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
<table>
|
2
|
-
<%- form_for(
|
2
|
+
<%- form_for("#{resource_instance_name.to_s.downcase}",
|
3
|
+
resource,
|
4
|
+
:url => resource.new_record? ? collection_url : resource_url(resource),
|
5
|
+
:html => { :method => (resource.new_record? ? "post" : "put") }) do |f| %>
|
3
6
|
<% if resource.errors.any? %>
|
4
7
|
<tr>
|
5
8
|
<td colspan="2">
|
@@ -12,10 +15,11 @@
|
|
12
15
|
</td>
|
13
16
|
</tr>
|
14
17
|
<% end %>
|
15
|
-
<% resource.attributes.
|
18
|
+
<% resource.attributes.each_pair do |field, value| %>
|
19
|
+
<% next if ['id', 'created_at', 'updated_at'].include?(field) %>
|
16
20
|
<tr>
|
17
|
-
<td><%=
|
18
|
-
<td><%= f.text_field
|
21
|
+
<td><%= field.titleize %></td>
|
22
|
+
<td><%= f.text_field field.to_sym %></td>
|
19
23
|
</tr>
|
20
24
|
<% end %>
|
21
25
|
<tr>
|
@@ -0,0 +1 @@
|
|
1
|
+
<p><%= link_to "New", new_resource_url %></p>
|
@@ -0,0 +1 @@
|
|
1
|
+
<p><%= link_to "Back", collection_url %></p>
|
@@ -0,0 +1,9 @@
|
|
1
|
+
<table class="<%= collection.first.class.to_s.downcase %> detail">
|
2
|
+
<% resource.attributes.each_pair do |attr, value| %>
|
3
|
+
<% next if ['id', 'created_at', 'updated_at'].include?(attr) %>
|
4
|
+
<tr>
|
5
|
+
<th><%= attr.titleize %></th>
|
6
|
+
<td><%= value %></td>
|
7
|
+
</tr>
|
8
|
+
<% end %>
|
9
|
+
</table>
|
data/lib/generators/inherited_resources_views/templates/app/views/inherited_resources/index.html.erb
CHANGED
@@ -1,25 +1,7 @@
|
|
1
|
-
<
|
1
|
+
<h1><%= controller.controller_name.titleize %></h1>
|
2
|
+
|
3
|
+
<%= render "index_navigation" %>
|
2
4
|
|
3
5
|
<% if collection.any? %>
|
4
|
-
|
5
|
-
<thead>
|
6
|
-
<tr>
|
7
|
-
<% collection.first.attributes.each do |a| %>
|
8
|
-
<th><%= a[0] %></th>
|
9
|
-
<% end %>
|
10
|
-
</tr>
|
11
|
-
</thead>
|
12
|
-
<tbody>
|
13
|
-
<% collection.each do |r| %>
|
14
|
-
<tr>
|
15
|
-
<% r.attributes.each do |a| %>
|
16
|
-
<td><%= a[1] %></td>
|
17
|
-
<% end %>
|
18
|
-
<td><%= link_to "Show", resource_url(r) %></td>
|
19
|
-
<td><%= link_to "Edit", edit_resource_url(r) %></td>
|
20
|
-
<td><%= link_to "Destroy", resource_url(r), :confirm => 'Are you sure?', :method => :delete %></td>
|
21
|
-
</tr>
|
22
|
-
<% end %>
|
23
|
-
</tbody>
|
24
|
-
</table>
|
6
|
+
<%= render "collection_table" %>
|
25
7
|
<% end %>
|
data/lib/generators/inherited_resources_views/templates/app/views/inherited_resources/show.html.erb
CHANGED
@@ -1,11 +1,5 @@
|
|
1
|
-
<
|
2
|
-
<% resource.attributes.each do |a| %>
|
3
|
-
<tr>
|
4
|
-
<th><%= a[0] %></th>
|
5
|
-
<td><%= a[1] %></td>
|
6
|
-
</tr>
|
7
|
-
<% end %>
|
8
|
-
</table>
|
1
|
+
<h1><%= resource.class %></h1>
|
9
2
|
|
10
|
-
|
11
|
-
|
3
|
+
<%= render("resource_detail") %>
|
4
|
+
|
5
|
+
<%= render("show_navigation") %>
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 4
|
8
|
+
- 0
|
9
|
+
version: 0.4.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Fred Wu
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-11-04 00:00:00 +11:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -50,7 +50,13 @@ files:
|
|
50
50
|
- lib/generators/inherited_resources_views/generators/current_generator.rb
|
51
51
|
- lib/generators/inherited_resources_views/generators/legacy_generator.rb
|
52
52
|
- lib/generators/inherited_resources_views/inherited_resources_views_generator.rb
|
53
|
+
- lib/generators/inherited_resources_views/templates/app/views/inherited_resources/_collection_table.html.erb
|
54
|
+
- lib/generators/inherited_resources_views/templates/app/views/inherited_resources/_edit_navigation.html.erb
|
53
55
|
- lib/generators/inherited_resources_views/templates/app/views/inherited_resources/_form.html.erb
|
56
|
+
- lib/generators/inherited_resources_views/templates/app/views/inherited_resources/_index_navigation.html.erb
|
57
|
+
- lib/generators/inherited_resources_views/templates/app/views/inherited_resources/_new_navigation.html.erb
|
58
|
+
- lib/generators/inherited_resources_views/templates/app/views/inherited_resources/_resource_detail.html.erb
|
59
|
+
- lib/generators/inherited_resources_views/templates/app/views/inherited_resources/_show_navigation.html.erb
|
54
60
|
- lib/generators/inherited_resources_views/templates/app/views/inherited_resources/edit.html.erb
|
55
61
|
- lib/generators/inherited_resources_views/templates/app/views/inherited_resources/index.html.erb
|
56
62
|
- lib/generators/inherited_resources_views/templates/app/views/inherited_resources/new.html.erb
|