i18n_rails_helpers 1.0.7 → 1.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -29,7 +29,12 @@ module ContextualLinkHelpers
29
29
 
30
30
  classes << "btn"
31
31
 
32
- url ||= {:action => action}
32
+ if action.is_a? Symbol
33
+ url ||= {:action => action}
34
+ title = t_action(action)
35
+ else
36
+ title = action
37
+ end
33
38
 
34
39
  icon = options.delete(:icon)
35
40
  icon ||= action
@@ -38,47 +43,47 @@ module ContextualLinkHelpers
38
43
  classes << "btn-#{type}"
39
44
 
40
45
  options.merge!(:class => classes.join(" "))
41
- link_to(url_for(url), options) do
42
- content_tag(:i, "", :class => "icon-#{action_to_icon(icon)}") + " " + t_action(action)
46
+ link_to(url_for(url), options) do
47
+ content_tag(:i, "", :class => "icon-#{action_to_icon(icon)}") + " " + title
43
48
  end
44
49
  end
45
-
50
+
46
51
  def contextual_link_to(action, resource_or_model = nil, link_options = {})
47
52
  # We don't want to change the passed in link_options
48
53
  options = link_options.dup
49
54
 
50
55
  # Handle both symbols and strings
51
- action = action.to_s
52
-
56
+ action = action.to_sym
57
+
53
58
  # Resource and Model setup
54
59
  # Use controller name to guess resource or model if not specified
55
60
  case action
56
- when 'new', 'index'
61
+ when :new, :index
57
62
  model = resource_or_model || controller_name.singularize.camelize.constantize
58
- when 'show', 'edit', 'delete'
63
+ when :show, :edit, :delete
59
64
  resource = resource_or_model || instance_variable_get("@#{controller_name.singularize}")
60
65
  model = resource.class
61
66
  end
62
67
  model_name = model.to_s.underscore
63
-
68
+
64
69
  # No link if CanCan is used and current user isn't authorized to call this action
65
70
  return if respond_to?(:cannot?) and cannot?(action.to_sym, model)
66
-
71
+
67
72
  # Option generation
68
73
  case action
69
- when 'delete'
74
+ when :delete
70
75
  options.merge!(:confirm => t_confirm_delete(resource), :method => :delete)
71
76
  end
72
77
 
73
78
  # Path generation
74
79
  case action
75
- when 'index'
80
+ when :index
76
81
  if model
77
82
  path = polymorphic_path(model)
78
83
  else
79
84
  path = url_for(:action => nil)
80
85
  end
81
- when 'show', 'delete'
86
+ when :show, :delete
82
87
  if resource
83
88
  path = polymorphic_path(resource)
84
89
  else
@@ -94,31 +99,31 @@ module ContextualLinkHelpers
94
99
 
95
100
  return icon_link_to(action, path, options)
96
101
  end
97
-
102
+
98
103
  def contextual_links_for(action = nil, resource_or_model = nil, options = {})
99
104
  # Use current action if not specified
100
105
  action ||= action_name
101
-
106
+
102
107
  # Handle both symbols and strings
103
- action = action.to_s
104
-
108
+ action = action.to_sym
109
+
105
110
  actions = []
106
111
  case action
107
- when 'new', 'create'
108
- actions << 'index'
109
- when 'show'
110
- actions += ['edit', 'delete', 'index']
111
- when 'edit', 'update'
112
- actions += ['show', 'delete', 'index']
113
- when 'index'
114
- actions << 'new'
112
+ when :new, :create
113
+ actions << :index
114
+ when :show
115
+ actions += [:edit, :delete, :index]
116
+ when :edit, :update
117
+ actions += [:show, :delete, :index]
118
+ when :index
119
+ actions << :new
115
120
  end
116
-
121
+
117
122
  links = actions.map{|link_for| contextual_link_to(link_for, resource_or_model, options)}
118
-
123
+
119
124
  return links.join("\n").html_safe
120
125
  end
121
-
126
+
122
127
  def contextual_links(action = nil, resource_or_model = nil, options = {})
123
128
  content_tag('div', :class => 'contextual') do
124
129
  contextual_links_for(action, resource_or_model, options)
@@ -1,3 +1,3 @@
1
1
  module I18nRailsHelpers
2
- VERSION = "1.0.7"
2
+ VERSION = "1.0.8"
3
3
  end
metadata CHANGED
@@ -1,33 +1,24 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: i18n_rails_helpers
3
- version: !ruby/object:Gem::Version
4
- hash: 25
5
- prerelease: false
6
- segments:
7
- - 1
8
- - 0
9
- - 7
10
- version: 1.0.7
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.8
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
13
- - "Simon H\xC3\xBCrlimann (CyT)"
7
+ authors:
8
+ - Simon Hürlimann (CyT)
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-09-06 00:00:00 +02:00
19
- default_executable:
12
+ date: 2013-02-12 00:00:00.000000000 Z
20
13
  dependencies: []
21
-
22
- description: Rails i18n view helpers for things like crud actions, models and and attributes.
14
+ description: Rails i18n view helpers for things like crud actions, models and and
15
+ attributes.
23
16
  email: simon.huerlimann@cyt.ch
24
17
  executables: []
25
-
26
18
  extensions: []
27
-
28
- extra_rdoc_files:
19
+ extra_rdoc_files:
29
20
  - README.markdown
30
- files:
21
+ files:
31
22
  - app/helpers/contextual_link_helpers.rb
32
23
  - app/helpers/i18n_helpers.rb
33
24
  - app/helpers/list_link_helpers.rb
@@ -38,39 +29,29 @@ files:
38
29
  - lib/i18n_rails_helpers/version.rb
39
30
  - rails/init.rb
40
31
  - README.markdown
41
- has_rdoc: true
42
32
  homepage: https://github.com/huerlisi/i18n_rails_helpers
43
33
  licenses: []
44
-
45
34
  post_install_message:
46
35
  rdoc_options: []
47
-
48
- require_paths:
36
+ require_paths:
49
37
  - lib
50
- required_ruby_version: !ruby/object:Gem::Requirement
38
+ required_ruby_version: !ruby/object:Gem::Requirement
51
39
  none: false
52
- requirements:
53
- - - ">="
54
- - !ruby/object:Gem::Version
55
- hash: 3
56
- segments:
57
- - 0
58
- version: "0"
59
- required_rubygems_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
45
  none: false
61
- requirements:
62
- - - ">="
63
- - !ruby/object:Gem::Version
64
- hash: 3
65
- segments:
66
- - 0
67
- version: "0"
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
68
50
  requirements: []
69
-
70
51
  rubyforge_project:
71
- rubygems_version: 1.3.7
52
+ rubygems_version: 1.8.23
72
53
  signing_key:
73
54
  specification_version: 3
74
55
  summary: I18n Rails helpers
75
56
  test_files: []
76
-
57
+ has_rdoc: