Class: Yarrow::Tools::OutputFile
- Inherits:
-
Object
- Object
- Yarrow::Tools::OutputFile
- Includes:
- Configurable
- Defined in:
- lib/yarrow/tools/output_file.rb
Overview
TODO: consider renaming this to OutputDocument.
Constant Summary collapse
- WRITE_MODE =
'w+:UTF-8'.freeze
Instance Method Summary collapse
-
#docroot ⇒ String
Docroot of the output target.
-
#index_name ⇒ String
Basename reflecting the server convention (usually: index.html).
-
#write(path, content) ⇒ Object
Write an output file to the specified path under the docroot.
Methods included from Configurable
Instance Method Details
#docroot ⇒ String
Returns Docroot of the output target.
15 16 17 |
# File 'lib/yarrow/tools/output_file.rb', line 15 def docroot @docroot ||= config.output_dir || 'public' end |
#index_name ⇒ String
Returns Basename reflecting the server convention (usually: index.html).
10 11 12 |
# File 'lib/yarrow/tools/output_file.rb', line 10 def index_name @index_name ||= config.index_name || 'index.html' end |
#write(path, content) ⇒ Object
Write an output file to the specified path under the docroot.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/yarrow/tools/output_file.rb', line 23 def write(path, content) # If the target path is a directory, # generate a default index filename. if path[path.length-1] == '/' path = "#{path}#{index_name}" end target_path = Pathname.new("#{docroot}#{path}") FileUtils.mkdir_p(target_path.dirname) File.open(target_path.to_s, WRITE_MODE) do |file| file.puts(content) end end |