Class: Docco::Writer
- Inherits:
-
Object
- Object
- Docco::Writer
- Defined in:
- lib/docco/writer.rb
Overview
Writes documents to the file system.
The Writer class handles writing page content to disk with proper directory creation, path handling, and optional overwrite protection. It transforms logical page paths into actual file system paths, appending ‘index.html’ to directory paths as needed.
The above example writes the following files:
output/index.html
output/docs/index.html
output/styles.css
Instance Method Summary collapse
-
#initialize(pages, output_dir:, overwrite: false) ⇒ Writer
constructor
Initializes a new Writer instance with pages and output configuration.
- #write ⇒ Object
Constructor Details
#initialize(pages, output_dir:, overwrite: false) ⇒ Writer
Initializes a new Writer instance with pages and output configuration.
Transforms page paths by:
-
Converting relative paths to absolute paths within output_dir
-
Appending ‘index.html’ to paths without file extensions (directory paths)
-
Creating Pathname objects for each path
51 52 53 54 55 56 57 58 59 |
# File 'lib/docco/writer.rb', line 51 def initialize(pages, output_dir:, overwrite: false) @pages = pages.transform_keys do |path| path = Pathname.new(File.join(output_dir, path)) path += 'index.html' if path.extname.empty? path end @overwrite = overwrite end |
Instance Method Details
#write ⇒ Object
61 62 63 64 65 |
# File 'lib/docco/writer.rb', line 61 def write @pages.each.with_object({}) do |(path, content), memo| memo[path.to_s] = write_page(path, content) end end |