piano 0.8.1 → 0.8.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +25 -17
- data/bin/piano +6 -1
- data/lib/piano.rb +35 -28
- data/lib/piano/routes.rb +1 -1
- data/lib/piano/version.rb +1 -1
- data/sample/index.haml +1 -1
- metadata +10 -10
data/README.rdoc
CHANGED
@@ -24,11 +24,11 @@ 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
|
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
28
|
|
29
|
-
Any route added to the <tt
|
29
|
+
Any route added to the <tt>Pianofile</tt> will be parsed before the default routes from Piano, overriding them.
|
30
30
|
|
31
|
-
==== Sample <tt
|
31
|
+
==== Sample <tt>Pianofile</tt>
|
32
32
|
|
33
33
|
This file, for example, will bring back the email masking functionality that was deprecated in version 0.7.6
|
34
34
|
|
@@ -106,30 +106,26 @@ Note: you can also add a <tt>server/folder/data/404.yaml</tt> file to keep layer
|
|
106
106
|
* Port number: Any number passed as an argument to the <tt>piano</tt> command will be used as the port number.
|
107
107
|
* Environment: Any string that does not matches any other argument will be setted as the environment.
|
108
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
|
109
112
|
|
110
|
-
|
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>.
|
111
114
|
|
112
|
-
Piano
|
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>.
|
113
117
|
|
114
118
|
require "piano"
|
115
119
|
|
116
|
-
class
|
120
|
+
class MyPiano < Sinatra::Base
|
121
|
+
helpers Sinatra::Piano
|
122
|
+
|
117
123
|
get "/" do
|
118
124
|
"Let's change the default behaviour"
|
119
125
|
end
|
120
126
|
end
|
121
127
|
|
122
|
-
|
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.
|
125
|
-
|
126
|
-
Tip: put
|
127
|
-
|
128
|
-
Piano.environment = :production
|
129
|
-
|
130
|
-
just before letting it play for play in production environment!
|
131
|
-
|
132
|
-
By setting <tt>Piano.etags = :off</tt>, etags will be disabled.
|
128
|
+
MyPiano.run!
|
133
129
|
|
134
130
|
=== Routes
|
135
131
|
|
@@ -144,6 +140,18 @@ To load the routes (the ones that match your requests with your haml, sass and c
|
|
144
140
|
end
|
145
141
|
|
146
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.
|
147
155
|
|
148
156
|
== Candies for the kidz
|
149
157
|
|
data/bin/piano
CHANGED
@@ -59,7 +59,12 @@ def make_sample
|
|
59
59
|
FileUtils.cp_r "#{source_dir}/sample", this_dir
|
60
60
|
end
|
61
61
|
|
62
|
-
if File.exists?(File.expand_path(Dir.pwd) + "
|
62
|
+
if File.exists?(File.expand_path(Dir.pwd) + "/Pianofile")
|
63
|
+
piano_file = File.expand_path(Dir.pwd) + "/Pianofile"
|
64
|
+
puts "Pianofile found, loading..."
|
65
|
+
load piano_file
|
66
|
+
end
|
67
|
+
if File.exists?(File.expand_path(Dir.pwd) + "/.piano") # Deprecate soon
|
63
68
|
load File.expand_path(Dir.pwd) + "/.piano"
|
64
69
|
end
|
65
70
|
|
data/lib/piano.rb
CHANGED
@@ -11,36 +11,13 @@ rescue Exception => error
|
|
11
11
|
Process.exit!
|
12
12
|
end
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
class AllButPattern
|
17
|
-
Match = Struct.new(:captures)
|
18
|
-
|
19
|
-
def initialize(except)
|
20
|
-
@except = except
|
21
|
-
@captures = Match.new([])
|
22
|
-
end
|
23
|
-
|
24
|
-
def match(str)
|
25
|
-
@captures unless @except === str
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def self.all_but(pattern)
|
30
|
-
AllButPattern.new(pattern)
|
31
|
-
end
|
32
|
-
|
33
|
-
set :root, File.expand_path(Dir.pwd)
|
34
|
-
set :views, File.expand_path(Dir.pwd)
|
35
|
-
set :etags, :on
|
36
|
-
set :etags?, Proc.new { settings.etags == :on }
|
37
|
-
|
38
|
-
helpers do
|
14
|
+
module Sinatra
|
15
|
+
module Piano
|
39
16
|
def try_haml(template)
|
40
17
|
file_name = "#{pwd}/#{template}.haml"
|
41
18
|
bad_luck file_name unless File.exists? file_name
|
42
19
|
|
43
|
-
if
|
20
|
+
if etags?
|
44
21
|
hash = hash_for template, :haml
|
45
22
|
hash += hash_for "data/#{template}", :yaml if File.exists? "#{pwd}/data/#{template}.yaml"
|
46
23
|
etag hash
|
@@ -52,7 +29,7 @@ class Piano < Sinatra::Base
|
|
52
29
|
file_name = "#{pwd}/#{template}.sass"
|
53
30
|
bad_luck file_name unless File.exists? file_name
|
54
31
|
|
55
|
-
etag hash_for(template, :sass) if
|
32
|
+
etag hash_for(template, :sass) if etags?
|
56
33
|
Sass.compile File.read(file_name), :syntax => :sass
|
57
34
|
end
|
58
35
|
|
@@ -60,7 +37,7 @@ class Piano < Sinatra::Base
|
|
60
37
|
file_name = "#{pwd}/#{template}.coffee"
|
61
38
|
bad_luck file_name unless File.exists? file_name
|
62
39
|
|
63
|
-
etag hash_for(template, :coffee) if
|
40
|
+
etag hash_for(template, :coffee) if etags?
|
64
41
|
CoffeeScript.compile(File.read(file_name))
|
65
42
|
end
|
66
43
|
|
@@ -104,8 +81,38 @@ class Piano < Sinatra::Base
|
|
104
81
|
return text if words.length <= length
|
105
82
|
words[0..(length-1)].join(" ") + "..."
|
106
83
|
end
|
84
|
+
|
85
|
+
def link(text, length = 5)
|
86
|
+
words = text
|
87
|
+
.gsub(/<.+?>/, "")
|
88
|
+
.gsub(" ", "-")
|
89
|
+
.downcase
|
90
|
+
.gsub(/[^a-z0-9\-]/, "")
|
91
|
+
.split("-")
|
92
|
+
words[0..(length-1)].join("-")
|
93
|
+
end
|
94
|
+
|
95
|
+
def etags?
|
96
|
+
if settings.respond_to? :etags
|
97
|
+
settings.etags == :on
|
98
|
+
else
|
99
|
+
true
|
100
|
+
end
|
101
|
+
end
|
107
102
|
end
|
108
103
|
|
104
|
+
helpers Piano
|
105
|
+
end
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
class Piano < Sinatra::Base
|
110
|
+
helpers Sinatra::Piano
|
111
|
+
|
112
|
+
set :root, File.expand_path(Dir.pwd)
|
113
|
+
set :views, File.expand_path(Dir.pwd)
|
114
|
+
set :etags, :on
|
115
|
+
|
109
116
|
def self.play!
|
110
117
|
self.run!
|
111
118
|
end
|
data/lib/piano/routes.rb
CHANGED
data/lib/piano/version.rb
CHANGED
data/sample/index.haml
CHANGED
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.8.
|
4
|
+
version: 0.8.3
|
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-
|
12
|
+
date: 2011-06-03 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: &
|
17
|
+
requirement: &21731508 !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: *
|
25
|
+
version_requirements: *21731508
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: haml
|
28
|
-
requirement: &
|
28
|
+
requirement: &21731208 !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: *
|
36
|
+
version_requirements: *21731208
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: sass
|
39
|
-
requirement: &
|
39
|
+
requirement: &21730932 !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: *
|
47
|
+
version_requirements: *21730932
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: coffee-script
|
50
|
-
requirement: &
|
50
|
+
requirement: &21730656 !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: *
|
58
|
+
version_requirements: *21730656
|
59
59
|
description: Out-of-the-box sinatra server for web site sketching using haml + sass
|
60
60
|
+ coffee-script
|
61
61
|
email:
|