Sha256: 519c02a2f24f35abc6666c26201a4e8ce94822f71cc386d71fafe43d8eab7ae3

Contents?: true

Size: 1.14 KB

Versions: 3

Compression:

Stored size: 1.14 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
      base_input=@root+'/posts'

      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|
          if child.basename.to_s=~/^*.md$/
            self.stack<<child
          end
        end
      end
    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

3 entries across 3 versions & 1 rubygems

Version Path
blogdown-0.1.2 lib/blogdown/file_pipeline.rb
blogdown-0.1.1 lib/blogdown/file_pipeline.rb
blogdown-0.1.0 lib/blogdown/file_pipeline.rb