Class: Yarrow::Web::Document

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

Instance Method Summary collapse

Constructor Details

#initialize(item, parent, is_index) ⇒ Document

This class is somewhat verbose for simplicity and long-term maintainability (having a clear and easy to follow construction, rather than doing anything too clever which has burned this lib in the past).



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

def initialize(item, parent, is_index)
  @item = item
  @parent = parent
  @is_index = is_index
end

Instance Method Details

#nameObject



13
14
15
# File 'lib/yarrow/web/document.rb', line 13

def name
  @item.props[:name]
end

#titleObject



17
18
19
# File 'lib/yarrow/web/document.rb', line 17

def title
  @item.props[:title]
end

#typeObject



21
22
23
# File 'lib/yarrow/web/document.rb', line 21

def type
  @item.props[:type]
end

#urlObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/yarrow/web/document.rb', line 25

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

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

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