Class: Havior::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/havior/builder.rb

Instance Method Summary collapse

Constructor Details

#initializeBuilder

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_javascriptsObject



17
18
19
# File 'lib/havior/builder.rb', line 17

def all_javascripts
  @components.inject([]){|acc,c|acc + c.javascripts}.uniq
end

#all_stylesheetsObject



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_javascriptsObject



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_stylesheetsObject



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