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.
- #join_class(name, separator = "-") ⇒ Object
-
#modifiers ⇒ Object
Returns clasess which are not defined as a base class.
-
#new(*args) ⇒ Object
Easy assess to create a new Attributes::Classname.
- #to_s ⇒ Object
Constructor Details
#initialize(*args, &block) ⇒ Classname
Returns a new instance of Classname.
49 50 51 52 |
# File 'lib/spark_components/attributes.rb', line 49 def initialize(*args, &block) super(*args, &block) @base_set = false end |
Instance Method Details
#add(*args) ⇒ Object
87 88 89 90 |
# File 'lib/spark_components/attributes.rb', line 87 def add(*args) push(*args.flatten.uniq.reject { |a| a.nil? || include?(a) }) self end |
#base ⇒ Object
78 79 80 |
# File 'lib/spark_components/attributes.rb', line 78 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.
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/spark_components/attributes.rb', line 65 def base=(klass) return if klass.nil? || klass.empty? if @base_set self[0] = klass else unshift klass @base_set = true end uniq! end |
#join_class(name, separator = "-") ⇒ Object
104 105 106 107 108 |
# File 'lib/spark_components/attributes.rb', line 104 def join_class(name, separator = "-") raise(SparkComponents::Attributes::Error, "Base class not defined for `join_class(#{name}, …)`") if base.nil? [base, name].join(separator) end |
#modifiers ⇒ Object
Returns clasess which are not defined as a base class
83 84 85 |
# File 'lib/spark_components/attributes.rb', line 83 def modifiers @base_set ? self[1..size] : self end |
#new(*args) ⇒ Object
Easy assess to create a new Attributes::Classname
93 94 95 96 97 98 99 100 101 102 |
# File 'lib/spark_components/attributes.rb', line 93 def new(*args) new_arr = self.class.new unless args.empty? new_arr.base = args.shift new_arr.add(*args) end new_arr end |
#to_s ⇒ Object
110 111 112 |
# File 'lib/spark_components/attributes.rb', line 110 def to_s join(" ") end |