Class: Havior::Builder
- Inherits:
-
Object
- Object
- Havior::Builder
- Defined in:
- lib/havior/builder.rb
Instance Method Summary collapse
- #all_javascripts ⇒ Object
- #all_stylesheets ⇒ Object
- #destribute(name, ajax_params = {}, erb_params = {}) ⇒ Object
-
#initialize ⇒ Builder
constructor
A new instance of Builder.
- #refer_to_javascripts ⇒ Object
- #refer_to_stylesheets ⇒ Object
Constructor Details
#initialize ⇒ Builder
Returns a new instance of Builder.
4 5 6 7 |
# File 'lib/havior/builder.rb', line 4 def initialize @count = 0 @components = [] end |
Instance Method Details
#all_javascripts ⇒ Object
17 18 19 |
# File 'lib/havior/builder.rb', line 17 def all_javascripts @components.inject([]){|acc,c|acc + c.javascripts}.uniq end |
#all_stylesheets ⇒ Object
20 21 22 |
# File 'lib/havior/builder.rb', line 20 def all_stylesheets @components.inject([]){|acc,c|acc + c.stylesheets}.uniq end |
#destribute(name, ajax_params = {}, erb_params = {}) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/havior/builder.rb', line 8 def destribute name, ajax_params = {}, erb_params={} namespace = name.to_s.camelize @count += 1 klass = Module.const_get("#{namespace}::Model") obj = klass.new @count @components.push obj obj.html(ajax_params, erb_params).html_safe end |
#refer_to_javascripts ⇒ Object
24 25 26 27 |
# File 'lib/havior/builder.rb', line 24 def refer_to_javascripts all_javascripts.map{|js| "<script type='text/javascript' src='#{js}'></script>" }.join end |
#refer_to_stylesheets ⇒ Object
28 29 30 31 |
# File 'lib/havior/builder.rb', line 28 def refer_to_stylesheets all_stylesheets.map{|css| "<link rel='stylesheet' type='text/css' href='#{css}'>" }.join end |