stasis 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +10 -0
- data/LICENSE +18 -0
- data/README.md +287 -0
- data/Rakefile +109 -0
- data/bin/stasis +30 -0
- data/config/gemsets.yml +9 -0
- data/config/gemspec.yml +17 -0
- data/lib/stasis.rb +291 -0
- data/lib/stasis/dev_mode.rb +55 -0
- data/lib/stasis/gems.rb +154 -0
- data/lib/stasis/plugin.rb +76 -0
- data/lib/stasis/plugins/before.rb +50 -0
- data/lib/stasis/plugins/helpers.rb +29 -0
- data/lib/stasis/plugins/ignore.rb +35 -0
- data/lib/stasis/plugins/instead.rb +15 -0
- data/lib/stasis/plugins/layout.rb +51 -0
- data/lib/stasis/plugins/priority.rb +41 -0
- data/lib/stasis/plugins/render.rb +71 -0
- data/lib/stasis/scope.rb +54 -0
- data/lib/stasis/scope/action.rb +25 -0
- data/lib/stasis/scope/controller.rb +62 -0
- data/lib/stasis/server.rb +90 -0
- data/site/arrow.png +0 -0
- data/site/controller.rb +72 -0
- data/site/github.png +0 -0
- data/site/index.html.haml +24 -0
- data/site/jquery-1.6.2.js +8982 -0
- data/site/stasis.css.scss +226 -0
- data/site/stasis.js.coffee +42 -0
- data/site/stasis.png +0 -0
- data/spec/fixtures/gemsets.yml +9 -0
- data/spec/fixtures/gemspec.yml +15 -0
- data/spec/fixtures/project/_partial.html.haml +1 -0
- data/spec/fixtures/project/before_render_partial.html.haml +1 -0
- data/spec/fixtures/project/before_render_text.html.haml +1 -0
- data/spec/fixtures/project/controller.rb +83 -0
- data/spec/fixtures/project/index.html.haml +16 -0
- data/spec/fixtures/project/layout.html.haml +3 -0
- data/spec/fixtures/project/layout_action.html.haml +1 -0
- data/spec/fixtures/project/layout_action_from_subdirectory.html.haml +1 -0
- data/spec/fixtures/project/layout_controller.html.haml +1 -0
- data/spec/fixtures/project/layout_controller_from_subdirectory.html.haml +1 -0
- data/spec/fixtures/project/no_controller/index.html.haml +12 -0
- data/spec/fixtures/project/not_dynamic.html +1 -0
- data/spec/fixtures/project/plugin.rb +16 -0
- data/spec/fixtures/project/subdirectory/_partial.html.haml +1 -0
- data/spec/fixtures/project/subdirectory/before_render_partial.html.haml +1 -0
- data/spec/fixtures/project/subdirectory/before_render_text.html.haml +1 -0
- data/spec/fixtures/project/subdirectory/controller.rb +66 -0
- data/spec/fixtures/project/subdirectory/ignore.html.haml +0 -0
- data/spec/fixtures/project/subdirectory/index.html.haml +14 -0
- data/spec/fixtures/project/subdirectory/layout.html.haml +3 -0
- data/spec/fixtures/project/subdirectory/layout_action.html.haml +1 -0
- data/spec/fixtures/project/subdirectory/layout_action_from_root.html.haml +1 -0
- data/spec/fixtures/project/subdirectory/layout_controller.html.haml +1 -0
- data/spec/fixtures/project/subdirectory/layout_controller_from_root.html.haml +1 -0
- data/spec/fixtures/project/time.html.haml +2 -0
- data/spec/spec_helper.rb +28 -0
- data/spec/stasis/gems_spec.rb +249 -0
- data/spec/stasis/plugins/before_spec.rb +53 -0
- data/spec/stasis/plugins/helpers_spec.rb +16 -0
- data/spec/stasis/plugins/ignore_spec.rb +17 -0
- data/spec/stasis/plugins/layout_spec.rb +22 -0
- data/spec/stasis/plugins/priority_spec.rb +22 -0
- data/spec/stasis/plugins/render_spec.rb +23 -0
- data/spec/stasis/server_spec.rb +29 -0
- data/spec/stasis_spec.rb +46 -0
- data/stasis.gemspec +32 -0
- metadata +227 -0
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Copyright (c) 2010
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
|
+
this software and associated documentation files (the "Software"), to deal in
|
5
|
+
the Software without restriction, including without limitation the rights to
|
6
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
7
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
8
|
+
subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
11
|
+
copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
15
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
16
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
17
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
18
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,287 @@
|
|
1
|
+
Stasis
|
2
|
+
======
|
3
|
+
|
4
|
+
Stasis is a dynamic framework for static sites.
|
5
|
+
|
6
|
+
Install
|
7
|
+
-------
|
8
|
+
|
9
|
+
Install via RubyGems:
|
10
|
+
|
11
|
+
<!-- language:console -->
|
12
|
+
|
13
|
+
$ gem install stasis
|
14
|
+
|
15
|
+
Templates
|
16
|
+
---------
|
17
|
+
|
18
|
+
At its most essential, Stasis takes a directory tree with [supported template files](#supported_markup_languages) and renders them.
|
19
|
+
|
20
|
+
Example directory structure:
|
21
|
+
|
22
|
+
<!-- language:console -->
|
23
|
+
|
24
|
+
project/
|
25
|
+
index.html.haml
|
26
|
+
other.txt
|
27
|
+
|
28
|
+
Run `stasis`:
|
29
|
+
|
30
|
+
<!-- highlight:stasis language:console -->
|
31
|
+
|
32
|
+
$ cd project
|
33
|
+
$ stasis
|
34
|
+
|
35
|
+
Stasis creates a `public` directory:
|
36
|
+
|
37
|
+
<!-- highlight:public/ language:console -->
|
38
|
+
|
39
|
+
project/
|
40
|
+
index.html.haml
|
41
|
+
other.txt
|
42
|
+
public/
|
43
|
+
index.html
|
44
|
+
other.txt
|
45
|
+
|
46
|
+
`index.html.haml` becomes `public/index.html`.
|
47
|
+
|
48
|
+
`other.txt` is copied as-is because `.txt` is an unrecognized template extension.
|
49
|
+
|
50
|
+
Controllers
|
51
|
+
-----------
|
52
|
+
|
53
|
+
Controllers contain Ruby code that is evaluated once before all templates render.
|
54
|
+
|
55
|
+
Example directory structure:
|
56
|
+
|
57
|
+
<!-- highlight:controller.rb language:console -->
|
58
|
+
|
59
|
+
project/
|
60
|
+
controller.rb
|
61
|
+
index.html.haml
|
62
|
+
subdirectory/
|
63
|
+
controller.rb
|
64
|
+
index.html.haml
|
65
|
+
|
66
|
+
Before
|
67
|
+
------
|
68
|
+
|
69
|
+
Use `before` blocks within `controller.rb` to execute code before a template renders.
|
70
|
+
|
71
|
+
`controller.rb`:
|
72
|
+
|
73
|
+
before 'index.html.haml' do
|
74
|
+
@something = true
|
75
|
+
end
|
76
|
+
|
77
|
+
`@something` is now available to the `index.html.haml` template.
|
78
|
+
|
79
|
+
The `before` method can take any number of paths and/or regular expressions:
|
80
|
+
|
81
|
+
before 'index.html.haml', /.*html.erb/ do
|
82
|
+
@something = true
|
83
|
+
end
|
84
|
+
|
85
|
+
Layouts
|
86
|
+
-------
|
87
|
+
|
88
|
+
`layout.html.haml`:
|
89
|
+
|
90
|
+
%html
|
91
|
+
%body= yield
|
92
|
+
|
93
|
+
In `controller.rb`, set the default layout:
|
94
|
+
|
95
|
+
layout 'layout.html.haml'
|
96
|
+
|
97
|
+
Set the layout for a particular template:
|
98
|
+
|
99
|
+
layout 'index.html.haml' => 'layout.html.haml'
|
100
|
+
|
101
|
+
Use a regular expression:
|
102
|
+
|
103
|
+
layout /.*html.haml/ => 'layout.html.haml'
|
104
|
+
|
105
|
+
Set the layout from a `before` block:
|
106
|
+
|
107
|
+
before 'index.html.haml' do
|
108
|
+
layout 'layout.html.haml'
|
109
|
+
end
|
110
|
+
|
111
|
+
Render
|
112
|
+
------
|
113
|
+
|
114
|
+
Within a template:
|
115
|
+
|
116
|
+
%html
|
117
|
+
%body= render '_partial.html.haml'
|
118
|
+
|
119
|
+
Within a `before` block:
|
120
|
+
|
121
|
+
before 'index.html.haml' do
|
122
|
+
@partial = render '_partial.html.haml'
|
123
|
+
end
|
124
|
+
|
125
|
+
Text:
|
126
|
+
|
127
|
+
render :text => 'Hello'
|
128
|
+
|
129
|
+
Local variables:
|
130
|
+
|
131
|
+
render 'index.html.haml', :locals => { :x => true }
|
132
|
+
|
133
|
+
Include a block for the template to `yield` to:
|
134
|
+
|
135
|
+
render 'index.html.haml' { 'Hello' }
|
136
|
+
|
137
|
+
Instead
|
138
|
+
-------
|
139
|
+
|
140
|
+
The `instead` method changes the output of the template being rendered:
|
141
|
+
|
142
|
+
before 'index.html.haml' do
|
143
|
+
instead render('subdirectory/index.html.haml')
|
144
|
+
end
|
145
|
+
|
146
|
+
Helpers
|
147
|
+
-------
|
148
|
+
|
149
|
+
`controller.rb`:
|
150
|
+
|
151
|
+
helpers do
|
152
|
+
def say_hello
|
153
|
+
'Hello'
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
The `say_hello` method is now available to all `before` blocks and templates.
|
158
|
+
|
159
|
+
Ignore
|
160
|
+
------
|
161
|
+
|
162
|
+
Use the `ignore` method in `controller.rb` to ignore certain paths.
|
163
|
+
|
164
|
+
Ignore filenames with an underscore at the beginning:
|
165
|
+
|
166
|
+
ignore /\/_.*/
|
167
|
+
|
168
|
+
Priority
|
169
|
+
--------
|
170
|
+
|
171
|
+
Use the `priority` method in `controller.rb` to change the file process order.
|
172
|
+
|
173
|
+
Copy `.txt` files before rendering the `index.html.erb` template:
|
174
|
+
|
175
|
+
priority /.*txt/ => 2, 'index.html.erb' => 1
|
176
|
+
|
177
|
+
The default priority is `0` for all files.
|
178
|
+
|
179
|
+
Usage
|
180
|
+
-----
|
181
|
+
|
182
|
+
### Command Line
|
183
|
+
|
184
|
+
Always execute the `stasis` command in the root directory of your project.
|
185
|
+
|
186
|
+
Development mode (auto-regenerate on save):
|
187
|
+
|
188
|
+
<!-- highlight:-d language:console -->
|
189
|
+
|
190
|
+
$ stasis -d
|
191
|
+
|
192
|
+
Only render specific files or directories:
|
193
|
+
|
194
|
+
<!-- highlight:-o language:console -->
|
195
|
+
|
196
|
+
$ stasis -o index.html.haml,subdirectory
|
197
|
+
|
198
|
+
Change the public (destination) directory:
|
199
|
+
|
200
|
+
<!-- highlight:-o language:console -->
|
201
|
+
|
202
|
+
$ stasis -p ../public
|
203
|
+
|
204
|
+
### Programmatic
|
205
|
+
|
206
|
+
Instanciate a `Stasis` object:
|
207
|
+
|
208
|
+
stasis = Stasis.new('/path/to/project/root')
|
209
|
+
|
210
|
+
Optionally specify a destination directory:
|
211
|
+
|
212
|
+
stasis = Stasis.new('/project', '/html')
|
213
|
+
|
214
|
+
Render all templates:
|
215
|
+
|
216
|
+
stasis.render
|
217
|
+
|
218
|
+
Render a specific template or directory:
|
219
|
+
|
220
|
+
stasis.render('index.html.haml', 'subdirectory')
|
221
|
+
|
222
|
+
Define local variables for `before` callbacks, views, and `helpers`:
|
223
|
+
|
224
|
+
stasis.render(:locals => { :x => 'y' })
|
225
|
+
|
226
|
+
More
|
227
|
+
----
|
228
|
+
|
229
|
+
### Supported Markup Languages
|
230
|
+
|
231
|
+
Stasis uses [Tilt](https://github.com/rtomayko/tilt) to support the following template engines:
|
232
|
+
|
233
|
+
<!-- language:console -->
|
234
|
+
|
235
|
+
ENGINE FILE EXTENSIONS
|
236
|
+
-------------------------- ----------------------
|
237
|
+
ERB .erb, .rhtml
|
238
|
+
Interpolated String .str
|
239
|
+
Erubis .erb, .rhtml, .erubis
|
240
|
+
Haml .haml
|
241
|
+
Sass .sass
|
242
|
+
Scss .scss
|
243
|
+
Less CSS .less
|
244
|
+
Builder .builder
|
245
|
+
Liquid .liquid
|
246
|
+
RDiscount .markdown, .mkd, .md
|
247
|
+
Redcarpet .markdown, .mkd, .md
|
248
|
+
BlueCloth .markdown, .mkd, .md
|
249
|
+
Kramdown .markdown, .mkd, .md
|
250
|
+
Maruku .markdown, .mkd, .md
|
251
|
+
RedCloth .textile
|
252
|
+
RDoc .rdoc
|
253
|
+
Radius .radius
|
254
|
+
Markaby .mab
|
255
|
+
Nokogiri .nokogiri
|
256
|
+
CoffeeScript .coffee
|
257
|
+
Creole (Wiki markup) .creole
|
258
|
+
Yajl .yajl
|
259
|
+
|
260
|
+
### Server Mode
|
261
|
+
|
262
|
+
Stasis can run as a server that uses [redis](http://redis.io) to wait for render jobs.
|
263
|
+
|
264
|
+
Stasis server that uses redis on port 6379:
|
265
|
+
|
266
|
+
<!-- highlight:-s language:console -->
|
267
|
+
|
268
|
+
$ stasis -s localhost:6379/0
|
269
|
+
|
270
|
+
Push to the server (in Ruby):
|
271
|
+
|
272
|
+
Stasis::Server.push(
|
273
|
+
# Paths to render
|
274
|
+
:paths => [ "index.html.haml", "subdirectory" ],
|
275
|
+
|
276
|
+
# Redis address
|
277
|
+
:redis => "localhost:6379/0",
|
278
|
+
|
279
|
+
# Return rendered templates (false by default)
|
280
|
+
:return => false,
|
281
|
+
|
282
|
+
# Block until templates generate (false by default)
|
283
|
+
:wait => false,
|
284
|
+
|
285
|
+
# Write to the filesystem (true by default)
|
286
|
+
:write => true
|
287
|
+
)
|
data/Rakefile
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/lib/stasis/gems'
|
2
|
+
|
3
|
+
Stasis::Gems.activate %w(rake rocco rspec)
|
4
|
+
|
5
|
+
require 'rake'
|
6
|
+
require 'rocco/tasks'
|
7
|
+
require 'spec/rake/spectask'
|
8
|
+
|
9
|
+
def gemspec
|
10
|
+
@gemspec ||= begin
|
11
|
+
file = File.expand_path('../stasis.gemspec', __FILE__)
|
12
|
+
eval(File.read(file), binding, file)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
if defined?(Spec::Rake::SpecTask)
|
17
|
+
desc "Run specs"
|
18
|
+
Spec::Rake::SpecTask.new do |t|
|
19
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
20
|
+
t.spec_opts = %w(-fs --color)
|
21
|
+
t.warning = true
|
22
|
+
end
|
23
|
+
task :spec
|
24
|
+
task :default => :spec
|
25
|
+
end
|
26
|
+
|
27
|
+
desc "Build gem(s)"
|
28
|
+
task :gem do
|
29
|
+
old_gemset = ENV['GEMSET']
|
30
|
+
root = File.expand_path('../', __FILE__)
|
31
|
+
pkg = "#{root}/pkg"
|
32
|
+
system "rm -Rf #{pkg}"
|
33
|
+
Stasis::Gems.gemset_names.each do |gemset|
|
34
|
+
ENV['GEMSET'] = gemset.to_s
|
35
|
+
system "cd #{root} && gem build stasis.gemspec"
|
36
|
+
system "mkdir -p #{pkg} && mv *.gem pkg"
|
37
|
+
end
|
38
|
+
ENV['GEMSET'] = old_gemset
|
39
|
+
end
|
40
|
+
|
41
|
+
namespace :gem do
|
42
|
+
desc "Install gem(s)"
|
43
|
+
task :install do
|
44
|
+
Rake::Task['gem'].invoke
|
45
|
+
Dir["#{File.dirname(__FILE__)}/pkg/*.gem"].each do |pkg|
|
46
|
+
system "gem install #{pkg} --no-ri --no-rdoc"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
desc "Push gem(s)"
|
51
|
+
task :push do
|
52
|
+
Rake::Task['gem'].invoke
|
53
|
+
Dir["#{File.dirname(__FILE__)}/pkg/*.gem"].each do |pkg|
|
54
|
+
system "gem push #{pkg}"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
namespace :gems do
|
60
|
+
desc "Install gem dependencies (DEV=0 DOCS=0 GEMSPEC=default SUDO=0)"
|
61
|
+
task :install do
|
62
|
+
dev = ENV['DEV'] == '1'
|
63
|
+
docs = ENV['DOCS'] == '1' ? '' : '--no-ri --no-rdoc'
|
64
|
+
gemset = ENV['GEMSET']
|
65
|
+
sudo = ENV['SUDO'] == '1' ? 'sudo' : ''
|
66
|
+
|
67
|
+
Stasis::Gems.gemset = gemset if gemset
|
68
|
+
|
69
|
+
if dev
|
70
|
+
gems = Stasis::Gems.gemspec.development_dependencies
|
71
|
+
else
|
72
|
+
gems = Stasis::Gems.gemspec.dependencies
|
73
|
+
end
|
74
|
+
|
75
|
+
gems.each do |name|
|
76
|
+
name = name.to_s
|
77
|
+
version = Stasis::Gems.versions[name]
|
78
|
+
if Gem.source_index.find_name(name, version).empty?
|
79
|
+
version = version ? "-v #{version}" : ''
|
80
|
+
system "#{sudo} gem install #{name} #{version} #{docs}"
|
81
|
+
else
|
82
|
+
puts "already installed: #{name} #{version}"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
desc "Validate the gemspec"
|
89
|
+
task :gemspec do
|
90
|
+
gemspec.validate
|
91
|
+
end
|
92
|
+
|
93
|
+
desc "Build web site"
|
94
|
+
task :site do
|
95
|
+
cmd = [
|
96
|
+
'cd site',
|
97
|
+
'../bin/stasis',
|
98
|
+
'rm -rf ../../public',
|
99
|
+
'mv public ../../',
|
100
|
+
'cd ../',
|
101
|
+
'git checkout gh-pages',
|
102
|
+
'rm -rf *.png *.html *.css *.js site',
|
103
|
+
'mv ../public/* .'
|
104
|
+
].join '&&'
|
105
|
+
`#{cmd}`
|
106
|
+
end
|
107
|
+
|
108
|
+
desc "Build Rocco Docs"
|
109
|
+
Rocco::make 'docs/'
|
data/bin/stasis
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + "/../lib/stasis")
|
4
|
+
|
5
|
+
Stasis::Gems.activate %w(slop)
|
6
|
+
require 'slop'
|
7
|
+
|
8
|
+
slop = Slop.parse :help => true do
|
9
|
+
on :d, :development, "Development mode\t\t(auto-regenerate)"
|
10
|
+
on :o, :only, "Only generate specific files\t(comma-separated)", :optional => true, :as => Array
|
11
|
+
on :p, :public, "Public directory path", :optional => true
|
12
|
+
on :s, :server, "Server mode\t\t\t(default redis host: localhost:6379/0)", :optional => true, :default => "localhost:6379/0"
|
13
|
+
end
|
14
|
+
|
15
|
+
options = slop.to_hash
|
16
|
+
options.delete(:server) unless slop.server?
|
17
|
+
|
18
|
+
if slop.development?
|
19
|
+
Stasis::DevMode.new(Dir.pwd, options)
|
20
|
+
elsif slop.only? && slop.public?
|
21
|
+
Stasis.new(Dir.pwd, slop[:public], options).render(*slop[:only])
|
22
|
+
elsif slop.only?
|
23
|
+
Stasis.new(Dir.pwd, options).render(*slop[:only])
|
24
|
+
elsif slop.server?
|
25
|
+
Stasis::Server.new(Dir.pwd, options)
|
26
|
+
elsif slop.public?
|
27
|
+
Stasis.new(Dir.pwd, slop[:public], options).render(*slop[:only])
|
28
|
+
else
|
29
|
+
Stasis.new(Dir.pwd, options).render
|
30
|
+
end
|