lib/sitefuel/processors/AbstractStringBasedProcessor.rb in sitefuel-0.0.0b vs lib/sitefuel/processors/AbstractStringBasedProcessor.rb in sitefuel-0.1.0a

- old
+ new

@@ -1,10 +1,10 @@ # # File:: AbstractStringBasedProcessor.rb # Author:: wkm -# Copyright:: 2009 -# License:: GPL +# Copyright:: 2009, Zanoccio LLC. +# License:: GPL version 2.0 (see LICENSE.rb) # # Defines an abstract processor that runs by loading an entire file into # memory as a string. Since most files we're looking at are very small # anyway (seeing as they're intended to be served millions of times) this # is usually fine. @@ -19,10 +19,14 @@ def self.processor_type 'String' end + def processor_symbol + 'S' + end + # lightweight wrapper for opening a resource and generating the file def self.process_file(filename, config = {}) proc = self.new() proc.configure(config) proc.open_file(filename) @@ -48,22 +52,26 @@ proc.generate_string end # opens a resource from a file def open_file(filename) + info "#{self.class} opening #{filename}" + self.document = File.read(filename) self.original_size = File.size(filename) self.resource_name = filename return self end # opens a resource directly from a string def open_string(string) + info "#{self.class} opening in embedded mode" + self.document = string self.original_size = string.length - self.resource_name = '<<in-memory string>>' + self.resource_name = '<<embedded string>>' end # generates the actual string def generate_string self.execute @@ -74,9 +82,18 @@ # generates the string and shoves it into the deployment abstraction def generate generate_string return self + end + + def save(file_tree) + file_name = create_file(file_tree) + File.open(file_name, 'w') do |file| + file << @document + end + + info "Wrote document into #{file}" end attr_reader :document protected \ No newline at end of file