Class: Webgen::PathHandler::Api

Inherits:
Object
  • Object
show all
Includes:
Base, PageUtils
Defined in:
lib/webgen/path_handler/api.rb

Overview

Path handler for Ruby API documentation via rdoc.

Constant Summary collapse

MANDATORY_INFOS =

The mandatory meta info keys that need to be set on an api path.

%W[rdoc_options]

Constants included from Base

Base::DEST_PATH_PARENT_SEGMENTS, Base::DEST_PATH_SEGMENTS

Class Method Summary collapse

Instance Method Summary collapse

Methods included from PageUtils

#create_node, #parse_meta_info!

Methods included from Base

#initialize, #parse_meta_info!

Class Method Details

.class_dirObject



107
# File 'lib/webgen/path_handler/api.rb', line 107

def (rdoc.generator).class_dir; nil; end

.file_dirObject



108
# File 'lib/webgen/path_handler/api.rb', line 108

def (rdoc.generator).file_dir; nil; end

Instance Method Details

#create_fragment_nodes_for_methods(api_path, klass_node, klass) ⇒ Object

Creates fragment nodes for methods under the “Class Methods” or “Instance Methods” fragments.



228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# File 'lib/webgen/path_handler/api.rb', line 228

def create_fragment_nodes_for_methods(api_path, klass_node, klass)
  ["Class", "Instance"].each do |type|
    method_list = klass.send("#{type.downcase}_method_list")
    next if method_list.empty?
    meth_url = "#{klass_node.alcn}##{type}-Methods"
    path = Webgen::Path.new(meth_url,
                            {'handler' => 'copy', 'modified_at' => api_path['modified_at'],
                              'pipeline' => [], 'no_output' => true,
                              'title' => "#{type} Methods"})
    meth_node = @website.ext.path_handler.create_secondary_nodes(path).first
    method_list.sort_by(&:name).each do |method|
      create_fragment_node_for_method(api_path, meth_node, method)
    end
  end
end

#create_nodes(path, blocks) ⇒ Object

Create the feed nodes.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/webgen/path_handler/api.rb', line 25

def create_nodes(path, blocks)
  if MANDATORY_INFOS.any? {|t| path.meta_info[t].nil?}
    raise Webgen::NodeCreationError.new("At least one of #{MANDATORY_INFOS.join('/')} is missing",
                                        "path_handler.api", path)
  end

  path['api_name'] ||= path.basename
  path['dir_name'] ||= path.basename

  cache_dir = @website.tmpdir(File.join('path_handler.api', path['api_name']))
  rdoc = rdoc_object(path['rdoc_options'], cache_dir)
  output_flag_file = rdoc.output_flag_file(cache_dir)

  dir_node = create_directory(path, Webgen::Path.new(path.parent_path + path['dir_name'] + '/'), false)

  api = OpenStruct.new
  api.directory = dir_node
  api.class_nodes = {}
  api.file_nodes = {}

  rdoc.store.all_classes_and_modules.sort.each do |klass|
    adapt_rdoc_class(path, klass)
    klass_node = create_page_node_for_class(path, dir_node, klass, output_flag_file)
    api.class_nodes[klass.full_name] = klass_node
    klass_node.node_info[:api] = api
    create_fragment_nodes_for_constants(path, klass_node, klass)
    create_fragment_nodes_for_attributes(path, klass_node, klass)
    create_fragment_nodes_for_methods(path, klass_node, klass)
  end

  rdoc.store.all_files.sort.each do |file|
    next unless file.text?
    file_node = create_page_node_for_file(path, dir_node, file, output_flag_file)
    api.file_nodes[file.full_name] = file_node
    file_node.node_info[:api] = api
  end

  nil
end