Module: LinkToAction::Utils
- Defined in:
- lib/link_to_action/utils.rb
Class Method Summary collapse
- .action_class(action, options) ⇒ Object
- .action_icon(action, options) ⇒ Object
- .add_icon_to_name(action, name, options) ⇒ Object
-
.t_action(object, action) ⇒ Object
TODO: inspect some advanced I18n actionpack/lib/action_view/helpers/form_helper.rb, submit_default_value.
Class Method Details
.action_class(action, options) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/link_to_action/utils.rb', line 25 def self.action_class(action, ) if LinkToAction.use_classes class_default = LinkToAction.class_default class_action = LinkToAction.send("class_#{action}") end size = .delete(:size) || 'default' classes = [] classes = [ class_default, class_action ] unless class_action == '' if [:class] classes = if LinkToAction.classes_append classes.concat [ [:class] ] else [ [:class] ] end end size_class = [ LinkToAction.send("size_class_#{size}") ] classes = classes.concat(size_class).compact.join(' ') classes unless classes.blank? end |
.action_icon(action, options) ⇒ Object
4 5 6 7 8 9 |
# File 'lib/link_to_action/utils.rb', line 4 def self.action_icon(action, ) icon = .delete(:icon) || LinkToAction.send("icon_#{action}") icon_size = .delete(:icon_size) || LinkToAction.icons_size icon_size = nil if icon_size == :default [ icon, icon_size ].compact.map {|i| "icon-#{i}"}.join(' ') unless icon == '' end |
.add_icon_to_name(action, name, options) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/link_to_action/utils.rb', line 11 def self.add_icon_to_name(action, name, ) icon = self.action_icon(action, ) icon_swap = .delete(:icon_swap) if LinkToAction.use_icons && icon icon = "<i class=\"#{icon}\"></i>" name = [icon, ERB::Util.html_escape(name) ] name.reverse! unless LinkToAction.icons_place_left name.reverse! if icon_swap name.join(' ').html_safe else name end end |
.t_action(object, action) ⇒ Object
TODO: inspect some advanced I18n actionpack/lib/action_view/helpers/form_helper.rb, submit_default_value
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/link_to_action/utils.rb', line 47 def self.t_action(object, action) object = object.last if object.kind_of? Array model = if object.respond_to?(:model_name) object.model_name.human else object.class.model_name.human if object.class.respond_to?(:model_name) end model = model.pluralize if action == :index I18n.t(:"helpers.link_to.#{action}", model: model) end |