Method: Webby::Builder#run

Defined in:
lib/webby/builder.rb

#run(opts = {}) ⇒ Object

call-seq:

run( :rebuild => false, :load_files => true )

Runs the Webby builder by loading in the layout files from the layouts/ folder and the content from the contents/ folder. Content is analyzed, and those that need to be copied or compiled (filtered using ERB, Texttile, Markdown, etc.) are handled. The results are placed in the output/ folder.

If the :rebuild flag is set to true, then all content is copied and/or compiled to the output folder.

A content file can mark itself as dirty by setting the dirty flag to true in the meta-data of the file. This will cause the contenet to always be compiled when the builder is run. Conversely, setting the dirty flag to false will cause the content to never be compiled or copied to the output folder.

A content file needs to be built if the age of the file is less then the age of the output product – i.e. the content file has been modified more recently than the output file.



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/webby/builder.rb', line 123

def run( opts = {} )
  opts[:load_files] = true unless opts.has_key?(:load_files)
  verbose = opts.getopt(:verbose, true)

  unless test(?d, output_dir)
    journal.create output_dir
    FileUtils.mkdir output_dir
  end

  ::Webby.load_files if opts[:load_files]

  Resources.pages.each do |page|
    unless page.dirty? or opts[:rebuild]
      journal.identical(page.destination) if verbose
      next
    end

    # copy the resource to the output directory if it is static
    if page.instance_of? Resources::Static
      FileUtils.mkdir_p ::File.dirname(page.destination)
      journal.create_or_update(page)
      FileUtils.cp page.path, page.destination
      FileUtils.chmod 0644, page.destination

    # otherwise, layout the resource and write the results to
    # the output directory
    else Renderer.write(page) end
  end

  # touch the cairn so we know when the website was last generated
  FileUtils.touch ::Webby.cairn

  nil
end