Class: Amber::CLI
- Inherits:
-
Object
- Object
- Amber::CLI
- Defined in:
- lib/amber/cli.rb
Instance Method Summary collapse
- #apache(options) ⇒ Object
- #build(options) ⇒ Object
- #clean(options) ⇒ Object
- #clear(options) ⇒ Object
- #init(options) ⇒ Object
-
#initialize(root, *args) ⇒ CLI
constructor
A new instance of CLI.
- #rebuild(options) ⇒ Object
- #server(options) ⇒ Object
Constructor Details
Instance Method Details
#apache(options) ⇒ Object
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/amber/cli.rb', line 82 def apache() site = Site.new(@root) directory = [:arg] unless directory puts "Missing DIRECTORY argument" exit 1 end directory = directory.gsub(%r{^/|/$}, '') Amber::Render::Apache.echo_config(site, directory) end |
#build(options) ⇒ Object
24 25 26 27 28 |
# File 'lib/amber/cli.rb', line 24 def build() site = Site.new(@root) site.load_pages site.render end |
#clean(options) ⇒ Object
35 36 37 |
# File 'lib/amber/cli.rb', line 35 def clean() clear() end |
#clear(options) ⇒ Object
30 31 32 33 |
# File 'lib/amber/cli.rb', line 30 def clear() site = Site.new(@root) site.clear end |
#init(options) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/amber/cli.rb', line 12 def init() new_dir = [:arg] mkdir(new_dir, nil) mkdir('amber', new_dir) copy_template_file('config.rb', 'amber', new_dir) touch('amber/menu.txt', new_dir) mkdir('amber/layouts', new_dir) mkdir('amber/locales', new_dir) mkdir('public', new_dir) mkdir('pages', new_dir) end |
#rebuild(options) ⇒ Object
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 |
# File 'lib/amber/cli.rb', line 39 def rebuild() site = Site.new(@root) site.continue_on_error = false site.load_pages FileUtils.mkdir_p(site.dest_dir) unless File.exist?(site.dest_dir) gitkeep = File.exist?(File.join(site.dest_dir, '.gitkeep')) temp_render = File.join(File.dirname(site.dest_dir), 'public-tmp') temp_old_pages = File.join(File.dirname(site.dest_dir), 'remove-me') site.with_destination(temp_render) do site.render end FileUtils.mv(site.dest_dir, temp_old_pages) FileUtils.mv(temp_render, site.dest_dir) site.with_destination(temp_old_pages) do site.clear FileUtils.rm_r(temp_old_pages) end if gitkeep FileUtils.touch(File.join(site.dest_dir, '.gitkeep')) end ensure # cleanup if something goes wrong. FileUtils.rm_r(temp_render) if temp_render && File.exist?(temp_render) FileUtils.rm_r(temp_old_pages) if temp_old_pages && File.exist?(temp_old_pages) end |
#server(options) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/amber/cli.rb', line 65 def server() require 'amber/server' host = nil port = nil if [:arg] host, port = [:arg].split(':') end if host.nil? || host.empty? host = DEFAULT_HOST end if port.nil? || port.empty? port = DEFAULT_PORT end site = Site.new(@root) Amber::Server.start(:port => port, :host => host, :site => site) end |