action_links 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +7 -1
- data/lib/action_links/configuration.rb +3 -0
- data/lib/action_links/helpers.rb +15 -1
- data/lib/action_links/link.rb +13 -3
- data/lib/action_links/version.rb +1 -1
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -51,4 +51,10 @@ Configuration is optional. Everything will work out of the box.
|
|
51
51
|
|
52
52
|
* Namespaced objects
|
53
53
|
|
54
|
-
action_links [:manage, @product]
|
54
|
+
action_links [:manage, @product]
|
55
|
+
|
56
|
+
* Return just the link with optional parameters
|
57
|
+
|
58
|
+
=action_link :edit, @event
|
59
|
+
// or more advanced
|
60
|
+
=action_link :clone, @event, link_wrapper: :li, url: url_for([:clone, @event]), icon: 'copy', text: 'Copy'
|
@@ -2,10 +2,13 @@ module ActionLinks
|
|
2
2
|
class Configuration
|
3
3
|
attr_accessor :bootstrap_action_classes
|
4
4
|
attr_accessor :bootstrap_action_icons
|
5
|
+
attr_accessor :action_icons
|
5
6
|
|
6
7
|
def initialize
|
7
8
|
@bootstrap_action_classes = { :show => 'btn', :edit => 'btn', :destroy => 'btn btn-danger' }
|
8
9
|
@bootstrap_action_icons = { :show => 'icon-eye-open', :edit => 'icon-pencil', :destroy => 'icon-remove icon-white' }
|
10
|
+
|
11
|
+
@action_icons = { :show => 'eye-open', :edit => 'pencil', :destroy => 'remove' }
|
9
12
|
end
|
10
13
|
end
|
11
14
|
end
|
data/lib/action_links/helpers.rb
CHANGED
@@ -21,7 +21,21 @@ module ActionLinks
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def action_link(action, object_or_array, options = {})
|
24
|
-
ActionLinks::Link.new(action, object_or_array, options
|
24
|
+
link = ActionLinks::Link.new(action, object_or_array, options)
|
25
|
+
|
26
|
+
link_url_or_array = options[:url] || link.url_array
|
27
|
+
|
28
|
+
if allowed_to_visit?(link) && (!current_page?(link_url_or_array) || link.destroy?) # Check user permissions on action
|
29
|
+
title = link.icon ? content_tag(:i, '', :class => "icon-#{link.icon}") + " " + link.title : link.title # append icon to title if it exists
|
30
|
+
|
31
|
+
html_link = link_to(title, link_url_or_array, link.html_options)
|
32
|
+
|
33
|
+
if options[:link_wrapper]
|
34
|
+
content_tag(options[:link_wrapper], html_link, :class=>options[:link_wrapper_class])
|
35
|
+
else
|
36
|
+
html_link # Return plain link if wrapper is not specified
|
37
|
+
end
|
38
|
+
end
|
25
39
|
end
|
26
40
|
|
27
41
|
def action_link_builder(object_or_array, options = {}, &block)
|
data/lib/action_links/link.rb
CHANGED
@@ -17,9 +17,19 @@ module ActionLinks
|
|
17
17
|
def object_name
|
18
18
|
@object_name ||= object.class.model_name.human
|
19
19
|
end
|
20
|
+
|
21
|
+
def icon
|
22
|
+
@icon ||= Proc.new {
|
23
|
+
if options.include? :icon # You have to do it this was to allow support of passing nil to :icon, without it getting overridden by ActionLinks.config
|
24
|
+
options[:icon]
|
25
|
+
else
|
26
|
+
ActionLinks.config.action_icons[action] || nil
|
27
|
+
end
|
28
|
+
}.call
|
29
|
+
end
|
20
30
|
|
21
31
|
def title
|
22
|
-
@title ||= I18n.t(action, :scope=>'action_links', :default=>action.to_s.humanize)
|
32
|
+
@title ||= options[:text] || I18n.t(action, :scope=>'action_links', :default=>action.to_s.humanize)
|
23
33
|
end
|
24
34
|
|
25
35
|
def url_array
|
@@ -39,13 +49,13 @@ module ActionLinks
|
|
39
49
|
end
|
40
50
|
|
41
51
|
def remote?
|
42
|
-
options[:remote].include? action
|
52
|
+
options[:remote].include? action if options[:remote]
|
43
53
|
end
|
44
54
|
|
45
55
|
def html_options
|
46
56
|
return @html_options unless @html_options.nil?
|
47
57
|
|
48
|
-
@html_options = { :class=>action.to_s.parameterize, :title=>"#{title} #{object_name}" }
|
58
|
+
@html_options = { :class=>"#{action.to_s.parameterize} #{options[:class]}", :title=>"#{title} #{object_name}" }
|
49
59
|
@html_options[:remote] = true if remote?
|
50
60
|
|
51
61
|
if action == :destroy
|
data/lib/action_links/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: action_links
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-11-16 00:00:00.000000000 Z
|
14
14
|
dependencies: []
|
15
15
|
description: Automatically includes action links (show, edit, destroy) based on the
|
16
16
|
current page and user roles/permissions
|