piano 0.7.3 → 0.7.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/README.rdoc +39 -7
  2. data/bin/piano +31 -0
  3. data/lib/piano.rb +33 -7
  4. data/lib/piano/version.rb +1 -1
  5. metadata +10 -10
data/README.rdoc CHANGED
@@ -10,7 +10,7 @@ The magic triplet, one command away!
10
10
 
11
11
  == Standalone Usage
12
12
 
13
- server/folder$ piano [<port-number> <environment>]
13
+ server/folder$ piano [<port-number> <environment> [options]]
14
14
 
15
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
16
 
@@ -79,6 +79,12 @@ For nicety sake, you can personalize 404 pages simply by creating a <tt>server/f
79
79
 
80
80
  Note: you can also add a <tt>server/folder/data/404.yaml</tt> file to keep layer separation even in your error pages.
81
81
 
82
+ == Command line options summary
83
+
84
+ * Port number: Any number passed as an argument to the <tt>piano</tt> command will be used as the port number.
85
+ * Environment: Any string that does not matches any other argument will be setted as the environment.
86
+ * <tt>noetags</tt>: Adding <tt>noetags</tt> to the shell command will cause Piano to run without etags.
87
+
82
88
  == Library Usage
83
89
 
84
90
  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.
@@ -87,8 +93,15 @@ If you want, you can include Piano as a library in your own server. Kind of defe
87
93
 
88
94
  Piano.play! # .play! added 4 the lulz; Piano.run! will do the trick aswell
89
95
 
90
- <tt>Piano</tt> inherits <tt>Sinatra::Base</tt>, so all of <tt>Sinatra::Base</tt> own methods are available.
96
+ <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
97
+
98
+ Piano.environment = :production
99
+
100
+ just before letting it play for play in production environment!
101
+
102
+ By setting <tt>Piano.etags = :off</tt>, etags will be disabled.
91
103
 
104
+ === And extending it...
92
105
  Of course, you can also do this:
93
106
 
94
107
  require "piano"
@@ -101,9 +114,24 @@ Of course, you can also do this:
101
114
 
102
115
  run! # or play!
103
116
  end
104
-
117
+
105
118
  Remember that the server folder will be the working directory when the script is executed, and not the script path as usual in Sinatra.
106
119
 
120
+ You can even do this:
121
+
122
+ class MySinatraServer < Sinatra::Base
123
+
124
+ use Piano
125
+
126
+ get "/" do
127
+ "My guess is this still won't work, yet I haven't properly tested it"
128
+ end
129
+
130
+ # ...many other things
131
+ end
132
+
133
+ ...currently I can't predict its behavior since I haven't tested it.
134
+
107
135
  == Candies for the kidz
108
136
 
109
137
  === Convenience helpers
@@ -150,17 +178,21 @@ Etags cause client side caching. This should not be a problem since the hash cha
150
178
 
151
179
  == Desired (future) features
152
180
 
153
- * Etag on/off (currently etags are hardcoded on)
154
- * Folder paths and sinatra default arguments configurable.
181
+ * Folder paths configurable.
155
182
  * Condition for disabling default Piano routes
156
183
  * Further documentation of Piano helpers
157
- * Custom error when there's no data
158
184
  * More helpers for semantic data handling.
159
185
  * Deploy of sample with command line <tt>--sample</tt> argument.
160
186
  * Online source files edition.
187
+ * Test <tt>use Piano</tt> within a <tt>Sinatra::Base</tt> class.
161
188
 
162
- DONE &gt; Setup to production enviroment option (why not?!)
163
189
  * Now it would be nice to give Piano personalized templates not only to 404 but for all error pages, specially 500
190
+ * Custom error when there's no data
191
+
192
+ ==== Done
193
+
194
+ * Setup to production enviroment option (why not?!)
195
+ * Etag on/off (currently etags are hardcoded on)
164
196
 
165
197
  == Tips
166
198
 
data/bin/piano CHANGED
@@ -7,6 +7,27 @@ unless ARGV.empty?
7
7
  ARGV.each do |arg|
8
8
  if arg =~ /^\d+$/
9
9
  Piano.port = arg
10
+ elsif arg =~ /^noetags$/
11
+ Piano.etags = :off
12
+ elsif arg =~ /^nocoffee%/
13
+ $nocoffeescript = true
14
+ elsif arg =~ /^sample$/
15
+ puts "Warning: the sample site folder files will be created in the current directory."
16
+ puts "Any files with the same name will be overwritten."
17
+ print "Do you want to continue? (Yn): "
18
+ while answer = gets
19
+ puts answer
20
+ # if answer =~ /^Y/
21
+ # puts "Building sample..."
22
+ # make_sample
23
+ # break
24
+ # elsif answer =~ /^n/
25
+ # puts "Exiting now"
26
+ # Process.exit!
27
+ # else
28
+ # print "Couldn't understand the answer, please do it again (Yn): "
29
+ # end
30
+ end
10
31
  elsif arg =~ /^[a-z]+$/
11
32
  Piano.environment = arg.to_sym
12
33
  end
@@ -14,4 +35,14 @@ unless ARGV.empty?
14
35
 
15
36
  end
16
37
 
38
+ def make_sample
39
+ require "fileutils"
40
+
41
+ source_dir = File.dirname(File.dirname(File.expand_path(__FILE__)))
42
+
43
+ this_dir = File.expand_path(Dir.pwd)
44
+
45
+ FileUtils.cp_r "#{source_dir}/sample", this_dir
46
+ end
47
+
17
48
  Piano.run!
data/lib/piano.rb CHANGED
@@ -1,12 +1,35 @@
1
1
  require "sinatra/base"
2
2
  require "haml"
3
3
  require "sass"
4
- require "coffee-script"
5
4
  require "yaml"
6
5
 
6
+ unless $notcoffeescript
7
+ require "coffee-script"
8
+ end
9
+
7
10
  class Piano < Sinatra::Base
11
+
12
+ class AllButPattern
13
+ Match = Struct.new(:captures)
14
+
15
+ def initialize(except)
16
+ @except = except
17
+ @captures = Match.new([])
18
+ end
19
+
20
+ def match(str)
21
+ @captures unless @except === str
22
+ end
23
+ end
24
+
25
+ def self.all_but(pattern)
26
+ AllButPattern.new(pattern)
27
+ end
28
+
8
29
  set :root, File.expand_path(Dir.pwd)
9
30
  set :views, File.expand_path(Dir.pwd)
31
+ set :etags, :on
32
+ set :etags?, Proc.new { settings.etags == :on }
10
33
 
11
34
  get "/" do
12
35
  @data = data_for "index"
@@ -23,7 +46,8 @@ class Piano < Sinatra::Base
23
46
  coffee something
24
47
  end
25
48
 
26
- get %r{/(.+)$} do |something|
49
+ get all_but(%r{/finetuner(:.+)$}) do
50
+ something = request.path[1..(request.path.length-1)]
27
51
  @data = data_for something
28
52
  try_haml something
29
53
  end
@@ -33,9 +57,11 @@ class Piano < Sinatra::Base
33
57
  file_name = "#{pwd}/#{template}.haml"
34
58
  bad_luck file_name unless File.exists? file_name
35
59
 
36
- hash = hash_for template, :haml
37
- hash += hash_for "data/#{template}", :yaml if File.exists? "#{pwd}/data/#{template}.yaml"
38
- etag hash
60
+ if settings.etags?
61
+ hash = hash_for template, :haml
62
+ hash += hash_for "data/#{template}", :yaml if File.exists? "#{pwd}/data/#{template}.yaml"
63
+ etag hash
64
+ end
39
65
  haml template.to_sym
40
66
  end
41
67
 
@@ -43,7 +69,7 @@ class Piano < Sinatra::Base
43
69
  file_name = "#{pwd}/#{template}.sass"
44
70
  bad_luck file_name unless File.exists? file_name
45
71
 
46
- etag hash_for(template, :sass)
72
+ etag hash_for(template, :sass) if settings.etags?
47
73
  Sass.compile File.read(file_name), :syntax => :sass
48
74
  end
49
75
 
@@ -51,7 +77,7 @@ class Piano < Sinatra::Base
51
77
  file_name = "#{pwd}/#{template}.coffee"
52
78
  bad_luck file_name unless File.exists? file_name
53
79
 
54
- etag hash_for(template, :coffee)
80
+ etag hash_for(template, :coffee) if settings.etags?
55
81
  CoffeeScript.compile(File.read(file_name))
56
82
  end
57
83
 
data/lib/piano/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Piano
2
- VERSION = "0.7.3"
2
+ VERSION = "0.7.4"
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.3
4
+ version: 0.7.4
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-10 00:00:00.000000000 -03:00
12
+ date: 2011-05-18 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: &21772596 !ruby/object:Gem::Requirement
17
+ requirement: &21455076 !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: *21772596
25
+ version_requirements: *21455076
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: haml
28
- requirement: &21772296 !ruby/object:Gem::Requirement
28
+ requirement: &21454776 !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: *21772296
36
+ version_requirements: *21454776
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: sass
39
- requirement: &21772020 !ruby/object:Gem::Requirement
39
+ requirement: &21454500 !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: *21772020
47
+ version_requirements: *21454500
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: coffee-script
50
- requirement: &21771744 !ruby/object:Gem::Requirement
50
+ requirement: &21454224 !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: *21771744
58
+ version_requirements: *21454224
59
59
  description: Out-of-the-box sinatra server for web site sketching using haml + sass
60
60
  + coffee-script
61
61
  email: