Module: Howdoc::Writers

Defined in:
lib/howdoc/writers.rb

Overview

One recorded document, several possible outputs. Adding a format is adding a class here, not rewriting the engine -- the same separation rspec_api_ documentation used to turn one test run into HTML and half a dozen API description languages.

Defined Under Namespace

Classes: Html, Index

Class Method Summary collapse

Class Method Details

.fetch(name) ⇒ Object



21
22
23
24
25
# File 'lib/howdoc/writers.rb', line 21

def fetch(name)
  registry.fetch(name.to_sym) do
    raise ArgumentError, "unknown Howdoc format #{name.inspect}, known: #{registry.keys.inspect}"
  end
end

.register(name, writer) ⇒ Object



17
18
19
# File 'lib/howdoc/writers.rb', line 17

def register(name, writer)
  registry[name.to_sym] = writer
end

.registryObject



13
14
15
# File 'lib/howdoc/writers.rb', line 13

def registry
  @registry ||= { html: Html }
end

.write(document) ⇒ Object



27
28
29
# File 'lib/howdoc/writers.rb', line 27

def write(document)
  Howdoc.config.formats.map { |format| fetch(format).call(document) }
end