Class: Element

Inherits:
Object
  • Object
show all
Defined in:
lib/shot_mvc/element.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(selector) ⇒ Element

Returns a new instance of Element.



24
25
26
27
# File 'lib/shot_mvc/element.rb', line 24

def initialize(selector)
	@selector = selector
	@app = nil
end

Instance Attribute Details

#appObject

Associated ApplicationInstance



16
17
18
# File 'lib/shot_mvc/element.rb', line 16

def app
  @app
end

#selectorObject

jQuery Selector



13
14
15
# File 'lib/shot_mvc/element.rb', line 13

def selector
  @selector
end

Class Method Details

.from_app_and_selector(app, selector) ⇒ Object



18
19
20
21
22
# File 'lib/shot_mvc/element.rb', line 18

def self.from_app_and_selector(app, selector)
	element = Element.new selector
	element.app = app
	element
end

Instance Method Details

#html=(html) ⇒ Object



39
40
41
# File 'lib/shot_mvc/element.rb', line 39

def html=(html)
	self.jq 'html', [html]
end

#jq(method, parameters = {}) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/shot_mvc/element.rb', line 29

def jq(method, parameters = {})
	unless app == nil
		@app.emit 'jq', {
				'selector'    => @selector,
				'method'      => method,
				'parameters'  => [parameters]
		}
	end
end

#render(template, data = nil) ⇒ Object



47
48
49
50
51
# File 'lib/shot_mvc/element.rb', line 47

def render(template, data = nil)
	template = @app.get 'template', template
	template.data = data unless data == nil
	self.html = template.render
end

#text=(text) ⇒ Object



43
44
45
# File 'lib/shot_mvc/element.rb', line 43

def text=(text)
	self.jq 'text', [text]
end