module Glimmer::UI::CustomWidget::ClassMethods
Public Instance Methods
after_body(&block)
click to toggle source
# File lib/glimmer/ui/custom_widget.rb, line 82 def after_body(&block) @after_body_blocks ||= [] @after_body_blocks << block end
before_body(&block)
click to toggle source
# File lib/glimmer/ui/custom_widget.rb, line 73 def before_body(&block) @before_body_blocks ||= [] @before_body_blocks << block end
body(&block)
click to toggle source
# File lib/glimmer/ui/custom_widget.rb, line 78 def body(&block) @body_block = block end
def_option_attr_accessors(new_options)
click to toggle source
# File lib/glimmer/ui/custom_widget.rb, line 61 def def_option_attr_accessors(new_options) new_options.each do |option, default| # TODO fix this in Opal by switching to define_method define_method(option) do options[:"#{option}"] end define_method("#{option}=") do |option_value| self.options[:"#{option}"] = option_value end end end
keyword()
click to toggle source
# File lib/glimmer/ui/custom_widget.rb, line 87 def keyword self.name.underscore.gsub('::', '__') end
option(new_option, default: nil)
click to toggle source
# File lib/glimmer/ui/custom_widget.rb, line 52 def option(new_option, default: nil) new_option = new_option.to_s.to_sym new_options = {new_option => default} '@options = options.merge(new_options)' @options = options.merge(new_options) 'def_option_attr_accessors(new_options)' def_option_attr_accessors(new_options) end
options(*new_options)
click to toggle source
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
# File lib/glimmer/ui/custom_widget.rb, line 41 def options(*new_options) new_options = new_options.compact.map(&:to_s).map(&:to_sym) if new_options.empty? @options ||= {} # maps options to defaults else new_options = new_options.reduce({}) {|new_options_hash, new_option| new_options_hash.merge(new_option => nil)} @options = options.merge(new_options) def_option_attr_accessors(new_options) end end
shortcut_keyword()
click to toggle source
Returns shortcut keyword to use for this custom widget (keyword minus namespace)
# File lib/glimmer/ui/custom_widget.rb, line 92 def shortcut_keyword self.name.underscore.gsub('::', '__').split('__').last end