Class: Stratus::Generator::Builder

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/stratus/generator/builder.rb

Instance Method Summary collapse

Methods included from Logging

#error, #fatal, #growl, #growler, #info, #notify

Constructor Details

#initialize(root_path, verbose = true) ⇒ Builder

Returns a new instance of Builder.



6
7
8
9
# File 'lib/stratus/generator/builder.rb', line 6

def initialize(root_path, verbose=true)
  @root_path = root_path
  @verbose = verbose
end

Instance Method Details

#copy_theme_filesObject



58
59
60
61
62
63
64
65
# File 'lib/stratus/generator/builder.rb', line 58

def copy_theme_files
  info "Theme..."
  delete_file Stratus.output_dir('theme'), true
  theme = Stratus.setting('theme', 'default')
  copy_file Stratus.site_path('themes', theme, 'images'), Stratus.output_dir('theme', 'images')
  copy_file Stratus.site_path('themes', theme, 'styles'), Stratus.output_dir('theme', 'styles')
  copy_file Stratus.site_path('themes', theme, 'scripts'), Stratus.output_dir('theme', 'scripts')
end

#executeObject



11
12
13
14
15
16
17
18
# File 'lib/stratus/generator/builder.rb', line 11

def execute
  sweep_content
  render_content
  copy_theme_files
  
  info "Done.", "\n"
  growl "Build complete."
end

#render_contentObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/stratus/generator/builder.rb', line 26

def render_content
  info "Rendering output..."
  make_dir Stratus.output_dir
  Stratus::Resources.collection_types.each do |col_type|
    info "#{col_type.capitalize}..."
    Stratus::Resources.content(:collection_type=>col_type).each do |r|
      output = renderer.render_content( r )
      write_file r.output_path, output
      # Copy attachments
      r.attachments.each do |attachment|
        copy_file attachment.source_path, attachment.output_path
      end
    end
    output = renderer.render_index_for( col_type )
    write_file Stratus.output_dir(col_type, 'index.html'), output
    if Stratus.content_setting( col_type, 'feed', true )
      output = renderer.render_index_for( col_type, 'feed' )
      write_file Stratus.output_dir(col_type, 'feed.xml'), output
    end
  end
  
  # Render HOME
  info "Homepage..."
  home = Stratus::Resources.homepage
  if home
    output = renderer.render_content( home, '.' )
    write_file Stratus.output_dir('index.html'), output
  else
    error "NO HOME PAGE DEFINED! UPDATE YOUR CONFIG FILE!!!"
  end
end

#sweep_contentObject



20
21
22
23
24
# File 'lib/stratus/generator/builder.rb', line 20

def sweep_content
  info "Scanning source structure..."
  scanner = Stratus::Generator::Scanner.new(@root_path)
  scanner.sweep
end