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, config = nil, style = nil) ⇒ Object
-
.extension(sym) ⇒ Object
Set an extension (by symbol) as being supported by this class.
Instance Method Summary collapse
-
#initialize(file_path, default_styles, config = nil, style = nil) ⇒ Renderer
constructor
A new instance of Renderer.
- #js ⇒ Object
- #to_html(static: false) ⇒ Object
Constructor Details
#initialize(file_path, default_styles, config = nil, style = nil) ⇒ Renderer
Returns a new instance of Renderer.
17 18 19 20 21 22 |
# File 'lib/docwatch/renderer.rb', line 17 def initialize(file_path, default_styles, config = nil, style = nil) @file_path = file_path @default_styles = default_styles @config = config @style = style end |
Class Method Details
.by_filetype(file_path, default_styles, config = nil, style = nil) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/docwatch/renderer.rb', line 10 def self.by_filetype(file_path, default_styles, config = nil, style = nil) extname = File.extname(file_path)[1..] return if extname.length == 0 @@extensions[extname.to_sym].first.new(file_path, default_styles, config, style) 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
24 25 26 |
# File 'lib/docwatch/renderer.rb', line 24 def js File.read(Docwatch.root_dir + '/res/inject.js') end |
#to_html(static: false) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/docwatch/renderer.rb', line 28 def to_html(static: false) parts = ['<!doctype html>', '<html>', '<head>', head, '</head>', '<body>', body] if !static parts << "<script>\n(function() {\n#{js}\n})()\n</script>" end parts.push('</body>', '</html>') parts.join("\n") end |