Class: Malline::ViewProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/malline/view_proxy.rb

Instance Method Summary collapse

Constructor Details

#initialize(template, tag) ⇒ ViewProxy

Returns a new instance of ViewProxy.



20
21
22
23
# File 'lib/malline/view_proxy.rb', line 20

def initialize template, tag
	@tpl = template
	@tag = tag
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(s, *args, &block) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/malline/view_proxy.rb', line 29

def method_missing(s, *args, &block)
	if args.last.is_a?(Hash)
		@tag[:attrs].merge!(args.pop)
	end

	if /\!$/ =~ s.to_s
		@tag[:attrs]['id'] = s.to_s.chomp('!')
	else
		if @tag[:attrs]['class']
			@tag[:attrs]['class'] << " #{s}"
		else
			@tag[:attrs]['class'] = s.to_s
		end
	end

	whitespace = @tpl.whitespace
	@tpl.whitespace = true if args.delete(:whitespace)
	txt = args.flatten.join('')
	@tag[:children] << txt unless txt.empty?

	@tpl.execute @tag[:children], &block if block_given?
	@tpl.whitespace = whitespace
	self
end

Instance Method Details

#__yld(&block) ⇒ Object



25
26
27
# File 'lib/malline/view_proxy.rb', line 25

def __yld &block
	@tpl.execute @tag[:children], &block
end