Added generator, ace-gen works!

master
Jakub Stastny aka botanicus 2011-06-12 20:46:39 +02:00
parent 4970d59081
commit a1596e5642
20 changed files with 183 additions and 2 deletions

View File

@ -1,3 +1,6 @@
= Version 0.4
* Added project generator (ace-gen).
= Version 0.3
* Added LazyRendering mixin.
* Added SassFilter.

View File

@ -20,6 +20,8 @@ rescue LoadError
end
templater = SimpleTemplater.new(:ace)
templater.discover!
generator = templater.find(:project)
if generator.nil?

View File

@ -1,5 +1,5 @@
# encoding: utf-8
module Ace
VERSION = "0.3.3"
VERSION = "0.4"
end

1
project_generator/content/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
output

View File

@ -0,0 +1,24 @@
# encoding: utf-8
# Use local clones if possible.
# If you want to use your local copy, just symlink it to vendor.
extend Module.new {
def gem(name, options = Hash.new)
local_path = File.expand_path("../vendor/#{name}", __FILE__)
if File.exist?(local_path)
super name, options.merge(path: local_path).delete_if { |key, _| [:git, :branch].include?(key) }
else
super name, options
end
end
}
source "http://gemcutter.org"
gem "ace"
gem "nake"
gem "template-inheritance"
group(:development)
gem "rack"
end

View File

@ -0,0 +1,26 @@
Copyright (c) <%= Time.now.year %> <%= @user %>
All the logic can be used under the MIT license (see bellow).
The actual articles though shall not be used by other people
in any circumstances unless the author gives permission to do
otherwise. In such case the copyright information shall not
be omitted as well as a link to its original source.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@ -0,0 +1,11 @@
h1. About
This is "<%= @name %>":<%= @url %>. It is written in "Ace":https://github.com/botanicus/ace, a powerful generator of static sites.
h1. Usage
_*NOTE:* You need Ruby 1.9.2 or later._
# Install all the dependencies via bundler: @bundle install@.
# Generate the output by running @./tasks.rb generate@.
# Run @./config.ru@ and view the content at "localhost:9292":http://localhost:9292/.

View File

View File

@ -0,0 +1,20 @@
#!/usr/bin/env bundle exec ace
# encoding: utf-8
Encoding.default_internal = "utf-8"
Encoding.default_external = "utf-8"
# Setup $LOAD_PATH.
require "bundler/setup"
# Custom setup.
require "pupu/adapters/ace"
Pupu.media_prefix = "/assets"
require "helpers"
# Load the app.
Dir["app/**/*.rb"].each do |file|
puts "~ Loading #{file}"
load file
end

View File

@ -0,0 +1,32 @@
#!/usr/bin/env rackup
# This is just for development. The only thing it does
# is serving of static files from the output/ directory.
use Rack::Head
class Server
def initialize(root)
@file_server = Rack::File.new(root)
end
def call(env)
path = env["PATH_INFO"]
returned = @file_server.call(env)
if returned[0] == 404 && env["PATH_INFO"].end_with?("/")
env["PATH_INFO"] = File.join(env["PATH_INFO"], "index.html")
returned = @file_server.call(env)
log "[404]", env["PATH_INFO"] if returned[0] == 404
returned
else
returned
end
end
private
def log(bold, message)
warn "~ \033[1;31m#{bold}\033[0m #{message}"
end
end
run Server.new("output")

View File

@ -0,0 +1,2 @@
title: ""
base_url: "<% @url %>"

View File

View File

@ -0,0 +1,7 @@
- extends "base.html"
- block(:description, "Hello world page, nothing fancy.")
- block(:keywords, "hello world, ace, whatever else")
= block(:body) do
%h1 Hello World!

View File

@ -0,0 +1,3 @@
User-agent: *
Disallow: /assets
Allow: /

View File

@ -0,0 +1,13 @@
!!! 5
%html
%head
%title= block(:title, "<%= @name %>")
%meta{"http-equiv" => "content-type", content: "text/html; charset=utf-8"}
%meta{"http-equiv" => "content-language", content: "en"}
%meta{name: "description", content: block(:description, "")}
%meta{name: "keywords", content: block(:keywords, "")}
= block(:head)
%body
= block(:body)
#footer
&copy; <%= Time.now.year %> &ndash; #{Time.now.year} <%= @user %> | Powered by <a href="https://github.com/botanicus/ace">Ace</a>.

View File

@ -0,0 +1,5 @@
# encoding: utf-8
require "ace/static"
rule Ace::Static, "index.html.haml"

View File

@ -0,0 +1,28 @@
#!/usr/bin/env bundle exec nake
# encoding: utf-8
Encoding.default_internal = "utf-8"
Encoding.default_external = "utf-8"
# Task.tasks.default_proc = lambda { |*| Task[:generate] }
Task.new(:generate) do |task|
task.description = "Generate static HTML."
task.define do
sh "./boot.rb"
end
end
Task.new(:rsync) do |task|
task.description = "Rsync the output to server."
# config
task.config[:user] = "TODO"
task.config[:server] = "TODO"
task.config[:path] = "TODO"
task.define do |options|
sh "rsync -av --delete output/ #{config[:user]}@#{config[:server]}:#{config[:path]}"
end
end

View File

@ -4,6 +4,10 @@
# You can update context hash and register hooks. Don't forget to use merge! instead of merge, because you are
# manipulating with one object, rather than returning new one.
# ace-gen project --user="Jakub Stastny" --name=101Ideas.cz --url=http://101ideas.cz
hook do |generator, context|
# TODO
context[:user] ||= ENV["USER"]
context[:name] || raise("You have to specify at least --title=WebTitle")
context[:url] ||= "http://#{context[:name]}"
end