Class: Webby::Apps::Main
- Inherits:
-
Object
- Object
- Webby::Apps::Main
- Defined in:
- lib/webby/apps/main.rb
Class Method Summary collapse
-
.run(args) ⇒ Object
Create a new instance of Main, and run the
webby
application given the command line args.
Instance Method Summary collapse
-
#app ⇒ Object
Return the Rake application object.
- #capture_command_line_args(args) ⇒ Object
-
#find_sitefile ⇒ Object
Search for the “Sitefile” starting in the current directory and working upwards through the filesystem until the root of the filesystem is reached.
- #import_default_tasks ⇒ Object
- #import_website_tasks ⇒ Object
-
#init(args) ⇒ Object
Initialize the Rake application object and load the core rake tasks, the site specific rake tasks, and the site specific ruby code.
-
#initialize ⇒ Main
constructor
Create a new Main webby object for building websites.
-
#parse(args) ⇒ Object
Parse the command line args for options and commands to invoke.
-
#rake ⇒ Object
Execute the rake command.
- #require_lib_files ⇒ Object
-
#run(args) ⇒ Object
Runs the main webby application.
Constructor Details
#initialize ⇒ Main
Create a new Main webby object for building websites.
17 18 19 |
# File 'lib/webby/apps/main.rb', line 17 def initialize @stdout = $stdout end |
Class Method Details
.run(args) ⇒ Object
Create a new instance of Main, and run the webby
application given the command line args.
11 12 13 |
# File 'lib/webby/apps/main.rb', line 11 def self.run( args ) self.new.run args end |
Instance Method Details
#app ⇒ Object
Return the Rake application object.
103 104 105 |
# File 'lib/webby/apps/main.rb', line 103 def app Rake.application end |
#capture_command_line_args(args) ⇒ Object
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/apps/main.rb', line 134 def capture_command_line_args(args) args = OpenStruct.new(:raw => args) if args.raw.size > 1 ::Webby.deprecated "multiple arguments used for page title", "please quote the page title" end dashed = args.raw.join('-').downcase spaced = args.raw.join(' ') dir = ::File.dirname(dashed) args.dir = ('.' == dir ? '' : dir) args.slug = ::Webby::Resources::File.basename(dashed).to_url args.title = ::Webby::Resources::File.basename(spaced).titlecase # page should be dir/slug without leading / args.page = ::File.join(args.dir, args.slug).gsub(/^\//, '') ::Webby.site.args = args Object.const_set(:SITE, Webby.site) args end |
#find_sitefile ⇒ Object
Search for the “Sitefile” starting in the current directory and working upwards through the filesystem until the root of the filesystem is reached. If a “Sitefile” is not found, a RuntimeError is raised.
111 112 113 114 115 116 117 118 119 120 |
# File 'lib/webby/apps/main.rb', line 111 def find_sitefile here = Dir.pwd while ! app.have_rakefile Dir.chdir("..") if Dir.pwd == here || .nosearch fail "No Sitefile found" end here = Dir.pwd end end |
#import_default_tasks ⇒ Object
122 123 124 |
# File 'lib/webby/apps/main.rb', line 122 def import_default_tasks Dir.glob(::Webby.libpath(%w[webby tasks *.rake])).sort.each {|fn| import fn} end |
#import_website_tasks ⇒ Object
126 127 128 |
# File 'lib/webby/apps/main.rb', line 126 def import_website_tasks Dir.glob(::File.join(%w[tasks *.rake])).sort.each {|fn| import fn} end |
#init(args) ⇒ Object
Initialize the Rake application object and load the core rake tasks, the site specific rake tasks, and the site specific ruby code. Any extra command line arguments are converted into a page name and directory that might get created (depending upon the task invoked).
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/webby/apps/main.rb', line 76 def init( args ) # Make sure we're in a folder with a Sitefile app.do_option('--rakefile', 'Sitefile') app.do_option('--nosearch', nil) app.do_option('--silent', nil) unless app.have_rakefile raise RuntimeError, "Sitefile not found" end import_default_tasks import_website_tasks require_lib_files capture_command_line_args(args) args end |
#parse(args) ⇒ Object
Parse the command line args for options and commands to invoke.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/webby/apps/main.rb', line 35 def parse( args ) opts = OptionParser.new opts. = 'Usage: webby [options] target [target args]' opts.separator '' opts.on('-D', '--describe [PATTERN]', 'describe the tasks (matching optional PATTERN), then exit') {|pattern| app.do_option('--describe', pattern)} opts.on('-P', '--prereqs', 'display the tasks and dependencies, then exit') {app.do_option('--prereqs', nil)} opts.on('-T', '--tasks [PATTERN]', 'display the tasks (matching optional PATTERN) with descriptions, then exit') {|pattern| app.do_option('--tasks', pattern)} opts.on('-t', '--trace', 'turn on invoke/execute tracing, enable full backtrace') {app.do_option('--trace', nil)} opts.separator '' opts.separator 'common options:' opts.on_tail( '-h', '--help', 'show this message' ) do @stdout.puts opts exit end opts.on_tail( '--version', 'show version' ) do @stdout.puts "Webby #{::Webby::VERSION}" exit end opts.parse! args ARGV.replace Array(args.shift) args.delete_if do |arg| if %r/^[A-Z_]+=/ =~ arg ARGV << arg next true end false end args end |
#rake ⇒ Object
Execute the rake command.
95 96 97 98 99 |
# File 'lib/webby/apps/main.rb', line 95 def rake app.init 'webby' app.load_rakefile app.top_level end |
#require_lib_files ⇒ Object
130 131 132 |
# File 'lib/webby/apps/main.rb', line 130 def require_lib_files Dir.glob(::File.join(%w[lib ** *.rb])).sort.each {|fn| require fn} end |
#run(args) ⇒ Object
Runs the main webby application. The command line arguments are passed in to this method as an array of strings. The command line arguments are parsed to figure out which rake task to invoke.
25 26 27 28 29 30 31 |
# File 'lib/webby/apps/main.rb', line 25 def run( args ) args = args.dup parse args init args rake end |