link_to_action 0.0.5 → 0.1.0

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.
data/.gitignore CHANGED
@@ -3,6 +3,7 @@
3
3
  .bundle
4
4
  .config
5
5
  .yardoc
6
+ .c9revisions
6
7
  Gemfile.lock
7
8
  InstalledFiles
8
9
  _yardoc
@@ -16,3 +17,4 @@ test/tmp
16
17
  test/version_tmp
17
18
  tmp
18
19
  nbproject
20
+ /.c9revisions/
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
- ilink_to 'undo large', t(:'helpers.link_to.back'), :back, options
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
- # TODO: Move icon names to options
25
- ICONS = {new: 'plus', edit: 'edit', destroy: 'trash'}
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
- iilink_to "#{LinkToAction::Helpers::ICONS[action]} large", name,
32
- polymorphic_path(object, params), options if cancan?(action, object)
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)
@@ -1,3 +1,3 @@
1
1
  module LinkToAction
2
- VERSION = "0.0.5"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -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.5
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-09-28 00:00:00.000000000 Z
12
+ date: 2012-10-01 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: link_to for specific actions
15
15
  email: