Class: AccordionsHelper::AccordionsRenderer

Inherits:
Object
  • Object
show all
Defined in:
lib/helpers/accordions_helper.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) {|_self| ... } ⇒ AccordionsRenderer

Returns a new instance of AccordionsRenderer.

Yields:

  • (_self)

Yield Parameters:

Raises:

  • (ArgumentError)


9
10
11
12
13
14
15
16
17
# File 'lib/helpers/accordions_helper.rb', line 9

def initialize( options={}, &block )
	raise ArgumentError, "Missing block" unless block_given?

	@template = eval( 'self', block.binding )
	@options = options
	@accordions = []

	yield self
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



41
42
43
# File 'lib/helpers/accordions_helper.rb', line 41

def method_missing( *args, &block )
	@template.send( *args, &block )
end

Instance Method Details

#create(accordion_id, accordion_text, options = {}, &block) ⇒ Object



19
20
21
22
# File 'lib/helpers/accordions_helper.rb', line 19

def create( accordion_id, accordion_text, options={}, &block )
	raise "Block needed for AccordionsRenderer#CREATE" unless block_given?
	@accordions << [ accordion_id, accordion_text, options, block ]
end

#renderObject



24
25
26
27
28
29
# File 'lib/helpers/accordions_helper.rb', line 24

def render
	content = @accordions.collect do |accordion|
		accordion_head(accordion) << accordion_body(accordion)
	end.join
	( :div, raw(content), { :id => :accordions }.merge( @options ) )
end