Class: RDoc::Generator::SDoc

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

Defined Under Namespace

Classes: FilesTree

Constant Summary collapse

DESCRIPTION =
'Searchable HTML documentation'
GENERATOR_DIRS =
[File.join('sdoc_local_editor', 'generator')]
TREE_FILE =
File.join 'panel', 'tree.js'
SEARCH_INDEX_FILE =
File.join 'js', '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.



163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/sdoc_local_editor/generator.rb', line 163

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

  @template_dir = Pathname.new(options.template_dir)
  @base_dir = Pathname.pwd.expand_path

  @json_index = RDoc::Generator::JsonIndex.new self, options
end

Instance Attribute Details

#base_dirObject (readonly)

Returns the value of attribute base_dir.



118
119
120
# File 'lib/sdoc_local_editor/generator.rb', line 118

def base_dir
  @base_dir
end

#optionsObject (readonly)

Returns the value of attribute options.



120
121
122
# File 'lib/sdoc_local_editor/generator.rb', line 120

def options
  @options
end

Class Method Details

.setup_options(options) ⇒ Object



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/sdoc_local_editor/generator.rb', line 122

def self.setup_options(options)
  @github = false
  options.se_index = true
  options.local_editor = 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

  opt.on("--local-editor", "-L",
         "Generate links to open file in local editor.",
         "The server serving this documentation should respond to",
         "a POST request to /open_editor/. The request will contain",
         "the following query parameters:",
         "  * file  -- the file path, relative to your code directory",
         "  * line  -- the line number in the file."
        ) do |value|
    options.local_editor = true
  end
  opt.separator nil

end

Instance Method Details

#class_dirObject



191
192
193
# File 'lib/sdoc_local_editor/generator.rb', line 191

def class_dir
  CLASS_DIR
end

#file_dirObject



195
196
197
# File 'lib/sdoc_local_editor/generator.rb', line 195

def file_dir
  FILE_DIR
end

#generate(top_levels) ⇒ Object



176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/sdoc_local_editor/generator.rb', line 176

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

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