Module: Pekky::Builder

Defined in:
lib/pekky/builder.rb

Class Method Summary collapse

Class Method Details

.buildObject



3
4
5
6
7
8
9
10
11
# File 'lib/pekky/builder.rb', line 3

def self.build
  check_for_output_dir
  copy_static_assets
  
  Pekky::Content.flush!
  
  Tree.add(Config.page_configs)
  Config.page_configs.each {|p| p.render}
end

.build!Object



13
14
15
16
# File 'lib/pekky/builder.rb', line 13

def self.build!
  clear_output_dir
  Pekky.build
end

.check_for_output_dirObject



22
23
24
# File 'lib/pekky/builder.rb', line 22

def self.check_for_output_dir      
  FileUtils.mkdir(Config[:output_dir]) unless File.exists?(Config[:output_dir])
end

.clear_output_dirObject



18
19
20
# File 'lib/pekky/builder.rb', line 18

def self.clear_output_dir
  system("rm -rf '#{Config[:output_dir]}/*'") if File.exists?(Config[:output_dir])
end

.copy_static_assetsObject



37
38
39
# File 'lib/pekky/builder.rb', line 37

def self.copy_static_assets
  system("cp -fR '#{Config[:public_dir]}/.' '#{Config[:output_dir]}/.'")
end

.directory(path) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/pekky/builder.rb', line 26

def self.directory(path)
  unless File.directory?(File.join(Config[:output_dir], path))
    parts = path.split("/")
    fragment = Config[:output_dir].clone
    while parts.length > 0
      fragment = File.join(fragment, parts.shift)
      FileUtils.mkdir(fragment) unless File.directory?(fragment)
    end
  end
end

.generate(destination) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/pekky/builder.rb', line 41

def self.generate(destination)
  destination ||= Dir.pwd
  FileUtils.mkdir(destination) unless File.exists?(destination)
  dirs = %w(content views views/layouts views/partials public public/stylesheets public/javascripts public/images)
  dirs.each do |d|
    FileUtils.mkdir(File.join(destination, d))
  end
  
  template_dir = File.expand_path("#{File.dirname(__FILE__)}/templates")
  system("cp '#{template_dir}/site.rb' '#{destination}'")
  system("cp '#{template_dir}/helpers.rb' '#{destination}'")
end