94 lines
1.9 KiB
Ruby
Executable File
94 lines
1.9 KiB
Ruby
Executable File
#!/usr/bin/env ruby
|
|
|
|
require 'rubygems'
|
|
require 'bundler'
|
|
|
|
begin
|
|
Bundler.setup(:default)
|
|
rescue Bundler::GemfileNotFound
|
|
$: << File.expand_path('../../lib', __FILE__)
|
|
end
|
|
|
|
require 'thor'
|
|
require 'attentive'
|
|
|
|
begin
|
|
load 'presentation.rb'
|
|
rescue LoadError => e
|
|
end
|
|
|
|
class Attentive::CLI < Thor
|
|
include Thor::Actions
|
|
|
|
default_task :start
|
|
|
|
desc "start", "Start a Rack server for previewing the presentation"
|
|
method_options [ :port, '-p' ] => 9393
|
|
def start
|
|
if Attentive.has_presentation?
|
|
Attentive::Server.start(options)
|
|
else
|
|
raise Attentive::NoPresentationError
|
|
end
|
|
end
|
|
|
|
def self.source_root
|
|
File.expand_path('../../skel', __FILE__)
|
|
end
|
|
|
|
desc "create", "Create a new skeleton presentation"
|
|
def create(name)
|
|
self.destination_root = File.join(Dir.pwd, name)
|
|
|
|
Dir[File.join(self.class.source_root, '**/*')].each do |file|
|
|
if File.file?(file)
|
|
filename = file.gsub(self.class.source_root + '/', '')
|
|
|
|
template filename, filename
|
|
end
|
|
end
|
|
end
|
|
|
|
desc "static", "Create a static copy of the site in _site"
|
|
def static
|
|
urls = [ '/' ]
|
|
|
|
Dir['assets/**/*'].each do |file|
|
|
if File.file?(file)
|
|
parts = file.split('/')[2..-1]
|
|
|
|
if !parts.empty?
|
|
file = parts.join('/')
|
|
|
|
%w{js css}.each do |root|
|
|
file.gsub!(%r{([^/]+\.#{root}).*$}, '\1')
|
|
end
|
|
|
|
urls << File.join('', 'assets', file)
|
|
end
|
|
end
|
|
end
|
|
|
|
target_dir = "_site"
|
|
|
|
FileUtils.rm_rf target_dir
|
|
FileUtils.mkdir_p target_dir
|
|
|
|
Attentive.middleware.replace([])
|
|
|
|
urls.each do |url|
|
|
response = Attentive::Server.call(Rack::MockRequest.env_for(url))
|
|
|
|
target = "#{target_dir}#{url}"
|
|
target += "index.html" if target[-1..-1] == '/'
|
|
|
|
puts "Writing #{target}..."
|
|
|
|
FileUtils.mkdir_p(File.dirname(target))
|
|
File.open(target, 'wb') { |fh| response.last.each { |part| fh.print part } }
|
|
end
|
|
end
|
|
end
|
|
|
|
Attentive::CLI.start
|