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 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
- $ rake link_to_action:install
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
@@ -1,6 +1,5 @@
1
1
  #!/usr/bin/env rake
2
2
  begin
3
- require 'bundler/gem_tasks'
4
3
  require 'bundler/setup'
5
4
  rescue LoadError
6
5
  puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
@@ -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
- class_string = [ class_default, class_action, size_class(size),
31
- options[:class] ].compact.join(' ')
32
- class_string unless class_string.blank?
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 = raw("#{icon} #{ERB::Util.html_escape(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
@@ -1,3 +1,3 @@
1
1
  module LinkToAction
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -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"
@@ -19,4 +19,5 @@ Gem::Specification.new do |s|
19
19
  s.add_development_dependency "rails", "~> 3.2.8"
20
20
  s.add_development_dependency "sqlite3"
21
21
  s.add_development_dependency "simplecov"
22
+ s.add_development_dependency "debugger"
22
23
  end
@@ -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