Class: Yuzu::Renderers::Breadcrumb

Inherits:
Object
  • Object
show all
Defined in:
lib/yuzu/renderers/breadcrumb.rb

Instance Method Summary collapse

Constructor Details

#initialize(website_obj, level = 0) ⇒ Breadcrumb

Returns a new instance of Breadcrumb.



14
15
16
17
# File 'lib/yuzu/renderers/breadcrumb.rb', line 14

def initialize(website_obj, level=0)
  @website_obj = website_obj
  @level = level
end

Instance Method Details

#configObject



104
105
106
# File 'lib/yuzu/renderers/breadcrumb.rb', line 104

def config
  @website_obj.config
end

#crumb_for(crumb_tag, level) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/yuzu/renderers/breadcrumb.rb', line 54

def crumb_for(crumb_tag, level)
  case crumb_tag
  when :home
    Crumb.new(@website_obj.root, level)

  when :blog
    Crumb.new(@website_obj.blog_folder, level)

  when :category
    folder? ? nil : CategoryCrumb.new(@website_obj, level)

  when :post
    if index?
      # Defer to parent.
      nil
    else
      Crumb.new(@website_obj, level)
    end

  when :parent
    @website_obj.parent.nil? ? nil : Breadcrumb.new(@website_obj.parent, level)

  else
    nil

  end
end

#crumbsObject



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/yuzu/renderers/breadcrumb.rb', line 40

def crumbs
  tr = []
  level_correct = 0
  ordered_structure.each_index do |i|
    crumb_tag = ordered_structure[i]
    crumb = crumb_for(crumb_tag, @level + i + level_correct)
    if crumb.nil?
      level_correct -= 1
    end
    tr.push(crumb)
  end
  tr.reject {|el| el.nil?}
end

#crumbs_to_sObject



23
24
25
# File 'lib/yuzu/renderers/breadcrumb.rb', line 23

def crumbs_to_s
  ordered_crumbs.collect {|crumb| crumb.to_s}.join(separator)
end

#file?Boolean

Returns:

  • (Boolean)


116
117
118
# File 'lib/yuzu/renderers/breadcrumb.rb', line 116

def file?
  @website_obj.file?
end

#folder?Boolean

Returns:

  • (Boolean)


112
113
114
# File 'lib/yuzu/renderers/breadcrumb.rb', line 112

def folder?
  @website_obj.folder?
end

#in_blog?Boolean

Returns:

  • (Boolean)


96
97
98
# File 'lib/yuzu/renderers/breadcrumb.rb', line 96

def in_blog?
  @website_obj.in_blog?
end

#index?Boolean

Returns:

  • (Boolean)


108
109
110
# File 'lib/yuzu/renderers/breadcrumb.rb', line 108

def index?
  @website_obj.index?
end

#is_blog?Boolean

Returns:

  • (Boolean)


100
101
102
# File 'lib/yuzu/renderers/breadcrumb.rb', line 100

def is_blog?
  @website_obj.is_blog?
end

#ordered_crumbsObject



35
36
37
38
# File 'lib/yuzu/renderers/breadcrumb.rb', line 35

def ordered_crumbs
  crumbs
  #reverse? ? crumbs.reverse : crumbs
end

#ordered_structureObject



82
83
84
# File 'lib/yuzu/renderers/breadcrumb.rb', line 82

def ordered_structure
  reverse? ? structure.reverse : structure
end

#reverse?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/yuzu/renderers/breadcrumb.rb', line 31

def reverse?
  true        # TODO make configurable
end

#separatorObject



27
28
29
# File 'lib/yuzu/renderers/breadcrumb.rb', line 27

def separator
  " #{config.breadcrumb_separator} "
end

#structureObject



86
87
88
89
90
91
92
93
94
# File 'lib/yuzu/renderers/breadcrumb.rb', line 86

def structure
  if file? and in_blog? and not is_blog? and not index?
    [:home, :blog, :category, :post]

  else
    [:parent, :post]

  end
end

#to_sObject



19
20
21
# File 'lib/yuzu/renderers/breadcrumb.rb', line 19

def to_s
  @website_obj.nil? ? "" : crumbs_to_s
end