link_to_action 0.2.1 → 0.2.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
@@ -58,7 +58,7 @@ And then execute:
58
58
 
59
59
  $ bundle
60
60
 
61
- Add initializer:
61
+ Add initializer and locale file:
62
62
 
63
63
  $ rails generate link_to_action:install
64
64
 
@@ -105,10 +105,33 @@ en:
105
105
  back: 'Back'
106
106
  ```
107
107
 
108
- ## Global CSS styles and icons
108
+ ## Global CSS styles, icons, and other options
109
109
 
110
- Look to `config/initializers/link_to_action.rb` for global options. Cancan also
111
- goes here.
110
+ Default options are:
111
+
112
+ ```ruby
113
+ config.use_cancan = false # overwrite this to use cancan
114
+ config.use_icons = false # overwrite this to use FontAwesome icons
115
+ config.icons_place_left = true
116
+ config.icons_size = 'large'
117
+ config.icon_new = 'plus'
118
+ config.icon_edit = 'edit'
119
+ config.icon_destroy = 'trash'
120
+ config.icon_back = 'undo'
121
+ config.use_classes = false # overwrite this to use Twitter Bootstrap classes
122
+ config.classes_append = false
123
+ config.class_default = 'btn'
124
+ config.class_new = 'btn-primary'
125
+ config.class_edit = nil
126
+ config.class_destroy = 'btn-danger'
127
+ config.class_back = nil
128
+ config.size_class_default = nil
129
+ config.size_class_large = 'btn-large'
130
+ config.size_class_small = 'btn-small'
131
+ config.size_class_mini = 'btn-mini'
132
+ config.show_methods = [ :name, :title, :to_s ]
133
+ ```
134
+ Look to `config/initializers/link_to_action.rb` for detailed description.
112
135
 
113
136
  ## Per-link options
114
137
 
@@ -125,10 +148,11 @@ goes here.
125
148
  `link_to_show` options:
126
149
  ```ruby
127
150
  :name # overwrites default name of the link
128
- :send # method to sent to object to get name
151
+ :send # method to send to object to get name
152
+ :raw # method to send to object to get name, output raw
129
153
  ```
130
154
 
131
- Examples
155
+ ## Examples
132
156
 
133
157
  ```ruby
134
158
  # Link with parameters
@@ -22,17 +22,20 @@ module LinkToAction::Helpers
22
22
 
23
23
  def link_to_show(object, options = {})
24
24
  name = options.delete(:name)
25
+ raw = options.delete(:raw)
25
26
  send = options.delete(:send)
26
- name = object.send(send) if send
27
- LinkToAction.show_methods.each do |m|
28
- name = object.try(m) unless name
27
+ unless name
28
+ method = raw || send ||
29
+ LinkToAction.show_methods.find { |m| object.respond_to?(m) }
30
+ name = object.send(method)
29
31
  end
32
+ name = raw(name) if raw
30
33
  link_to name, object, options
31
34
  end
32
35
 
33
36
  # TODO: Move to separate module to avoid clashes
34
37
  private
35
-
38
+
36
39
  def action_class(action, options)
37
40
  if LinkToAction.use_classes
38
41
  class_default = LinkToAction.class_default
@@ -110,4 +113,4 @@ module LinkToAction::Helpers
110
113
  end
111
114
  end
112
115
 
113
- ActionView::Base.send :include, LinkToAction::Helpers
116
+ ActionView::Base.send :include, LinkToAction::Helpers
@@ -1,3 +1,3 @@
1
1
  module LinkToAction
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
@@ -21,6 +21,13 @@ class HelperTest < ActionView::TestCase
21
21
  link_to_show(@user, send: :login)
22
22
  end
23
23
 
24
+ test 'link_to_show using custom method raw' do
25
+ user = @user
26
+ user.login = '<a href="http://example.com">example</a>'
27
+ assert_equal "<a href=\"/users/1\">#{user.login}</a>",
28
+ link_to_show(user, raw: :login)
29
+ end
30
+
24
31
  test 'link_to_edit' do
25
32
  assert_equal "<a href=\"/users/1/edit\">Edit My User</a>", link_to_edit(@user)
26
33
  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.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -141,6 +141,8 @@ files:
141
141
  - test/link_to_action_test.rb
142
142
  - test/support/misc_helpers.rb
143
143
  - test/test_helper.rb
144
+ - test/dummy/log/test.log
145
+ - test/dummy/log/development.log
144
146
  homepage: https://github.com/denispeplin/link_to_action
145
147
  licenses: []
146
148
  post_install_message:
@@ -155,7 +157,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
155
157
  version: '0'
156
158
  segments:
157
159
  - 0
158
- hash: 1452578497091669240
160
+ hash: -1116709200470108002
159
161
  required_rubygems_version: !ruby/object:Gem::Requirement
160
162
  none: false
161
163
  requirements:
@@ -164,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
164
166
  version: '0'
165
167
  segments:
166
168
  - 0
167
- hash: 1452578497091669240
169
+ hash: -1116709200470108002
168
170
  requirements: []
169
171
  rubyforge_project:
170
172
  rubygems_version: 1.8.24
@@ -176,6 +178,8 @@ test_files:
176
178
  - test/link_to_action_test.rb
177
179
  - test/test_helper.rb
178
180
  - test/support/misc_helpers.rb
181
+ - test/dummy/log/test.log
182
+ - test/dummy/log/development.log
179
183
  - test/dummy/config.ru
180
184
  - test/dummy/public/404.html
181
185
  - test/dummy/public/422.html