Class: RDoc::Generator::Sixfish

Inherits:
Object
  • Object
show all
Extended by:
Loggability
Includes:
FileUtils
Defined in:
lib/rdoc/generator/sixfish.rb

Overview

The Sixfish generator class.

Constant Summary collapse

DATADIR =

The data directory in the project if that exists, otherwise the gem datadir

if ENV['SIXFISH_DATADIR']
	Pathname( ENV['SIXFISH_DATADIR'] )
elsif Gem.loaded_specs[ 'rdoc-generator-sixfish' ] &&
	File.exist?( Gem.loaded_specs['rdoc-generator-sixfish'].datadir )
	Pathname( Gem.loaded_specs['rdoc-generator-sixfish'].datadir )
else
	Pathname( __FILE__ ).dirname.parent.parent.parent + 'data/rdoc-generator-sixfish'
end

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(store, options) ⇒ Sixfish

Set up some instance variables



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/rdoc/generator/sixfish.rb', line 64

def initialize( store, options )
	@store      = store
	@options    = options
	$DEBUG_RDOC = $VERBOSE || $DEBUG

	self.log.debug "Setting up generator for %p with options: %p" % [ @store, @options ]

	extend( FileUtils::Verbose ) if $DEBUG_RDOC
	extend( FileUtils::DryRun ) if options.dry_run

	@base_dir       = Pathname.pwd.expand_path
	@template_dir   = DATADIR
	@output_dir     = Pathname( @options.op_dir ).expand_path( @base_dir )

	@template_cache = {}
	@files          = nil
	@classes        = nil

	Inversion::Template.configure( :template_paths => [self.template_dir + 'templates'] )
end

Instance Attribute Details

#base_dirObject (readonly)

The base directory (current working directory) as a Pathname



91
92
93
# File 'lib/rdoc/generator/sixfish.rb', line 91

def base_dir
  @base_dir
end

#optionsObject (readonly)

The command-line options given to the rdoc command



100
101
102
# File 'lib/rdoc/generator/sixfish.rb', line 100

def options
  @options
end

#output_dirObject (readonly)

The output directory as a Pathname



97
98
99
# File 'lib/rdoc/generator/sixfish.rb', line 97

def output_dir
  @output_dir
end

#storeObject (readonly)

The RDoc::Store that contains the parsed CodeObjects



103
104
105
# File 'lib/rdoc/generator/sixfish.rb', line 103

def store
  @store
end

#template_dirObject (readonly)

The directory containing templates as a Pathname



94
95
96
# File 'lib/rdoc/generator/sixfish.rb', line 94

def template_dir
  @template_dir
end

Class Method Details

.setup_options(rdoc_options) ⇒ Object

Add generator-specific options to the option-parser



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/rdoc/generator/sixfish.rb', line 46

def self::setup_options( rdoc_options )
	op = rdoc_options.option_parser

	op.accept( URI ) do |string|
		uri = URI.parse( string ) rescue nil
		raise OptionParser::InvalidArgument unless uri
		uri
	end
	op.on( '--additional-stylesheet=URL', URI,
	       "Add an additional (preferred) stylesheet",
		   "link to each generated page. This allows",
		   "the output style to be overridden." ) do |url|
		rdoc_options.additional_stylesheet = url
	end
end

Instance Method Details

#class_dirObject Also known as: file_dir

Backward-compatible (no-op) method.



114
115
116
# File 'lib/rdoc/generator/sixfish.rb', line 114

def class_dir # :nodoc:
	nil
end

#copy_static_assetsObject

Copies static files from the static_path into the output directory



224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/rdoc/generator/sixfish.rb', line 224

def copy_static_assets
	asset_paths = self.find_static_assets

	self.log.debug "Copying assets from paths: %s" % [ asset_paths.join(', ') ]

	asset_paths.each do |path|

		# For plain files, just install them
		if path.file?
			self.log.debug "  plain file; installing as-is"
			install( path, self.output_dir, :mode => 0644 )

		# Glob all the files out of subdirectories and install them
		elsif path.directory?
			self.log.debug "  directory %p; copying contents" % [ path ]

			Pathname.glob( path + '{css,fa,fonts,img,js}/**/*'.to_s ).each do |asset|
				next if asset.directory? || asset.basename.to_s.start_with?( '.' )

				dst = asset.relative_path_from( path )
				dst.dirname.mkpath

				self.log.debug "    %p -> %p" % [ asset, dst ]
				install asset, dst, :mode => 0644
			end
		end
	end
end

#debug_msg(*msg) ⇒ Object

Output progress information if debugging is enabled



107
108
109
110
# File 'lib/rdoc/generator/sixfish.rb', line 107

def debug_msg( *msg )
	return unless $DEBUG_RDOC
	$stderr.puts( *msg )
end

#gen_sub_directoriesObject

Create the directories the generated docs will live in if they don’t already exist.



122
123
124
# File 'lib/rdoc/generator/sixfish.rb', line 122

def gen_sub_directories
	self.output_dir.mkpath
end

#generateObject

Build the initial indices and output objects based on the files in the generator’s store.



128
129
130
131
132
133
134
135
136
# File 'lib/rdoc/generator/sixfish.rb', line 128

def generate
	self.populate_data_objects

	self.generate_index_page
	self.generate_class_files
	self.generate_file_files

	self.copy_static_assets
end

#generate_class_filesObject

Generate a documentation file for each class and module



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/rdoc/generator/sixfish.rb', line 166

def generate_class_files
	layout = self.load_layout_template
	template = self.load_template( 'class.tmpl' )

	self.log.debug "Generating class documentation in #{self.output_dir}"

	@classes.each do |klass|
		self.log.debug "  working on %s (%s)" % [klass.full_name, klass.path]

		out_file = self.output_dir + klass.path
		out_file.dirname.mkpath

		template.klass = klass

		layout.contents = template
		layout.rel_prefix = self.output_dir.relative_path_from( out_file.dirname )
		layout.pageclass = 'class-page'

		out_file.open( 'w', 0644 ) {|io| io.print(layout.render) }
	end
end

#generate_file_filesObject

Generate a documentation file for each file



190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/rdoc/generator/sixfish.rb', line 190

def generate_file_files
	layout = self.load_layout_template
	template = self.load_template( 'file.tmpl' )

	self.log.debug "Generating file documentation in #{self.output_dir}"

	@files.select {|f| f.text? }.each do |file|
		out_file = self.output_dir + file.path
		out_file.dirname.mkpath

		self.log.debug "  working on %s (%s)" % [file.full_name, out_file]

		template.file = file

		# If the page itself has an H1, use it for the header, otherwise make one
		# out of the name of the file
		if md = file.description.match( %r{<h1.*?>.*?</h1>}i )
			template.header = md[ 0 ]
			template.description = file.description[ md.offset(0)[1] + 1 .. -1 ]
		else
			template.header = File.basename( file.full_name, File.extname(file.full_name) )
			template.description = file.description
		end

		layout.contents = template
		layout.rel_prefix = self.output_dir.relative_path_from(out_file.dirname)
		layout.pageclass = 'file-page'

		out_file.open( 'w', 0644 ) {|io| io.print(layout.render) }
	end
end

#generate_index_pageObject

Generate an index page which lists all the classes which are documented.



150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/rdoc/generator/sixfish.rb', line 150

def generate_index_page
	self.log.debug "Generating index page"
	template = self.load_template( 'index.tmpl' )
	self.set_toplevel_variables( template )

	out_file = self.output_dir + 'index.html'
	out_file.dirname.mkpath

	template.rel_prefix = self.output_dir.relative_path_from( out_file.dirname )
	template.pageclass = 'index-page'

	out_file.open( 'w', 0644 ) {|io| io.print(template.render) }
end

#populate_data_objectsObject

Populate the data objects necessary to generate documentation from the generator’s store.



141
142
143
144
145
146
# File 'lib/rdoc/generator/sixfish.rb', line 141

def populate_data_objects
	@files   = self.store.all_files.sort
	@classes = self.store.all_classes_and_modules.sort
	@methods = @classes.map {|m| m.method_list }.flatten.sort
	@modsort = self.get_sorted_module_list( @classes )
end