link_to_action 0.1.3 → 0.2.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/README.md +2 -3
- data/Rakefile +0 -1
- data/lib/generators/link_to_action/templates/link_to_action.rb +7 -1
- data/lib/link_to_action/helpers.rb +18 -4
- data/lib/link_to_action/version.rb +1 -1
- data/lib/link_to_action.rb +8 -1
- data/link_to_action.gemspec +1 -0
- data/test/default_values_test.rb +3 -1
- data/test/dummy/log/test.log +5692 -0
- data/test/helpers_test.rb +34 -0
- metadata +20 -9
data/README.md
CHANGED
@@ -19,8 +19,7 @@ really pretty, you will also need icons.
|
|
19
19
|
So how I18n-friendly button-style link with icon looks like in a view code?
|
20
20
|
Well, it can look like this:
|
21
21
|
|
22
|
-
<%= link_to raw("<i class=\"icon-edit\"></i> #{t(:edit)}"),
|
23
|
-
edit_comment_path(@comment), class: 'btn' %>
|
22
|
+
<%= link_to raw("<i class=\"icon-edit\"></i> #{t(:edit)}"), edit_comment_path(@comment), class: 'btn' %>
|
24
23
|
|
25
24
|
And scaffolded code was:
|
26
25
|
|
@@ -55,7 +54,7 @@ And then execute:
|
|
55
54
|
|
56
55
|
Add initializer:
|
57
56
|
|
58
|
-
$
|
57
|
+
$ rails generate link_to_action:install
|
59
58
|
|
60
59
|
Edit config/initializers/link_to_action.rb. Note that CSS classes, icons and
|
61
60
|
cancan are disabled by default.
|
data/Rakefile
CHANGED
@@ -5,6 +5,9 @@ LinkToAction.setup do |config|
|
|
5
5
|
# Add icons to links, default false
|
6
6
|
# config.use_icons = false
|
7
7
|
|
8
|
+
# Place icons to left, default true
|
9
|
+
# config.icons_place_left = true
|
10
|
+
|
8
11
|
# Icons by default are adopted to font-awesome
|
9
12
|
# Icons size, default 'large'
|
10
13
|
# config.icons_size = 'large'
|
@@ -18,6 +21,9 @@ LinkToAction.setup do |config|
|
|
18
21
|
# Use classes, default false
|
19
22
|
# config.use_classes = false
|
20
23
|
|
24
|
+
# Append classes when :class option is specified, default false
|
25
|
+
# config.classes_append = false
|
26
|
+
|
21
27
|
# Classes by default are adopted to twitter-bootstrap
|
22
28
|
# config.class_default = 'btn'
|
23
29
|
|
@@ -32,4 +38,4 @@ LinkToAction.setup do |config|
|
|
32
38
|
# config.size_class_large = 'btn-large'
|
33
39
|
# config.size_class_small = 'btn-small'
|
34
40
|
# config.size_class_mini = 'btn-mini'
|
35
|
-
end
|
41
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# require 'ruby-debug'
|
2
|
+
# uncomment line above add 'debugger' somewhere (without quotes) to debug something
|
1
3
|
module LinkToAction::Helpers
|
2
4
|
def link_to_new(object, options = {})
|
3
5
|
link_to_action(:new, object, options)
|
@@ -27,9 +29,16 @@ module LinkToAction::Helpers
|
|
27
29
|
class_action = LinkToAction.send("class_#{action}")
|
28
30
|
end
|
29
31
|
size = options.delete(:size) || 'default'
|
30
|
-
|
31
|
-
|
32
|
-
|
32
|
+
classes = [ class_default, class_action ]
|
33
|
+
if options[:class]
|
34
|
+
classes = if LinkToAction.classes_append
|
35
|
+
classes.concat [ options[:class] ]
|
36
|
+
else
|
37
|
+
options[:class]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
classes = [ classes ,size_class(size) ].flatten.compact.join(' ')
|
41
|
+
classes.strip unless classes.blank?
|
33
42
|
end
|
34
43
|
|
35
44
|
def size_class(size)
|
@@ -37,6 +46,7 @@ module LinkToAction::Helpers
|
|
37
46
|
end
|
38
47
|
|
39
48
|
def action_icon(action, icon, icon_size)
|
49
|
+
icon_size = nil if icon_size == :default
|
40
50
|
[ icon, icon_size ].compact.join(' ')
|
41
51
|
end
|
42
52
|
|
@@ -64,10 +74,14 @@ module LinkToAction::Helpers
|
|
64
74
|
end
|
65
75
|
|
66
76
|
def iilink_to(icon_name, name, path, options = {})
|
77
|
+
icon_swap = options.delete(:icon_swap)
|
67
78
|
if LinkToAction.use_icons
|
68
79
|
icon_class = icon_name.split(' ').map {|i| "icon-#{i}"}.join(' ')
|
69
80
|
icon = "<i class=\"#{icon_class}\"></i>"
|
70
|
-
name =
|
81
|
+
name = [icon, ERB::Util.html_escape(name) ]
|
82
|
+
name.reverse! unless LinkToAction.icons_place_left
|
83
|
+
name.reverse! if icon_swap
|
84
|
+
name = raw(name.join(' '))
|
71
85
|
end
|
72
86
|
link_to name, path, options
|
73
87
|
end
|
data/lib/link_to_action.rb
CHANGED
@@ -14,6 +14,10 @@ module LinkToAction
|
|
14
14
|
mattr_accessor :icons_size
|
15
15
|
@@icons_size = 'large'
|
16
16
|
|
17
|
+
# 'position' word is too long
|
18
|
+
mattr_accessor :icons_place_left
|
19
|
+
@@icons_place_left = true
|
20
|
+
|
17
21
|
mattr_accessor :icon_new
|
18
22
|
@@icon_new = 'plus'
|
19
23
|
|
@@ -29,6 +33,9 @@ module LinkToAction
|
|
29
33
|
mattr_accessor :use_classes
|
30
34
|
@@use_classes = false
|
31
35
|
|
36
|
+
mattr_accessor :classes_append
|
37
|
+
@@classes_append = false
|
38
|
+
|
32
39
|
mattr_accessor :class_default
|
33
40
|
@@class_default = 'btn'
|
34
41
|
|
@@ -60,4 +67,4 @@ module LinkToAction
|
|
60
67
|
end
|
61
68
|
end
|
62
69
|
|
63
|
-
I18n.load_path << "#{File.dirname(__FILE__)}/link_to_action/locale/en.yml"
|
70
|
+
I18n.load_path << "#{File.dirname(__FILE__)}/link_to_action/locale/en.yml"
|
data/link_to_action.gemspec
CHANGED
data/test/default_values_test.rb
CHANGED
@@ -5,11 +5,13 @@ class DefaultValuesTest < ActiveSupport::TestCase
|
|
5
5
|
use_cancan: false,
|
6
6
|
use_icons: false,
|
7
7
|
icons_size: 'large',
|
8
|
+
icons_place_left: true,
|
8
9
|
icon_new: 'plus',
|
9
10
|
icon_edit: 'edit',
|
10
11
|
icon_destroy: 'trash',
|
11
12
|
icon_back: 'undo',
|
12
13
|
use_classes: false,
|
14
|
+
classes_append: false,
|
13
15
|
class_default: 'btn',
|
14
16
|
class_new: 'btn-primary',
|
15
17
|
class_edit: nil,
|
@@ -26,4 +28,4 @@ class DefaultValuesTest < ActiveSupport::TestCase
|
|
26
28
|
assert_equal value, LinkToAction.send(key)
|
27
29
|
end
|
28
30
|
end
|
29
|
-
end
|
31
|
+
end
|