Class: Blogdown::FilePipeline

Inherits:
Object
  • Object
show all
Defined in:
lib/blogdown/file_pipeline.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root) ⇒ FilePipeline

Returns a new instance of FilePipeline.



6
7
8
9
10
11
# File 'lib/blogdown/file_pipeline.rb', line 6

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

Instance Attribute Details

#stackObject

THis keeps track of files being processed



5
6
7
# File 'lib/blogdown/file_pipeline.rb', line 5

def stack
  @stack
end

Instance Method Details

#load_filesArray

Returns The files under posts folder.

Returns:

  • (Array)

    The files under posts folder



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/blogdown/file_pipeline.rb', line 14

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

#writer(name, contents) ⇒ Object

Writes given contents into a file with a name given as a parameter

Parameters:

  • name (String)

    The name of the file to be written

  • contents (String)

    The contents to be written on the file



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/blogdown/file_pipeline.rb', line 33

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