Class: Rake::WebbyTask

Inherits:
TaskLib
  • Object
show all
Defined in:
lib/webby/webby_task.rb

Overview

The WebbyTask defines several rake tasks for working with Webby based websites:

:build

Build the site by compiling only those resources in the content folder that have been modifed recently. If the a content file has a modification time more recent then its corresponding output file, then it will be built by this task.

:rebuild

Rebuild the entire site from the content folder and store the results in the output folder.

:autobuild

Monitors the content and layout directories for modified resources and compiles those files as needed. This task returns only when the user hits Ctrl-C.

:create:page

Create a new page in the content folder based on the template ‘page’ found in the templates folder. One task will be created for each file found in the templates folder.

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ WebbyTask

call-seq:

WebbyTask.new {|self| block}

Create the tasks used by Webby to build a website and to create new pages in the website.

Yields:

  • (_self)

Yield Parameters:



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/webby/webby_task.rb', line 60

def initialize
  yield self if block_given?

  # load any user defined libraries
  glob = File.join(FileUtils.pwd, 'lib', '**', '*.rb')
  Dir.glob(glob).sort.each {|fn| require fn}

  # create the Webby rake tasks
  define_build_tasks
  namespace(:create) {define_create_tasks}
end

Instance Method Details

#define_build_tasksObject

Defines the :build and :rebuild tasks



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/webby/webby_task.rb', line 74

def define_build_tasks
  desc "build the website"
  task :build do |t|
    ::Webby::Builder.run
  end

  desc "rebuild the website"
  task :rebuild do |t|
    ::Webby::Builder.run :rebuild => true
  end

  desc "continuously build the website"
  task :autobuild do |t|
    ::Webby::AutoBuilder.run
  end
end

#define_create_tasksObject

Scans the templates directory for any files, and creats a corresponding task for creating a new page based on that template.



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/webby/webby_task.rb', line 94

def define_create_tasks
  FileList["#{template_dir}/*"].each do |template|
    name = template.pathmap '%n'

    desc "create a new #{name} page"
    task name do |t|
      raise "Usage:  rake #{t.name} path" unless ARGV.length == 2

      page = t.application.top_level_tasks.pop
      page = File.join(content_dir, page)
      page << '.txt' if File.extname(page).empty?

      ::Webby::Builder.create page, :from => template
    end  # task
  end  # each
end

#page_defaultsObject

Global page attributes



45
46
47
# File 'lib/webby/webby_task.rb', line 45

def page_defaults
  ::Webby.page_defaults
end

#page_defaults=(hash) ⇒ Object

Merge the given hash with the page defaults hash



50
51
52
# File 'lib/webby/webby_task.rb', line 50

def page_defaults=( hash )
  ::Webby.page_defaults.merge! hash
end