Class: Docwatch::Renderer

Inherits:
Object
  • Object
show all
Defined in:
lib/docwatch/renderer.rb

Direct Known Subclasses

Html, Markdown

Defined Under Namespace

Classes: Html, Markdown

Constant Summary collapse

@@extensions =
{}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path) ⇒ Renderer

Returns a new instance of Renderer.



17
18
19
# File 'lib/docwatch/renderer.rb', line 17

def initialize(file_path)
    @file_path = file_path
end

Class Method Details

.by_filetype(file_path) ⇒ Object



10
11
12
13
14
15
# File 'lib/docwatch/renderer.rb', line 10

def self.by_filetype(file_path)
    extname = File.extname(file_path)[1..]
    return if extname.length == 0

    @@extensions[extname.to_sym].first.new(file_path)
end

.extension(sym) ⇒ Object

Set an extension (by symbol) as being supported by this class.



6
7
8
# File 'lib/docwatch/renderer.rb', line 6

def self.extension(sym)
    (@@extensions[sym] ||= []) << self
end

Instance Method Details

#jsObject



21
22
23
# File 'lib/docwatch/renderer.rb', line 21

def js
    File.read(Docwatch.root_dir + '/res/inject.js')
end

#to_htmlObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/docwatch/renderer.rb', line 25

def to_html
    return "        <!doctype html>\n        <html>\n        <head>\n        \#{head}\n        </head>\n        <body>\n        \#{body}\n        <script>\n        (function() {\n        \#{js}\n        })()\n        </script>\n        </body>\n        </html>\n    EOF\nend\n"