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, default_styles) ⇒ Renderer

Returns a new instance of Renderer.



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

def initialize(file_path, default_styles)
    @file_path = file_path
    @default_styles = default_styles
end

Class Method Details

.by_filetype(file_path, default_styles) ⇒ Object



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

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

    @@extensions[extname.to_sym].first.new(file_path, default_styles)
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



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

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

#to_htmlObject



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

def to_html
    return <<~EOF
        <!doctype html>
        <html>
        <head>
        #{head}
        </head>
        <body>
        #{body}
        <script>
        (function() {
        #{js}
        })()
        </script>
        </body>
        </html>
    EOF
end