Class: Blogdown::Publisher

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

Instance Method Summary collapse

Constructor Details

#initialize(root) ⇒ Publisher

Returns a new instance of Publisher.



6
7
8
9
# File 'lib/blogdown/publisher.rb', line 6

def initialize root
  @pipeline=Blogdown::FilePipeline.new root
  @base=root
end

Instance Method Details

#clean_outputObject



32
33
34
35
36
37
38
39
40
41
# File 'lib/blogdown/publisher.rb', line 32

def clean_output
  base_root=@base+'/output'
  base_root=Pathname base_root
  if base_root.exist?
    base_root.rmtree
    base_root.mkpath
  else
    base_root.mkpath
  end
end

#composeObject



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/blogdown/publisher.rb', line 11

def compose
  clean_output
  if @pipeline.stack.empty?
    raise IOError, "No file to compose"
  else
    @pipeline.stack.each do |file|
      htm=transform(file.read)
      @pipeline.writer(file.basename,htm)
    end
  end

end

#file_stackObject



28
29
30
# File 'lib/blogdown/publisher.rb', line 28

def file_stack
  @pipeline.stack
end

#kramdown_optionsObject



43
44
45
# File 'lib/blogdown/publisher.rb', line 43

def kramdown_options
  {coderay_css: "style", coderay_line_numbers: nil}
end

#transform(txt) ⇒ Object



24
25
26
# File 'lib/blogdown/publisher.rb', line 24

def transform(txt)
  Kramdown::Document.new(txt,kramdown_options).to_html
end