lib/rpub/book.rb in rpub-0.4.0 vs lib/rpub/book.rb in rpub-0.5.0

- old
+ new

@@ -1,29 +1,22 @@ module Rpub # The Book object wraps a collection of chapter objects and knows about its # ordering, the book metadata from the configuration file and the book output # filename. class Book + extend Forwardable include Enumerable - include HashDelegation - delegate_to_hash :config + def_delegators :@context, :fonts, :config, :layout - # @return [Hash] The hash of configuration options read from the config.yml file. - attr_reader :config - # @return [Array<Chapter>] List of chapters, one for every input markdown file. attr_reader :chapters - # @return [Array<String>] all the fonts referred to in the stylesheet - attr_reader :fonts - - # @return [String] the path the layout HTML file to use to wrap the chapter in. - attr_reader :layout - - def initialize(layout, config = {}, fonts = []) - @chapters, @config, @layout, @fonts = [], config, layout, fonts + def initialize(context) + @chapters = [] + @context = context + @context.chapter_files.each(&method(:<<)) end def each(&block) chapters.each(&block) end @@ -31,15 +24,15 @@ def has_fonts? fonts.any? end def has_toc? - !!config.fetch('toc') { false } + !!config.toc end def has_cover? - !!config.fetch('cover_image') { false } + !!config.cover_image end def outline inject([]) { |all, chapter| all << [chapter.filename, chapter.outline] } end @@ -69,9 +62,9 @@ end # @return [String] output filename for epub, based on the book title and # version number. def filename - @filename ||= [config['title'], config['version']].join('-').gsub(/[^\w\.]/i, '-').squeeze('-').downcase.chomp('-') + '.epub' + @filename ||= [config.title, config.version].join('-').gsub(/[^\w\.]/i, '-').squeeze('-').downcase.chomp('-') + '.epub' end end end