Class: Havior::Model

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id) ⇒ Model

Returns a new instance of Model.



4
5
6
7
8
9
10
11
# File 'lib/havior/model.rb', line 4

def initialize id
  prefix = "havior"
  components = self.class.name.underscore.split("/")[0..-2]
  @dir = components.join("/")
  html_class_name = prefix + "-" + components.join("-")
  @html_identifier = "#{html_class_name}-#{id}"
  @html_classes = ["havior", html_class_name]
end

Instance Attribute Details

#html_classesObject (readonly)

Returns the value of attribute html_classes.



3
4
5
# File 'lib/havior/model.rb', line 3

def html_classes
  @html_classes
end

#html_identifierObject (readonly)

Returns the value of attribute html_identifier.



3
4
5
# File 'lib/havior/model.rb', line 3

def html_identifier
  @html_identifier
end

Instance Method Details

#html(ajax_params = {}, erb_params = {}) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/havior/model.rb', line 20

def html ajax_params={}, erb_params={} 
  action_view = ActionView::Base.new "#{Rails.root}/app/haviors/#{@dir}/views" 
  erb_params.each{|k,v| action_view.assign(k=>v) }
  ajax_params.each{|k,v| action_view.assign(k=>v) }
  data = ajax_params.map{|k,v| "data-#{k}='#{v}'" }.join(' ')
  return "<div id=\"\#{@html_identifier}\" class=\"\#{@html_classes.join(' ')}\" \#{data}>\n  \#{action_view.render(template: self.erb_script)}\n</div>\n"
end

#javascriptsObject



13
14
15
# File 'lib/havior/model.rb', line 13

def javascripts
  []
end

#stylesheetsObject



16
17
18
# File 'lib/havior/model.rb', line 16

def stylesheets
  []
end