Class: Playgroundbook::ChapterCollator
- Inherits:
-
Object
- Object
- Playgroundbook::ChapterCollator
- Defined in:
- lib/playgroundbook_renderer/chapter_collator.rb
Instance Method Summary collapse
- #collate!(chapter_name, 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/playgroundbook_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_name, 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 |
# File 'lib/playgroundbook_renderer/chapter_collator.rb', line 14 def collate!(chapter_name, parsed_chapter, imports) @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) 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
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/playgroundbook_renderer/chapter_collator.rb', line 37 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
49 50 51 52 53 54 55 56 57 |
# File 'lib/playgroundbook_renderer/chapter_collator.rb', line 49 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 |