rack-server-pages 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/.gitignore +11 -0
  2. data/.travis.yml +6 -0
  3. data/Gemfile +53 -0
  4. data/Gemfile.lock +127 -0
  5. data/Guardfile +16 -0
  6. data/README.md +401 -0
  7. data/Rakefile +11 -0
  8. data/config.ru +13 -0
  9. data/lib/rack-server-pages.rb +1 -0
  10. data/lib/rack/server_pages.rb +348 -0
  11. data/public/README.erb +3 -0
  12. data/public/_layout.html.erb +9 -0
  13. data/public/index.html +16 -0
  14. data/public/info.php +1 -0
  15. data/public/sample.erb +8 -0
  16. data/public/style.css +106 -0
  17. data/rack-server-pages.gemspec +22 -0
  18. data/spec/lib/rack/server_pages_spec.rb +69 -0
  19. data/spec/spec_helper.rb +40 -0
  20. data/views/about.html.slim +11 -0
  21. data/views/article.html.md +16 -0
  22. data/views/betty.css.sass +11 -0
  23. data/views/contact.xml.builder +5 -0
  24. data/views/examples/_layout.html.erb +14 -0
  25. data/views/examples/_time.html.erb +1 -0
  26. data/views/examples/builder.xml.builder +0 -0
  27. data/views/examples/coffee.js.coffee +0 -0
  28. data/views/examples/erb.html.erb +2 -0
  29. data/views/examples/haml.html.haml +6 -0
  30. data/views/examples/html.html +1 -0
  31. data/views/examples/index.html.erb +9 -0
  32. data/views/examples/less.css.less +0 -0
  33. data/views/examples/liquid.html.liquid +0 -0
  34. data/views/examples/markaby.html.mab +0 -0
  35. data/views/examples/markdown.html.markdown +6 -0
  36. data/views/examples/nokogiri.xml.nokogiri +0 -0
  37. data/views/examples/radius.html.radius +0 -0
  38. data/views/examples/rdoc.html.rdoc +0 -0
  39. data/views/examples/sass.css.sass +11 -0
  40. data/views/examples/scss.css.scss +0 -0
  41. data/views/examples/slim.html.slim +2 -0
  42. data/views/examples/source.html.slim +9 -0
  43. data/views/examples/textile.html.textile +0 -0
  44. data/views/examples/wiki.html.wiki +0 -0
  45. data/views/examples/yajl.json.yajl +0 -0
  46. data/views/script.js.coffee +13 -0
  47. metadata +106 -0
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .DS_Store
6
+ *.swp
7
+ tmp/*
8
+ .sass-cache
9
+ coverage/
10
+ .rbenv-version
11
+ .rvmrc
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - jruby
data/Gemfile ADDED
@@ -0,0 +1,53 @@
1
+ source :rubygems
2
+
3
+ gem 'rack'
4
+ #gemspec #didn't work in heroku
5
+
6
+ group :development do
7
+ gem 'rake'
8
+ gem 'thin'
9
+ gem 'guard'
10
+ gem 'guard-bundler'
11
+ gem 'guard-rspec'
12
+ #gem 'rb-readline'
13
+ #gem 'rb-inotify', :require => false
14
+ #gem 'rb-fsevent', :require => false
15
+ #gem 'rb-fchange', :require => false
16
+ end
17
+
18
+ group :test do
19
+ gem 'simplecov'
20
+ gem 'rack-test', :require => 'rack/test'
21
+ gem 'rspec'
22
+ end
23
+
24
+ group :development, :test do
25
+ gem 'tapp'
26
+ # gem 'ruby-debug', :platforms => :ruby_18
27
+ # gem 'ruby-debug19', :require => 'ruby-debug', :platforms => :ruby_19
28
+ end
29
+
30
+ # Tilt
31
+ gem 'tilt'
32
+ gem 'RedCloth'
33
+ gem 'bluecloth'
34
+ gem 'builder'
35
+ gem 'coffee-script'
36
+ gem 'contest'
37
+ gem 'creole'
38
+ gem 'erubis'
39
+ gem 'haml'
40
+ gem 'kramdown'
41
+ gem 'less', :platforms => [:ruby_18, :ruby_19]
42
+ gem 'liquid'
43
+ gem 'markaby'
44
+ gem 'maruku'
45
+ gem 'nokogiri'
46
+ gem 'radius'
47
+ gem 'rdiscount'
48
+ gem 'rdoc'
49
+ #gem 'redcarpet'
50
+ gem 'sass'
51
+ gem 'wikicloth'
52
+ gem 'yajl-ruby'
53
+ gem 'slim'
data/Gemfile.lock ADDED
@@ -0,0 +1,127 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ RedCloth (4.2.9)
5
+ RedCloth (4.2.9-java)
6
+ bluecloth (2.2.0)
7
+ builder (3.0.0)
8
+ coffee-script (2.2.0)
9
+ coffee-script-source
10
+ execjs
11
+ coffee-script-source (1.2.0)
12
+ commonjs (0.2.0)
13
+ therubyracer (~> 0.9.9)
14
+ contest (0.1.3)
15
+ creole (0.4.2)
16
+ daemons (1.1.5)
17
+ diff-lcs (1.1.3)
18
+ erubis (2.7.0)
19
+ eventmachine (0.12.10)
20
+ eventmachine (0.12.10-java)
21
+ execjs (1.2.13)
22
+ multi_json (~> 1.0)
23
+ expression_parser (0.9.0)
24
+ ffi (1.0.11)
25
+ ffi (1.0.11-java)
26
+ guard (0.9.4)
27
+ ffi (>= 0.5.0)
28
+ thor (~> 0.14.6)
29
+ guard-bundler (0.1.3)
30
+ bundler (>= 1.0.0)
31
+ guard (>= 0.2.2)
32
+ guard-rspec (0.5.10)
33
+ guard (>= 0.8.4)
34
+ haml (3.1.4)
35
+ json (1.6.4)
36
+ json (1.6.4-java)
37
+ kramdown (0.13.4)
38
+ less (2.0.8)
39
+ commonjs (~> 0.2.0)
40
+ therubyracer (~> 0.9.9)
41
+ libv8 (3.3.10.4)
42
+ liquid (2.3.0)
43
+ markaby (0.7.2)
44
+ builder (>= 2.0.0)
45
+ maruku (0.6.0)
46
+ syntax (>= 1.0.0)
47
+ multi_json (1.0.4)
48
+ nokogiri (1.5.0)
49
+ nokogiri (1.5.0-java)
50
+ rack (1.4.0)
51
+ rack-test (0.6.1)
52
+ rack (>= 1.0)
53
+ radius (0.7.1)
54
+ rake (0.9.2.2)
55
+ rdiscount (1.6.8)
56
+ rdoc (3.12)
57
+ json (~> 1.4)
58
+ rspec (2.7.0)
59
+ rspec-core (~> 2.7.0)
60
+ rspec-expectations (~> 2.7.0)
61
+ rspec-mocks (~> 2.7.0)
62
+ rspec-core (2.7.1)
63
+ rspec-expectations (2.7.0)
64
+ diff-lcs (~> 1.1.2)
65
+ rspec-mocks (2.7.0)
66
+ sass (3.1.12)
67
+ simplecov (0.5.4)
68
+ multi_json (~> 1.0.3)
69
+ simplecov-html (~> 0.5.3)
70
+ simplecov-html (0.5.3)
71
+ slim (1.0.4)
72
+ temple (~> 0.3.4)
73
+ tilt (~> 1.3.2)
74
+ syntax (1.0.0)
75
+ tapp (1.3.0)
76
+ thor
77
+ temple (0.3.4)
78
+ therubyracer (0.9.9)
79
+ libv8 (~> 3.3.10)
80
+ thin (1.3.1)
81
+ daemons (>= 1.0.9)
82
+ eventmachine (>= 0.12.6)
83
+ rack (>= 1.0.0)
84
+ thor (0.14.6)
85
+ tilt (1.3.3)
86
+ wikicloth (0.7.1)
87
+ builder
88
+ expression_parser
89
+ yajl-ruby (1.1.0)
90
+
91
+ PLATFORMS
92
+ java
93
+ ruby
94
+
95
+ DEPENDENCIES
96
+ RedCloth
97
+ bluecloth
98
+ builder
99
+ coffee-script
100
+ contest
101
+ creole
102
+ erubis
103
+ guard
104
+ guard-bundler
105
+ guard-rspec
106
+ haml
107
+ kramdown
108
+ less
109
+ liquid
110
+ markaby
111
+ maruku
112
+ nokogiri
113
+ rack
114
+ rack-test
115
+ radius
116
+ rake
117
+ rdiscount
118
+ rdoc
119
+ rspec
120
+ sass
121
+ simplecov
122
+ slim
123
+ tapp
124
+ thin
125
+ tilt
126
+ wikicloth
127
+ yajl-ruby
data/Guardfile ADDED
@@ -0,0 +1,16 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+ group 'backend' do
4
+ guard 'bundler' do
5
+ watch('Gemfile')
6
+ # Uncomment next line if Gemfile contain `gemspec' command
7
+ # watch(/^.+\.gemspec/)
8
+ end
9
+ guard 'rspec', :cli => '--color --format nested', :bundler => true do
10
+ watch(%r{^lib/([\w/]+)\.rb}) { |m| "spec/lib/#{m[1]}_spec.rb" }
11
+
12
+ watch(%r{^spec/(.+)\_spec.rb}) { |m| "spec/#{m[1]}_spec.rb" }
13
+
14
+ watch('spec/spec_helper.rb') { "bundle exec rake spec" }
15
+ end
16
+ end
data/README.md ADDED
@@ -0,0 +1,401 @@
1
+ Rack Server Pages
2
+ =================
3
+
4
+ Rack middleware and application for serving dynamic pages in very simple way.
5
+ There are no controllers or models, just only views like a jsp, asp and php!
6
+
7
+ <http://github.com/migrs/rack-server-pages>
8
+
9
+ [![Build Status](https://secure.travis-ci.org/migrs/rack-server-pages.png)](http://travis-ci.org/migrs/rack-server-pages)
10
+
11
+ ## Features
12
+
13
+ - Serving dynamic pages (default: ERB)
14
+ - Serving static files
15
+ - No requirements (except Rack)
16
+ - Tilt support (optional)
17
+ - Include a partial template
18
+ - Layout template
19
+ - Integrate with any rack applications (Rails, Sinatra, etc...)
20
+ - Extremely simple and easy to use!
21
+
22
+ ## Requirements
23
+
24
+ - [Ruby](http://ruby-lang.org/) 1.8.7 or 1.9.x
25
+ - [Rack](http://github.com/rack/rack)
26
+
27
+ ## Install
28
+
29
+ [RubyGems](http://rubygems.org/gems/rack-server-pages) available
30
+
31
+ gem install rack-server-pages
32
+
33
+ ## Basic usage
34
+
35
+ ### Run as Rack application
36
+
37
+ Create `config.ru`
38
+
39
+ require 'rack-server-pages'
40
+ run Rack::ServerPages
41
+
42
+ Create `public/index.erb`
43
+
44
+ <h1>Hello rack!</h1>
45
+ <p><%= Time.now %></p>
46
+
47
+ Finally running `rackup`
48
+
49
+ rackup
50
+
51
+ and visit <http://localhost:9292/>
52
+
53
+ Valid requests,
54
+
55
+ - <http://localhost:9292/>
56
+ - <http://localhost:9292/index>
57
+ - <http://localhost:9292/index.erb>
58
+ - <http://localhost:9292/index.html>
59
+
60
+ ### Use as Rack middleware
61
+
62
+ Edit `config.ru`
63
+
64
+ require 'rack-server-pages'
65
+ use Rack::ServerPages
66
+ run Rack::ServerPages::NotFound # or your MyApp
67
+
68
+ And same as above.
69
+
70
+ ## Template bindings
71
+
72
+ - CoreHelper
73
+ - layout(file)
74
+ - partial(file)
75
+ - redirect(target, status=302) (same as [Sinatra](http://www.sinatrarb.com/intro#Browser%20Redirect))
76
+ - halt(\*args) (same as [Sinatra](http://www.sinatrarb.com/intro#Halting))
77
+ - url(path)
78
+
79
+ - [Rack::Request](http://rack.rubyforge.org/doc/Rack/Request.html)
80
+ - request
81
+ - env
82
+ - params
83
+ - session
84
+ - cookies
85
+ - logger
86
+
87
+ - [Rack::Response](http://rack.rubyforge.org/doc/Rack/Response.html)
88
+ - response
89
+ - headers
90
+ - set\_cookies
91
+ - delete\_cookie
92
+
93
+ - [ERB::Util](http://www.ruby-doc.org/stdlib-1.9.3/libdoc/erb/rdoc/ERB/Util.html)
94
+ - h (alias for: html\_escape)
95
+ - u (alias for: url\_encode)
96
+
97
+ ## Configurations
98
+
99
+ ### Rack middleware
100
+
101
+ with parameter
102
+
103
+ use Rack::ServerPages, :view_path => 'public'
104
+
105
+ with block
106
+
107
+ use Rack::ServerPages do |config|
108
+ config.view_path = 'public'
109
+ end
110
+
111
+ ### Rack application
112
+
113
+ with parameter
114
+
115
+ run Rack::ServerPages[:view_path => 'public']
116
+
117
+ with block
118
+
119
+ run Rack::ServerPages.new { |config|
120
+ config.view_path = 'public'
121
+ }
122
+
123
+ ### Options
124
+
125
+ - view\_path
126
+ - Views folders to load templates from.
127
+ - default: [views, public]
128
+
129
+ - effective\_path
130
+ - default: nil
131
+
132
+ - default\_charset
133
+ - default: utf-8
134
+
135
+ - cache\_control
136
+ - default: nil
137
+
138
+ - failure\_app
139
+ - default: nil
140
+
141
+ ## Tilt support
142
+ [Tilt](http://github.com/rtomayko/tilt) is generic interface to multiple Ruby template engines.
143
+ If you want to use Tilt, just `require 'tilt'` and require template engine libraries that you want.
144
+
145
+ require 'rack-server-pages'
146
+ require 'tilt'
147
+ require 'rdiscount' # markdown library
148
+ run Rack::ServerPages
149
+
150
+ or put your `Gemfile`
151
+
152
+ ### [Markdown](http://daringfireball.net/projects/markdown/)
153
+
154
+ `views/article.html.md`
155
+
156
+ A First Level Header
157
+ ====================
158
+
159
+ A Second Level Header
160
+ ---------------------
161
+
162
+ Now is the time for all good men to come to
163
+ the aid of their country. This is just a
164
+ regular paragraph.
165
+
166
+ ### Header 3
167
+
168
+ > This is a blockquote.
169
+ > Thank you
170
+
171
+ [source](http://github.com/migrs/rack-server-pages)
172
+
173
+ <http://localhost:9292/article.html>
174
+
175
+ <h1>A First Level Header</h1>
176
+
177
+ <h2>A Second Level Header</h2>
178
+
179
+ <p>Now is the time for all good men to come to
180
+ the aid of their country. This is just a
181
+ regular paragraph.</p>
182
+
183
+ <h3>Header 3</h3>
184
+
185
+ <blockquote><p>This is a blockquote.
186
+ Thank you</p></blockquote>
187
+
188
+ <p><a href="http://github.com/migrs/rack-server-pages">source</a></p>
189
+
190
+
191
+ ### [Slim](http://slim-lang.com/)
192
+
193
+ `views/about.html.slim`
194
+
195
+ doctype html
196
+ html
197
+ head
198
+ title Slim Core Example
199
+ meta name="keywords" content="template language"
200
+
201
+ body
202
+ h1 Markup examples
203
+
204
+ div id="content" class="example1"
205
+ p Nest by indentation
206
+
207
+ <http://localhost:9292/about.html>
208
+
209
+ <!DOCTYPE html>
210
+ <html>
211
+ <head>
212
+ <title>Slim Core Example</title>
213
+ <meta content="template language" name="keywords" />
214
+ </head>
215
+ <body>
216
+ <h1>Markup examples</h1>
217
+ <div class="example1" id="content">
218
+ <p>Nest by indentation</p>
219
+ </div>
220
+ </body>
221
+ </html>
222
+
223
+ ### [Sass](http://sass-lang.com/)
224
+
225
+ `views/betty.css.sass`
226
+
227
+ $blue: #3bbfce
228
+ $margin: 16px
229
+
230
+ .content-navigation
231
+ border-color: $blue
232
+ color: darken($blue, 9%)
233
+
234
+ .border
235
+ padding: $margin / 2
236
+ margin: $margin / 2
237
+ border-color: $blue
238
+
239
+ <http://localhost:9292/betty.css>
240
+
241
+ .content-navigation {
242
+ border-color: #3bbfce;
243
+ color: #2ca2af; }
244
+
245
+ .border {
246
+ padding: 8px;
247
+ margin: 8px;
248
+ border-color: #3bbfce; }
249
+
250
+ ### [Builder](http://builder.rubyforge.org/)
251
+
252
+ `views/contact.xml.builder`
253
+
254
+ xml.instruct!
255
+ xml.result do |result|
256
+ result.name "John"
257
+ result.phone "910-1974"
258
+ end
259
+
260
+ <http://localhost:9292/contact.xml>
261
+
262
+ <result>
263
+ <name>John</name>
264
+ <phone>910-1974</phone>
265
+ </result>
266
+
267
+ ### [CoffeeScript](http://jashkenas.github.com/coffee-script/)
268
+
269
+ `views/script.js.coffee`
270
+ number = 42
271
+ opposite = true
272
+
273
+ number = -42 if opposite
274
+
275
+ square = (x) -> x * x
276
+
277
+ list = [1, 2, 3, 4, 5]
278
+
279
+ math =
280
+ root: Math.sqrt
281
+ square: square
282
+ cube: (x) -> x * square x
283
+
284
+ <http://localhost:9292/script.js>
285
+
286
+ (function() {
287
+ var list, math, number, opposite, square;
288
+
289
+ number = 42;
290
+
291
+ opposite = true;
292
+
293
+ if (opposite) number = -42;
294
+
295
+ square = function(x) {
296
+ return x * x;
297
+ };
298
+
299
+ list = [1, 2, 3, 4, 5];
300
+
301
+ math = {
302
+ root: Math.sqrt,
303
+ square: square,
304
+ cube: function(x) {
305
+ return x * square(x);
306
+ }
307
+ };
308
+
309
+ }).call(this);
310
+
311
+ see more <http://localhost:9292/examples/>
312
+
313
+ ## Integrate with Rack applications
314
+
315
+ At first, create sample file: `public/hello.erb` or `views/hello.html.erb`
316
+
317
+ <p>Hello Rack Server Pages!</p>
318
+ <p><%= Time.now %></p>
319
+
320
+ ### Rails
321
+
322
+ Add to `config/environment.rb` (Rails2) or `config/application.rb` (Rails3)
323
+
324
+ config.middleware.use Rack::ServerPages
325
+
326
+ And run
327
+
328
+ Rails2
329
+
330
+ script/server
331
+
332
+ Rails3
333
+
334
+ rails s
335
+
336
+ - <http://localhost:3000/> is Rails response
337
+ - <http://localhost:3000/hello> is Rack Server Pages response
338
+
339
+ ### Sinatra
340
+
341
+ Create `sinatra_sample.rb`
342
+
343
+ require 'sinatra'
344
+ require 'rack-server-pages'
345
+
346
+ get '/' do
347
+ '<p>Hello Sinatra!</p>'
348
+ end
349
+
350
+
351
+ And run
352
+
353
+ ruby sinatra_sample.rb`
354
+
355
+ - <http://localhost:4567/> is Sinatra response
356
+ - <http://localhost:4567/hello> is Rack Server Pages response
357
+
358
+ ## Customization
359
+
360
+ ### Customize file extension associations
361
+
362
+ #### e.g. .php as ERB
363
+
364
+ ERBTemplate (default)
365
+
366
+ Rack::ServerPages::Template::ERBTemplate.extensions << 'php'
367
+
368
+ TiltTemplate (see. [Template Mappings](http://github.com/rtomayko/tilt))
369
+
370
+ Tilt.register Tilt::ERBTemplate, 'php'
371
+
372
+ And create `public/info.php` :)
373
+
374
+ <%= phpinfo(); %>
375
+
376
+ <http://localhost:9292/info.php>
377
+
378
+ ## Demo site
379
+
380
+ <http://rack-server-pages.heroku.com/>
381
+
382
+ ## ToDo
383
+
384
+ ### Implements
385
+ - Before/After filter
386
+ - Support Helpers
387
+ - Static file generator (for designer)
388
+
389
+ ### Tasks
390
+ - Tutorials
391
+ - for PHP user
392
+ - for Designer
393
+ - for Windows user
394
+ - More documents
395
+ - Deployment using apache / passenger / nginx
396
+ - Complete Tilt examples
397
+ - Philosophy
398
+ - Benchmark
399
+
400
+ ## License
401
+ [rack-server-pages](http://github.com/migrs/rack-server-pages) is Copyright (c) 2011 [Masato Igarashi](http://github.com/migrs)(@[migrs](http://twitter.com/migrs)) and distributed under the [MIT license](http://www.opensource.org/licenses/mit-license).