Sha256: 9a23de3abe7f258552af5299807e8978f1bca8955dd3fba1f6d451ef8a0ca174

Contents?: true

Size: 1.24 KB

Versions: 1

Compression:

Stored size: 1.24 KB

Contents

module Blogdown
  class FilePipeline
    # THis keeps track of files being processed

    attr_accessor :stack
    def initialize(root)
      @root=root
      @base=Pathname(@root)
      @stack=[]
      load_files
    end

    # @return [Array]  The files under posts folder
    def load_files
      puts "loading files from #{@root.to_s}"
      base_input=@root

      base=Pathname.new(base_input)
      unless base.exist?
        raise Blogdown::Exceptions::DirectoryNotFound, "please make sure the posts folder is present"
      end
      if base.exist?
        base.each_child do|child|
            puts "loading #{child.to_s}"
            self.stack<<child
            puts "Done"
        end
      end
      puts "Finished loading #{self.stack.length} files"
    end

    # Writes given contents into a file with a name given as a parameter
    # @param name [String] The name of the file to be written
    # @param contents [String] The contents to be written on the file
    def writer(name,contents)
      file=@base.to_s+"/output/#{name}.html"

      begin
        file=File.new(file.to_s,"w")
        file.write(contents)
        file.close
      rescue Exception=>e
        raise e
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
blogdown-0.2.0 lib/blogdown/file_pipeline.rb