Class: Docwatch::Renderer
- Inherits:
-
Object
- Object
- Docwatch::Renderer
- Defined in:
- lib/docwatch/renderer.rb
Defined Under Namespace
Constant Summary collapse
- @@extensions =
{}
Class Method Summary collapse
- .by_filetype(file_path, default_styles) ⇒ Object
-
.extension(sym) ⇒ Object
Set an extension (by symbol) as being supported by this class.
Instance Method Summary collapse
-
#initialize(file_path, default_styles) ⇒ Renderer
constructor
A new instance of Renderer.
- #js ⇒ Object
- #to_html ⇒ Object
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
#js ⇒ Object
22 23 24 |
# File 'lib/docwatch/renderer.rb', line 22 def js File.read(Docwatch.root_dir + '/res/inject.js') end |
#to_html ⇒ Object
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 |