Class: RWEB::Generator

Inherits:
Object show all
Defined in:
lib/rweb.rb

Overview

The core of document generation is this Generator class, an abstract class that sets the footprint and makes sure that any implementing class has all required methods covered. Generators must provide all of the methods with proper semantics outlined in each method’s documentation.

Any state changes in the documentation (like the transition from code block to document block) must be handled by identifying the state changes through methods.

Direct Known Subclasses

PlainGenerator, XHTMLGenerator

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(docs, directives) ⇒ Generator

This method gets the array of documentation/code chunks and the block of detected directives. Any derived class must ensure that docs and directives are appropriately passed up the chain to this implementation. Too, any derived class must ensure that an @style member is set to the appropriate documentation style (as per the “style” keyword in directives).



321
322
323
324
# File 'lib/rweb.rb', line 321

def initialize(docs, directives)
  @docs = docs
  @directives = directives
end

Instance Attribute Details

#directivesObject (readonly)

Returns the value of attribute directives.



325
326
327
# File 'lib/rweb.rb', line 325

def directives
  @directives
end

#docsObject (readonly)

Returns the value of attribute docs.



325
326
327
# File 'lib/rweb.rb', line 325

def docs
  @docs
end

#styleObject (readonly)

Returns the value of attribute style.



325
326
327
# File 'lib/rweb.rb', line 325

def style
  @style
end

Instance Method Details

#code(chunk) ⇒ Object

This method gets called to perform any transformations on code chunks. For example code can be syntax-highlighted.

Raises:

  • (NotImplementedError)


342
343
344
# File 'lib/rweb.rb', line 342

def code(chunk)
  raise NotImplementedError, "#{self.class.name}#code is an abstract method."
end

#doc(chunk) ⇒ Object

This method gets called to perform any transformations on documentation chunks. For example Markdown-formatted plaintext might get run through BlueCloth to get turned into proper HTML here.

Raises:

  • (NotImplementedError)


336
337
338
# File 'lib/rweb.rb', line 336

def doc(chunk)
  raise NotImplementedError, "#{self.class.name}#doc is an abstract method."
end

This method gets called at the end of the document for closing document sequences: e.g. XHTML’s </html> and </body> tags.

Raises:

  • (NotImplementedError)


348
349
350
# File 'lib/rweb.rb', line 348

def footer
  raise NotImplementedError, "#{self.class.name}#footer is an abstract method."
end

#header(title) ⇒ Object

This method gets called at the beginning of the document for initialization of the document format: e.g. XHTML’s <html>, <head> and <body> tags.

Raises:

  • (NotImplementedError)


329
330
331
# File 'lib/rweb.rb', line 329

def header(title)
  raise NotImplementedError, "#{self.class.name}#header is an abstract method."
end