Class: Arrow::Template::Container

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/arrow/template/container.rb

Overview

The Arrow::Template::Container class, a derivative of Arrow::Object. Instances of this class are stateful containers for ContainerDirective nodes .

Authors

Please see the file LICENSE in the top-level directory for licensing details.

Constant Summary collapse

SVNRev =

SVN Revision

%q$Rev$
SVNId =

SVN Id

%q$Id$
DelegatedMethods =

The methods of collections which are delegated to their contents Array

( (Array.instance_methods(false) | Enumerable.instance_methods(false)) -
%w{<<} )

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Object

deprecate_class_method, deprecate_method, inherited

Constructor Details

#initialize(name, *contents) ⇒ Container

Create a new Arrow::Template::Container object with the given name and contents.



39
40
41
42
43
44
45
46
47
# File 'lib/arrow/template/container.rb', line 39

def initialize( name, *contents )
	@name = name
	@contents = contents

	@sortblock = nil
	@filters = []

	super()
end

Instance Attribute Details

#contentsObject

The contents of the container



59
60
61
# File 'lib/arrow/template/container.rb', line 59

def contents
  @contents
end

#filtersObject (readonly)

The Array of transform functions applied to this container at render time, in the order in which they will be applied.



66
67
68
# File 'lib/arrow/template/container.rb', line 66

def filters
  @filters
end

#nameObject (readonly)

The name of the container



62
63
64
# File 'lib/arrow/template/container.rb', line 62

def name
  @name
end

#sortblockObject (readonly)

The sort block associated with the container.



69
70
71
# File 'lib/arrow/template/container.rb', line 69

def sortblock
  @sortblock
end

Instance Method Details

#<<(object) ⇒ Object

Add the given object/s to this container.



73
74
75
76
# File 'lib/arrow/template/container.rb', line 73

def <<( object )
	@contents << object
	return self
end

#addFilter(&block) ⇒ Object

Add the specified filter block to the container. When the container is used in a render, the filter block will be called once for each contained object and whatever it returns will be used instead of the original.



83
84
85
# File 'lib/arrow/template/container.rb', line 83

def addFilter( &block )
	@filters << block
end

#each(&block) ⇒ Object

Iterate over the contents of this container after applying filters, sort blocks, etc. to them.

Raises:

  • (LocalJumpError)


98
99
100
101
102
103
104
105
106
107
108
# File 'lib/arrow/template/container.rb', line 98

def each( &block )
	raise LocalJumpError, "no block given" unless block_given?

	contents = @contents.dup
	contents.sort!( &@sortblock ) if @sortblock
	@filters.each {|filter|
		contents = contents.collect( &filter )
	}

	Arrow::Template::Iterator.new( *contents ).each( &block )
end

#lastObject

Return the last value to be set in this container



112
113
114
# File 'lib/arrow/template/container.rb', line 112

def last
	@contents.last
end

#setSort(&block) ⇒ Object

Add the specified sort block to the container. When the container is used in a render, its contents will be used in the order returned from the sort block.



91
92
93
# File 'lib/arrow/template/container.rb', line 91

def setSort( &block )
	@sortblock = block
end