Class: Guilded::Guilder
- Inherits:
-
Object
- Object
- Guilded::Guilder
- Defined in:
- lib/guilded/guilder.rb
Instance Attribute Summary collapse
-
#components ⇒ Object
readonly
Returns the value of attribute components.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
- #add(name, options = {}) ⇒ Object
- #add_data(new_data) ⇒ Object
- #component?(name) ⇒ Boolean
-
#initialize ⇒ Guilder
constructor
A new instance of Guilder.
- #javascript? ⇒ Boolean
- #javascript_from_components? ⇒ Boolean
- #javascript_from_data? ⇒ Boolean
- #javascript_initializer ⇒ Object
Constructor Details
#initialize ⇒ Guilder
Returns a new instance of Guilder.
7 8 9 10 |
# File 'lib/guilded/guilder.rb', line 7 def initialize @components = [] @data = Guilded::Data.new end |
Instance Attribute Details
#components ⇒ Object (readonly)
Returns the value of attribute components.
4 5 6 |
# File 'lib/guilded/guilder.rb', line 4 def components @components end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
4 5 6 |
# File 'lib/guilded/guilder.rb', line 4 def data @data end |
Instance Method Details
#add(name, options = {}) ⇒ Object
12 13 14 |
# File 'lib/guilded/guilder.rb', line 12 def add( name, ={} ) components << Guilded::Component.new( name, ) end |
#add_data(new_data) ⇒ Object
16 17 18 |
# File 'lib/guilded/guilder.rb', line 16 def add_data( new_data ) data.add new_data end |
#component?(name) ⇒ Boolean
34 35 36 |
# File 'lib/guilded/guilder.rb', line 34 def component?( name ) components.any? { |component| component.name == name } end |
#javascript? ⇒ Boolean
38 39 40 |
# File 'lib/guilded/guilder.rb', line 38 def javascript? javascript_from_components? || javascript_from_data? end |
#javascript_from_components? ⇒ Boolean
42 43 44 |
# File 'lib/guilded/guilder.rb', line 42 def javascript_from_components? components.any? { |component| component.javascript? } end |
#javascript_from_data? ⇒ Boolean
46 47 48 |
# File 'lib/guilded/guilder.rb', line 46 def javascript_from_data? !data.empty? end |
#javascript_initializer ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/guilded/guilder.rb', line 20 def javascript_initializer code = "<script type=\"text/javascript\">\n//<![CDATA[\n" code << data.to_javascript if javascript_from_components? code << "var initGuilded = function(){" components.each { |component| code << component.javascript_initializer } code << "};" code << "jQuery('document').ready(initGuilded);" end code << "jQuery('body').trigger('guildedInitialized');" code << "\n//]]>\n</script>" code end |