Class: SparkComponents::Attributes::Classname
- Inherits:
-
Array
- Object
- Array
- SparkComponents::Attributes::Classname
- Defined in:
- lib/spark_components/attributes.rb
Instance Method Summary collapse
- #add(*args) ⇒ Object
- #base ⇒ Object
-
#base=(klass) ⇒ Object
Many elements have a base class which defines core utlitiy This classname may serve as a root for other element classnames and should be distincly accessible.
-
#initialize(*args, &block) ⇒ Classname
constructor
A new instance of Classname.
-
#modifiers ⇒ Object
Returns clasess which are not defined as a base class.
- #to_s ⇒ Object
Constructor Details
#initialize(*args, &block) ⇒ Classname
Returns a new instance of Classname.
43 44 45 46 |
# File 'lib/spark_components/attributes.rb', line 43 def initialize(*args, &block) super(*args, &block) @base_set = false end |
Instance Method Details
#add(*args) ⇒ Object
81 82 83 |
# File 'lib/spark_components/attributes.rb', line 81 def add(*args) push(*args.uniq.reject { |a| a.nil? || include?(a) }) end |
#base ⇒ Object
72 73 74 |
# File 'lib/spark_components/attributes.rb', line 72 def base first if @base_set end |
#base=(klass) ⇒ Object
Many elements have a base class which defines core utlitiy This classname may serve as a root for other element classnames and should be distincly accessible
For example:
classes = Classname.new
classes.base = 'nav__item'
now generate a wrapper: "#{classes.base}__wrapper"
Ensure base class is the first element in the classes array.
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/spark_components/attributes.rb', line 59 def base=(klass) return if klass.blank? if @base_set self[0] = klass else unshift klass @base_set = true end uniq! end |
#modifiers ⇒ Object
Returns clasess which are not defined as a base class
77 78 79 |
# File 'lib/spark_components/attributes.rb', line 77 def modifiers @base_set ? self[1..size] : self end |
#to_s ⇒ Object
85 86 87 |
# File 'lib/spark_components/attributes.rb', line 85 def to_s join(" ").html_safe end |