haml-server 0.2 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/bin/haml-server +123 -2
  2. metadata +46 -44
data/bin/haml-server CHANGED
@@ -62,11 +62,107 @@
62
62
  # :css
63
63
  # @import url(/stylesheets/screen.css);
64
64
 
65
+ ##### Helpers
66
+
67
+ # You can create a file called `helpers.rb` to define any helpers you might
68
+ # want to make available.
69
+ #
70
+ # # helpers.rb
71
+ # require "pygmentize"
72
+ #
73
+ # def highlight(code, format)
74
+ # Pygmentize.process(code, format)
75
+ # end
76
+ #
77
+ # alias hi highlight
78
+ #
79
+ # And then in your views, you can access the helpers:
80
+ #
81
+ # # index.haml
82
+ #
83
+ # %h3 Example code
84
+ # ~ hi "puts '1 + 2 # => 3'", :ruby
85
+ #
86
+ # The helpers are reloaded before each request, so you can add and remove them
87
+ # without restarting the server.
88
+
89
+ #### Running on Heroku (cedar stack)
90
+
91
+ # With Heroku's cedar stack, it's now super easy to deploy your `haml-server`
92
+ # site for anyone to see. Here's a step-by-step walkthrough for deploying to
93
+ # Heroku, with some recommendations for how to structe the site.
94
+
95
+ ##### Structure
96
+
97
+ # Since we'll be adding some additional files to get things wired up, I
98
+ # recommend you move your views and static files into a separate folder like
99
+ # `site` (the walkthrough will assume that you've done so). So your site might
100
+ # look like this:
101
+ #
102
+ # > tree
103
+ # .
104
+ # ├── helpers.rb
105
+ # └── site
106
+ # ├── index.haml
107
+ # ├── layout.haml
108
+ # └── screen.css
109
+ #
110
+ # When working locally, then, you'll want to run the site with: `haml-server
111
+ # site`.
112
+ #
113
+ # Now to get things set up for Heroku, we'll need to add a few files:
114
+ #
115
+ # # Gemfile
116
+ # source :rubygems
117
+ # gem "haml-server"
118
+ #
119
+ # # Procfile
120
+ # web: bundle exec haml-server -p $PORT site
121
+ #
122
+ # Now the project should look like this:
123
+ #
124
+ # > tree
125
+ # .
126
+ # ├── Gemfile
127
+ # ├── Procfile
128
+ # ├── helpers.rb
129
+ # └── site
130
+ # ├── index.haml
131
+ # ├── layout.haml
132
+ # └── screen.css
133
+
134
+ ##### Deploy
135
+
136
+ # First we'll need to get our environment in order by running:
137
+ # > gem install bundler
138
+ # > bundle
139
+ #
140
+ # This will install any dependencies, and store those in a file called
141
+ # `Gemfile.lock`.
142
+ #
143
+ # Now we should set up the site as a `git` repository, and commit our files.
144
+ #
145
+ # > git init
146
+ # > git add .
147
+ # > git commit -m "Initial commit"
148
+ #
149
+ # We're almost done! Now we'll create a new application and deploy it:
150
+ #
151
+ # > gem install heroku
152
+ # > heroku apps:create --stack cedar
153
+ # > git push heroku master
154
+ # > heroku open
155
+ #
156
+ # `heroku open` will open up your site in the browser. Done!
157
+
65
158
  #### The code
66
159
 
67
160
  # `HAML`, check!
68
161
  require "haml"
69
162
 
163
+ # `SASS`, check!
164
+ require "sass"
165
+
70
166
  # Okay. In any other context, this would be pretty evil. Let me explain.
71
167
  # Sinatra is a well-behaving citizen, and calls `ARGV.dup` before parsing its
72
168
  # options. Unfortunately for us, that means if we want to easily add
@@ -96,18 +192,43 @@ require "pathname"
96
192
 
97
193
  template_dir = Pathname(Dir.pwd) + (ARGV.shift || ".")
98
194
 
99
- set :public, template_dir
100
- set :views , template_dir
195
+ set :public_folder, template_dir
196
+ set :views, template_dir
101
197
 
102
198
  # If a favicon wasn't already matched by the public handler, just return a 404.
103
199
  get "/favicon.ico" do
104
200
  404
105
201
  end
106
202
 
203
+ # This will be a container module for user-defined helpers. `Helpers.reload!`
204
+ # will clean up any existing methods in the module, and then load helpers
205
+ # defined in a `helpers.rb` file if it exists.
206
+ module Helpers
207
+ class << self
208
+ def reload!
209
+ # First we remove all instance methods in the helper module.
210
+ instance_methods.each do |method|
211
+ remove_method(method)
212
+ end
213
+
214
+ # And now we load any helper methods into the module from the file
215
+ # `helpers.rb` if it exists.
216
+ module_eval(File.read("helpers.rb")) if File.file?("helpers.rb")
217
+ end
218
+ end
219
+ end
220
+
221
+ # Include our module into the Sinatra application.
222
+ helpers Helpers
223
+
107
224
  # This is our basic handler for all requests that come through to Sinatra.
108
225
  # We'll extract the necessary path information, and then render either a haml
109
226
  # or sass file.
110
227
  handler = lambda do
228
+
229
+ # Reload our helpers for each request.
230
+ Helpers.reload!
231
+
111
232
  path = request.path_info
112
233
 
113
234
  extension = File.extname(path)
metadata CHANGED
@@ -1,78 +1,80 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: haml-server
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.3'
4
5
  prerelease:
5
- version: "0.2"
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Bernerd Schaefer
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-04-24 00:00:00 +02:00
14
- default_executable:
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
12
+ date: 2012-01-11 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
17
15
  name: sinatra
18
- prerelease: false
19
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &70098912206340 !ruby/object:Gem::Requirement
20
17
  none: false
21
- requirements:
22
- - - ">="
23
- - !ruby/object:Gem::Version
24
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
25
22
  type: :runtime
26
- version_requirements: *id001
27
- - !ruby/object:Gem::Dependency
23
+ prerelease: false
24
+ version_requirements: *70098912206340
25
+ - !ruby/object:Gem::Dependency
28
26
  name: haml
27
+ requirement: &70098912204600 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
29
34
  prerelease: false
30
- requirement: &id002 !ruby/object:Gem::Requirement
35
+ version_requirements: *70098912204600
36
+ - !ruby/object:Gem::Dependency
37
+ name: sass
38
+ requirement: &70098912203780 !ruby/object:Gem::Requirement
31
39
  none: false
32
- requirements:
33
- - - ">="
34
- - !ruby/object:Gem::Version
35
- version: "0"
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
36
44
  type: :runtime
37
- version_requirements: *id002
45
+ prerelease: false
46
+ version_requirements: *70098912203780
38
47
  description: Server for HAML files
39
48
  email: bj.schaefer@gmail.com
40
- executables:
49
+ executables:
41
50
  - haml-server
42
51
  extensions: []
43
-
44
52
  extra_rdoc_files: []
45
-
46
- files:
53
+ files:
47
54
  - README
48
55
  - bin/haml-server
49
- has_rdoc: true
50
56
  homepage: http://github.com/bernerdschaefer/haml-server
51
57
  licenses: []
52
-
53
58
  post_install_message:
54
59
  rdoc_options: []
55
-
56
- require_paths:
60
+ require_paths:
57
61
  - lib
58
- required_ruby_version: !ruby/object:Gem::Requirement
62
+ required_ruby_version: !ruby/object:Gem::Requirement
59
63
  none: false
60
- requirements:
61
- - - ">="
62
- - !ruby/object:Gem::Version
63
- version: "0"
64
- required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
69
  none: false
66
- requirements:
67
- - - ">="
68
- - !ruby/object:Gem::Version
69
- version: "0"
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
70
74
  requirements: []
71
-
72
75
  rubyforge_project:
73
- rubygems_version: 1.5.0
76
+ rubygems_version: 1.8.10
74
77
  signing_key:
75
78
  specification_version: 3
76
79
  summary: Server for HAML files
77
80
  test_files: []
78
-