i18n_rails_helpers 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
@@ -48,9 +48,11 @@ module ContextualLinkHelpers
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
-
def contextual_link_to(action,
|
52
|
-
# We don't want to change the passed in
|
53
|
-
options =
|
51
|
+
def contextual_link_to(action, options = {})
|
52
|
+
# We don't want to change the passed in options
|
53
|
+
options = options.dup
|
54
|
+
|
55
|
+
resource_or_model = options.delete(:resource) || options.delete(:model)
|
54
56
|
|
55
57
|
# Handle both symbols and strings
|
56
58
|
action = action.to_sym
|
@@ -104,7 +106,9 @@ module ContextualLinkHelpers
|
|
104
106
|
return icon_link_to(action, path, options)
|
105
107
|
end
|
106
108
|
|
107
|
-
def contextual_links_for(
|
109
|
+
def contextual_links_for(options = {})
|
110
|
+
action = options.delete(:action)
|
111
|
+
|
108
112
|
# Use current action if not specified
|
109
113
|
action ||= action_name
|
110
114
|
|
@@ -123,14 +127,14 @@ module ContextualLinkHelpers
|
|
123
127
|
actions << :new
|
124
128
|
end
|
125
129
|
|
126
|
-
links = actions.map{|link_for| contextual_link_to(link_for,
|
130
|
+
links = actions.map{|link_for| contextual_link_to(link_for, options)}
|
127
131
|
|
128
132
|
return links.join("\n").html_safe
|
129
133
|
end
|
130
134
|
|
131
|
-
def contextual_links(
|
135
|
+
def contextual_links(options = {}, &block)
|
132
136
|
content_tag('div', :class => I18nRailsHelpers.contextual_class) do
|
133
|
-
content = contextual_links_for(
|
137
|
+
content = contextual_links_for(options)
|
134
138
|
if block_given?
|
135
139
|
additional_content = capture(&block)
|
136
140
|
content += ("\n" + additional_content).html_safe
|
@@ -1,15 +1,44 @@
|
|
1
1
|
module ListLinkHelpers
|
2
|
+
def action_to_icon(action)
|
3
|
+
case action.to_s
|
4
|
+
when 'new'
|
5
|
+
"plus"
|
6
|
+
when 'show'
|
7
|
+
"eye-open"
|
8
|
+
when 'edit'
|
9
|
+
"edit"
|
10
|
+
when 'delete'
|
11
|
+
"trash"
|
12
|
+
when "index", "list"
|
13
|
+
"list-alt"
|
14
|
+
when "update"
|
15
|
+
"refresh"
|
16
|
+
when "copy"
|
17
|
+
"repeat"
|
18
|
+
else
|
19
|
+
action
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
2
23
|
# List link helpers
|
3
24
|
def list_link_to(action, url, options = {})
|
4
|
-
|
5
|
-
|
6
|
-
|
25
|
+
classes = []
|
26
|
+
if class_options = options.delete(:class)
|
27
|
+
classes << class_options.split(' ')
|
28
|
+
end
|
29
|
+
|
30
|
+
icon = options.delete(:icon)
|
31
|
+
icon ||= action
|
32
|
+
|
33
|
+
link_to(url_for(url), options) do
|
34
|
+
content_tag(:i, "", :class => "icon-#{action_to_icon(icon)}")
|
35
|
+
end
|
7
36
|
end
|
8
|
-
|
37
|
+
|
9
38
|
def list_link_for(action, resource_or_model = nil, options = {})
|
10
39
|
# Handle both symbols and strings
|
11
40
|
action = action.to_s
|
12
|
-
|
41
|
+
|
13
42
|
# Resource and Model setup
|
14
43
|
# Support nested resources
|
15
44
|
if resource_or_model.is_a? Array
|
@@ -17,7 +46,7 @@ module ListLinkHelpers
|
|
17
46
|
else
|
18
47
|
main_resource_or_model = resource_or_model
|
19
48
|
end
|
20
|
-
|
49
|
+
|
21
50
|
# Use controller name to guess resource or model if not specified
|
22
51
|
case action
|
23
52
|
when 'new', 'index'
|
@@ -27,10 +56,10 @@ module ListLinkHelpers
|
|
27
56
|
model = resource.class
|
28
57
|
end
|
29
58
|
model_name = model.to_s.underscore
|
30
|
-
|
59
|
+
|
31
60
|
# No link if CanCan is used and current user isn't authorized to call this action
|
32
61
|
return if respond_to?(:can?) and cannot?(action.to_sym, model)
|
33
|
-
|
62
|
+
|
34
63
|
# Link generation
|
35
64
|
case action
|
36
65
|
when 'index', 'show'
|
@@ -41,17 +70,17 @@ module ListLinkHelpers
|
|
41
70
|
else
|
42
71
|
path = polymorphic_path(resource_or_model, :action => action)
|
43
72
|
end
|
44
|
-
|
73
|
+
|
45
74
|
return list_link_to(action, path, options)
|
46
75
|
end
|
47
|
-
|
76
|
+
|
48
77
|
def list_links_for(action = nil, resource_or_model = nil)
|
49
78
|
# Use current action if not specified
|
50
79
|
action ||= action_name
|
51
|
-
|
80
|
+
|
52
81
|
# Handle both symbols and strings
|
53
82
|
action = action.to_s
|
54
|
-
|
83
|
+
|
55
84
|
actions = []
|
56
85
|
case action
|
57
86
|
when 'new', 'create'
|
@@ -63,9 +92,9 @@ module ListLinkHelpers
|
|
63
92
|
when 'index'
|
64
93
|
actions << 'new'
|
65
94
|
end
|
66
|
-
|
95
|
+
|
67
96
|
links = actions.map{|link_for| contextual_link_to(link_for, resource_or_model)}
|
68
|
-
|
97
|
+
|
69
98
|
return links.join("\n").html_safe
|
70
99
|
end
|
71
100
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: i18n_rails_helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-04-22 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Rails i18n view helpers for things like crud actions, models and and
|
15
15
|
attributes.
|