Module: Bootstrap::CommonHelper
- Defined in:
- app/helpers/bootstrap/common_helper.rb
Overview
Utililty methods used by Bootstrap::*Helper classes
Constant Summary collapse
- ArgumentError =
Class.new(::ArgumentError)
Instance Method Summary collapse
-
#arrayify_and_stringify_elements(arg) ⇒ Array of String
Returns a new Array of String from arg.
-
#canonicalize_options(hash) ⇒ Hash
Returns a new Hash with: * keys converted to Symbols * the
:class
key has its value converted to an Array of String. -
#caret(options = {}) ⇒ String
Returns down-caret character used in various dropdown menus.
-
#ensure_class(hash, klasses) ⇒ Hash
Returns new (canonicalized) Hash where :class value includes klasses.
-
#extract_extras(*args) ⇒ Array
Returns extra arguments that are Bootstrap modifiers.
Instance Method Details
#arrayify_and_stringify_elements(arg) ⇒ Array of String
Returns a new Array of String from arg.
31 32 33 34 35 36 37 38 39 |
# File 'app/helpers/bootstrap/common_helper.rb', line 31 def arrayify_and_stringify_elements(arg) return false if arg == false case when arg.blank? then [] when arg.is_a?(Array) then arg else arg.to_s.strip.split(/\s/) end.map(&:to_s) end |
#canonicalize_options(hash) ⇒ Hash
Returns a new Hash with:
-
keys converted to Symbols
-
the
:class
key has its value converted to an Array of String
15 16 17 18 19 20 21 |
# File 'app/helpers/bootstrap/common_helper.rb', line 15 def (hash) raise ArgumentError.new("expected a Hash, got #{hash.inspect}") unless hash.is_a?(Hash) hash.symbolize_keys.tap do |h| h[:class] = arrayify_and_stringify_elements(h[:class]) end end |
#caret(options = {}) ⇒ String
Returns down-caret character used in various dropdown menus.
46 47 48 49 50 |
# File 'app/helpers/bootstrap/common_helper.rb', line 46 def caret(={}) = () = ensure_class(, 'caret') content_tag(:span, nil, ) end |
#ensure_class(hash, klasses) ⇒ Hash
Returns new (canonicalized) Hash where :class value includes klasses.
60 61 62 63 64 65 66 67 68 |
# File 'app/helpers/bootstrap/common_helper.rb', line 60 def ensure_class(hash, klasses) hash = (hash) hash.dup.tap do |h| Array(klasses).map(&:to_s).each do |k| h[:class] << k unless h[:class].include?(k) end end end |
#extract_extras(*args) ⇒ Array
Returns extra arguments that are Bootstrap modifiers. Basically 2nd argument up to (not including) the last (Hash) argument.
77 78 79 80 81 |
# File 'app/helpers/bootstrap/common_helper.rb', line 77 def extract_extras(*args) args. args.shift args end |