link_to_action 0.0.5 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/README.md +9 -0
- data/lib/generators/link_to_action/templates/link_to_action.rb +28 -0
- data/lib/link_to_action/helpers.rb +28 -7
- data/lib/link_to_action/version.rb +1 -1
- data/lib/link_to_action.rb +44 -0
- metadata +2 -2
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -22,7 +22,16 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
+
In general:
|
26
|
+
|
25
27
|
link_to_{action} object, options
|
28
|
+
|
29
|
+
Per action:
|
30
|
+
|
31
|
+
link_to_new MyModel
|
32
|
+
link_to_edit @my_instance
|
33
|
+
link_to_destroy @my_instance
|
34
|
+
link_to_back
|
26
35
|
|
27
36
|
## Contributing
|
28
37
|
|
@@ -4,4 +4,32 @@ LinkToAction.setup do |config|
|
|
4
4
|
|
5
5
|
# Add icons to links, default false
|
6
6
|
# config.use_icons = false
|
7
|
+
|
8
|
+
# Icons by default are adopted to font-awesome
|
9
|
+
# Icons size, default 'large'
|
10
|
+
# config.icons_size = 'large'
|
11
|
+
|
12
|
+
# Icons for actions
|
13
|
+
# config.icon_new = 'plus'
|
14
|
+
# config.icon_edit = 'edit'
|
15
|
+
# config.icon_destroy = 'trash'
|
16
|
+
# config.icon_back = 'undo'
|
17
|
+
|
18
|
+
# Use classes, default false
|
19
|
+
# config.use_classes = false
|
20
|
+
|
21
|
+
# Classes by default are adopted to twitter-bootstrap
|
22
|
+
# config.class_default = 'btn'
|
23
|
+
|
24
|
+
# Classes for actions
|
25
|
+
# config.class_new = 'btn-primary'
|
26
|
+
# config.class_edit = nil
|
27
|
+
# config.class_destroy = 'btn-danger'
|
28
|
+
# config.class_back = nil
|
29
|
+
|
30
|
+
# Size can be set using class, by default is adopted to twitter-bootstrap
|
31
|
+
# config.size_class_default = nil
|
32
|
+
# config.size_class_large = 'btn-large'
|
33
|
+
# config.size_class_small = 'btn-small'
|
34
|
+
# config.size_class_mini = 'btn-mini'
|
7
35
|
end
|
@@ -15,25 +15,46 @@ module LinkToAction::Helpers
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def link_to_back(options = {})
|
18
|
-
|
18
|
+
link_to_action :back, nil, options
|
19
19
|
end
|
20
20
|
|
21
21
|
# TODO: Move to separate module to avoid clashes
|
22
22
|
private
|
23
23
|
|
24
|
-
|
25
|
-
|
24
|
+
def action_class(action, options)
|
25
|
+
class_default = LinkToAction.class_default
|
26
|
+
class_action = LinkToAction.send("class_#{action}")
|
27
|
+
if options[:size]
|
28
|
+
size_class = LinkToAction.send("size_class_#{options[:size]}")
|
29
|
+
else
|
30
|
+
size_class = LinkToAction.size_class_default
|
31
|
+
end
|
32
|
+
[class_default, class_action, size_class, options[:class]].compact.join(' ')
|
33
|
+
end
|
34
|
+
|
35
|
+
def action_icon(action)
|
36
|
+
[ LinkToAction.send("icon_#{action}"), LinkToAction.icons_size ].join(' ')
|
37
|
+
end
|
26
38
|
|
27
39
|
def link_to_action(action, object, options)
|
28
40
|
name = options.delete(:name) || t_action(object, action)
|
29
41
|
params = options.delete(:params) || {}
|
30
42
|
params[:action] = action if [ :new, :edit ].include? action
|
31
|
-
|
32
|
-
|
43
|
+
options[:class] = action_class(action, options)
|
44
|
+
iilink_to action_icon(action), name, action_path(action, object, params),
|
45
|
+
options if cancan?(action, object)
|
46
|
+
end
|
47
|
+
|
48
|
+
def action_path(action, object, params)
|
49
|
+
if action == :back
|
50
|
+
action
|
51
|
+
else
|
52
|
+
polymorphic_path(object, params)
|
53
|
+
end
|
33
54
|
end
|
34
55
|
|
35
56
|
def cancan?(*args)
|
36
|
-
LinkToAction.use_cancan ? can?(*args) : true
|
57
|
+
args[0] == :back || LinkToAction.use_cancan ? can?(*args) : true
|
37
58
|
end
|
38
59
|
|
39
60
|
def iilink_to(icon_name, name, path, options = {})
|
@@ -51,7 +72,7 @@ module LinkToAction::Helpers
|
|
51
72
|
model = if object.respond_to?(:model_name)
|
52
73
|
object.model_name.human
|
53
74
|
else
|
54
|
-
object.class.model_name.human
|
75
|
+
object.class.model_name.human if object.class.respond_to?(:model_name)
|
55
76
|
end
|
56
77
|
|
57
78
|
t(:"helpers.link_to.#{action}", model: model)
|
data/lib/link_to_action.rb
CHANGED
@@ -11,6 +11,50 @@ module LinkToAction
|
|
11
11
|
mattr_accessor :use_icons
|
12
12
|
@@use_icons = false
|
13
13
|
|
14
|
+
mattr_accessor :icons_size
|
15
|
+
@@icons_size = 'large'
|
16
|
+
|
17
|
+
mattr_accessor :icon_new
|
18
|
+
@@icon_new = 'plus'
|
19
|
+
|
20
|
+
mattr_accessor :icon_edit
|
21
|
+
@@icon_edit = 'edit'
|
22
|
+
|
23
|
+
mattr_accessor :icon_destroy
|
24
|
+
@@icon_destroy = 'trash'
|
25
|
+
|
26
|
+
mattr_accessor :icon_back
|
27
|
+
@@icon_back = 'undo'
|
28
|
+
|
29
|
+
mattr_accessor :use_classes
|
30
|
+
@@use_classes = false
|
31
|
+
|
32
|
+
mattr_accessor :class_default
|
33
|
+
@@class_default = 'btn'
|
34
|
+
|
35
|
+
mattr_accessor :class_new
|
36
|
+
@@class_new = 'btn-primary'
|
37
|
+
|
38
|
+
mattr_accessor :class_edit
|
39
|
+
@@class_edit = nil
|
40
|
+
|
41
|
+
mattr_accessor :class_destroy
|
42
|
+
@@class_destroy = 'btn-danger'
|
43
|
+
|
44
|
+
mattr_accessor :class_back
|
45
|
+
@@class_back = nil
|
46
|
+
|
47
|
+
mattr_accessor :size_class_default
|
48
|
+
@@size_class_default = nil
|
49
|
+
|
50
|
+
mattr_accessor :size_class_large
|
51
|
+
@@size_class_large = 'btn-large'
|
52
|
+
|
53
|
+
mattr_accessor :size_class_small
|
54
|
+
@@size_class_small = 'btn-small'
|
55
|
+
|
56
|
+
mattr_accessor :size_class_mini
|
57
|
+
@@size_class_mini = 'btn-mini'
|
14
58
|
def self.setup
|
15
59
|
yield self
|
16
60
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: link_to_action
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.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: 2012-
|
12
|
+
date: 2012-10-01 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: link_to for specific actions
|
15
15
|
email:
|