inherited_templates 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +0 -0
- data/lib/generators/inherited_templates/defaults_generator.rb +13 -0
- data/lib/generators/inherited_templates/templates/defaults/_form.html.haml +3 -0
- data/lib/generators/inherited_templates/templates/defaults/_index_table.html.haml +8 -0
- data/lib/generators/inherited_templates/templates/defaults/_index_table_body.html.haml +15 -0
- data/lib/generators/inherited_templates/templates/defaults/_index_table_foot.html.haml +0 -0
- data/lib/generators/inherited_templates/templates/defaults/_index_table_head.html.haml +7 -0
- data/lib/generators/inherited_templates/templates/defaults/_show_table.html.haml +4 -0
- data/lib/generators/inherited_templates/templates/defaults/_show_table_body.html.haml +7 -0
- data/lib/generators/inherited_templates/templates/defaults/_show_table_foot.html.haml +0 -0
- data/lib/generators/inherited_templates/templates/defaults/_show_table_head.html.haml +0 -0
- data/lib/generators/inherited_templates/templates/defaults/edit.html.haml +10 -0
- data/lib/generators/inherited_templates/templates/defaults/index.html.haml +8 -0
- data/lib/generators/inherited_templates/templates/defaults/new.html.haml +8 -0
- data/lib/generators/inherited_templates/templates/defaults/show.html.haml +10 -0
- data/lib/inherited_templates.rb +20 -0
- data/lib/inherited_templates/action_controller/base.rb +32 -0
- data/lib/inherited_templates/action_view/base.rb +34 -0
- data/lib/inherited_templates/action_view/helpers.rb +40 -0
- data/lib/inherited_templates/inherited_resources/name_helpers.rb +21 -0
- data/lib/inherited_templates/version.rb +3 -0
- metadata +155 -0
data/README.md
ADDED
File without changes
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module InheritedTemplates
|
2
|
+
module Generators
|
3
|
+
class DefaultsGenerator < Rails::Generators::Base
|
4
|
+
desc "Creates default template files for your application."
|
5
|
+
|
6
|
+
source_root File.expand_path("../templates", __FILE__)
|
7
|
+
|
8
|
+
def copy_views
|
9
|
+
directory "defaults", "app/views/defaults"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
- if collection.any?
|
2
|
+
%table{ :class => "index #{resource_collection_name}", :id => "index_#{resource_collection_name}" }
|
3
|
+
= render :partial => "index_table_head"
|
4
|
+
= render :partial => "index_table_body"
|
5
|
+
= render :partial => "index_table_foot"
|
6
|
+
- else
|
7
|
+
%p.empty
|
8
|
+
= t("#{resource_collection_name}.label.empty", :default => "No #{resource_collection_name}")
|
@@ -0,0 +1,15 @@
|
|
1
|
+
%tbody
|
2
|
+
- collection.each do |r|
|
3
|
+
%tr{ :class => cycle("odd", "even") }
|
4
|
+
- r.attributes.each do |c|
|
5
|
+
%td
|
6
|
+
= c[1]
|
7
|
+
|
8
|
+
%td.actions
|
9
|
+
%ul
|
10
|
+
%li.first
|
11
|
+
= resource_link :show, r
|
12
|
+
%li
|
13
|
+
= resource_link :edit, r
|
14
|
+
%li.last
|
15
|
+
= resource_link :destroy, r
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module InheritedTemplates
|
2
|
+
end
|
3
|
+
|
4
|
+
module InheritedResources
|
5
|
+
Base.class_eval do
|
6
|
+
class << self
|
7
|
+
def inherit_resources_with_inherit_templates(base)
|
8
|
+
base.send :include, InheritedTemplates::InheritedResources::NameHelpers
|
9
|
+
|
10
|
+
inherit_resources_without_inherit_templates(base)
|
11
|
+
end
|
12
|
+
|
13
|
+
alias_method_chain :inherit_resources, :inherit_templates
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
ActionView::Base.send :include, InheritedTemplates::ActionView::Base
|
19
|
+
ActionView::Helpers.send :include, InheritedTemplates::ActionView::Helpers
|
20
|
+
#ActionController::Base.send :include, InheritedTemplates::ActionController::Base
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module InheritedTemplates
|
2
|
+
module ActionController
|
3
|
+
module Base
|
4
|
+
def self.included(base)
|
5
|
+
base.class_eval do
|
6
|
+
def self.register_default_view_path(path)
|
7
|
+
unless view_paths.include? path
|
8
|
+
#resource_view_path = ::ActionView::PathSet.type_cast(path.to_s)
|
9
|
+
resource_view_path = ::ActionView::PathSet.new(Array.wrap(path.to_s))
|
10
|
+
|
11
|
+
resource_view_path.instance_eval do
|
12
|
+
def [](path)
|
13
|
+
super(path.to_s.sub(%r[\A[^/]+/], ''))
|
14
|
+
end
|
15
|
+
|
16
|
+
def relative_path_for_template_file(full_file_path)
|
17
|
+
full_file_path.split("#{@path}/").last
|
18
|
+
end
|
19
|
+
|
20
|
+
def templates_dir_from_path(path)
|
21
|
+
@path
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
append_view_path(resource_view_path)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module InheritedTemplates
|
2
|
+
module ActionView
|
3
|
+
module Base
|
4
|
+
def self.included(base)
|
5
|
+
base.class_eval do
|
6
|
+
class << self
|
7
|
+
def process_view_paths(value)
|
8
|
+
PathSet.new(Array.wrap(value))
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class PathSet < ::ActionView::PathSet
|
15
|
+
def find(path, prefix = nil, partial = false, details = {}, key = nil)
|
16
|
+
begin
|
17
|
+
super
|
18
|
+
rescue ::ActionView::MissingTemplate
|
19
|
+
super(path, "defaults", partial, details, key)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def find_template(original_template_path, format = nil, html_fallback = true)
|
24
|
+
begin
|
25
|
+
super
|
26
|
+
rescue ::ActionView::MissingTemplate
|
27
|
+
original_template_path.sub!(/^[\w]+/, "defaults")
|
28
|
+
super
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module InheritedTemplates
|
2
|
+
module ActionView
|
3
|
+
module Helpers
|
4
|
+
def self.included(base)
|
5
|
+
base.class_eval do
|
6
|
+
def resource_link(action, r = nil)
|
7
|
+
case action
|
8
|
+
when :index
|
9
|
+
link_to(
|
10
|
+
t("#{resource_collection_name}.action.index", :default => "Back"),
|
11
|
+
polymorphic_path(controller_name)
|
12
|
+
).html_safe
|
13
|
+
when :new
|
14
|
+
link_to(
|
15
|
+
t("#{resource_collection_name}.action.new", :default => "New"),
|
16
|
+
new_polymorphic_path(controller_name.singularize)
|
17
|
+
).html_safe
|
18
|
+
when :show
|
19
|
+
link_to(
|
20
|
+
t("#{resource_collection_name}.action.show", :default => "Show"),
|
21
|
+
polymorphic_path(r)
|
22
|
+
).html_safe
|
23
|
+
when :edit
|
24
|
+
link_to(
|
25
|
+
t("#{resource_collection_name}.action.edit", :default => "Edit"),
|
26
|
+
edit_polymorphic_path(r)
|
27
|
+
).html_safe
|
28
|
+
when :destroy
|
29
|
+
link_to(
|
30
|
+
t("#{resource_collection_name}.action.destroy", :default => "Destroy"),
|
31
|
+
polymorphic_path(r),
|
32
|
+
{ :confirm => t("#{resource_collection_name}.confirm.destroy", :default => "Are you sure?"), :method => :delete }
|
33
|
+
).html_safe
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module InheritedTemplates
|
2
|
+
module InheritedResources
|
3
|
+
module NameHelpers
|
4
|
+
def self.included(base)
|
5
|
+
base.class_eval do
|
6
|
+
def resource_name
|
7
|
+
resource_class.human_name
|
8
|
+
end
|
9
|
+
|
10
|
+
helper_method :resource_name
|
11
|
+
|
12
|
+
def resources_name
|
13
|
+
resource_name.pluralize
|
14
|
+
end
|
15
|
+
|
16
|
+
helper_method :resources_name
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: inherited_templates
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 19
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 6
|
10
|
+
version: 0.0.6
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Thomas Boerger
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-09-28 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: inherited_resources
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 27
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 0
|
33
|
+
- 6
|
34
|
+
version: 1.0.6
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: formtastic
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 43
|
46
|
+
segments:
|
47
|
+
- 0
|
48
|
+
- 9
|
49
|
+
- 8
|
50
|
+
version: 0.9.8
|
51
|
+
type: :runtime
|
52
|
+
version_requirements: *id002
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: will_paginate
|
55
|
+
prerelease: false
|
56
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
hash: 27
|
62
|
+
segments:
|
63
|
+
- 2
|
64
|
+
- 3
|
65
|
+
- 12
|
66
|
+
version: 2.3.12
|
67
|
+
type: :runtime
|
68
|
+
version_requirements: *id003
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: validation_reflection
|
71
|
+
prerelease: false
|
72
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
hash: 15424055
|
78
|
+
segments:
|
79
|
+
- 1
|
80
|
+
- 0
|
81
|
+
- 0
|
82
|
+
- rc
|
83
|
+
- 1
|
84
|
+
version: 1.0.0.rc.1
|
85
|
+
type: :runtime
|
86
|
+
version_requirements: *id004
|
87
|
+
description: With InheritedTemplates you can create global default templates for your InheritedResources controllers
|
88
|
+
email:
|
89
|
+
- tboerger@tbpro.de
|
90
|
+
executables: []
|
91
|
+
|
92
|
+
extensions: []
|
93
|
+
|
94
|
+
extra_rdoc_files: []
|
95
|
+
|
96
|
+
files:
|
97
|
+
- lib/inherited_templates.rb
|
98
|
+
- lib/generators/inherited_templates/templates/defaults/show.html.haml
|
99
|
+
- lib/generators/inherited_templates/templates/defaults/edit.html.haml
|
100
|
+
- lib/generators/inherited_templates/templates/defaults/_index_table_body.html.haml
|
101
|
+
- lib/generators/inherited_templates/templates/defaults/_show_table_body.html.haml
|
102
|
+
- lib/generators/inherited_templates/templates/defaults/new.html.haml
|
103
|
+
- lib/generators/inherited_templates/templates/defaults/index.html.haml
|
104
|
+
- lib/generators/inherited_templates/templates/defaults/_index_table_foot.html.haml
|
105
|
+
- lib/generators/inherited_templates/templates/defaults/_show_table.html.haml
|
106
|
+
- lib/generators/inherited_templates/templates/defaults/_index_table.html.haml
|
107
|
+
- lib/generators/inherited_templates/templates/defaults/_show_table_foot.html.haml
|
108
|
+
- lib/generators/inherited_templates/templates/defaults/_index_table_head.html.haml
|
109
|
+
- lib/generators/inherited_templates/templates/defaults/_show_table_head.html.haml
|
110
|
+
- lib/generators/inherited_templates/templates/defaults/_form.html.haml
|
111
|
+
- lib/generators/inherited_templates/defaults_generator.rb
|
112
|
+
- lib/inherited_templates/inherited_resources/name_helpers.rb
|
113
|
+
- lib/inherited_templates/action_controller/base.rb
|
114
|
+
- lib/inherited_templates/version.rb
|
115
|
+
- lib/inherited_templates/action_view/helpers.rb
|
116
|
+
- lib/inherited_templates/action_view/base.rb
|
117
|
+
- README.md
|
118
|
+
has_rdoc: true
|
119
|
+
homepage: http://github.com/tbpro/inherited_templates
|
120
|
+
licenses: []
|
121
|
+
|
122
|
+
post_install_message:
|
123
|
+
rdoc_options: []
|
124
|
+
|
125
|
+
require_paths:
|
126
|
+
- lib
|
127
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
128
|
+
none: false
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
hash: 3
|
133
|
+
segments:
|
134
|
+
- 0
|
135
|
+
version: "0"
|
136
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ">="
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
hash: 23
|
142
|
+
segments:
|
143
|
+
- 1
|
144
|
+
- 3
|
145
|
+
- 6
|
146
|
+
version: 1.3.6
|
147
|
+
requirements: []
|
148
|
+
|
149
|
+
rubyforge_project: "[none]"
|
150
|
+
rubygems_version: 1.3.7
|
151
|
+
signing_key:
|
152
|
+
specification_version: 3
|
153
|
+
summary: A simple way to implement default templates for InheritedResources
|
154
|
+
test_files: []
|
155
|
+
|