Module: Glimmer::UI::CustomWidget::ClassMethods
- Defined in:
- lib/glimmer/ui/custom_widget.rb
Instance Method Summary collapse
- #after_body(&block) ⇒ Object
- #before_body(&block) ⇒ Object
- #body(&block) ⇒ Object
- #def_option_attr_accessors(new_options) ⇒ Object
- #keyword ⇒ Object
- #option(new_option, default: nil) ⇒ Object
- #options(*new_options) ⇒ Object
-
#shortcut_keyword ⇒ Object
Returns shortcut keyword to use for this custom widget (keyword minus namespace).
Instance Method Details
#after_body(&block) ⇒ Object
82 83 84 85 |
# File 'lib/glimmer/ui/custom_widget.rb', line 82 def after_body(&block) @after_body_blocks ||= [] @after_body_blocks << block end |
#before_body(&block) ⇒ Object
73 74 75 76 |
# File 'lib/glimmer/ui/custom_widget.rb', line 73 def before_body(&block) @before_body_blocks ||= [] @before_body_blocks << block end |
#body(&block) ⇒ Object
78 79 80 |
# File 'lib/glimmer/ui/custom_widget.rb', line 78 def body(&block) @body_block = block end |
#def_option_attr_accessors(new_options) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/glimmer/ui/custom_widget.rb', line 61 def def_option_attr_accessors() .each do |option, default| # TODO fix this in Opal by switching to define_method define_method(option) do [:"#{option}"] end define_method("#{option}=") do |option_value| self.[:"#{option}"] = option_value end end end |
#keyword ⇒ Object
87 88 89 |
# File 'lib/glimmer/ui/custom_widget.rb', line 87 def keyword self.name.underscore.gsub('::', '__') end |
#option(new_option, default: nil) ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/glimmer/ui/custom_widget.rb', line 52 def option(new_option, default: nil) new_option = new_option.to_s.to_sym = {new_option => default} '@options = options.merge(new_options)' @options = .merge() 'def_option_attr_accessors(new_options)' def_option_attr_accessors() end |
#options(*new_options) ⇒ Object
Allows defining convenience option accessors for an array of option names Example: ‘options :color1, :color2` defines `#color1` and `#color2` where they return the instance values `options` and `options` respectively. Can be called multiple times to set more options additively. When passed no arguments, it returns list of all option names captured so far
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/glimmer/ui/custom_widget.rb', line 41 def (*) = .compact.map(&:to_s).map(&:to_sym) if .empty? @options ||= {} # maps options to defaults else = .reduce({}) {|, new_option| .merge(new_option => nil)} @options = .merge() def_option_attr_accessors() end end |
#shortcut_keyword ⇒ Object
Returns shortcut keyword to use for this custom widget (keyword minus namespace)
92 93 94 |
# File 'lib/glimmer/ui/custom_widget.rb', line 92 def shortcut_keyword self.name.underscore.gsub('::', '__').split('__').last end |