inherited_resources_helpers 0.0.1
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.
@@ -0,0 +1,11 @@
|
|
1
|
+
module InheritedResources
|
2
|
+
module Helpers
|
3
|
+
module LinkTo
|
4
|
+
[:index, :new, :show, :edit, :destroy].each do |action|
|
5
|
+
define_method(:"link_to_#{action}") do |*args|
|
6
|
+
link_to(t(:".#{action}"), controller.send(:"#{action}_path"), args.extract_options!)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module InheritedResources
|
2
|
+
module Helpers
|
3
|
+
module Resources
|
4
|
+
def resource
|
5
|
+
member_action? ? super : build_resource
|
6
|
+
end
|
7
|
+
|
8
|
+
def resources
|
9
|
+
@resources ||= with_chain(resource).tap { |r| r.unshift(route_prefix) if route_prefix }
|
10
|
+
@resources.dup
|
11
|
+
end
|
12
|
+
|
13
|
+
def parent_resources
|
14
|
+
resources[0..-2]
|
15
|
+
end
|
16
|
+
|
17
|
+
protected
|
18
|
+
|
19
|
+
MEMBER_ACTIONS = [:show, :edit, :update, :destroy]
|
20
|
+
|
21
|
+
def member_action?
|
22
|
+
MEMBER_ACTIONS.include?(params[:action].to_sym)
|
23
|
+
end
|
24
|
+
|
25
|
+
def route_prefix
|
26
|
+
@route_prefix ||= self.class.resources_configuration[:self][:route_prefix].try(:to_sym)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module InheritedResources
|
2
|
+
module Helpers
|
3
|
+
module UrlFor
|
4
|
+
def index_url(options = {})
|
5
|
+
polymorphic_url(parent_resources << resource_class, options)
|
6
|
+
end
|
7
|
+
|
8
|
+
def new_url(options = {})
|
9
|
+
polymorphic_url(parent_resources.unshift(:new) << resource_class.name.underscore, options)
|
10
|
+
end
|
11
|
+
|
12
|
+
def show_url(options = {})
|
13
|
+
raise "can't generate show_url because the current resource (#{resource.inspect}) is a new record" if resource.new_record?
|
14
|
+
polymorphic_url(resources, options)
|
15
|
+
end
|
16
|
+
|
17
|
+
def edit_url(options = {})
|
18
|
+
raise "can't generate edit_url because the current resource (#{resource.inspect}) is a new record" if resource.new_record?
|
19
|
+
polymorphic_url(resources.unshift(:edit), options)
|
20
|
+
end
|
21
|
+
|
22
|
+
[:index, :new, :show, :edit].each do |action|
|
23
|
+
define_method(:"#{action}_path") do |*args|
|
24
|
+
send(:"#{action}_url", args.extract_options!.reverse_merge(:routing_type => :path))
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'inherited_resources'
|
2
|
+
|
3
|
+
module InheritedResources
|
4
|
+
module Helpers
|
5
|
+
autoload :Resources, 'inherited_resources/helpers/resources'
|
6
|
+
autoload :UrlFor, 'inherited_resources/helpers/url_for'
|
7
|
+
autoload :LinkTo, 'inherited_resources/helpers/link_to'
|
8
|
+
end
|
9
|
+
|
10
|
+
Base.class_eval do
|
11
|
+
class << self
|
12
|
+
def inherited_with_helpers(base)
|
13
|
+
base.send :include, Helpers::Resources
|
14
|
+
base.send :include, Helpers::UrlFor
|
15
|
+
inherited_without_helpers(base)
|
16
|
+
end
|
17
|
+
alias_method_chain :inherited, :helpers # TODO ugh.
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: inherited_resources_helpers
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Sven Fuchs
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-09-11 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: "[description]"
|
23
|
+
email: svenfuchs@artweb-design.de
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files: []
|
29
|
+
|
30
|
+
files:
|
31
|
+
- lib/inherited_resources/helpers/link_to.rb
|
32
|
+
- lib/inherited_resources/helpers/resources.rb
|
33
|
+
- lib/inherited_resources/helpers/url_for.rb
|
34
|
+
- lib/inherited_resources/helpers/version.rb
|
35
|
+
- lib/inherited_resources/helpers.rb
|
36
|
+
has_rdoc: true
|
37
|
+
homepage: http://github.com/svenfuchs/inherited_resources_helpers
|
38
|
+
licenses: []
|
39
|
+
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
none: false
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
hash: 3
|
51
|
+
segments:
|
52
|
+
- 0
|
53
|
+
version: "0"
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 23
|
60
|
+
segments:
|
61
|
+
- 1
|
62
|
+
- 3
|
63
|
+
- 6
|
64
|
+
version: 1.3.6
|
65
|
+
requirements: []
|
66
|
+
|
67
|
+
rubyforge_project: "[none]"
|
68
|
+
rubygems_version: 1.3.7
|
69
|
+
signing_key:
|
70
|
+
specification_version: 3
|
71
|
+
summary: "[summary]"
|
72
|
+
test_files: []
|
73
|
+
|