action_links 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -16,25 +16,39 @@ From the command line
16
16
  > bundle install
17
17
 
18
18
 
19
+ == Configuration
20
+
21
+ Configuration is optional. Everything will work out of the box.
22
+
23
+ ActionLinks.configure do |config|
24
+ config.bootstrap_action_classes = { :show => 'btn', :edit => 'btn', :destroy => 'btn btn-danger' }
25
+ config.bootstrap_action_icons = { :show => 'icon-eye-open', :edit => 'icon-pencil', :destroy => 'icon-remove icon-white' }
26
+ end
27
+
19
28
  == Usage
20
29
 
21
30
  * Basic Usage
22
31
 
23
- =action_links @user
32
+ action_links @user
24
33
 
25
34
  * Include actions
26
35
 
27
- =action_links @user, :include => [:download]
36
+ action_links @user, :include => [:download]
28
37
 
29
38
  * Exclude actions
30
39
 
31
- =action_links @user, :exclude => [:edit, :destroy]
40
+ action_links @user, :exclude => [:edit, :destroy]
32
41
 
33
42
  * Pass in block
34
43
 
35
- =action_links @user do
36
- =link_to "Hello World", dashboard_path
44
+ action_links @user do
45
+ link_to "Hello World", dashboard_path
46
+ end
47
+
48
+ * Bootstrap buttons. See configuration to customize button types and icons.
49
+
50
+ bootstrap_action_links @user
37
51
 
38
52
  * Namespaced objects
39
53
 
40
- =action_links [:manage, @product]
54
+ action_links [:manage, @product]
@@ -2,4 +2,13 @@ require 'action_links/version'
2
2
  require 'action_links/engine' if defined?(Rails)
3
3
 
4
4
  module ActionLinks
5
- end
5
+ require 'action_links/configuration'
6
+
7
+ def self.configure
8
+ yield config
9
+ end
10
+
11
+ def self.config
12
+ @config ||= Configuration.new
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ module ActionLinks
2
+ class Configuration
3
+ attr_accessor :bootstrap_action_classes
4
+ attr_accessor :bootstrap_action_icons
5
+
6
+ def initialize
7
+ @bootstrap_action_classes = { :show => 'btn', :edit => 'btn', :destroy => 'btn btn-danger' }
8
+ @bootstrap_action_icons = { :show => 'icon-eye-open', :edit => 'icon-pencil', :destroy => 'icon-remove icon-white' }
9
+ end
10
+ end
11
+ end
@@ -1,14 +1,11 @@
1
1
  module ActionLinks
2
2
  module Helpers
3
-
4
- def action_links(object_or_array, options={}, &block)
3
+ def action_links(object_or_array, options = {}, &block)
5
4
  list = ActionLinks::List.new(object_or_array, options)
6
5
 
7
6
  links = list.links.map { |link|
8
- unless current_page?(link.url_array) && !link.destroy?
9
- if permitted_to?(link.action, link.object)
10
- link_to(link.title, link.url_array, link.html_options)
11
- end
7
+ if allowed_to_visit?(link) && !already_at?(link)
8
+ link_to(link.title, link.url_array, link.html_options)
12
9
  end
13
10
  }
14
11
 
@@ -22,5 +19,48 @@ module ActionLinks
22
19
  }.join("\n").html_safe
23
20
  end
24
21
  end
22
+
23
+ def action_link(action, object_or_array, options = {})
24
+ ActionLinks::Link.new(action, object_or_array, options = {})
25
+ end
26
+
27
+ def action_link_builder(object_or_array, options = {}, &block)
28
+ ActionLinks::List.new(object_or_array, options).links.each do |link|
29
+ if allowed_to_visit?(link) && !already_at?(link)
30
+ yield(link)
31
+ end
32
+ end
33
+
34
+ nil
35
+ end
36
+
37
+ def bootstrap_action_links(object_or_array, options = {})
38
+ css_classes = options[:bootstrap_action_classes] || ActionLinks.config.bootstrap_action_classes
39
+ icons = options[:bootstrap_action_icons] || ActionLinks.config.bootstrap_action_icons
40
+
41
+ links = []
42
+
43
+ ActionLinks::List.new(object_or_array, options).links.each do |link|
44
+ if allowed_to_visit?(link) && !already_at?(link)
45
+ links << link_to(link.url_array, link.html_options.merge(:class => css_classes[link.action])) do
46
+ link_content = [content_tag(:span, link.title, :class => :title)]
47
+ link_content.unshift(content_tag(:i, '', :class => icons[link.action])) if icons[link.action]
48
+ link_content.join(' ').html_safe
49
+ end
50
+ end
51
+ end
52
+
53
+ links.join("\n").html_safe
54
+ end
55
+
56
+ private
57
+
58
+ def already_at?(link)
59
+ current_page?(link.url_array) && !link.destroy?
60
+ end
61
+
62
+ def allowed_to_visit?(link)
63
+ permitted_to?(link.action, link.object)
64
+ end
25
65
  end
26
66
  end
@@ -1,3 +1,3 @@
1
1
  module ActionLinks
2
- VERSION = '0.2.2'
2
+ VERSION = '0.3.0'
3
3
  end
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.2.2
4
+ version: 0.3.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-06-30 00:00:00.000000000 Z
13
+ date: 2012-07-13 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
@@ -26,6 +26,7 @@ files:
26
26
  - Rakefile
27
27
  - action_links.gemspec
28
28
  - lib/action_links.rb
29
+ - lib/action_links/configuration.rb
29
30
  - lib/action_links/engine.rb
30
31
  - lib/action_links/helpers.rb
31
32
  - lib/action_links/link.rb