Module: Compony::ComponentMixins::Default::Labelling
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/compony/component_mixins/default/labelling.rb
Overview
This module contains all methods for Component that concern labelling and look
Instance Method Summary collapse
-
#color(&block) ⇒ Object
DSL method and accessor.
-
#icon(&block) ⇒ Object
DSL method and accessor.
-
#label(data_or_format = nil, format: :long, &block) ⇒ Object
DSL method and accessor When assigning via DSL, pass format as first parameter.
Instance Method Details
#color(&block) ⇒ Object
DSL method and accessor
55 56 57 58 59 60 61 |
# File 'lib/compony/component_mixins/default/labelling.rb', line 55 def color(&block) if block_given? @color_block = block else @color_block.call end end |
#icon(&block) ⇒ Object
DSL method and accessor
46 47 48 49 50 51 52 |
# File 'lib/compony/component_mixins/default/labelling.rb', line 46 def icon(&block) if block_given? @icon_block = block else @icon_block.call end end |
#label(data_or_format = nil, format: :long, &block) ⇒ Object
DSL method and accessor When assigning via DSL, pass format as first parameter. When accessing the value, pass foramt as named parameter
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/compony/component_mixins/default/labelling.rb', line 13 def label(data_or_format = nil, format: :long, &block) format = data_or_format if block_given? format ||= :long format = format.to_sym if block_given? # Assignment via DSL if format == :all @label_blocks[:short] = block @label_blocks[:long] = block else @label_blocks[format] = block end else # Retrieval of the actual label fail('Label format :all may only be used for setting a label (with a block), not for retrieving it.') if format == :all label_block = @label_blocks[format] || fail("Format #{format} was not found for #{inspect}.") case label_block.arity when 0 label_block.call when 1 data_or_format ||= data if data_or_format.blank? fail "Label block of #{inspect} takes an argument, but no data was provided and a call to `data` did not return any data either." end label_block.call(data_or_format) else fail "#{inspect} has a label block that takes 2 or more arguments, which is unsupported." end end end |