Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

First commit

  • Loading branch information...
commit 1ea33667eb4dba9846f5f6e9f2dd5390469e106d 1 parent 7d56265
@winton authored
View
2  LICENSE
@@ -15,4 +15,4 @@ 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.
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
195 README.md
@@ -1,36 +1,183 @@
-GemTemplate
-===========
+Stasis
+======
-A gem template for new projects.
+A general-purpose static site generator.
+
+Philosophy
+----------
+
+My preferred stack = static markup/assets (Nginx) + services (Node.js).
+
+Stasis helps with the first part of the equation. It can even get fairly dynamic if you need it to.
Requirements
------------
-<pre>
-gem install stencil
-</pre>
+ gem install stasis
+
+Supported Template Engines
+--------------------------
+
+Stasis uses [Tilt](https://github.com/rtomayko/tilt) to support the following template engines:
+
+ ENGINE FILE EXTENSIONS REQUIRED LIBRARIES
+ -------------------------- ----------------- ----------------------------
+ ERB .erb none (included ruby stdlib)
+ Interpolated String .str none (included ruby core)
+ Haml .haml haml
+ Sass .sass haml
+ Less CSS .less less
+ Builder .builder builder
+ Liquid .liquid liquid
+ RDiscount .markdown rdiscount
+ RedCloth .textile redcloth
+ RDoc .rdoc rdoc
+ Radius .radius radius
+ Markaby .mab markaby
+ Nokogiri .nokogiri nokogiri
+ CoffeeScript .coffee coffee-script (+node coffee)
+ Slim .slim slim (>= 0.7)
+
+Example
+-------
+
+Create a directory for your project and a markup file:
+
+### view.erb
+
+ Welcome <%= '!' * 3 %>
+
+Generate Static Files
+---------------------
+
+Open your terminal, `cd` into your project directory, and run the `stasis` command:
+
+ stasis
+
+You now have a `public` directory with rendered markup:
+
+ public/
+ view.html
+ view.erb
+
+Controllers
+-----------
+
+A controller defines `before` and `after` render callbacks.
+
+The only reserved filename in a Stasis project is `controller.rb`.
+
+### controller.rb
+
+ # Call before any file renders
+
+ before do
+ @title = 'Default Title'
+ end
+
+ # Call only before view.erb renders
+
+ before 'view.erb' do
+ @title = 'My Site'
+ end
+
+### view.erb
+
+ Welcome to <%= @title %>!
+
+### Multiple Controllers
+
+You can have a `controller.rb` at any directory level:
+
+ controller.rb
+ index.erb
+ pages/
+ controller.rb
+ page.erb
+
+This allows you to better organize your callbacks.
+
+Read more about [callback execution order](https://github.com/winton/stasis/wiki/Callback-Execution-Order).
+
+Layouts
+-------
+
+Create the layout markup:
+
+### layout.erb
+
+ <html>
+ <head>
+ <title><%= @title %></title>
+ </head>
+ <body><%= yield %></body>
+ </html>
+
+### controller.rb
+
+ before 'view.erb' do
+ @layout = 'layout.erb'
+ @title = 'My Site'
+ end
+
+ before 'layout.erb' do
+ @ignore = true
+ end
+
+We want `view.erb` to use the layout, so we set `@layout = 'layout.erb'`.
+
+We do not want a `public/layout.html` file, so we set `@ignore = true`.
+
+Change the Path
+---------------
+
+Let's say we want `view.erb` to be our front page.
+
+### controller.rb
+
+ before 'view.erb' do
+ @path = '/'
+ end
+
+Adding `@path = '/'` changes the render location to `public/index.html`.
+
+Continuous Rendering
+--------------------
+
+To continuously render files as you change them, run:
+
+ stasis -c
+
+Web Server
+----------
-Setup the template
-------------------
+To start Stasis in web server mode, run:
-You only have to do this once.
+ stasis -p 3000
-<pre>
-git clone git@github.com:winton/gem_template.git
-cd gem_template
-stencil
-</pre>
+In your browser, visit [http://localhost:3000](http://localhost:3000).
-Setup a new project
--------------------
+In web server mode, Stasis continuously renders (`-c`).
-Do this for every new project.
+Programmatically Generate Content
+---------------------------------
-<pre>
-mkdir my_project
-git init
-stencil gem_template
-rake rename
-</pre>
+ require 'rubygems'
+ require 'stasis'
+
+ stasis = Stasis.new '/path/to/project'
+
+ # Generate all files
+ stasis.generate '**/*'
+
+ # Generate one file
+ stasis.generate 'view.erb'
+
+ # Generate one file with extra callbacks
+ stasis.generate 'view.erb' do
+ before do
+ @path = "/custom/path"
+ end
+ end
-The last command does a find-replace (gem\_template -> my\_project) on files and filenames.
+Extra callbacks execute before any filters defined in the project.
View
18 Rakefile
@@ -1,13 +1,13 @@
-require File.dirname(__FILE__) + '/lib/gem_template/gems'
+require File.dirname(__FILE__) + '/lib/stasis/gems'
-GemTemplate::Gems.activate %w(rake rspec)
+Stasis::Gems.activate %w(rake rspec)
require 'rake'
require 'spec/rake/spectask'
def gemspec
@gemspec ||= begin
- file = File.expand_path('../gem_template.gemspec', __FILE__)
+ file = File.expand_path('../stasis.gemspec', __FILE__)
eval(File.read(file), binding, file)
end
end
@@ -29,9 +29,9 @@ task :gem do
root = File.expand_path('../', __FILE__)
pkg = "#{root}/pkg"
system "rm -Rf #{pkg}"
- GemTemplate::Gems.gemset_names.each do |gemset|
+ Stasis::Gems.gemset_names.each do |gemset|
ENV['GEMSET'] = gemset.to_s
- system "cd #{root} && gem build gem_template.gemspec"
+ system "cd #{root} && gem build stasis.gemspec"
system "mkdir -p #{pkg} && mv *.gem pkg"
end
ENV['GEMSET'] = old_gemset
@@ -63,17 +63,17 @@ namespace :gems do
gemset = ENV['GEMSET']
sudo = ENV['SUDO'] == '1' ? 'sudo' : ''
- GemTemplate::Gems.gemset = gemset if gemset
+ Stasis::Gems.gemset = gemset if gemset
if dev
- gems = GemTemplate::Gems.gemspec.development_dependencies
+ gems = Stasis::Gems.gemspec.development_dependencies
else
- gems = GemTemplate::Gems.gemspec.dependencies
+ gems = Stasis::Gems.gemspec.dependencies
end
gems.each do |name|
name = name.to_s
- version = GemTemplate::Gems.versions[name]
+ version = Stasis::Gems.versions[name]
if Gem.source_index.find_name(name, version).empty?
version = version ? "-v #{version}" : ''
system "#{sudo} gem install #{name} #{version} #{docs}"
View
3  bin/gem_template
@@ -1,3 +0,0 @@
-#!/usr/bin/env ruby
-
-require File.expand_path(File.dirname(__FILE__) + "/../lib/gem_template")
View
5 bin/stasis
@@ -0,0 +1,5 @@
+#!/usr/bin/env ruby
+
+require File.expand_path(File.dirname(__FILE__) + "/../lib/stasis")
+
+Stasis.generate Dir.pwd, '**/*'
View
5 config/gemsets.yml
@@ -1,3 +1,4 @@
-gem_template:
+stasis:
rake: >=0.8.7
- rspec: ~>1.0
+ rspec: ~>1.0
+ tilt: ~>1.2
View
14 config/gemspec.yml
@@ -1,13 +1,13 @@
-name: gem_template
+name: stasis
version: 0.1.0
authors:
- -
-email:
-homepage:
-summary:
-description:
+ - Winton Welsh
+email: mail@wintoni.us
+homepage: http://wintoni.us
+summary: Markup-agnostic static site generator
+description: A markup-agnostic static site generator.
dependencies:
- -
+ - tilt
development_dependencies:
- rake
- rspec
View
8 lib/gem_template.rb
@@ -1,8 +0,0 @@
-require File.dirname(__FILE__) + '/gem_template/gems'
-
-GemTemplate::Gems.activate %w()
-
-$:.unshift File.dirname(__FILE__)
-
-module GemTemplate
-end
View
98 lib/stasis.rb
@@ -0,0 +1,98 @@
+require 'rubygems'
+require 'slim'
+require 'yaml'
+
+require File.dirname(__FILE__) + '/stasis/gems'
+
+Stasis::Gems.activate %w(tilt)
+require 'tilt'
+
+$:.unshift File.dirname(__FILE__)
+
+class Stasis
+
+ attr_reader :controllers, :root
+
+ def initialize(root)
+ @root = root
+ @controllers = Dir["#{root}/**/controller.rb"].inject({}) do |hash, path|
+ context = Context::Controller.new
+ context.instance_eval File.read(path), path
+ hash[File.dirname(path)] = context
+ hash
+ end
+ end
+
+ def generate(*paths)
+ paths.collect! { |p| "#{root}/#{p}" }
+ Dir[*paths].each do |path|
+ rel_path = path[root.length+1..-1]
+ next unless File.file?(path)
+ next unless Tilt.mappings.keys.include?(File.extname(path)[1..-1])
+ context = Context::Render.new rel_path
+ trigger :before, context, path, rel_path
+ next if context.ignore
+ template = Tilt.new path
+ view = template.render(context)
+ trigger :after, context, path, rel_path
+ if context.layout
+ layout_path = "#{root}/#{context.layout}"
+ trigger :before, context, layout_path, context.layout
+ template = Tilt.new layout_path
+ layout = template.render(context) { view }
+ trigger :after, context, layout_path, context.layout
+ end
+ puts view.inspect
+ puts layout.inspect
+ end
+ end
+
+ def trigger(type, context, path, rel_path)
+ dir = File.dirname path
+ begin
+ callbacks = controllers[dir]
+ if callbacks
+ blocks = callbacks.send(type, nil)
+ blocks += callbacks.send(type, rel_path)
+ blocks += callbacks.send(type, File.basename(rel_path))
+ blocks.each do |block|
+ context.instance_eval &block
+ end
+ end
+ dir = File.expand_path('../', dir)
+ end while dir != root && dir != '/'
+ end
+
+ class Context
+ class Controller
+
+ def after(view=nil, &block)
+ @after ||= {}
+ @after[view] ||= []
+ if block
+ @after[view] << block
+ else
+ @after[view]
+ end
+ end
+
+ def before(view=nil, &block)
+ @before ||= {}
+ @before[view] ||= []
+ if block
+ @before[view] << block
+ else
+ @before[view]
+ end
+ end
+ end
+
+ class Render
+ attr_reader :ignore, :path, :layout, :view
+
+ def initialize(rel_path)
+ @view = rel_path
+ end
+ end
+ end
+end
View
4 lib/gem_template/gems.rb → lib/stasis/gems.rb
@@ -1,8 +1,8 @@
-unless defined?(GemTemplate::Gems)
+unless defined?(Stasis::Gems)
require 'yaml'
- module GemTemplate
+ class Stasis
module Gems
class <<self
View
8 spec/fixtures/project/controller.rb
@@ -0,0 +1,8 @@
+before 'layout.erb' do
+ @ignore = true
+end
+
+before 'view.erb' do
+ @layout = 'layout.erb'
+ @title = 'My Site'
+end
View
6 spec/fixtures/project/layout.erb
@@ -0,0 +1,6 @@
+<html>
+ <head>
+ <title><%= @title %></title>
+ </head>
+ <body><%= yield %></body>
+</html>
View
2  spec/fixtures/project/view.erb
@@ -0,0 +1,2 @@
+<h1><%= @title %></h1>
+Welcome!
View
4 spec/gem_template_spec.rb
@@ -1,4 +0,0 @@
-require 'spec_helper'
-
-describe GemTemplate do
-end
View
6 spec/spec_helper.rb
@@ -1,11 +1,11 @@
require 'pp'
$root = File.expand_path('../../', __FILE__)
-require "#{$root}/lib/gem_template/gems"
+require "#{$root}/lib/stasis/gems"
-GemTemplate::Gems.activate :rspec
+Stasis::Gems.activate :rspec
-require "#{$root}/lib/gem_template"
+require "#{$root}/lib/stasis"
Spec::Runner.configure do |config|
end
View
106 spec/gem_template/gems_spec.rb → spec/stasis/gems_spec.rb
@@ -1,36 +1,36 @@
require 'spec_helper'
-describe GemTemplate::Gems do
+describe Stasis::Gems do
before(:each) do
- @old_config = GemTemplate::Gems.config
+ @old_config = Stasis::Gems.config
- GemTemplate::Gems.config.gemspec = "#{$root}/spec/fixtures/gemspec.yml"
- GemTemplate::Gems.config.gemsets = [
+ Stasis::Gems.config.gemspec = "#{$root}/spec/fixtures/gemspec.yml"
+ Stasis::Gems.config.gemsets = [
"#{$root}/spec/fixtures/gemsets.yml"
]
- GemTemplate::Gems.config.warn = true
+ Stasis::Gems.config.warn = true
- GemTemplate::Gems.gemspec true
- GemTemplate::Gems.gemset = nil
+ Stasis::Gems.gemspec true
+ Stasis::Gems.gemset = nil
end
after(:each) do
- GemTemplate::Gems.config = @old_config
+ Stasis::Gems.config = @old_config
end
describe :activate do
it "should activate gems" do
- GemTemplate::Gems.stub!(:gem)
- GemTemplate::Gems.should_receive(:gem).with('rspec', '=1.3.1')
- GemTemplate::Gems.should_receive(:gem).with('rake', '=0.8.7')
- GemTemplate::Gems.activate :rspec, 'rake'
+ Stasis::Gems.stub!(:gem)
+ Stasis::Gems.should_receive(:gem).with('rspec', '=1.3.1')
+ Stasis::Gems.should_receive(:gem).with('rake', '=0.8.7')
+ Stasis::Gems.activate :rspec, 'rake'
end
end
describe :gemset= do
before(:each) do
- GemTemplate::Gems.config.gemsets = [
+ Stasis::Gems.config.gemsets = [
{
:name => {
:rake => '>0.8.6',
@@ -45,15 +45,15 @@
describe :default do
before(:each) do
- GemTemplate::Gems.gemset = :default
+ Stasis::Gems.gemset = :default
end
it "should set @gemset" do
- GemTemplate::Gems.gemset.should == :default
+ Stasis::Gems.gemset.should == :default
end
it "should set @gemsets" do
- GemTemplate::Gems.gemsets.should == {
+ Stasis::Gems.gemsets.should == {
:name => {
:rake => ">0.8.6",
:default => {
@@ -71,7 +71,7 @@
end
it "should set Gems.versions" do
- GemTemplate::Gems.versions.should == {
+ Stasis::Gems.versions.should == {
:externals => "=1.0.2",
:mysql => "=2.8.1",
:rake => ">0.8.6",
@@ -80,26 +80,26 @@
end
it "should return proper values for Gems.dependencies" do
- GemTemplate::Gems.dependencies.should == [ :rake, :mysql ]
- GemTemplate::Gems.development_dependencies.should == []
+ Stasis::Gems.dependencies.should == [ :rake, :mysql ]
+ Stasis::Gems.development_dependencies.should == []
end
it "should return proper values for Gems.gemset_names" do
- GemTemplate::Gems.gemset_names.should == [ :default, :rspec2, :solo ]
+ Stasis::Gems.gemset_names.should == [ :default, :rspec2, :solo ]
end
end
describe :rspec2 do
before(:each) do
- GemTemplate::Gems.gemset = "rspec2"
+ Stasis::Gems.gemset = "rspec2"
end
it "should set @gemset" do
- GemTemplate::Gems.gemset.should == :rspec2
+ Stasis::Gems.gemset.should == :rspec2
end
it "should set @gemsets" do
- GemTemplate::Gems.gemsets.should == {
+ Stasis::Gems.gemsets.should == {
:name => {
:rake => ">0.8.6",
:default => {
@@ -117,7 +117,7 @@
end
it "should set Gems.versions" do
- GemTemplate::Gems.versions.should == {
+ Stasis::Gems.versions.should == {
:mysql2 => "=0.2.6",
:rake => ">0.8.6",
:rspec => "=2.3.0"
@@ -125,26 +125,26 @@
end
it "should return proper values for Gems.dependencies" do
- GemTemplate::Gems.dependencies.should == [ :rake, :mysql2 ]
- GemTemplate::Gems.development_dependencies.should == []
+ Stasis::Gems.dependencies.should == [ :rake, :mysql2 ]
+ Stasis::Gems.development_dependencies.should == []
end
it "should return proper values for Gems.gemset_names" do
- GemTemplate::Gems.gemset_names.should == [ :default, :rspec2, :solo ]
+ Stasis::Gems.gemset_names.should == [ :default, :rspec2, :solo ]
end
end
describe :solo do
before(:each) do
- GemTemplate::Gems.gemset = :solo
+ Stasis::Gems.gemset = :solo
end
it "should set @gemset" do
- GemTemplate::Gems.gemset.should == :solo
+ Stasis::Gems.gemset.should == :solo
end
it "should set @gemsets" do
- GemTemplate::Gems.gemsets.should == {
+ Stasis::Gems.gemsets.should == {
:name => {
:rake => ">0.8.6",
:default => {
@@ -162,28 +162,28 @@
end
it "should set Gems.versions" do
- GemTemplate::Gems.versions.should == {:rake=>">0.8.6"}
+ Stasis::Gems.versions.should == {:rake=>">0.8.6"}
end
it "should return proper values for Gems.dependencies" do
- GemTemplate::Gems.dependencies.should == [:rake]
- GemTemplate::Gems.development_dependencies.should == []
+ Stasis::Gems.dependencies.should == [:rake]
+ Stasis::Gems.development_dependencies.should == []
end
it "should return proper values for Gems.gemset_names" do
- GemTemplate::Gems.gemset_names.should == [ :default, :rspec2, :solo ]
+ Stasis::Gems.gemset_names.should == [ :default, :rspec2, :solo ]
end
end
describe :nil do
before(:each) do
- GemTemplate::Gems.gemset = nil
+ Stasis::Gems.gemset = nil
end
it "should set everything to nil" do
- GemTemplate::Gems.gemset.should == nil
- GemTemplate::Gems.gemsets.should == nil
- GemTemplate::Gems.versions.should == nil
+ Stasis::Gems.gemset.should == nil
+ Stasis::Gems.gemsets.should == nil
+ Stasis::Gems.versions.should == nil
end
end
end
@@ -195,18 +195,18 @@
it "should return the correct gemset for name gem" do
Gem.should_receive(:loaded_specs).and_return({ "name" => nil })
- GemTemplate::Gems.send(:gemset_from_loaded_specs).should == :default
+ Stasis::Gems.send(:gemset_from_loaded_specs).should == :default
end
it "should return the correct gemset for name-rspec gem" do
Gem.should_receive(:loaded_specs).and_return({ "name-rspec2" => nil })
- GemTemplate::Gems.send(:gemset_from_loaded_specs).should == :rspec2
+ Stasis::Gems.send(:gemset_from_loaded_specs).should == :rspec2
end
end
describe :reload_gemspec do
it "should populate @gemspec" do
- GemTemplate::Gems.gemspec.hash.should == {
+ Stasis::Gems.gemspec.hash.should == {
"name" => "name",
"version" => "0.1.0",
"authors" => ["Author"],
@@ -224,26 +224,26 @@
end
it "should create methods from keys of @gemspec" do
- GemTemplate::Gems.gemspec.name.should == "name"
- GemTemplate::Gems.gemspec.version.should == "0.1.0"
- GemTemplate::Gems.gemspec.authors.should == ["Author"]
- GemTemplate::Gems.gemspec.email.should == "email@email.com"
- GemTemplate::Gems.gemspec.homepage.should == "http://github.com/author/name"
- GemTemplate::Gems.gemspec.summary.should == "Summary"
- GemTemplate::Gems.gemspec.description.should == "Description"
- GemTemplate::Gems.gemspec.dependencies.should == [
+ Stasis::Gems.gemspec.name.should == "name"
+ Stasis::Gems.gemspec.version.should == "0.1.0"
+ Stasis::Gems.gemspec.authors.should == ["Author"]
+ Stasis::Gems.gemspec.email.should == "email@email.com"
+ Stasis::Gems.gemspec.homepage.should == "http://github.com/author/name"
+ Stasis::Gems.gemspec.summary.should == "Summary"
+ Stasis::Gems.gemspec.description.should == "Description"
+ Stasis::Gems.gemspec.dependencies.should == [
"rake",
{ "default" => ["mysql"] },
{ "rspec2" => [ "mysql2" ] }
]
- GemTemplate::Gems.gemspec.development_dependencies.should == nil
+ Stasis::Gems.gemspec.development_dependencies.should == nil
end
it "should produce a valid gemspec" do
- GemTemplate::Gems.gemset = :default
- gemspec = File.expand_path("../../../gem_template.gemspec", __FILE__)
+ Stasis::Gems.gemset = :default
+ gemspec = File.expand_path("../../../stasis.gemspec", __FILE__)
gemspec = eval(File.read(gemspec), binding, gemspec)
gemspec.validate.should == true
end
end
-end
+end
View
9 spec/stasis_spec.rb
@@ -0,0 +1,9 @@
+require 'spec_helper'
+
+describe Stasis do
+
+ it "should" do
+ stasis = Stasis.new("#{$root}/spec/fixtures/project")
+ stasis.generate("**/*")
+ end
+end
View
20 gem_template.gemspec → stasis.gemspec
@@ -3,26 +3,26 @@ root = File.expand_path('../', __FILE__)
lib = "#{root}/lib"
$:.unshift lib unless $:.include?(lib)
-require 'gem_template/gems'
-GemTemplate::Gems.gemset ||= ENV['GEMSET'] || :default
+require 'stasis/gems'
+Stasis::Gems.gemset ||= ENV['GEMSET'] || :default
Gem::Specification.new do |s|
- GemTemplate::Gems.gemspec.hash.each do |key, value|
- if key == 'name' && GemTemplate::Gems.gemset != :default
- s.name = "#{value}-#{GemTemplate::Gems.gemset}"
- elsif key == 'summary' && GemTemplate::Gems.gemset == :solo
+ Stasis::Gems.gemspec.hash.each do |key, value|
+ if key == 'name' && Stasis::Gems.gemset != :default
+ s.name = "#{value}-#{Stasis::Gems.gemset}"
+ elsif key == 'summary' && Stasis::Gems.gemset == :solo
s.summary = value + " (no dependencies)"
elsif !%w(dependencies development_dependencies).include?(key)
s.send "#{key}=", value
end
end
- GemTemplate::Gems.dependencies.each do |g|
- s.add_dependency g.to_s, GemTemplate::Gems.versions[g]
+ Stasis::Gems.dependencies.each do |g|
+ s.add_dependency g.to_s, Stasis::Gems.versions[g]
end
- GemTemplate::Gems.development_dependencies.each do |g|
- s.add_development_dependency g.to_s, GemTemplate::Gems.versions[g]
+ Stasis::Gems.development_dependencies.each do |g|
+ s.add_development_dependency g.to_s, Stasis::Gems.versions[g]
end
s.executables = `cd #{root} && git ls-files bin/*`.split("\n").collect { |f| File.basename(f) }
Please sign in to comment.
Something went wrong with that request. Please try again.