Module: PDoc::Generators::Html::Helpers::MenuHelper

Included in:
DocPage
Defined in:
lib/pdoc/generators/html/helpers.rb

Constant Summary collapse

NODES =
[
  :namespaces,
  :classes,
  :mixins,
  :utilities
]
LEAVES =
[
  :constants,
  :class_methods,
  :class_properties,
  :instance_methods,
  :instance_properties
]

Instance Method Summary collapse

Instance Method Details

#class_names_for(obj, options = {}) ⇒ Object



239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/pdoc/generators/html/helpers.rb', line 239

def class_names_for(obj, options = {})
  classes = []
  classes << obj.type.gsub(/\s+/, '-')
  classes << "deprecated" if obj.deprecated?
  if doc_instance
    if obj == doc_instance
      classes << "current"
    elsif obj.ancestor_of?(doc_instance)
      classes << "current-parent"
    end
  end
  classes.join(' ')
end

#leaf_submenu(obj) ⇒ Object



224
225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/pdoc/generators/html/helpers.rb', line 224

def leaf_submenu(obj)
  items = []
  if obj.respond_to?(:constructor) && obj.constructor
    items << (:li, menu_item(obj.constructor, :name => :short))
  end
  LEAVES.each do |prop|
    if obj.respond_to?(prop)
      obj.send(prop).sort!.map do |item|
        items << (:li, menu_item(item, :name => :short))
      end
    end
  end
  (:ul, items.join("\n"))
end


180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/pdoc/generators/html/helpers.rb', line 180

def menu(obj)
  if obj.parent
    html = menu_item(obj, :name => :long)
  
    html << node_submenu(obj)
  
    if obj == doc_instance && obj.respond_to?(:constants)
      html << leaf_submenu(obj)
    elsif doc_instance && doc_instance.respond_to?(:parent)
      parent = doc_instance.parent
      html << leaf_submenu(parent) if parent == obj && obj.respond_to?(:constants)
    end
  
    (:li, html)
  else #root
    node_submenu(obj)
  end
end


218
219
220
221
222
# File 'lib/pdoc/generators/html/helpers.rb', line 218

def menu_item(obj, options = {})
  options = options.dup
  options[:class] = class_names_for(obj, options)
  (:div, auto_link(obj, options), :class => 'menu-item')
end

#node_submenu(obj) ⇒ Object



199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/pdoc/generators/html/helpers.rb', line 199

def node_submenu(obj)
  children = []
  options = {}
  
  NODES.each do |prop|
    children.concat(obj.send(prop)) if obj.respond_to?(prop)
  end
  
  list_items = children.sort.map { |item| menu(item) }
  if obj.respond_to?(:sections)
    obj.sections.each { |section| list_items << menu(section) }
    options[:class] = "menu-items"
    options[:id] = "api_menu"
  elsif obj.type == "section"
    options[:class] = "menu-section"
  end
  list_items.empty? ? '' : (:ul, list_items.join("\n"), options)
end