link_to_action 0.0.1 → 0.0.2

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/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Set of helpers: link_to_new, link_to_edit, link_to_destroy
4
4
 
5
- NOTE: only link_to_new is available in version 0.0.1
5
+ NOTE: only link_to_new and link_to_edit are available in version 0.0.2
6
6
 
7
7
  ## Installation
8
8
 
@@ -0,0 +1,5 @@
1
+ en:
2
+ helpers:
3
+ link_to:
4
+ new: 'New %{model}'
5
+ edit: 'Edit %{model}'
@@ -1,3 +1,3 @@
1
1
  module LinkToAction
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,17 +1,30 @@
1
1
  require "link_to_action/version"
2
2
  require 'action_view'
3
3
  require 'active_model'
4
+ require 'active_support'
4
5
 
5
6
  module LinkToAction
6
7
  def link_to_new(object, options = {})
7
- name = options.delete(:name) || t_action(object, :create)
8
- params = options.delete(:params) || {}
9
- params[:action] = :new
10
- ilink_to 'plus large', name, polymorphic_url(object, params), options if can?(:create, object)
8
+ link_to_action(:new, object, options)
9
+ end
10
+
11
+ def link_to_edit(object, options = {})
12
+ link_to_action(:edit, object, options)
11
13
  end
12
14
 
13
15
  private
14
16
 
17
+ ICONS = {new: 'plus', edit: 'edit'}
18
+
19
+ def link_to_action(action, object, options)
20
+ name = options.delete(:name) || t_action(object, action)
21
+ params = options.delete(:params) || {}
22
+ params[:action] = action
23
+ # TODO: make icon and can? optional
24
+ ilink_to "#{LinkToAction::ICONS[action]} large", name,
25
+ polymorphic_url(object, params), options if can?(action, object)
26
+ end
27
+
15
28
  def ilink_to(*args)
16
29
  icon = args[0].split(' ').map {|i| "icon-#{i}"}.join(' ')
17
30
  name = args[1]
@@ -28,8 +41,10 @@ module LinkToAction
28
41
  object.class.model_name.human
29
42
  end
30
43
 
31
- t(:"helpers.submit.#{action}", model: model)
44
+ t(:"helpers.link_to.#{action}", model: model)
32
45
  end
33
46
  end
34
47
 
35
- ActionView::Base.send :include, LinkToAction
48
+ ActionView::Base.send :include, LinkToAction
49
+
50
+ I18n.load_path << "#{File.dirname(__FILE__)}/link_to_action/locale/en.yml"
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.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -24,6 +24,7 @@ files:
24
24
  - README.md
25
25
  - Rakefile
26
26
  - lib/link_to_action.rb
27
+ - lib/link_to_action/locale/en.yml
27
28
  - lib/link_to_action/version.rb
28
29
  - link_to_action.gemspec
29
30
  homepage: https://github.com/denispeplin/link_to_action