lib/amiba/site.rb in amiba-0.0.7 vs lib/amiba/site.rb in amiba-0.0.8
- old
+ new
@@ -7,12 +7,14 @@
class Preview < Thor::Group
include Amiba::Generator
namespace :"site:preview"
class_option :port, :default => 4321
+ # class_option :drafts, :default => false
def create
+ # invoke Amiba::Site::Generate, [], :drafts => options[:drafts]
invoke Amiba::Site::Generate
end
def preview
root = File.expand_path(File.join(Amiba::Configuration.site_dir, "public"))
@@ -32,10 +34,11 @@
end
end
class S3Upload < Thor::Group
include Amiba::Generator
+ include Amiba::Repo
namespace :"site:upload:s3"
class_option :credentials, :default => :default
class_option :target, :default => "site"
@@ -71,10 +74,15 @@
file = @bucket.files.create(:key=>name, :body=>data, :public=>true)
say_status "Uploaded", name, :green
end
end
+ def git_push
+ push
+ say_status "Changes pushed to git", "", :green
+ end
+
def complete
host = "http://#{bucket}.s3-website-#{Fog.credentials[:region]}.amazonaws.com/"
say_status "Available at", host, :green
end
@@ -91,10 +99,11 @@
class Generate < Thor::Group
include Amiba::Generator
namespace :"site:generate"
+ class_option :drafts, :default => false
def self.source_root
Dir.pwd
end
@@ -140,20 +149,20 @@
end
end
end
def build_entries
- Amiba::Source::Entry.all.each do |entry|
+ Amiba::Source::Entry.send(state).each do |entry|
build_page entry
end
end
def build_pages
Dir.glob('pages/**/[^_]*').each do |page_file|
next if File.directory? page_file
page = Amiba::Source::Page.new(File.relpath(page_file, "pages"))
- next unless page.state == "published"
+ next unless (page.state == "published" || options[:drafts])
build_page page
end
end
def build_json
@@ -175,17 +184,25 @@
begin
create_file(feed.output_filename) do
Tilt.new(feed.filename).render(Amiba::Scope.new(feed), :xml => Builder::XmlMarkup.new)
end
rescue
- puts "Unable to process #{feed.name}, skipping"
+ say_status "Failed", "Unable to process #{feed.name}: #{$!}, skipping", :red
end
end
end
private
+ def state
+ if options[:drafts]
+ :any
+ else
+ :published
+ end
+ end
+
def build_layout(page)
layout = Amiba::Source::Layout.new(page.layout)
return layout if File.exists? layout.staged_filename
create_file(layout.staged_filename) do layout.content end
layout
@@ -197,10 +214,10 @@
begin
create_file(page.output_filename) do
Tilt.new(layout.staged_filename).render(Amiba::Scope.new(page))
end
rescue
- puts "Unable to process #{page.name}: #{$!}, skipping"
+ say_status "Failed", "Unable to process #{page.name}: #{$!}, skipping", :red
end
end
end
end