Class: MiddlemanMdocs::Navigation::Item

Inherits:
Object
  • Object
show all
Defined in:
lib/middleman-mdocs/navigation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(label, value = nil) ⇒ Item

Returns a new instance of Item.



6
7
8
9
10
11
12
13
14
# File 'lib/middleman-mdocs/navigation.rb', line 6

def initialize(label, value = nil)
  @label = label
  @value = value
  if @value.is_a?(Hash) && @value.group?
    @group = @value.group
  elsif @value.is_a?(Array)
    @recursive = true
  end
end

Instance Attribute Details

#groupObject (readonly)

Returns the value of attribute group.



4
5
6
# File 'lib/middleman-mdocs/navigation.rb', line 4

def group
  @group
end

#labelObject (readonly)

Returns the value of attribute label.



4
5
6
# File 'lib/middleman-mdocs/navigation.rb', line 4

def label
  @label
end

#valueObject (readonly)

Returns the value of attribute value.



4
5
6
# File 'lib/middleman-mdocs/navigation.rb', line 4

def value
  @value
end

Instance Method Details

#group?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/middleman-mdocs/navigation.rb', line 24

def group?
  !!@group
end

#groupped(sitemap) ⇒ Object



32
33
34
35
36
# File 'lib/middleman-mdocs/navigation.rb', line 32

def groupped(sitemap)
  sitemap.select_by_meta(@group.to_sym).group_by do |resource|
    resource.[@group.to_sym]
  end
end

#link?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/middleman-mdocs/navigation.rb', line 20

def link?
  value.is_a?(String)
end

#recursive?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/middleman-mdocs/navigation.rb', line 28

def recursive?
  !!@recursive
end

#separator?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/middleman-mdocs/navigation.rb', line 16

def separator?
  value.nil?
end

#tr(group) ⇒ Object



38
39
40
# File 'lib/middleman-mdocs/navigation.rb', line 38

def tr(group)
  I18n.t(group, scope: [:mdocs, self.group], default: group)
end