piano 0.7.6 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc CHANGED
@@ -24,7 +24,9 @@ Other files (images, plain text files, etc) will be loaded from the <tt>server/f
24
24
 
25
25
  == Extending functionality
26
26
 
27
- Piano will try to load a file named <tt>server/folder/.piano</tt>. There you can add functionality, like custom helpers.
27
+ Piano will try to load a file named <tt>server/folder/.piano</tt>. There you can add functionality, like custom helpers and routes.
28
+
29
+ Any route added to the <tt>.piano</tt> file will be parsed before the default routes from Piano, overriding them.
28
30
 
29
31
  ==== Sample <tt>.piano</tt> file
30
32
 
@@ -107,13 +109,21 @@ Note: you can also add a <tt>server/folder/data/404.yaml</tt> file to keep layer
107
109
 
108
110
  == Library Usage
109
111
 
110
- If you want, you can include Piano as a library in your own server. Kind of defeats the point of using Piano, but useful if you want to extend its functionality.
112
+ Piano is fully usable as a library. Its main utility is provide the helpers, <tt>sass("template")</tt>, <tt>coffee("template")</tt>, <tt>try_haml("template")</tt>.
111
113
 
112
114
  require "piano"
115
+
116
+ class Piano
117
+ get "/" do
118
+ "Let's change the default behaviour"
119
+ end
120
+ end
113
121
 
114
122
  Piano.play! # .play! added 4 the lulz; Piano.run! will do the trick aswell
123
+
124
+ <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.
115
125
 
116
- <tt>Piano</tt> inherits <tt>Sinatra::Base</tt>, so all of <tt>Sinatra::Base</tt> own methods are available. Read the Sinatra documentation for further information. Tip: put
126
+ Tip: put
117
127
 
118
128
  Piano.environment = :production
119
129
 
@@ -121,36 +131,19 @@ just before letting it play for play in production environment!
121
131
 
122
132
  By setting <tt>Piano.etags = :off</tt>, etags will be disabled.
123
133
 
124
- === And extending it...
125
- Of course, you can also do this:
134
+ === Routes
135
+
136
+ 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.
126
137
 
127
138
  require "piano"
128
139
 
129
- class ExtendingPiano < Piano
130
- get "/" do
131
- "This will not work since this route has already been matched."
140
+ class Piano
141
+ get "/special" do
142
+ "A special route, overriding the default 'special.haml'"
132
143
  end
133
- # ...but you can add "before do" and "after do" filters
134
-
135
- run! # or play!
136
144
  end
137
-
138
- Remember that the server folder will be the working directory when the script is executed, and not the script path as usual in Sinatra.
139
-
140
- You can even do this:
141
-
142
- class MySinatraServer < Sinatra::Base
143
145
 
144
- use Piano
145
-
146
- get "/" do
147
- "My guess is this still won't work, yet I haven't properly tested it"
148
- end
149
-
150
- # ...many other things
151
- end
152
-
153
- ...currently I can't predict its behavior since I haven't tested it.
146
+ require "piano/routes"
154
147
 
155
148
  == Candies for the kidz
156
149
 
@@ -189,17 +182,14 @@ Etags cause client side caching. This should not be a problem since the hash cha
189
182
  * haml (http://haml-lang.com)
190
183
  * sass (http://sass-lang.com)
191
184
  * coffee-script (http://github.com/josh/ruby-coffee-script)
192
- * therubyracer (http://rubygems.org/gems/therubyracer)
193
185
 
194
186
  == Desired (future) features
195
187
 
196
188
  * Folder paths configurable.
197
- * Condition for disabling default Piano routes
198
189
  * Further documentation of Piano helpers
199
190
  * More helpers for semantic data handling.
200
191
  * Deploy of sample with command line <tt>--sample</tt> argument.
201
192
  * Online source files edition.
202
- * Test <tt>use Piano</tt> within a <tt>Sinatra::Base</tt> class.
203
193
 
204
194
  * Now it would be nice to give Piano personalized templates not only to 404 but for all error pages, specially 500
205
195
  * Custom error when there's no data
@@ -208,7 +198,9 @@ Etags cause client side caching. This should not be a problem since the hash cha
208
198
 
209
199
  * Setup to production enviroment option (why not?!)
210
200
  * Etag on/off (currently etags are hardcoded on)
211
- * CoffeeScript appears to ve working everywhere once <tt>therubyracer</tt> was added as a dependency, so the nocoffee option was deleted.
201
+ * 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.
202
+ * Default Piano routes are now overridable.
203
+ * No longer relevant since Piano is now fully extendable -> Test <tt>use Piano</tt> within a <tt>Sinatra::Base</tt> class.
212
204
 
213
205
  == Tips
214
206
 
data/bin/piano CHANGED
@@ -55,4 +55,6 @@ if File.exists?(File.expand_path(Dir.pwd) + "/.piano")
55
55
  load File.expand_path(Dir.pwd) + "/.piano"
56
56
  end
57
57
 
58
- Piano.run!
58
+ require "piano/routes"
59
+
60
+ Piano.play!
data/lib/piano.rb CHANGED
@@ -34,28 +34,7 @@ class Piano < Sinatra::Base
34
34
  set :views, File.expand_path(Dir.pwd)
35
35
  set :etags, :on
36
36
  set :etags?, Proc.new { settings.etags == :on }
37
-
38
- get "/" do
39
- @data = data_for "index"
40
- try_haml "index"
41
- end
42
-
43
- get %r{/(.+?).css} do |something|
44
- content_type :css
45
- sass something
46
- end
47
-
48
- get %r{/(.+?).js} do |something|
49
- content_type :js
50
- coffee something
51
- end
52
-
53
- get all_but(%r{/finetuner(:.+)$}) do
54
- something = request.path[1..(request.path.length-1)]
55
- @data = data_for something
56
- try_haml something
57
- end
58
-
37
+
59
38
  helpers do
60
39
  def try_haml(template)
61
40
  file_name = "#{pwd}/#{template}.haml"
@@ -103,6 +82,7 @@ class Piano < Sinatra::Base
103
82
  end
104
83
 
105
84
  def bad_luck(path)
85
+ content_type :html
106
86
  if settings.environment == :production
107
87
  if File.exists? "#{pwd}/404.haml"
108
88
  @data = data_for "404"
@@ -0,0 +1,22 @@
1
+ class Piano
2
+ get "/" do
3
+ @data = data_for "index"
4
+ try_haml "index"
5
+ end
6
+
7
+ get %r{/(.+?).css} do |something|
8
+ content_type :css
9
+ sass something
10
+ end
11
+
12
+ get %r{/(.+?).js} do |something|
13
+ content_type :js
14
+ coffee something
15
+ end
16
+
17
+ get all_but(%r{/finetuner(:.+)$}) do
18
+ something = request.path[1..(request.path.length-1)]
19
+ @data = data_for something
20
+ try_haml something
21
+ end
22
+ end
data/lib/piano/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Piano
2
- VERSION = "0.7.6"
2
+ VERSION = "0.8.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: piano
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.6
4
+ version: 0.8.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-05-25 00:00:00.000000000 -03:00
12
+ date: 2011-05-26 00:00:00.000000000 -03:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: sinatra
17
- requirement: &20217504 !ruby/object:Gem::Requirement
17
+ requirement: &18131160 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 1.2.6
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *20217504
25
+ version_requirements: *18131160
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: haml
28
- requirement: &20217204 !ruby/object:Gem::Requirement
28
+ requirement: &18130860 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: 3.1.1
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *20217204
36
+ version_requirements: *18130860
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: sass
39
- requirement: &20216928 !ruby/object:Gem::Requirement
39
+ requirement: &18130584 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: 3.1.1
45
45
  type: :runtime
46
46
  prerelease: false
47
- version_requirements: *20216928
47
+ version_requirements: *18130584
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: coffee-script
50
- requirement: &20216652 !ruby/object:Gem::Requirement
50
+ requirement: &18130308 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ! '>='
@@ -55,7 +55,7 @@ dependencies:
55
55
  version: 2.2.0
56
56
  type: :runtime
57
57
  prerelease: false
58
- version_requirements: *20216652
58
+ version_requirements: *18130308
59
59
  description: Out-of-the-box sinatra server for web site sketching using haml + sass
60
60
  + coffee-script
61
61
  email:
@@ -71,6 +71,7 @@ files:
71
71
  - Rakefile
72
72
  - bin/piano
73
73
  - lib/piano.rb
74
+ - lib/piano/routes.rb
74
75
  - lib/piano/version.rb
75
76
  - piano.gemspec
76
77
  - sample/app.coffee