Class: Yarrow::LegacyWeb::IndexDocument
- Inherits:
-
BaseDocument
- Object
- BaseDocument
- Yarrow::LegacyWeb::IndexDocument
- Defined in:
- lib/yarrow/web/document.rb
Instance Method Summary collapse
-
#initialize(collection, item = nil, is_index = false) ⇒ IndexDocument
constructor
Represents the index document of a collection.
Methods inherited from BaseDocument
#body, #breadcrumbs, #index, #index_body, #name, #resource, #title, #type, #url
Constructor Details
#initialize(collection, item = nil, is_index = false) ⇒ IndexDocument
Represents the index document of a collection. This contains a reference to the individual items in the collection as well as any document content itself.
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/yarrow/web/document.rb', line 101 def initialize(collection, item=nil, is_index=false) @collection = collection @item = item # The parent node of the collection is the first incoming node link @parent = collection.in(:collection).first @is_index = is_index template_map = collection.out_e(:child).to.all.inject([]) do |result, node| result << Document.new(node, false) end instance_variable_set("@children", template_map) define_singleton_method(:children){ template_map } if @item.nil? @resource = collection.props[:resource] @type = collection.props[:type] @node = collection else @resource = item.props[:resource] @type = item.props[:type] @node = item end instance_variable_set("@#{@type}", @resource) define_singleton_method(@type){ @resource } end |