Class: Yarrow::Web::BaseDocument

Inherits:
Object
  • Object
show all
Defined in:
lib/yarrow/web/document.rb

Direct Known Subclasses

Document, IndexDocument

Instance Method Summary collapse

Instance Method Details

#bodyObject



52
53
54
55
# File 'lib/yarrow/web/document.rb', line 52

def body
  return @resource.body.to_html if @resource.respond_to?(:body)
  ""
end

TODO: manage behaviour with and without current item TODO: link to manifest

TODO: replace @item and @collection with @node internally and in class interface



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/yarrow/web/document.rb', line 31

def breadcrumbs
  path = []

  current_parent = @node.in(:collection)

  while !current_parent.first.nil?
    path << current_parent.first.props[:resource]
    current_parent = current_parent.in(:collection)
  end

  path.reverse
end

#indexObject

TODO: confirm this can be deleted



13
14
15
16
17
18
19
20
# File 'lib/yarrow/web/document.rb', line 13

def index
  _index = @item.out_e(:index)
  unless _index.first.nil?
    _index.first.to.props
  else
    nil
  end
end

#index_bodyObject

TODO: confirm this can be deleted



23
24
25
# File 'lib/yarrow/web/document.rb', line 23

def index_body
  @item.props[:index_body]
end

#nameObject



44
45
46
# File 'lib/yarrow/web/document.rb', line 44

def name
  @resource.name
end

#resourceObject



4
5
6
# File 'lib/yarrow/web/document.rb', line 4

def resource
  @resource
end

#titleObject



48
49
50
# File 'lib/yarrow/web/document.rb', line 48

def title
  @resource.title
end

#typeObject



8
9
10
# File 'lib/yarrow/web/document.rb', line 8

def type
  @type
end

#urlObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/yarrow/web/document.rb', line 57

def url
  if @parent.nil?
    "/"
  else
    segments = [@resource.name]
    current = @parent

    until current.in(:collection).first.nil? do
      segments << current.props[:resource].name
      current = current.in(:collection).first
    end

    suffix = @is_index ? "/" : ""

    "/" + segments.reverse.join("/") + suffix
  end
end