piano 0.10.4 → 0.10.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,234 +1,248 @@
1
- = Piano
2
-
3
- Out-of-the-box Sinatra server for fast website sketching using Haml and Sass and CoffeeScript (and YAML!).
4
-
5
- The magic triplet, one command away!
6
-
7
- == Installation
8
-
9
- gem install piano
10
-
11
- == Standalone Usage
12
-
13
- server/folder$ piano [<port-number> <environment> [options]]
14
-
15
- Piano will start a Sinatra server based in the same folder where you run the command, in the port and environment given. If no port is given, Piano will start in the default Sinatra port <tt>4567</tt> and the default environment <tt>:development</tt>.
16
-
17
- Haml (http://haml-lang.com) <tt>.haml</tt> files and Sass (http://sass-lang.com) <tt>.sass</tt> and CoffeeScript (http://github.com/josh/ruby-coffee-script) <tt>.coffee</tt> files in the base folder will automatically be mapped to urls.
18
-
19
- yoursite.com/users => server/folder/users.haml
20
- yoursite.com/style.css => server/folder/style.sass
21
- yoursite.com/app.js => server/folder/app.coffee
22
-
23
- Other files (images, plain text files, etc) will be loaded from the <tt>server/folder/public</tt> as is default behavior in Sinatra.
24
-
25
- == Extending functionality
26
-
27
- Piano will try to load a file named <tt>server/folder/Pianofile</tt>. There you can add functionality, like custom helpers and routes.
28
-
29
- Any route added to the <tt>Pianofile</tt> will be parsed before the default routes from Piano, overriding them.
30
-
31
- ==== Sample <tt>Pianofile</tt>
32
-
33
- This file, for example, will bring back the email masking functionality that was deprecated in version 0.7.6
34
-
35
- Note: as version 0.8.4, direct DSL usage, Sinatra-style, is available. This documentation will be updated as soon as is stable.
36
-
37
- helpers do
38
- def unicode_entities(string)
39
- encodings = ""
40
- string.codepoints do |c|
41
- encodings += "&##{c};"
42
- end
43
- encodings
44
- end
45
- end
46
-
47
- == YAML Data
48
-
49
- When receiving a request for <tt>"/users"</tt>, Piano will look up for a YAML file <tt>server/folder/data/users.haml</tt>. If it is there, the YAML file will be loaded and available for the correspondent Haml template in the <tt>@data</tt> variable.
50
-
51
- == 5 minutes site!
52
-
53
- ...all working with stylesheet, scripts and YAML data sources.
54
-
55
- ==== folder/index.haml
56
-
57
- !!! 5
58
- %head
59
- %title= @data['title']
60
- = style "style.css"
61
- = script "app.js"
62
- %body
63
- %h1= @data['title']
64
- %p= @data['description']
65
- %ul
66
- - @data['list'].each do |item|
67
- %li= item
68
-
69
- ==== folder/style.sass
70
-
71
- body
72
- width: 960px
73
- margin: 0 auto
74
- font:
75
- family: sans-serif
76
- size: 15px
77
-
78
- ==== folder/app.coffee
79
-
80
- alert "This is too simple to be true"
81
-
82
- ==== folder/data/index.yaml
83
-
84
- title: 5 minutes site!
85
- description: Is amazing how simple it gets
86
- list:
87
- - and I can have
88
- - a list
89
- - also.
90
-
91
- Note: You can find this sample in the repository within the <tt>/sample</tt> folder.
92
-
93
- == Going :production!
94
-
95
- Piano goes production in command line just adding <tt>production</tt> to its arguments. When it goes, it goes this way:
96
-
97
- * Now any unmatched route will give a zero-information-disclosure nice old 404 error page
98
- * And the default behaviour for 500 errors in Sinatra.
99
-
100
- For nicety sake, you can personalize 404 pages simply by creating a <tt>server/folder/404.haml</tt> template. Beware when you do: out there be dragons.
101
-
102
- Note: you can also add a <tt>server/folder/data/404.yaml</tt> file to keep layer separation even in your error pages.
103
-
104
- == Command line options summary
105
-
106
- * Port number: Any number passed as an argument to the <tt>piano</tt> command will be used as the port number.
107
- * Environment: Any string that does not matches any other argument will be setted as the environment.
108
- * <tt>noetags</tt>: Adding <tt>noetags</tt> to the shell command will cause Piano to run without etags.
109
- * <tt>views:<views_path></tt> Sets the views folder, within server/folder
110
- * <tt>public:<public_path></tt> Sets the public folder, within server/folder
111
- == Library Usage as Sinatra Extension
112
-
113
- Piano is fully usable as a Sinatra Extension. Provide the helpers, <tt>sass("template")</tt>, <tt>coffee("template")</tt>, <tt>try_haml("template")</tt>.
114
-
115
- Note: Prior to version 0.8.2, Piano was intended to be used as a subclass of Sinatra::Base, but now it works both as a Sinatra Extension and as a subclass.
116
- Further moves to keep most functionality as a Sinatra Extension will be done in the future, except in the <tt>piano/routes</tt>.
117
-
118
- require "piano"
119
-
120
- class MyPiano < Sinatra::Base
121
- helpers Sinatra::Piano
122
-
123
- get "/" do
124
- "Let's change the default behaviour"
125
- end
126
- end
127
-
128
- MyPiano.run!
129
-
130
- === Routes
131
-
132
- To load the routes (the ones that match your requests with your haml, sass and coffee templates) you have to require also <tt>"piano/routes"</tt>. Usually you'll want to load them after you define your own ones, otherwise you won't be able to override them.
133
-
134
- require "piano"
135
-
136
- class Piano
137
- get "/special" do
138
- "A special route, overriding the default 'special.haml'"
139
- end
140
- end
141
-
142
- require "piano/routes"
143
-
144
- Piano.play! # .play! added 4 the lulz; Piano.run! will do the trick aswell
145
-
146
- <tt>Piano</tt> inherits <tt>Sinatra::Base</tt>, so all of <tt>Sinatra::Base</tt> own methods are available. Read the Sinatra documentation (http://www.sinatrarb.com/intro) for further information.
147
-
148
- Tip: put
149
-
150
- Piano.environment = :production
151
-
152
- just before letting it play for play in production environment!
153
-
154
- By setting <tt>Piano.etags = :off</tt>, etags will be disabled.
155
-
156
- == Candies for the kidz
157
-
158
- === Convenience helpers
159
-
160
- ==== <tt>style</tt> and <tt>script</tt>
161
-
162
- Piano features two convenience helpers to include stylesheets and javascripts: <tt>style("style.css")</tt> and <tt>script("app.js")</tt>.
163
-
164
- You can use them in your haml templates like this:
165
-
166
- !!! 5
167
- %html
168
- %head
169
- %title Out-of-the-box is pretty awesome!
170
- = style "style.css"
171
- = script "app.js"
172
-
173
- ==== <tt>extract</tt>
174
-
175
- Another helper you may find useful is <tt>extract("source_text/html", word_count = 80)</tt>. Returns an extract of the first <tt>word_count</tt> words (default is 80), html tags stripped, and closed by <tt>"..."</tt> . It does nothing is the text is less than <tt>word_count</tt> words in length.
176
-
177
- %p= extract content, 25
178
-
179
- Code is poetry.
180
-
181
- === Etags
182
-
183
- Since parsing YAML, Sass, Haml and CoffeeScript can be quite a burden for the processor, each response is marked with an Etag hash featuring the required file name and the timestamp of the last modification.
184
-
185
- Etags cause client side caching. This should not be a problem since the hash changes every time a source file is modified (including the YAML data files), forcing the User-Agent to update its cache, but still is worth noting as I might not be fully aware of cache-related issues that Etag-ging may trigger.
186
-
187
- == Gem dependencies
188
-
189
- * sinatra (http://sinatrarb.com)
190
- * haml (http://haml-lang.com)
191
- * sass (http://sass-lang.com)
192
- * coffee-script (http://github.com/josh/ruby-coffee-script)
193
-
194
- == Desired (future) features
195
-
196
- * Folder paths configurable.
197
- * <tt>style</tt> and <tt>script</tt> helpers working with symbols.
198
- * Further documentation of Piano helpers
199
- * More helpers for semantic data handling.
200
- * Deploy of sample with command line <tt>--sample</tt> argument.
201
- * Online source files edition.
202
-
203
- * Now it would be nice to give Piano personalized templates not only to 404 but for all error pages, specially 500
204
- * Custom error when there's no data
205
-
206
- ==== Done
207
-
208
- * Setup to production enviroment option (why not?!)
209
- * Etag on/off (currently etags are hardcoded on)
210
- * CoffeeScript appears to be working everywhere once <tt>therubyracer</tt> was setup to be suggested for install in no default javascript environment, so the nocoffee option was deleted.
211
- * Default Piano routes are now overridable.
212
- * No longer relevant since Piano is now fully extendable -> Test <tt>use Piano</tt> within a <tt>Sinatra::Base</tt> class.
213
-
214
- == Tips
215
-
216
- As for v0.7.3, Piano has now the ability to go <tt>:production</tt> mode both in command line and library modes.
217
-
218
- == Deprecated functions
219
-
220
- From version 0.7.6 on, <tt>unicode_entities</tt> has been deprecated for better Ruby version backwards compatibility.
221
-
222
- = License
223
-
224
- (The MIT License)
225
-
226
- Copyright © 2011:
227
-
228
- * Xavier Via (http://germino.com.ar)
229
-
230
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
231
-
232
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
233
-
234
- THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 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.
1
+ = Piano
2
+
3
+ Out-of-the-box Sinatra server for fast website sketching using Haml and Sass and CoffeeScript (and YAML!).
4
+
5
+ The magic triplet, one command away!
6
+
7
+ == Installation
8
+
9
+ gem install piano
10
+
11
+ == Standalone Usage
12
+
13
+ server/folder$ piano [<port-number> <environment> [options]]
14
+
15
+ Piano will start a Sinatra server based in the same folder where you run the command, in the port and environment given. If no port or environment is given, Piano will start in the default Sinatra port <tt>4567</tt> and the default environment <tt>:development</tt>.
16
+
17
+ Haml (http://haml-lang.com) <tt>.haml</tt> files and Sass (http://sass-lang.com) <tt>.sass</tt> and CoffeeScript (http://github.com/josh/ruby-coffee-script) <tt>.coffee</tt> files in the base folder will automatically be mapped to urls.
18
+
19
+ yoursite.com/users => server/folder/users.haml
20
+ yoursite.com/style.css => server/folder/style.sass
21
+ yoursite.com/app.js => server/folder/app.coffee
22
+
23
+ Other files (images, plain text files, etc) will be loaded from the <tt>server/folder/public</tt> as is default behavior in Sinatra.
24
+
25
+ == Extending functionality
26
+
27
+ Piano will try to load a file named <tt>server/folder/Pianofile</tt>. There you can add functionality, like custom helpers and routes.
28
+
29
+ Any route added to the <tt>Pianofile</tt> will be parsed before the default routes from Piano, overriding them.
30
+
31
+ ==== Sample <tt>Pianofile</tt>
32
+
33
+ This file, for example, will bring back the email masking functionality that was deprecated in version 0.7.6
34
+
35
+ get "/" do
36
+ "Hi! Just testing"
37
+ end
38
+
39
+ get "/email" do
40
+ "Here is my email: #{unicode_entities('xavier@example.com')}"
41
+ end
42
+
43
+ post "/" do # The "/" route, is considered "index" for the haml and yaml files
44
+ require "psych"
45
+
46
+ File.open "data/index.yaml", "w" do |file|
47
+ file.write params.to_yaml
48
+ end
49
+ end
50
+
51
+ helpers do
52
+ def unicode_entities(string)
53
+ encodings = ""
54
+ string.codepoints do |c|
55
+ encodings += "&##{c};"
56
+ end
57
+ encodings
58
+ end
59
+ end
60
+
61
+ == YAML Data
62
+
63
+ When receiving a request for <tt>"/users"</tt>, Piano will look up for a YAML file <tt>server/folder/data/users.haml</tt>. If it is there, the YAML file will be loaded and available for the correspondent Haml template in the <tt>@data</tt> variable.
64
+
65
+ == 5 minutes site!
66
+
67
+ ...all working with stylesheet, scripts and YAML data sources.
68
+
69
+ ==== folder/index.haml
70
+
71
+ !!! 5
72
+ %head
73
+ %title= @data['title']
74
+ = style "style.css"
75
+ = script "app.js"
76
+ %body
77
+ %h1= @data['title']
78
+ %p= @data['description']
79
+ %ul
80
+ - @data['list'].each do |item|
81
+ %li= item
82
+
83
+ ==== folder/style.sass
84
+
85
+ body
86
+ width: 960px
87
+ margin: 0 auto
88
+ font:
89
+ family: sans-serif
90
+ size: 15px
91
+
92
+ ==== folder/app.coffee
93
+
94
+ alert "This is too simple to be true"
95
+
96
+ ==== folder/data/index.yaml
97
+
98
+ title: 5 minutes site!
99
+ description: Is amazing how simple it gets
100
+ list:
101
+ - and I can have
102
+ - a list
103
+ - also.
104
+
105
+ Note: You can find this sample in the repository within the <tt>/sample</tt> folder.
106
+
107
+ == Going :production!
108
+
109
+ Piano goes production in command line just adding <tt>production</tt> to its arguments. When it goes, it goes this way:
110
+
111
+ * Now any unmatched route will give a zero-information-disclosure nice old 404 error page
112
+ * And the default behaviour for 500 errors in Sinatra.
113
+
114
+ For nicety sake, you can personalize 404 pages simply by creating a <tt>server/folder/404.haml</tt> template. Beware when you do: out there be dragons.
115
+
116
+ Note: you can also add a <tt>server/folder/data/404.yaml</tt> file to keep layer separation even in your error pages.
117
+
118
+ == Command line options summary
119
+
120
+ * Port number: Any number passed as an argument to the <tt>piano</tt> command will be used as the port number.
121
+ * Environment: Any string that does not matches any other argument will be setted as the environment.
122
+ * <tt>noetags</tt>: Adding <tt>noetags</tt> to the shell command will cause Piano to run without etags.
123
+ * <tt>views:<views_path></tt> Sets the views folder, within server/folder
124
+ * <tt>public:<public_path></tt> Sets the public folder, within server/folder
125
+ == Library Usage as Sinatra Extension
126
+
127
+ Piano is fully usable as a Sinatra Extension. Provide the helpers, <tt>sass("template")</tt>, <tt>coffee("template")</tt>, <tt>try_haml("template")</tt>.
128
+
129
+ Note: Prior to version 0.8.2, Piano was intended to be used as a subclass of Sinatra::Base, but now it works both as a Sinatra Extension and as a subclass.
130
+ Further moves to keep most functionality as a Sinatra Extension will be done in the future, except in the <tt>piano/routes</tt>.
131
+
132
+ require "piano"
133
+
134
+ class MyPiano < Sinatra::Base
135
+ helpers Sinatra::Piano
136
+
137
+ get "/" do
138
+ "Let's change the default behaviour"
139
+ end
140
+ end
141
+
142
+ MyPiano.run!
143
+
144
+ === Routes
145
+
146
+ To load the routes (the ones that match your requests with your haml, sass and coffee templates) you have to require also <tt>"piano/routes"</tt>. Usually you'll want to load them after you define your own ones, otherwise you won't be able to override them.
147
+
148
+ require "piano"
149
+
150
+ class Piano
151
+ get "/special" do
152
+ "A special route, overriding the default 'special.haml'"
153
+ end
154
+ end
155
+
156
+ require "piano/routes"
157
+
158
+ Piano.play! # .play! added 4 the lulz; Piano.run! will do the trick aswell
159
+
160
+ <tt>Piano</tt> inherits <tt>Sinatra::Base</tt>, so all of <tt>Sinatra::Base</tt> own methods are available. Read the Sinatra documentation (http://www.sinatrarb.com/intro) for further information.
161
+
162
+ Tip: put
163
+
164
+ Piano.environment = :production
165
+
166
+ just before letting it play for play in production environment!
167
+
168
+ By setting <tt>Piano.etags = :off</tt>, etags will be disabled.
169
+
170
+ == Candies for the kidz
171
+
172
+ === Convenience helpers
173
+
174
+ ==== <tt>style</tt> and <tt>script</tt>
175
+
176
+ Piano features two convenience helpers to include stylesheets and javascripts: <tt>style("style.css")</tt> and <tt>script("app.js")</tt>.
177
+
178
+ You can use them in your haml templates like this:
179
+
180
+ !!! 5
181
+ %html
182
+ %head
183
+ %title Out-of-the-box is pretty awesome!
184
+ = style "style.css"
185
+ = script "app.js"
186
+
187
+ ==== <tt>extract</tt>
188
+
189
+ Another helper you may find useful is <tt>extract("source_text/html", word_count = 80)</tt>. Returns an extract of the first <tt>word_count</tt> words (default is 80), html tags stripped, and closed by <tt>"..."</tt> . It does nothing is the text is less than <tt>word_count</tt> words in length.
190
+
191
+ %p= extract content, 25
192
+
193
+ Code is poetry.
194
+
195
+ === Etags
196
+
197
+ Since parsing YAML, Sass, Haml and CoffeeScript can be quite a burden for the processor, each response is marked with an Etag hash featuring the required file name and the timestamp of the last modification.
198
+
199
+ Etags cause client side caching. This should not be a problem since the hash changes every time a source file is modified (including the YAML data files), forcing the User-Agent to update its cache, but still is worth noting as I might not be fully aware of cache-related issues that Etag-ging may trigger.
200
+
201
+ == Gem dependencies
202
+
203
+ * sinatra (http://sinatrarb.com)
204
+ * haml (http://haml-lang.com)
205
+ * sass (http://sass-lang.com)
206
+ * coffee-script (http://github.com/josh/ruby-coffee-script)
207
+
208
+ == Desired (future) features
209
+
210
+ * Folder paths configurable.
211
+ * <tt>style</tt> and <tt>script</tt> helpers working with symbols.
212
+ * Further documentation of Piano helpers
213
+ * More helpers for semantic data handling.
214
+ * Deploy of sample with command line <tt>--sample</tt> argument.
215
+ * Online source files edition.
216
+
217
+ * Now it would be nice to give Piano personalized templates not only to 404 but for all error pages, specially 500
218
+ * Custom error when there's no data
219
+
220
+ ==== Done
221
+
222
+ * Setup to production enviroment option (why not?!)
223
+ * Etag on/off (currently etags are hardcoded on)
224
+ * CoffeeScript appears to be working everywhere once <tt>therubyracer</tt> was setup to be suggested for install in no default javascript environment, so the nocoffee option was deleted.
225
+ * Default Piano routes are now overridable.
226
+ * No longer relevant since Piano is now fully extendable -> Test <tt>use Piano</tt> within a <tt>Sinatra::Base</tt> class.
227
+
228
+ == Tips
229
+
230
+ As for v0.7.3, Piano has now the ability to go <tt>:production</tt> mode both in command line and library modes.
231
+
232
+ == Deprecated functions
233
+
234
+ From version 0.7.6 on, <tt>unicode_entities</tt> has been deprecated for better Ruby version backwards compatibility.
235
+
236
+ = License
237
+
238
+ (The MIT License)
239
+
240
+ Copyright © 2011:
241
+
242
+ * Xavier Via (http://germino.com.ar)
243
+
244
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
245
+
246
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
247
+
248
+ THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 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.