Class: Vedeu::Renderers::File
- Inherits:
-
Object
- Object
- Vedeu::Renderers::File
- Includes:
- Options
- Defined in:
- lib/vedeu/output/renderers/file.rb
Overview
Writes the given output to a file.
Instance Attribute Summary collapse
-
#options ⇒ Hash<Symbol => void>
included
from Options
private
Combines the options provided at instantiation with the default values.
Instance Method Summary collapse
-
#clear(output = '', opts = {}) ⇒ String
Render a cleared output.
- #compress? ⇒ Boolean included from Options
-
#defaults ⇒ Hash
private
Returns the default options/attributes for this class.
- #filename ⇒ String private
-
#initialize(options = {}) ⇒ Vedeu::Renderers::File
constructor
Returns a new instance of Vedeu::Renderers::File.
-
#out(output) ⇒ String
private
Compresses the output depending on configuration.
- #render(output = '', opts = {}) ⇒ String
- #timestamp ⇒ Float private
- #write_file? ⇒ Boolean private
Constructor Details
#initialize(options = {}) ⇒ Vedeu::Renderers::File
Returns a new instance of Vedeu::Renderers::File.
21 22 23 |
# File 'lib/vedeu/output/renderers/file.rb', line 21 def initialize( = {}) @options = || {} end |
Instance Attribute Details
#options ⇒ Hash<Symbol => void> (private) Originally defined in module Options
Combines the options provided at instantiation with the default values.
Instance Method Details
#clear(output = '', opts = {}) ⇒ String
Render a cleared output.
30 31 32 33 34 35 36 |
# File 'lib/vedeu/output/renderers/file.rb', line 30 def clear(output = '', opts = {}) @options = .merge!(opts) ::File.write(filename, out(output)) if write_file? out(output) end |
#compress? ⇒ Boolean Originally defined in module Options
#defaults ⇒ Hash (private)
Returns the default options/attributes for this class.
89 90 91 92 93 94 95 96 |
# File 'lib/vedeu/output/renderers/file.rb', line 89 def defaults { compression: Vedeu::Configuration.compression?, filename: 'out', timestamp: false, write_file: true, } end |
#filename ⇒ String (private)
66 67 68 |
# File 'lib/vedeu/output/renderers/file.rb', line 66 def filename [:filename] + end |
#out(output) ⇒ String (private)
Compresses the output depending on configuration.
55 56 57 58 59 60 61 62 63 |
# File 'lib/vedeu/output/renderers/file.rb', line 55 def out(output) if compress? Vedeu::Output::Compressor.render(output, ) else output end end |
#render(output = '', opts = {}) ⇒ String
41 42 43 44 45 46 47 |
# File 'lib/vedeu/output/renderers/file.rb', line 41 def render(output = '', opts = {}) @options = .merge!(opts) ::File.write(filename, out(output)) if write_file? out(output) end |
#timestamp ⇒ Float (private)
71 72 73 74 75 76 77 78 79 |
# File 'lib/vedeu/output/renderers/file.rb', line 71 def if [:timestamp] "_#{Time.now.to_f}".freeze else ''.freeze end end |
#write_file? ⇒ Boolean (private)
82 83 84 |
# File 'lib/vedeu/output/renderers/file.rb', line 82 def write_file? [:write_file] end |