Class: Helmsman::Helm
- Inherits:
-
Object
- Object
- Helmsman::Helm
- Includes:
- ActionView::Helpers::TagHelper, ActionView::Helpers::UrlHelper
- Defined in:
- lib/helmsman/helm.rb
Instance Attribute Summary collapse
-
#additional ⇒ Object
Returns the value of attribute additional.
-
#i18n_key ⇒ Object
Returns the value of attribute i18n_key.
-
#i18n_scope ⇒ Object
Returns the value of attribute i18n_scope.
- #name ⇒ Object
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #configure_li_class ⇒ Object
- #current? ⇒ Boolean
- #default_disabled_tooltip_translation_key ⇒ Object
- #disabled? ⇒ Boolean
- #disabled_title ⇒ Object
- #disabled_tooltip_translation_key ⇒ Object
- #enabled? ⇒ Boolean
- #html_safe? ⇒ Boolean
-
#initialize(options = {}) ⇒ Helm
constructor
A new instance of Helm.
- #li_content ⇒ Object
- #li_options ⇒ Object
- #name_translation_key ⇒ Object
- #to_s ⇒ Object
- #to_str ⇒ Object
- #visible? ⇒ Boolean
Constructor Details
#initialize(options = {}) ⇒ Helm
Returns a new instance of Helm.
9 10 11 12 13 14 15 16 17 |
# File 'lib/helmsman/helm.rb', line 9 def initialize( = {}) @disabled = .fetch(:disabled) { false } @visible = .fetch(:visible) { true } @current = .fetch(:current) { false } @li_class = [:li_class] || [] @i18n_scope = .fetch(:i18n_scope) @i18n_key = .fetch(:i18n_key) @url = [:url] end |
Instance Attribute Details
#additional ⇒ Object
Returns the value of attribute additional.
3 4 5 |
# File 'lib/helmsman/helm.rb', line 3 def additional @additional end |
#i18n_key ⇒ Object
Returns the value of attribute i18n_key.
3 4 5 |
# File 'lib/helmsman/helm.rb', line 3 def i18n_key @i18n_key end |
#i18n_scope ⇒ Object
Returns the value of attribute i18n_scope.
3 4 5 |
# File 'lib/helmsman/helm.rb', line 3 def i18n_scope @i18n_scope end |
#name ⇒ Object
69 70 71 |
# File 'lib/helmsman/helm.rb', line 69 def name @name || I18n.translate("#{i18n_scope}#{i18n_key}").html_safe end |
#url ⇒ Object
Returns the value of attribute url.
3 4 5 |
# File 'lib/helmsman/helm.rb', line 3 def url @url end |
Instance Method Details
#configure_li_class ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/helmsman/helm.rb', line 36 def configure_li_class if @li_class.respond_to?(:to_ary) @li_class.to_ary else @li_class.to_s.split(/\s+/) end.tap do |li_class| yield li_class end.select(&:present?).uniq.sort * ' ' end |
#current? ⇒ Boolean
104 105 106 |
# File 'lib/helmsman/helm.rb', line 104 def current? @current end |
#default_disabled_tooltip_translation_key ⇒ Object
88 89 90 |
# File 'lib/helmsman/helm.rb', line 88 def default_disabled_tooltip_translation_key "#{i18n_scope}disabled_tooltip" end |
#disabled? ⇒ Boolean
92 93 94 |
# File 'lib/helmsman/helm.rb', line 92 def disabled? @disabled end |
#disabled_title ⇒ Object
73 74 75 76 77 78 |
# File 'lib/helmsman/helm.rb', line 73 def disabled_title I18n.translate( disabled_tooltip_translation_key, default: I18n.translate(default_disabled_tooltip_translation_key) ).html_safe end |
#disabled_tooltip_translation_key ⇒ Object
84 85 86 |
# File 'lib/helmsman/helm.rb', line 84 def disabled_tooltip_translation_key "#{i18n_scope}#{i18n_key}_disabled_tooltip" end |
#enabled? ⇒ Boolean
100 101 102 |
# File 'lib/helmsman/helm.rb', line 100 def enabled? !@disabled end |
#html_safe? ⇒ Boolean
23 24 25 |
# File 'lib/helmsman/helm.rb', line 23 def html_safe? true end |
#li_content ⇒ Object
31 32 33 34 |
# File 'lib/helmsman/helm.rb', line 31 def li_content link = link_to_if(enabled?, name, url) if url disabled? ? link : "#{link}#{additional}".html_safe end |
#li_options ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/helmsman/helm.rb', line 46 def if enabled? li_class = configure_li_class do |li_class| if current? li_class << Helmsman.current_css_class end end { class: li_class } else li_class = configure_li_class do |li_class| li_class << Helmsman.disabled_css_class end { rel: 'tooltip', title: disabled_title, class: li_class, data: { placement: 'bottom' } } end end |
#name_translation_key ⇒ Object
80 81 82 |
# File 'lib/helmsman/helm.rb', line 80 def name_translation_key "#{i18n_scope}#{i18n_key}" end |
#to_s ⇒ Object
19 20 21 |
# File 'lib/helmsman/helm.rb', line 19 def to_s visible? ? content_tag(:li, li_content, ) : ''.html_safe end |
#to_str ⇒ Object
27 28 29 |
# File 'lib/helmsman/helm.rb', line 27 def to_str to_s end |
#visible? ⇒ Boolean
96 97 98 |
# File 'lib/helmsman/helm.rb', line 96 def visible? @visible end |