lib/caracal/document.rb in caracal-1.3.0 vs lib/caracal/document.rb in caracal-1.4.0

- old
+ new

@@ -35,13 +35,13 @@ module Caracal class Document - #------------------------------------------------------------- + #------------------------------------------------------ # Configuration - #------------------------------------------------------------- + #------------------------------------------------------ # mixins (order is important) include Caracal::Core::CustomProperties include Caracal::Core::FileName include Caracal::Core::Ignorables @@ -62,15 +62,15 @@ include Caracal::Core::Rules include Caracal::Core::Tables include Caracal::Core::Text - #------------------------------------------------------------- + #------------------------------------------------------ # Public Class Methods - #------------------------------------------------------------- + #------------------------------------------------------ - #============ OUTPUT ==================================== + #============ OUTPUT ================================== # This method renders a new Word document and returns it as a # a string. # def self.render(f_name = nil, &block) @@ -84,20 +84,21 @@ # This method renders a new Word document and saves it to the # file system. # def self.save(f_name = nil, &block) docx = new(f_name, &block) - buffer = docx.render - - File.open("./#{ docx.name }", 'wb') { |f| f.write(buffer.string) } + docx.save + # buffer = docx.render + # + # File.open(docx.path, 'wb') { |f| f.write(buffer.string) } end - #------------------------------------------------------------- + #------------------------------------------------------ # Public Instance Methods - #------------------------------------------------------------- + #------------------------------------------------------ # This method instantiates a new word document. # def initialize(name = nil, &block) file_name(name) @@ -117,21 +118,21 @@ (block.arity < 1) ? instance_eval(&block) : block[self] end end - #============ GETTERS =================================== + #============ GETTERS ================================= # This method returns an array of models which constitute the # set of instructions for producing the document content. # def contents @contents ||= [] end - #============ RENDERING ================================= + #============ RENDERING =============================== # This method renders the word document instance into # a string buffer. Order is important! # def render @@ -151,16 +152,24 @@ render_numbering(zip) # Must go here: Depends on document renderer end end + #============ SAVING ================================== - #------------------------------------------------------------- + def save + buffer = render + + File.open(path, 'wb') { |f| f.write(buffer.string) } + end + + + #------------------------------------------------------ # Private Instance Methods - #------------------------------------------------------------- + #------------------------------------------------------ private - #============ RENDERERS ===================================== + #============ RENDERERS =============================== def render_app(zip) content = ::Caracal::Renderers::AppRenderer.render(self) zip.put_next_entry('docProps/app.xml')