Class: Playgroundbook::ChapterCollator
- Inherits:
-
Object
- Object
- Playgroundbook::ChapterCollator
- Defined in:
- lib/renderer/chapter_collator.rb
Instance Method Summary collapse
- #collate(chapter, parsed_chapter, imports) ⇒ Object
-
#initialize(page_writer = PageWriter.new, ui = Cork::Board.new) ⇒ ChapterCollator
constructor
A new instance of ChapterCollator.
- #write_chapter_manifest(chapter_name, page_dir_names) ⇒ Object
- #write_preamble(preamble) ⇒ Object
Constructor Details
#initialize(page_writer = PageWriter.new, ui = Cork::Board.new) ⇒ ChapterCollator
Returns a new instance of ChapterCollator.
9 10 11 12 |
# File 'lib/renderer/chapter_collator.rb', line 9 def initialize(page_writer = PageWriter.new, ui = Cork::Board.new) @page_writer = page_writer @ui = ui end |
Instance Method Details
#collate(chapter, parsed_chapter, imports) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/renderer/chapter_collator.rb', line 14 def collate(chapter, parsed_chapter, imports) chapter_name = chapter['name'] @ui.puts "Processing #{chapter_name.green}." chapter_directory_name = "#{chapter_name}.playgroundchapter" Dir.mkdir(chapter_directory_name) unless Dir.exist?(chapter_directory_name) Dir.chdir(chapter_directory_name) do Dir.mkdir(PagesDirectoryName) unless Dir.exist?(PagesDirectoryName) Dir.chdir(PagesDirectoryName) do parsed_chapter[:page_names].each_with_index do |page_name, index| @ui.puts " Processing #{page_name.green}." page_contents = parsed_chapter[:page_contents][index] page_dir_name = parsed_chapter[:page_dir_names][index] @page_writer.write_page(page_name, page_dir_name, imports, page_contents, chapter) end end write_chapter_manifest(chapter_name, parsed_chapter[:page_dir_names]) write_preamble(parsed_chapter[:preamble]) end end |
#write_chapter_manifest(chapter_name, page_dir_names) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/renderer/chapter_collator.rb', line 38 def write_chapter_manifest(chapter_name, page_dir_names) manifest_contents = { "Name" => chapter_name, "Pages" => page_dir_names, "Version" => "1.0", "ContentVersion" => "1.0" } File.open(ManifestFileName, "w") do |file| file.write(manifest_contents.to_plist) end end |
#write_preamble(preamble) ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/renderer/chapter_collator.rb', line 50 def write_preamble(preamble) Dir.mkdir(SharedSourcesDirectoryName) unless Dir.exist?(SharedSourcesDirectoryName) Dir.chdir(SharedSourcesDirectoryName) do File.open(PreambleFileName, "w") do |file| file.write(preamble) end end end |