Class: RDoc::Generator::SDoc

Inherits:
Object
  • Object
show all
Includes:
ERB::Util, SDoc::GitHub, SDoc::Helpers, SDoc::Templatable
Defined in:
lib/sdoc/generator.rb

Defined Under Namespace

Classes: FilesTree

Constant Summary collapse

DESCRIPTION =
'Searchable HTML documentation'
GENERATOR_DIRS =
[File.join('sdoc', 'generator')]
TYPE_CLASS =

Used in js to reduce index sizes

1
TYPE_METHOD =
2
TYPE_FILE =
3
TREE_FILE =
File.join 'panel', 'tree.js'
SEARCH_INDEX_FILE =
File.join 'panel', 'search_index.js'
FILE_DIR =
'files'
CLASS_DIR =
'classes'
RESOURCES_DIR =
File.join('resources', '.')

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ SDoc

Returns a new instance of SDoc.

Raises:

  • (RDoc::Error)


91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/sdoc/generator.rb', line 91

def initialize(options)
  @options = options
  if @options.respond_to?('diagram=')
    @options.diagram = false
  end
  @github_url_cache = {}
  @options.template = 'direct' if @options.template == 'sdoc'
  template = @options.template

  templ_dir = self.class.template_dir_for template

  raise RDoc::Error, "could not find template #{template.inspect}" unless
  templ_dir

  @template_dir = Pathname.new File.expand_path(templ_dir)
  @basedir = Pathname.pwd.expand_path
end

Instance Attribute Details

#basedirObject (readonly)

Returns the value of attribute basedir.



59
60
61
# File 'lib/sdoc/generator.rb', line 59

def basedir
  @basedir
end

#optionsObject (readonly)

Returns the value of attribute options.



61
62
63
# File 'lib/sdoc/generator.rb', line 61

def options
  @options
end

Class Method Details

.setup_options(options) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/sdoc/generator.rb', line 63

def self.setup_options(options)
  @github = false
  options.se_index = true

  opt = options.option_parser
  opt.separator nil
  opt.separator "SDoc generator options:"
  opt.separator nil
  opt.on("--github", "-g",
         "Generate links to github.") do |value|
    options.github = true
  end
  opt.separator nil

  opt.on("--no-se-index", "-ns",
         "Do not generated index file for search engines.",
         "",
         "SDoc uses javascript to refrence individual documentation pages.",
         "Search engine crawlers are not smart enough to find all the",
         "referenced pages.",
         "To help them SDoc generates a static file with links to every",
         "documentation page. This file is not shown to the user."
         ) do |value|
    options.se_index = false
  end
  opt.separator nil
end

.template_dir_for(template) ⇒ Object



132
133
134
135
136
137
138
139
140
# File 'lib/sdoc/generator.rb', line 132

def self.template_dir_for template
  $LOAD_PATH.map do |path|
    GENERATOR_DIRS.map do |dir|
      File.join path, dir, 'template', template
    end
  end.flatten.find do |dir|
    File.directory? dir
  end
end

Instance Method Details

#class_dirObject



124
125
126
# File 'lib/sdoc/generator.rb', line 124

def class_dir
  CLASS_DIR
end

#file_dirObject



128
129
130
# File 'lib/sdoc/generator.rb', line 128

def file_dir
  FILE_DIR
end

#generate(top_levels) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/sdoc/generator.rb', line 109

def generate(top_levels)
  @outputdir = Pathname.new(@options.op_dir).expand_path(@basedir)
  @files = top_levels.sort
  @classes = RDoc::TopLevel.all_classes_and_modules.sort

  # Now actually write the output
  copy_resources
  generate_class_tree
  generate_search_index
  generate_file_files
  generate_class_files
  generate_index_file
  generate_se_index if @options.se_index
end