Class: Yarrow::Output::Web::IndexedFile
- Inherits:
-
Object
- Object
- Yarrow::Output::Web::IndexedFile
- Defined in:
- lib/yarrow/output/web/indexed_file.rb
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.
Instance Method Details
#docroot ⇒ String
Returns Docroot of the output target.
13 14 15 |
# File 'lib/yarrow/output/web/indexed_file.rb', line 13 def docroot @docroot ||= config.output_dir || 'public' end |
#index_name ⇒ String
Returns Basename reflecting the server convention (usually: index.html).
8 9 10 |
# File 'lib/yarrow/output/web/indexed_file.rb', line 8 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.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/yarrow/output/web/indexed_file.rb', line 21 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 |