piano 0.11.0 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +66 -39
- data/bin/piano +16 -16
- data/lib/piano.rb +15 -14
- data/lib/piano/base.rb +5 -5
- data/lib/piano/{controllerloader.rb → controller_loader.rb} +7 -5
- data/lib/piano/routes.rb +6 -6
- data/lib/piano/version.rb +1 -1
- data/lib/sinatra/piano.rb +46 -40
- data/piano.gemspec +1 -0
- metadata +146 -144
data/README.rdoc
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
= Piano
|
2
2
|
|
3
|
-
Out-of-the-box Sinatra server for fast website sketching using Haml and Sass and CoffeeScript (and YAML!).
|
3
|
+
Out-of-the-box Sinatra server for fast website sketching using Haml (or Slim) and Sass and CoffeeScript (and YAML!).
|
4
4
|
|
5
5
|
The magic triplet, one command away!
|
6
6
|
|
@@ -14,7 +14,7 @@ The magic triplet, one command away!
|
|
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 or environment is given, Piano will start in the default Sinatra port <tt>4567</tt> and the default environment <tt>:development</tt>.
|
16
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.
|
17
|
+
Haml (http://haml-lang.com) <tt>.haml</tt> (or Slim (http://slim-lang.com) <tt>.slim</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
18
|
|
19
19
|
yoursite.com/users => server/folder/users.haml
|
20
20
|
yoursite.com/style.css => server/folder/style.sass
|
@@ -32,25 +32,25 @@ Any route added to the <tt>Pianofile</tt> will be parsed before the default rout
|
|
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
|
|
35
|
-
get
|
36
|
-
|
35
|
+
get '/' do
|
36
|
+
'Hi! Just testing'
|
37
37
|
end
|
38
38
|
|
39
|
-
get
|
39
|
+
get '/email' do
|
40
40
|
"Here is my email: #{unicode_entities('xavier@example.com')}"
|
41
41
|
end
|
42
42
|
|
43
|
-
post
|
43
|
+
post '/' do # The '/' route, is considered "index" for the haml and yaml files
|
44
44
|
require "psych"
|
45
|
-
|
46
|
-
File.open
|
45
|
+
|
46
|
+
File.open 'data/index.yaml', 'w' do |file|
|
47
47
|
file.write params.to_yaml
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
51
|
helpers do
|
52
52
|
def unicode_entities(string)
|
53
|
-
encodings =
|
53
|
+
encodings = ''
|
54
54
|
string.codepoints do |c|
|
55
55
|
encodings += "&##{c};"
|
56
56
|
end
|
@@ -71,8 +71,8 @@ When receiving a request for <tt>"/users"</tt>, Piano will look up for a YAML fi
|
|
71
71
|
!!! 5
|
72
72
|
%head
|
73
73
|
%title= @data['title']
|
74
|
-
= style
|
75
|
-
= script
|
74
|
+
= style 'style.css'
|
75
|
+
= script 'app.js'
|
76
76
|
%body
|
77
77
|
%h1= @data['title']
|
78
78
|
%p= @data['description']
|
@@ -80,6 +80,22 @@ When receiving a request for <tt>"/users"</tt>, Piano will look up for a YAML fi
|
|
80
80
|
- @data['list'].each do |item|
|
81
81
|
%li= item
|
82
82
|
|
83
|
+
Or if slim:
|
84
|
+
|
85
|
+
==== folder/index.slim
|
86
|
+
|
87
|
+
doctype html
|
88
|
+
head
|
89
|
+
title= @data['title']
|
90
|
+
== style 'style.css'
|
91
|
+
== script 'app.js'
|
92
|
+
body
|
93
|
+
h1= @data['title']
|
94
|
+
p= @data['description']
|
95
|
+
ul
|
96
|
+
- @data['list'].each do |item|
|
97
|
+
li= item
|
98
|
+
|
83
99
|
==== folder/style.sass
|
84
100
|
|
85
101
|
body
|
@@ -92,7 +108,7 @@ When receiving a request for <tt>"/users"</tt>, Piano will look up for a YAML fi
|
|
92
108
|
==== folder/app.coffee
|
93
109
|
|
94
110
|
alert "This is too simple to be true"
|
95
|
-
|
111
|
+
|
96
112
|
==== folder/data/index.yaml
|
97
113
|
|
98
114
|
title: 5 minutes site!
|
@@ -101,7 +117,7 @@ When receiving a request for <tt>"/users"</tt>, Piano will look up for a YAML fi
|
|
101
117
|
- and I can have
|
102
118
|
- a list
|
103
119
|
- also.
|
104
|
-
|
120
|
+
|
105
121
|
Note: You can find this sample in the repository within the <tt>/sample</tt> folder.
|
106
122
|
|
107
123
|
== Going :production!
|
@@ -129,43 +145,43 @@ Piano is fully usable as a Sinatra Extension. Provide the helpers, <tt>sass("tem
|
|
129
145
|
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
146
|
Further moves to keep most functionality as a Sinatra Extension will be done in the future, except in the <tt>piano/routes</tt>.
|
131
147
|
|
132
|
-
require
|
133
|
-
|
134
|
-
class MyPiano < Sinatra::Base
|
148
|
+
require 'piano'
|
149
|
+
|
150
|
+
class MyPiano < Sinatra::Base
|
135
151
|
helpers Sinatra::Piano
|
136
|
-
|
137
|
-
get
|
152
|
+
|
153
|
+
get '/' do
|
138
154
|
"Let's change the default behaviour"
|
139
155
|
end
|
140
|
-
end
|
141
|
-
|
142
|
-
MyPiano.run!
|
156
|
+
end
|
157
|
+
|
158
|
+
MyPiano.run!
|
143
159
|
|
144
160
|
=== Routes
|
145
161
|
|
146
162
|
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
163
|
|
148
|
-
require
|
149
|
-
|
150
|
-
class Piano
|
151
|
-
get
|
164
|
+
require 'piano/base'
|
165
|
+
|
166
|
+
class Piano::Base
|
167
|
+
get '/special' do
|
152
168
|
"A special route, overriding the default 'special.haml'"
|
153
169
|
end
|
154
170
|
end
|
155
|
-
|
156
|
-
require
|
157
|
-
|
158
|
-
Piano.play! # .play! added 4 the lulz; Piano.run! will do the trick aswell
|
171
|
+
|
172
|
+
require 'piano/routes'
|
173
|
+
|
174
|
+
Piano::Base.play! # .play! added 4 the lulz; Piano.run! will do the trick aswell
|
159
175
|
|
160
176
|
<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
177
|
|
162
178
|
Tip: put
|
163
|
-
|
164
|
-
Piano.environment = :production
|
179
|
+
|
180
|
+
Piano::Base.environment = :production
|
165
181
|
|
166
182
|
just before letting it play for play in production environment!
|
167
183
|
|
168
|
-
By setting <tt>Piano.etags = :off</tt>, etags will be disabled.
|
184
|
+
By setting <tt>Piano::Base.etags = :off</tt>, etags will be disabled.
|
169
185
|
|
170
186
|
== Candies for the kidz
|
171
187
|
|
@@ -181,9 +197,18 @@ You can use them in your haml templates like this:
|
|
181
197
|
%html
|
182
198
|
%head
|
183
199
|
%title Out-of-the-box is pretty awesome!
|
184
|
-
= style
|
185
|
-
= script
|
186
|
-
|
200
|
+
= style 'style.css'
|
201
|
+
= script 'app.js'
|
202
|
+
|
203
|
+
Or in slim:
|
204
|
+
|
205
|
+
doctype html
|
206
|
+
html
|
207
|
+
head
|
208
|
+
title Out-of-the-box is pretty awesome!
|
209
|
+
== style 'style.css'
|
210
|
+
== script 'app.js'
|
211
|
+
|
187
212
|
==== <tt>extract</tt>
|
188
213
|
|
189
214
|
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.
|
@@ -197,11 +222,11 @@ No, it does not print an anchor: it strips all strange characters from a string
|
|
197
222
|
Really useful when generating uri's for articles, or html id attributes.
|
198
223
|
|
199
224
|
%a(href="/articles/#{article.id}-#{link(article.title)}")= article.title
|
200
|
-
|
225
|
+
|
201
226
|
or
|
202
|
-
|
227
|
+
|
203
228
|
%h2(id="#{link(subtitle,4)}")= subtitle
|
204
|
-
|
229
|
+
|
205
230
|
In this example, the second argument (4) ensures that the link is done with no more than four of the subtitle's words.
|
206
231
|
|
207
232
|
=== <tt>flash</tt>
|
@@ -240,6 +265,8 @@ As for v0.7.3, Piano has now the ability to go <tt>:production</tt> mode both in
|
|
240
265
|
|
241
266
|
== Deprecated functions
|
242
267
|
|
268
|
+
From version 0.11.0 on, <tt>flash?</tt> has been deprecated and the <tt>flash</tt> helpers has been replaced with the <tt>sinatra-flash</tt> gem.
|
269
|
+
|
243
270
|
From version 0.7.6 on, <tt>unicode_entities</tt> has been deprecated for better Ruby version backwards compatibility.
|
244
271
|
|
245
272
|
= License
|
@@ -248,7 +275,7 @@ From version 0.7.6 on, <tt>unicode_entities</tt> has been deprecated for better
|
|
248
275
|
|
249
276
|
Copyright © 2011:
|
250
277
|
|
251
|
-
* Xavier Via (http://
|
278
|
+
* Xavier Via (http://xaviervia.com.ar)
|
252
279
|
|
253
280
|
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:
|
254
281
|
|
data/bin/piano
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
require
|
3
|
-
require
|
2
|
+
require 'piano'
|
3
|
+
require 'metafun/delegator'
|
4
4
|
|
5
5
|
unless ARGV.empty?
|
6
|
-
|
6
|
+
|
7
7
|
args = {}
|
8
|
-
|
8
|
+
|
9
9
|
ARGV.each do |arg|
|
10
10
|
if arg =~ /^\d+$/
|
11
11
|
args[:port] = arg
|
12
12
|
elsif arg =~ /^noetags$/
|
13
13
|
args[:etags] = :off
|
14
|
-
elsif arg ==
|
14
|
+
elsif arg == '-v'
|
15
15
|
puts Piano::VERSION
|
16
16
|
Process.exit!
|
17
17
|
elsif arg =~ /^views:/
|
@@ -36,28 +36,28 @@ if args
|
|
36
36
|
end
|
37
37
|
|
38
38
|
self.extend Metafun::Delegator
|
39
|
-
self.delegate Piano::Base,
|
39
|
+
self.delegate Piano::Base, :get, :patch, :put, :post, :delete,
|
40
40
|
:head, :options, :template, :fetch, :layout,
|
41
|
-
:before, :after, :error, :not_found,
|
42
|
-
:configure, :set, :mime_type, :enable,
|
43
|
-
:disable, :use, :development?, :test?,
|
41
|
+
:before, :after, :error, :not_found,
|
42
|
+
:configure, :set, :mime_type, :enable,
|
43
|
+
:disable, :use, :development?, :test?,
|
44
44
|
:production?, :helpers, :settings, :play!
|
45
45
|
|
46
46
|
self.helpers Sinatra::Piano
|
47
47
|
|
48
|
-
$LOAD_PATH << Dir.pwd +
|
48
|
+
$LOAD_PATH << Dir.pwd + '/lib'
|
49
49
|
|
50
|
-
if File.exists?(
|
51
|
-
puts
|
52
|
-
load
|
50
|
+
if File.exists?('Pianofile')
|
51
|
+
puts 'Pianofile found, loading...'
|
52
|
+
load 'Pianofile'
|
53
53
|
end
|
54
54
|
|
55
|
-
if File.directory?(
|
55
|
+
if File.directory?('controllers')
|
56
56
|
puts "'controllers' directory found, loading '.controller' files"
|
57
|
-
Piano::ControllerLoader.folder
|
57
|
+
Piano::ControllerLoader.folder 'controllers'
|
58
58
|
end
|
59
59
|
|
60
|
-
require
|
60
|
+
require 'piano/routes'
|
61
61
|
|
62
62
|
puts "Starting Sinatra from Piano #{Piano::VERSION}"
|
63
63
|
Piano::Base.play!
|
data/lib/piano.rb
CHANGED
@@ -1,22 +1,23 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'sinatra/base'
|
2
|
+
require 'sinatra/flash'
|
3
3
|
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
4
|
+
require 'haml'
|
5
|
+
require 'slim'
|
6
|
+
require 'sass'
|
7
|
+
require 'compass'
|
8
|
+
require 'yaml'
|
9
|
+
require 'i18n'
|
9
10
|
|
10
11
|
begin
|
11
|
-
require
|
12
|
+
require 'coffee-script'
|
12
13
|
rescue Exception => error
|
13
|
-
puts
|
14
|
-
puts
|
14
|
+
puts 'No JavaScript environment was found. Please install therubyracer gem'
|
15
|
+
puts ' gem install therubyracer'
|
15
16
|
Process.exit!
|
16
17
|
end
|
17
18
|
|
18
|
-
require
|
19
|
+
require 'sinatra/piano'
|
19
20
|
|
20
|
-
require
|
21
|
-
require
|
22
|
-
require
|
21
|
+
require 'piano/base'
|
22
|
+
require 'piano/controller_loader'
|
23
|
+
require 'piano/version'
|
data/lib/piano/base.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
module Piano
|
2
|
-
class Base < Sinatra::Base
|
2
|
+
class Base < Sinatra::Base
|
3
3
|
register Sinatra::Piano
|
4
4
|
register Sinatra::Flash
|
5
|
-
|
5
|
+
|
6
6
|
Compass.configuration do |config|
|
7
7
|
config.project_path = File.expand_path(Dir.pwd)
|
8
8
|
config.sass_dir = File.expand_path(Dir.pwd)
|
@@ -12,12 +12,12 @@ module Piano
|
|
12
12
|
set :root, File.expand_path(Dir.pwd)
|
13
13
|
set :views, File.expand_path(Dir.pwd)
|
14
14
|
set :sass, Compass.sass_engine_options
|
15
|
-
set :data, File.expand_path(Dir.pwd
|
15
|
+
set :data, File.expand_path("#{Dir.pwd}/data")
|
16
16
|
set :etags, :on
|
17
17
|
set :multidomain, :off
|
18
|
-
|
18
|
+
|
19
19
|
def self.play!
|
20
20
|
self.run!
|
21
|
-
end
|
21
|
+
end
|
22
22
|
end
|
23
23
|
end
|
@@ -6,17 +6,19 @@ module Piano
|
|
6
6
|
load item
|
7
7
|
end
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
# Iterates recursively over the path and calls the block
|
11
11
|
# with each newfound file
|
12
12
|
def self.recursive path, &block
|
13
13
|
files = []
|
14
14
|
Dir.new(File.expand_path(path)).each do |file|
|
15
15
|
if File.directory? "#{path}/#{file}"
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
unless file == '..' or file == '.'
|
17
|
+
recursive "#{path}/#{file}" do |item|
|
18
|
+
files << "#{item}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
elsif file.end_with? '.controller'
|
20
22
|
files << "#{path}/#{file}"
|
21
23
|
end
|
22
24
|
end
|
data/lib/piano/routes.rb
CHANGED
@@ -1,21 +1,21 @@
|
|
1
1
|
module Piano
|
2
2
|
class Base
|
3
|
-
get
|
4
|
-
@data = data_for
|
3
|
+
get '/' do
|
4
|
+
@data = data_for 'index'
|
5
5
|
fetch :index
|
6
6
|
end
|
7
|
-
|
7
|
+
|
8
8
|
get %r{/(.+?).css$} do |something|
|
9
9
|
content_type :css
|
10
10
|
fetch something, :sass
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
get %r{/(.+?).js$} do |something|
|
14
14
|
content_type :js
|
15
15
|
fetch something, :coffee
|
16
16
|
end
|
17
|
-
|
18
|
-
get
|
17
|
+
|
18
|
+
get '/*' do
|
19
19
|
something = request.path[1..(request.path.length-1)]
|
20
20
|
@data = data_for something
|
21
21
|
fetch something
|
data/lib/piano/version.rb
CHANGED
data/lib/sinatra/piano.rb
CHANGED
@@ -1,96 +1,102 @@
|
|
1
1
|
module Sinatra
|
2
|
-
|
2
|
+
|
3
3
|
# Piano was originally though as a Sinatra extension
|
4
4
|
# That's why the code was defined here
|
5
|
-
module Piano
|
6
|
-
|
7
|
-
# Replacemente for :try_haml, :sass & :coffee. Agnostic
|
5
|
+
module Piano
|
6
|
+
|
7
|
+
# Replacemente for :try_haml, :try_slim, :sass & :coffee. Agnostic
|
8
8
|
# Work in progress
|
9
|
-
def fetch
|
9
|
+
def fetch(*args)
|
10
10
|
resource = args.shift
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
|
12
|
+
unless type = args.shift
|
13
|
+
[:haml, :slim].each do |t|
|
14
|
+
file_name = "#{settings.views}/#{resource}.#{t}"
|
15
|
+
if File.exists?(file_name)
|
16
|
+
type = t and break
|
17
|
+
end
|
18
|
+
end
|
15
19
|
end
|
16
|
-
|
17
|
-
|
18
|
-
return bad_luck file_name unless File.exists? file_name
|
20
|
+
|
21
|
+
return bad_luck("#{settings.views}/#{resource}.haml/slim") unless type
|
19
22
|
|
20
23
|
if etags?
|
21
|
-
if
|
22
|
-
hash = hash_for resource,
|
24
|
+
if [:haml, :slim].include? type
|
25
|
+
hash = hash_for resource, type
|
23
26
|
if File.exists? "#{settings.views}/#{settings.data}/#{resource}.yaml"
|
24
27
|
hash += hash_for "#{settings.data}/#{resource}", :yaml
|
25
28
|
end
|
26
|
-
|
29
|
+
|
27
30
|
etag hash
|
28
31
|
else
|
29
32
|
etag hash_for(resource, type)
|
30
|
-
end
|
33
|
+
end
|
31
34
|
end
|
32
|
-
|
35
|
+
|
33
36
|
send type, resource.to_sym, *args # Send the template to Sinatra to take care of it
|
34
37
|
end
|
35
|
-
|
38
|
+
|
36
39
|
# Loads and parses the YAML data from the data directory
|
37
40
|
def data_for(template)
|
38
41
|
file_name = "#{settings.data}/#{template}.yaml"
|
39
42
|
YAML.load_file(file_name) if File.exists?(file_name)
|
40
43
|
end
|
41
|
-
|
44
|
+
|
42
45
|
# Sugar: formats a css stylesheet <link /> tag with the input
|
43
|
-
def style
|
46
|
+
def style(path, more = '')
|
44
47
|
"<link rel='stylesheet' type='text/css' href='#{path}' #{more} />"
|
45
48
|
end
|
46
|
-
|
49
|
+
|
47
50
|
# Sugar: formats a javascript <script> tag with the input
|
48
|
-
def script
|
51
|
+
def script(path, more = '')
|
49
52
|
"<script type='text/javascript' src='#{path}' #{more} ></script>"
|
50
53
|
end
|
51
|
-
|
54
|
+
|
52
55
|
# Fails. Shouts a 404 response and prints hints
|
53
56
|
#
|
54
57
|
# If Piano is running in production mode, prints a plain 404 html
|
55
|
-
# or, if a 404.haml exists in the :views directory, returns it
|
58
|
+
# or, if a 404.haml or 404.slim exists in the :views directory, returns it
|
56
59
|
def bad_luck(path)
|
57
60
|
content_type :html
|
58
61
|
if settings.environment == :production
|
59
62
|
if File.exists? "#{settings.views}/404.haml"
|
60
63
|
@data = data_for "404"
|
61
64
|
halt 404, haml(:"404")
|
65
|
+
elsif File.exists? "#{settings.views}/404.slim"
|
66
|
+
@data = data_for "404"
|
67
|
+
halt 404, slim(:"404")
|
62
68
|
else
|
63
|
-
halt 404,
|
69
|
+
halt 404, '<h1>404 - Not Found</h1><p>Piano has found nothing in this address</p>'
|
64
70
|
end
|
65
71
|
else
|
66
72
|
halt 404, "<h1>You have still to put something here.</h1><p>This is <em>#{path}</em></p><blockquote>Good luck!</blockquote>"
|
67
73
|
end
|
68
74
|
end
|
69
|
-
|
75
|
+
|
70
76
|
# Builds a hash for a file within the :views directory
|
71
77
|
# Note: I feel like this functionality should be private
|
72
78
|
def hash_for(name, type)
|
73
|
-
"#{name}.#{type} -
|
79
|
+
"#{name}.#{type} - #{File.mtime("#{settings.views}/#{name}.#{type}")}"
|
74
80
|
end
|
75
|
-
|
81
|
+
|
76
82
|
# Makes an extract out of the given text with the default length
|
77
83
|
# of 80 words
|
78
|
-
#
|
84
|
+
#
|
79
85
|
# If an integer is passed as the second argument, the length
|
80
86
|
# of the result is adjusted properly:
|
81
|
-
#
|
87
|
+
#
|
82
88
|
# extract "Hello World! Too much text is inconvenient", 2
|
83
89
|
#
|
84
90
|
# returns
|
85
|
-
#
|
91
|
+
#
|
86
92
|
# => "Hello World!..."
|
87
93
|
#
|
88
94
|
def extract(text, length = 80)
|
89
|
-
words = text.gsub(/<.+?>/,
|
95
|
+
words = text.gsub(/<.+?>/, '').split
|
90
96
|
return text if words.length <= length
|
91
|
-
words[0..(length-1)].join(
|
97
|
+
words[0..(length-1)].join(' ') + '...'
|
92
98
|
end
|
93
|
-
|
99
|
+
|
94
100
|
# Returns a url-friendly version of the given link, with a
|
95
101
|
# default maximum of 5 words.
|
96
102
|
# `link` strips any non-letter or special character, downcases the
|
@@ -105,20 +111,20 @@ module Sinatra
|
|
105
111
|
#
|
106
112
|
# You can specify a word length in the second argument.
|
107
113
|
def link(text, length = 5)
|
108
|
-
words = text.gsub(/<.+?>/,
|
109
|
-
words[0..(length-1)].join(
|
114
|
+
words = text.gsub(/<.+?>/, '').gsub(' ', '-').downcase.gsub(/[^a-z0-9\-]/, '').split('-')
|
115
|
+
words[0..(length-1)].join('-')
|
110
116
|
end
|
111
|
-
|
117
|
+
|
112
118
|
# Shorthand to settings.etags == :on
|
113
119
|
def etags?
|
114
120
|
if settings.respond_to? :etags
|
115
121
|
settings.etags == :on
|
116
|
-
else
|
122
|
+
else
|
117
123
|
true
|
118
124
|
end
|
119
125
|
end
|
120
|
-
|
126
|
+
|
121
127
|
end
|
122
|
-
|
128
|
+
|
123
129
|
register Piano
|
124
130
|
end
|
data/piano.gemspec
CHANGED
@@ -16,6 +16,7 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.add_dependency "sinatra", ">= 1.2.6"
|
17
17
|
s.add_dependency "sinatra-flash", ">= 0.3.0"
|
18
18
|
s.add_dependency "haml", ">= 3.1.1"
|
19
|
+
s.add_dependency "slim"
|
19
20
|
s.add_dependency "sass", ">= 3.1.1"
|
20
21
|
s.add_dependency "compass", ">= 0.12.2"
|
21
22
|
s.add_dependency "coffee-script", ">= 2.2.0"
|
metadata
CHANGED
@@ -1,159 +1,170 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: piano
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.12.0
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 11
|
9
|
-
- 0
|
10
|
-
version: 0.11.0
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Xavier Via
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-07-29 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
21
15
|
name: sinatra
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
hash: 19
|
29
|
-
segments:
|
30
|
-
- 1
|
31
|
-
- 2
|
32
|
-
- 6
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
33
21
|
version: 1.2.6
|
34
22
|
type: :runtime
|
35
|
-
version_requirements: *id001
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
|
-
name: sinatra-flash
|
38
23
|
prerelease: false
|
39
|
-
|
40
|
-
none: false
|
41
|
-
requirements:
|
42
|
-
- -
|
43
|
-
- !ruby/object:Gem::Version
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.2.6
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: sinatra-flash
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
49
37
|
version: 0.3.0
|
50
38
|
type: :runtime
|
51
|
-
|
52
|
-
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.3.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
53
47
|
name: haml
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 3.1.1
|
54
|
+
type: :runtime
|
54
55
|
prerelease: false
|
55
|
-
|
56
|
-
none: false
|
57
|
-
requirements:
|
58
|
-
- -
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
hash: 1
|
61
|
-
segments:
|
62
|
-
- 3
|
63
|
-
- 1
|
64
|
-
- 1
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
65
61
|
version: 3.1.1
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: slim
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
66
70
|
type: :runtime
|
67
|
-
version_requirements: *id003
|
68
|
-
- !ruby/object:Gem::Dependency
|
69
|
-
name: sass
|
70
71
|
prerelease: false
|
71
|
-
|
72
|
-
none: false
|
73
|
-
requirements:
|
74
|
-
- -
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: sass
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
81
85
|
version: 3.1.1
|
82
86
|
type: :runtime
|
83
|
-
version_requirements: *id004
|
84
|
-
- !ruby/object:Gem::Dependency
|
85
|
-
name: compass
|
86
87
|
prerelease: false
|
87
|
-
|
88
|
-
none: false
|
89
|
-
requirements:
|
90
|
-
- -
|
91
|
-
- !ruby/object:Gem::Version
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 3.1.1
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: compass
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
97
101
|
version: 0.12.2
|
98
102
|
type: :runtime
|
99
|
-
version_requirements: *id005
|
100
|
-
- !ruby/object:Gem::Dependency
|
101
|
-
name: coffee-script
|
102
103
|
prerelease: false
|
103
|
-
|
104
|
-
none: false
|
105
|
-
requirements:
|
106
|
-
- -
|
107
|
-
- !ruby/object:Gem::Version
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 0.12.2
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: coffee-script
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
113
117
|
version: 2.2.0
|
114
118
|
type: :runtime
|
115
|
-
version_requirements: *id006
|
116
|
-
- !ruby/object:Gem::Dependency
|
117
|
-
name: i18n
|
118
119
|
prerelease: false
|
119
|
-
|
120
|
-
none: false
|
121
|
-
requirements:
|
122
|
-
- -
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: 2.2.0
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: i18n
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
129
133
|
version: 0.6.0
|
130
134
|
type: :runtime
|
131
|
-
version_requirements: *id007
|
132
|
-
- !ruby/object:Gem::Dependency
|
133
|
-
name: metafun
|
134
135
|
prerelease: false
|
135
|
-
|
136
|
-
none: false
|
137
|
-
requirements:
|
138
|
-
- -
|
139
|
-
- !ruby/object:Gem::Version
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: 0.6.0
|
142
|
+
- !ruby/object:Gem::Dependency
|
143
|
+
name: metafun
|
144
|
+
requirement: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ! '>='
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
144
150
|
type: :runtime
|
145
|
-
|
146
|
-
|
147
|
-
|
151
|
+
prerelease: false
|
152
|
+
version_requirements: !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ! '>='
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
description: Out-of-the-box sinatra server for web site sketching using haml + sass
|
159
|
+
+ coffee-script
|
160
|
+
email:
|
148
161
|
- xavierviacanel@gmail.com
|
149
|
-
executables:
|
162
|
+
executables:
|
150
163
|
- piano
|
151
164
|
- piano~
|
152
165
|
extensions: []
|
153
|
-
|
154
166
|
extra_rdoc_files: []
|
155
|
-
|
156
|
-
files:
|
167
|
+
files:
|
157
168
|
- .gitignore
|
158
169
|
- Gemfile
|
159
170
|
- README.rdoc
|
@@ -162,7 +173,7 @@ files:
|
|
162
173
|
- bin/piano~
|
163
174
|
- lib/piano.rb
|
164
175
|
- lib/piano/base.rb
|
165
|
-
- lib/piano/
|
176
|
+
- lib/piano/controller_loader.rb
|
166
177
|
- lib/piano/routes.rb
|
167
178
|
- lib/piano/version.rb
|
168
179
|
- lib/sinatra/piano.rb
|
@@ -173,36 +184,27 @@ files:
|
|
173
184
|
- sample/style.sass
|
174
185
|
homepage: http://github.com/xaviervia/piano
|
175
186
|
licenses: []
|
176
|
-
|
177
187
|
post_install_message:
|
178
188
|
rdoc_options: []
|
179
|
-
|
180
|
-
require_paths:
|
189
|
+
require_paths:
|
181
190
|
- lib
|
182
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
191
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
183
192
|
none: false
|
184
|
-
requirements:
|
185
|
-
- -
|
186
|
-
- !ruby/object:Gem::Version
|
187
|
-
|
188
|
-
|
189
|
-
- 0
|
190
|
-
version: "0"
|
191
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
193
|
+
requirements:
|
194
|
+
- - ! '>='
|
195
|
+
- !ruby/object:Gem::Version
|
196
|
+
version: '0'
|
197
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
192
198
|
none: false
|
193
|
-
requirements:
|
194
|
-
- -
|
195
|
-
- !ruby/object:Gem::Version
|
196
|
-
|
197
|
-
segments:
|
198
|
-
- 0
|
199
|
-
version: "0"
|
199
|
+
requirements:
|
200
|
+
- - ! '>='
|
201
|
+
- !ruby/object:Gem::Version
|
202
|
+
version: '0'
|
200
203
|
requirements: []
|
201
|
-
|
202
204
|
rubyforge_project: piano
|
203
|
-
rubygems_version: 1.8.
|
205
|
+
rubygems_version: 1.8.21
|
204
206
|
signing_key:
|
205
207
|
specification_version: 3
|
206
|
-
summary: Out-of-the-box sinatra server for web site sketching using haml + sass +
|
208
|
+
summary: Out-of-the-box sinatra server for web site sketching using haml + sass +
|
209
|
+
coffee-script
|
207
210
|
test_files: []
|
208
|
-
|