haml-server 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README +6 -0
  2. data/bin/haml-server +91 -0
  3. metadata +78 -0
data/README ADDED
@@ -0,0 +1,6 @@
1
+ haml-server
2
+ ===========
3
+
4
+ A simple server for serving up a directory of `HTML` and `HAML` files. Check
5
+ out the `rocco` generated docs for more information at
6
+ http://bernerdschaefer.github.com/haml-server
data/bin/haml-server ADDED
@@ -0,0 +1,91 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # **haml-server** is a dead-simple Sinatra app for serving up a directory of
4
+ # files. There are a few other projects much more ambitious than this (such as
5
+ # [serve][1]), but haml-server's goal is simple: serve haml files. Why? Because
6
+ # writing `HTML` is a pain -- especially when you're just putting together a
7
+ # prototype, or, say, testing out some javascript behavior.
8
+ #
9
+ # [1]: https://github.com/jlong/serve
10
+
11
+ #### Usage
12
+
13
+ # Think of `haml-server` as `python -m SimpleHTTPServer`... but for `HAML`!
14
+ #
15
+ # haml-server # serves the current directory at localhost:4567
16
+ # haml-server . # ^ same as above
17
+ # haml-server -p 8000 sub/dir
18
+ #
19
+ # Visiting `http://localhost:4567/` will render `index.haml`. Visiting
20
+ # `/path/to/resource` will render `path/to/resource.haml`. Simple.
21
+ #
22
+ # You can also create a file called "layout.haml" to apply a layout to each of
23
+ # your pages:
24
+ #
25
+ # # layout.haml
26
+ # %html
27
+ # %body
28
+ # = yield
29
+
30
+ #### The code
31
+
32
+ # `HAML`, check!
33
+ require "haml"
34
+
35
+ # Okay. In any other context, this would be pretty evil. Let me explain.
36
+ # Sinatra is a well-behaving citizen, and calls `ARGV.dup` before parsing its
37
+ # options. Unfortunately for us, that means if we want to easily add
38
+ # additional arguments, we either have to 1) re-parse `ARGV` (which would mean
39
+ # copying the options from `sinatra/main.rb`) or 2) just redefine `ARGV.dup`.
40
+ # Should be clear which one I prefer.
41
+ def ARGV.dup
42
+ self
43
+ end
44
+
45
+ # Yep. This is a hack, too. Sinatra only automatically runs itself when the
46
+ # file is directly called -- but that's not the case when running through
47
+ # rubygem's wrapped command. Solution? Just pretend we were executed directly.
48
+ $0 = __FILE__
49
+
50
+ # And now we can load sinatra, knowing that the options will be parsed out of
51
+ # `ARGV` and the server will start automatically.
52
+ require "sinatra"
53
+
54
+ # I love Pathname. This line works just like you'd expect it to:
55
+ #
56
+ # Pathname("/data/foo") + "." # => /data/foo
57
+ # Pathname("/data/foo") + "../" # => /data
58
+ # Pathname("/data/foo") + "/data" # => /data
59
+ #
60
+ require "pathname"
61
+
62
+ template_dir = Pathname(Dir.pwd) + (ARGV.shift || ".")
63
+
64
+ set :public, template_dir
65
+ set :views , template_dir
66
+
67
+ # If a favicon wasn't already matched by the public handler, just return a 404.
68
+ get "/favicon.ico" do
69
+ 404
70
+ end
71
+
72
+ # This is our basic handler for all requests that come through to Sinatra. We
73
+ # match `GET`, `PUT`, `POST`, and `DELETE` requests with "/*", and Sinatra the
74
+ # path in `params[:splat]`. Since we've only got one splat, we grab the first
75
+ # one.
76
+ handler = lambda do
77
+ path = params[:splat].first
78
+
79
+ # If the path is empty, it's a request for the index page. Otherwise, we
80
+ # render the `HAML` template with the same name.
81
+ haml path == "" ? :index : path.to_sym
82
+ end
83
+
84
+ # Now we bind our handler to all of the `HTTP` verbs.
85
+ get "/*", &handler
86
+ put "/*", &handler
87
+ post "/*", &handler
88
+ delete "/*", &handler
89
+
90
+ # And that's it! We let Sinatra handle the rest: it will parse out any provided
91
+ # options (see `haml-server -h`) and then run the server for us.
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: haml-server
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: "0.1"
6
+ platform: ruby
7
+ authors:
8
+ - Bernerd Schaefer
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-04-06 00:00:00 +02:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: sinatra
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: "0"
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: haml
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: "0"
36
+ type: :runtime
37
+ version_requirements: *id002
38
+ description: Server for HAML files
39
+ email: bj.schaefer@gmail.com
40
+ executables:
41
+ - haml-server
42
+ extensions: []
43
+
44
+ extra_rdoc_files: []
45
+
46
+ files:
47
+ - README
48
+ - bin/haml-server
49
+ has_rdoc: true
50
+ homepage: http://github.com/bernerdschaefer/haml-server
51
+ licenses: []
52
+
53
+ post_install_message:
54
+ rdoc_options: []
55
+
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: "0"
70
+ requirements: []
71
+
72
+ rubyforge_project:
73
+ rubygems_version: 1.5.0
74
+ signing_key:
75
+ specification_version: 3
76
+ summary: Server for HAML files
77
+ test_files: []
78
+