Class: GovukPublishingComponents::Presenters::SharedHelper
- Inherits:
-
Object
- Object
- GovukPublishingComponents::Presenters::SharedHelper
- Defined in:
- lib/govuk_publishing_components/presenters/shared_helper.rb
Instance Attribute Summary collapse
-
#classes ⇒ Object
readonly
Returns the value of attribute classes.
-
#heading_level ⇒ Object
readonly
Returns the value of attribute heading_level.
-
#margin_bottom ⇒ Object
readonly
Returns the value of attribute margin_bottom.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #get_heading_level ⇒ Object
- #get_heading_size(option, fallback) ⇒ Object
-
#initialize(local_assigns) ⇒ SharedHelper
constructor
A new instance of SharedHelper.
- #t_lang(content, options = {}) ⇒ Object
- #t_locale(content, options = {}) ⇒ Object
- #t_locale_check(locale) ⇒ Object
- #valid_heading_size?(size) ⇒ Boolean
Constructor Details
#initialize(local_assigns) ⇒ SharedHelper
Returns a new instance of SharedHelper.
6 7 8 9 10 |
# File 'lib/govuk_publishing_components/presenters/shared_helper.rb', line 6 def initialize(local_assigns) = local_assigns @margin_bottom = [:margin_bottom] || 3 @heading_level = [:heading_level] || 2 end |
Instance Attribute Details
#classes ⇒ Object (readonly)
Returns the value of attribute classes.
4 5 6 |
# File 'lib/govuk_publishing_components/presenters/shared_helper.rb', line 4 def classes @classes end |
#heading_level ⇒ Object (readonly)
Returns the value of attribute heading_level.
4 5 6 |
# File 'lib/govuk_publishing_components/presenters/shared_helper.rb', line 4 def heading_level @heading_level end |
#margin_bottom ⇒ Object (readonly)
Returns the value of attribute margin_bottom.
4 5 6 |
# File 'lib/govuk_publishing_components/presenters/shared_helper.rb', line 4 def margin_bottom @margin_bottom end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/govuk_publishing_components/presenters/shared_helper.rb', line 4 def end |
Instance Method Details
#get_heading_level ⇒ Object
12 13 14 15 16 |
# File 'lib/govuk_publishing_components/presenters/shared_helper.rb', line 12 def get_heading_level return [*1..6].include?(@heading_level) ? "h#{@heading_level}" : "h2" unless @heading_level.zero? "span" end |
#get_heading_size(option, fallback) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/govuk_publishing_components/presenters/shared_helper.rb', line 22 def get_heading_size(option, fallback) govuk_class = "govuk-heading-" if valid_heading_size?(option) "#{govuk_class}#{option}" else "#{govuk_class}#{fallback}" end end |
#t_lang(content, options = {}) ⇒ Object
54 55 56 57 |
# File 'lib/govuk_publishing_components/presenters/shared_helper.rb', line 54 def t_lang(content, = {}) locale = t_locale(content, ) "lang=#{locale}" unless locale.eql?(I18n.locale) end |
#t_locale(content, options = {}) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/govuk_publishing_components/presenters/shared_helper.rb', line 32 def t_locale(content, = {}) # Check if the content string has a translation content_translation_available = translation_present?(content) # True, return locale this_locale = I18n.locale if content_translation_available # If false, return default locale this_locale = I18n.default_locale unless content_translation_available # Check if default string passed in if [:default].present? # Check if the default string has a translation default_translation_available = translation_present?([:default]) # If true, return locale this_locale = I18n.locale if default_translation_available # If false, return default_locale this_locale = I18n.default_locale unless default_translation_available end this_locale end |
#t_locale_check(locale) ⇒ Object
59 60 61 |
# File 'lib/govuk_publishing_components/presenters/shared_helper.rb', line 59 def t_locale_check(locale) locale.presence unless locale.to_s.eql?(I18n.locale.to_s) end |
#valid_heading_size?(size) ⇒ Boolean
18 19 20 |
# File 'lib/govuk_publishing_components/presenters/shared_helper.rb', line 18 def valid_heading_size?(size) %w[xl l m s].include?(size) end |