inherited_resources_views 0.1.0

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.
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ pkg
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 [name of plugin creator]
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # Inherited Resources Views
2
+
3
+ ## Introduction
4
+
5
+ Using [Inherited Resources](http://github.com/josevalim/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!
6
+
7
+ Brought to you by [Envato](http://envato.com) and [Wuit](http://wuit.com).
8
+
9
+ ## Difference to Other Seemly Similar Projects
10
+
11
+ If you are confused about the difference to some other similarly named projects, please read on.
12
+
13
+ ### Difference to Inherit Views
14
+
15
+ [Inherit Views](http://github.com/ianwhite/inherit_views) adds the ability to render views from parent controllers. It does not share views between different resources.
16
+
17
+ ### Difference to Inherited Views
18
+
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
+
21
+ ## Todo
22
+
23
+ * Add tests
24
+ * Make default views more elegant and perhaps customisable
25
+
26
+ ## Dependencies
27
+
28
+ * **Rails 3.0+**
29
+ * [Inherited Resources](http://github.com/josevalim/inherited_resources)
30
+
31
+ ## Installation
32
+
33
+ As a Rails plugin:
34
+
35
+ rails plugin install git://github.com/fredwu/inherited_resources_views.git
36
+
37
+ As a gem:
38
+
39
+ gem install inherited_resources_views
40
+
41
+ ## Usage
42
+
43
+ It is *extremely* simple to use Inherited Resources Views. The only step you need to do after the installation is to customise the default views:
44
+
45
+ rails generate inherited_resources_views
46
+
47
+ This will generate a set of views in your `app/views/inherited_resources_views` folder. Edit away!
48
+
49
+ ## Author
50
+
51
+ Copyright (c) 2010 Fred Wu (<http://fredwu.me>), released under the MIT license
52
+
53
+ * Envato - <http://envato.com>
54
+ * Wuit - <http://wuit.com>
data/Rakefile ADDED
@@ -0,0 +1,40 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
7
+
8
+ desc 'Test the inherited_resources_views plugin.'
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.libs << 'test'
12
+ t.pattern = 'test/**/*_test.rb'
13
+ t.verbose = true
14
+ end
15
+
16
+ desc 'Generate documentation for the inherited_resources_views plugin.'
17
+ Rake::RDocTask.new(:rdoc) do |rdoc|
18
+ rdoc.rdoc_dir = 'rdoc'
19
+ rdoc.title = 'InheritedResourcesViews'
20
+ rdoc.options << '--line-numbers' << '--inline-source'
21
+ rdoc.rdoc_files.include('README')
22
+ rdoc.rdoc_files.include('lib/**/*.rb')
23
+ end
24
+
25
+ begin
26
+ require 'jeweler'
27
+ Jeweler::Tasks.new do |s|
28
+ s.name = "inherited_resources_views"
29
+ s.version = "0.1.0"
30
+ s.summary = "A lot of times resources share the same views, so why not DRY 'em up using Inherited Resources Views!"
31
+ s.description = "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!"
32
+ s.email = "ifredwu@gmail.com"
33
+ s.homepage = "http://github.com/fredwu/inherited_resources_views"
34
+ s.authors = ["Fred Wu"]
35
+ s.add_dependency("inherited_resources", ">= 1.1")
36
+ end
37
+ Jeweler::GemcutterTasks.new
38
+ rescue LoadError
39
+ puts "Jeweler not available. Install it with: gem install jeweler"
40
+ end
@@ -0,0 +1,25 @@
1
+ <table>
2
+ <%= form_for(resource) do |f| %>
3
+ <% if resource.errors.any? %>
4
+ <tr>
5
+ <td colspan="2">
6
+ <h2><%= pluralize(resource.errors.count, "error") %> prohibited this testa from being saved:</h2>
7
+ <ul>
8
+ <% resource.errors.full_messages.each do |msg| %>
9
+ <li><%= msg %></li>
10
+ <% end %>
11
+ </ul>
12
+ </td>
13
+ </tr>
14
+ <% end %>
15
+ <% resource.attributes.each do |a| %>
16
+ <tr>
17
+ <td><%= a[0] %></td>
18
+ <td><%= f.text_field a[0].to_sym %></td>
19
+ </tr>
20
+ <% end %>
21
+ <tr>
22
+ <td colspan="2"><%= f.submit %></td>
23
+ </tr>
24
+ <% end %>
25
+ </table>
@@ -0,0 +1,4 @@
1
+ <%= render "form" %>
2
+
3
+ <p><%= link_to "Show", resource %></p>
4
+ <p><%= link_to "Back", eval("#{controller_name}_path") %></p>
@@ -0,0 +1,25 @@
1
+ <p><%= link_to "New", eval("new_#{controller_name.singularize}_path") %></p>
2
+
3
+ <% if collection.any? %>
4
+ <table>
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", r %></td>
19
+ <td><%= link_to "Edit", eval("edit_#{controller_name.singularize}_path(r)") %></td>
20
+ <td><%= link_to "Destroy", r, :confirm => 'Are you sure?', :method => :delete %></td>
21
+ </tr>
22
+ <% end %>
23
+ </tbody>
24
+ </table>
25
+ <% end %>
@@ -0,0 +1,3 @@
1
+ <%= render "form" %>
2
+
3
+ <p><%= link_to "Back", eval("#{controller_name}_path") %></p>
@@ -0,0 +1,11 @@
1
+ <table>
2
+ <% resource.attributes.each do |a| %>
3
+ <tr>
4
+ <th><%= a[0] %></th>
5
+ <td><%= a[1] %></td>
6
+ </tr>
7
+ <% end %>
8
+ </table>
9
+
10
+ <p><%= link_to "Edit", eval("edit_#{controller_name.singularize}_path(resource)") %></p>
11
+ <p><%= link_to "Back", eval("#{controller_name}_path") %></p>
@@ -0,0 +1,58 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{inherited_resources_views}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Fred Wu"]
12
+ s.date = %q{2010-08-05}
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
+ s.email = %q{ifredwu@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "README.md"
17
+ ]
18
+ s.files = [
19
+ ".gitignore",
20
+ "MIT-LICENSE",
21
+ "README.md",
22
+ "Rakefile",
23
+ "app/views/inherited_resources/_form.html.erb",
24
+ "app/views/inherited_resources/edit.html.erb",
25
+ "app/views/inherited_resources/index.html.erb",
26
+ "app/views/inherited_resources/new.html.erb",
27
+ "app/views/inherited_resources/show.html.erb",
28
+ "inherited_resources_views.gemspec",
29
+ "lib/generators/inherited_resources_views_generator.rb",
30
+ "lib/inherited_resources_views.rb",
31
+ "lib/inherited_resources_views/action_view.rb",
32
+ "test/inherited_resources_views_test.rb",
33
+ "test/test_helper.rb"
34
+ ]
35
+ s.homepage = %q{http://github.com/fredwu/inherited_resources_views}
36
+ s.rdoc_options = ["--charset=UTF-8"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = %q{1.3.7}
39
+ s.summary = %q{A lot of times resources share the same views, so why not DRY 'em up using Inherited Resources Views!}
40
+ s.test_files = [
41
+ "test/inherited_resources_views_test.rb",
42
+ "test/test_helper.rb"
43
+ ]
44
+
45
+ if s.respond_to? :specification_version then
46
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
47
+ s.specification_version = 3
48
+
49
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
50
+ s.add_runtime_dependency(%q<inherited_resources>, [">= 1.1"])
51
+ else
52
+ s.add_dependency(%q<inherited_resources>, [">= 1.1"])
53
+ end
54
+ else
55
+ s.add_dependency(%q<inherited_resources>, [">= 1.1"])
56
+ end
57
+ end
58
+
@@ -0,0 +1,59 @@
1
+ class InheritedResourcesViewsGenerator < Rails::Generators::Base
2
+ desc "Generates inherited_resource_views templates."
3
+
4
+ class_option :template_engine, :type => :string, :aliases => "-t", :default => "erb",
5
+ :desc => "Template engine for the views. Available options are 'erb' and 'haml'."
6
+
7
+ def self.source_root
8
+ @_views_source_root ||= File.expand_path("../../../app/views", __FILE__)
9
+ end
10
+
11
+ def copy_views
12
+ case options[:template_engine]
13
+ when "haml"
14
+ verify_haml_existence
15
+ verify_haml_version
16
+ create_and_copy_haml_views
17
+ else
18
+ directory "inherited_resources", "app/views/inherited_resources"
19
+ end
20
+ end
21
+
22
+ protected
23
+
24
+ def verify_haml_existence
25
+ begin
26
+ require 'haml'
27
+ rescue LoadError
28
+ say "HAML is not installed, or it is not specified in your Gemfile."
29
+ exit
30
+ end
31
+ end
32
+
33
+ def verify_haml_version
34
+ unless Haml.version[:major] == 2 and Haml.version[:minor] >= 3 or Haml.version[:major] >= 3
35
+ say "To generate HAML templates, you need to install HAML 2.3 or above."
36
+ exit
37
+ end
38
+ end
39
+
40
+ def create_and_copy_haml_views
41
+ require 'tmpdir'
42
+ html_root = "#{self.class.source_root}/inherited_resources"
43
+
44
+ Dir.mktmpdir("inherited_resources_views-haml.") do |haml_root|
45
+ Dir["#{html_root}/**/*"].each do |path|
46
+ relative_path = path.sub(html_root, "")
47
+ source_path = (haml_root + relative_path).sub(/erb$/, "haml")
48
+
49
+ if File.directory?(path)
50
+ FileUtils.mkdir_p(source_path)
51
+ else
52
+ `html2haml -r #{path} #{source_path}`
53
+ end
54
+ end
55
+
56
+ directory haml_root, "app/views/inherited_resources"
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,10 @@
1
+ require 'inherited_resources_views/action_view'
2
+
3
+ class ActionController::Base
4
+ def self.inherited(base)
5
+ super
6
+ if base.respond_to?(:inherit_resources)
7
+ ActionView::Base.send :include, InheritedResourcesViews::ActionView
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,19 @@
1
+ module InheritedResourcesViews
2
+ module ActionView
3
+ def self.included(base)
4
+ base.class_eval do
5
+ def self.process_view_paths(value)
6
+ PathSet.new(Array.wrap(value))
7
+ end
8
+ end
9
+ end
10
+
11
+ class PathSet < ::ActionView::PathSet
12
+ def find(path, prefix = nil, partial = false, details = {}, key = nil)
13
+ super
14
+ rescue ::ActionView::MissingTemplate
15
+ super(path, "inherited_resources", partial, details, key)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class InheritedResourcesViewsTest < ActiveSupport::TestCase
4
+ # Replace this with your real tests.
5
+ test "the truth" do
6
+ assert true
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'active_support'
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: inherited_resources_views
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Fred Wu
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-08-05 00:00:00 +10:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: inherited_resources
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 1
30
+ - 1
31
+ version: "1.1"
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ description: 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!
35
+ email: ifredwu@gmail.com
36
+ executables: []
37
+
38
+ extensions: []
39
+
40
+ extra_rdoc_files:
41
+ - README.md
42
+ files:
43
+ - .gitignore
44
+ - MIT-LICENSE
45
+ - README.md
46
+ - Rakefile
47
+ - app/views/inherited_resources/_form.html.erb
48
+ - app/views/inherited_resources/edit.html.erb
49
+ - app/views/inherited_resources/index.html.erb
50
+ - app/views/inherited_resources/new.html.erb
51
+ - app/views/inherited_resources/show.html.erb
52
+ - inherited_resources_views.gemspec
53
+ - lib/generators/inherited_resources_views_generator.rb
54
+ - lib/inherited_resources_views.rb
55
+ - lib/inherited_resources_views/action_view.rb
56
+ - test/inherited_resources_views_test.rb
57
+ - test/test_helper.rb
58
+ has_rdoc: true
59
+ homepage: http://github.com/fredwu/inherited_resources_views
60
+ licenses: []
61
+
62
+ post_install_message:
63
+ rdoc_options:
64
+ - --charset=UTF-8
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ segments:
73
+ - 0
74
+ version: "0"
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ segments:
81
+ - 0
82
+ version: "0"
83
+ requirements: []
84
+
85
+ rubyforge_project:
86
+ rubygems_version: 1.3.7
87
+ signing_key:
88
+ specification_version: 3
89
+ summary: A lot of times resources share the same views, so why not DRY 'em up using Inherited Resources Views!
90
+ test_files:
91
+ - test/inherited_resources_views_test.rb
92
+ - test/test_helper.rb