almost-sinatra 0.1.0 → 1.0.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.
- checksums.yaml +4 -4
- data/LICENSE.md +116 -0
- data/Manifest.txt +1 -0
- data/README.md +334 -0
- data/Rakefile +3 -3
- data/lib/almost-sinatra.rb +4 -3
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70ffc92b28161e2db66b6bed8149acbaf7e85a3f
|
4
|
+
data.tar.gz: 1ca81d13f7633e8d75249242a534aeffda3cce43
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2064e179bd420c95f64551896963f30fd40648ff0274482f3dfbb4af3055c57299cdc86f36868c1a5149ddddaa0a726bbd1697c442496ec8edbd0e864c8fa992
|
7
|
+
data.tar.gz: d09540bedba02aa5c8ef1c3284ab258af7f27507f92176acd66125324cf91bb31c61cddf22d84d196093993180c71a20f773884e0896678002b6627dcb510b7c
|
data/LICENSE.md
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
CC0 1.0 Universal
|
2
|
+
|
3
|
+
Statement of Purpose
|
4
|
+
|
5
|
+
The laws of most jurisdictions throughout the world automatically confer
|
6
|
+
exclusive Copyright and Related Rights (defined below) upon the creator and
|
7
|
+
subsequent owner(s) (each and all, an "owner") of an original work of
|
8
|
+
authorship and/or a database (each, a "Work").
|
9
|
+
|
10
|
+
Certain owners wish to permanently relinquish those rights to a Work for the
|
11
|
+
purpose of contributing to a commons of creative, cultural and scientific
|
12
|
+
works ("Commons") that the public can reliably and without fear of later
|
13
|
+
claims of infringement build upon, modify, incorporate in other works, reuse
|
14
|
+
and redistribute as freely as possible in any form whatsoever and for any
|
15
|
+
purposes, including without limitation commercial purposes. These owners may
|
16
|
+
contribute to the Commons to promote the ideal of a free culture and the
|
17
|
+
further production of creative, cultural and scientific works, or to gain
|
18
|
+
reputation or greater distribution for their Work in part through the use and
|
19
|
+
efforts of others.
|
20
|
+
|
21
|
+
For these and/or other purposes and motivations, and without any expectation
|
22
|
+
of additional consideration or compensation, the person associating CC0 with a
|
23
|
+
Work (the "Affirmer"), to the extent that he or she is an owner of Copyright
|
24
|
+
and Related Rights in the Work, voluntarily elects to apply CC0 to the Work
|
25
|
+
and publicly distribute the Work under its terms, with knowledge of his or her
|
26
|
+
Copyright and Related Rights in the Work and the meaning and intended legal
|
27
|
+
effect of CC0 on those rights.
|
28
|
+
|
29
|
+
1. Copyright and Related Rights. A Work made available under CC0 may be
|
30
|
+
protected by copyright and related or neighboring rights ("Copyright and
|
31
|
+
Related Rights"). Copyright and Related Rights include, but are not limited
|
32
|
+
to, the following:
|
33
|
+
|
34
|
+
i. the right to reproduce, adapt, distribute, perform, display, communicate,
|
35
|
+
and translate a Work;
|
36
|
+
|
37
|
+
ii. moral rights retained by the original author(s) and/or performer(s);
|
38
|
+
|
39
|
+
iii. publicity and privacy rights pertaining to a person's image or likeness
|
40
|
+
depicted in a Work;
|
41
|
+
|
42
|
+
iv. rights protecting against unfair competition in regards to a Work,
|
43
|
+
subject to the limitations in paragraph 4(a), below;
|
44
|
+
|
45
|
+
v. rights protecting the extraction, dissemination, use and reuse of data in
|
46
|
+
a Work;
|
47
|
+
|
48
|
+
vi. database rights (such as those arising under Directive 96/9/EC of the
|
49
|
+
European Parliament and of the Council of 11 March 1996 on the legal
|
50
|
+
protection of databases, and under any national implementation thereof,
|
51
|
+
including any amended or successor version of such directive); and
|
52
|
+
|
53
|
+
vii. other similar, equivalent or corresponding rights throughout the world
|
54
|
+
based on applicable law or treaty, and any national implementations thereof.
|
55
|
+
|
56
|
+
2. Waiver. To the greatest extent permitted by, but not in contravention of,
|
57
|
+
applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and
|
58
|
+
unconditionally waives, abandons, and surrenders all of Affirmer's Copyright
|
59
|
+
and Related Rights and associated claims and causes of action, whether now
|
60
|
+
known or unknown (including existing as well as future claims and causes of
|
61
|
+
action), in the Work (i) in all territories worldwide, (ii) for the maximum
|
62
|
+
duration provided by applicable law or treaty (including future time
|
63
|
+
extensions), (iii) in any current or future medium and for any number of
|
64
|
+
copies, and (iv) for any purpose whatsoever, including without limitation
|
65
|
+
commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes
|
66
|
+
the Waiver for the benefit of each member of the public at large and to the
|
67
|
+
detriment of Affirmer's heirs and successors, fully intending that such Waiver
|
68
|
+
shall not be subject to revocation, rescission, cancellation, termination, or
|
69
|
+
any other legal or equitable action to disrupt the quiet enjoyment of the Work
|
70
|
+
by the public as contemplated by Affirmer's express Statement of Purpose.
|
71
|
+
|
72
|
+
3. Public License Fallback. Should any part of the Waiver for any reason be
|
73
|
+
judged legally invalid or ineffective under applicable law, then the Waiver
|
74
|
+
shall be preserved to the maximum extent permitted taking into account
|
75
|
+
Affirmer's express Statement of Purpose. In addition, to the extent the Waiver
|
76
|
+
is so judged Affirmer hereby grants to each affected person a royalty-free,
|
77
|
+
non transferable, non sublicensable, non exclusive, irrevocable and
|
78
|
+
unconditional license to exercise Affirmer's Copyright and Related Rights in
|
79
|
+
the Work (i) in all territories worldwide, (ii) for the maximum duration
|
80
|
+
provided by applicable law or treaty (including future time extensions), (iii)
|
81
|
+
in any current or future medium and for any number of copies, and (iv) for any
|
82
|
+
purpose whatsoever, including without limitation commercial, advertising or
|
83
|
+
promotional purposes (the "License"). The License shall be deemed effective as
|
84
|
+
of the date CC0 was applied by Affirmer to the Work. Should any part of the
|
85
|
+
License for any reason be judged legally invalid or ineffective under
|
86
|
+
applicable law, such partial invalidity or ineffectiveness shall not
|
87
|
+
invalidate the remainder of the License, and in such case Affirmer hereby
|
88
|
+
affirms that he or she will not (i) exercise any of his or her remaining
|
89
|
+
Copyright and Related Rights in the Work or (ii) assert any associated claims
|
90
|
+
and causes of action with respect to the Work, in either case contrary to
|
91
|
+
Affirmer's express Statement of Purpose.
|
92
|
+
|
93
|
+
4. Limitations and Disclaimers.
|
94
|
+
|
95
|
+
a. No trademark or patent rights held by Affirmer are waived, abandoned,
|
96
|
+
surrendered, licensed or otherwise affected by this document.
|
97
|
+
|
98
|
+
b. Affirmer offers the Work as-is and makes no representations or warranties
|
99
|
+
of any kind concerning the Work, express, implied, statutory or otherwise,
|
100
|
+
including without limitation warranties of title, merchantability, fitness
|
101
|
+
for a particular purpose, non infringement, or the absence of latent or
|
102
|
+
other defects, accuracy, or the present or absence of errors, whether or not
|
103
|
+
discoverable, all to the greatest extent permissible under applicable law.
|
104
|
+
|
105
|
+
c. Affirmer disclaims responsibility for clearing rights of other persons
|
106
|
+
that may apply to the Work or any use thereof, including without limitation
|
107
|
+
any person's Copyright and Related Rights in the Work. Further, Affirmer
|
108
|
+
disclaims responsibility for obtaining any necessary consents, permissions
|
109
|
+
or other rights required for any use of the Work.
|
110
|
+
|
111
|
+
d. Affirmer understands and acknowledges that Creative Commons is not a
|
112
|
+
party to this document and has no duty or obligation with respect to this
|
113
|
+
CC0 or use of the Work.
|
114
|
+
|
115
|
+
For more information, please see
|
116
|
+
<http://creativecommons.org/publicdomain/zero/1.0/>
|
data/Manifest.txt
CHANGED
data/README.md
CHANGED
@@ -1 +1,335 @@
|
|
1
1
|
# Almost Sinatra
|
2
|
+
|
3
|
+
|
4
|
+
## What's Sinatra?
|
5
|
+
|
6
|
+
Simple (yet powerful and flexible) micro webframework.
|
7
|
+
|
8
|
+
``` ruby
|
9
|
+
require 'sinatra'
|
10
|
+
|
11
|
+
get '/' do
|
12
|
+
'Hallo Vienna! Servus Wien!'
|
13
|
+
end
|
14
|
+
```
|
15
|
+
|
16
|
+
Trivia Quiz - How Many Lines of Ruby Code?
|
17
|
+
|
18
|
+
- (A) 20 Lines
|
19
|
+
- (B) 200 Lines
|
20
|
+
- (C) 2 000 Lines
|
21
|
+
- (D) 20 000 Lines
|
22
|
+
|
23
|
+
|
24
|
+
## What's Almost Sinatra?
|
25
|
+
|
26
|
+
Sinatra refactored, only six lines now. A hack by Konstantin Haase.
|
27
|
+
|
28
|
+
[almost_sinatra.rb](https://github.com/rkh/almost-sinatra/blob/master/almost_sinatra.rb):
|
29
|
+
|
30
|
+
``` ruby
|
31
|
+
%w.rack tilt date INT TERM..map{|l|trap(l){$r.stop}rescue require l};$u=Date;$z=($u.new.year + 145).abs;puts "== Almost Sinatra/No Version has taken the stage on #$z for development with backup from Webrick"
|
32
|
+
$n=Module.new{extend Rack;a,D,S,q=Rack::Builder.new,Object.method(:define_method),/@@ *([^\n]+)\n(((?!@@)[^\n]*\n)*)/m
|
33
|
+
%w[get post put delete].map{|m|D.(m){|u,&b|a.map(u){run->(e){[200,{"Content-Type"=>"text/html"},[a.instance_eval(&b)]]}}}}
|
34
|
+
Tilt.mappings.map{|k,v|D.(k){|n,*o|$t||=(h=$u._jisx0301("hash, please");File.read(caller[0][/^[^:]+/]).scan(S){|a,b|h[a]=b};h);v[0].new(*o){n=="#{n}"?n:$t[n.to_s]}.render(a,o[0].try(:[],:locals)||{})}}
|
35
|
+
%w[set enable disable configure helpers use register].map{|m|D.(m){|*_,&b|b.try :[]}};END{Rack::Handler.get("webrick").run(a,Port:$z){|s|$r=s}}
|
36
|
+
%w[params session].map{|m|D.(m){q.send m}};a.use Rack::Session::Cookie;a.use Rack::Lock;D.(:before){|&b|a.use Rack::Config,&b};before{|e|q=Rack::Request.new e;q.params.dup.map{|k,v|params[k.to_sym]=v}}}
|
37
|
+
```
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
## Almost Sinatra - A Breakdown Line by Line
|
42
|
+
|
43
|
+
### Line 1/6
|
44
|
+
|
45
|
+
(Like) Sinatra = Rack + Tilt
|
46
|
+
|
47
|
+
Line 1:
|
48
|
+
|
49
|
+
``` ruby
|
50
|
+
%w.rack tilt date INT TERM..map{|l|trap(l){$r.stop}rescue require l};$u=Date;$z=($u.new.year + 145).abs;puts "== Almost Sinatra/No Version has taken the stage on #$z for development with backup from Webrick"
|
51
|
+
```
|
52
|
+
|
53
|
+
Breakdown:
|
54
|
+
|
55
|
+
```
|
56
|
+
require 'rack'
|
57
|
+
require 'tilt'
|
58
|
+
|
59
|
+
trap( 'INT' ) { $server.stop } # rename $r to $server
|
60
|
+
trap( 'TERM' ) { $server.stop }
|
61
|
+
|
62
|
+
$port = 4567 # rename $z to $port
|
63
|
+
|
64
|
+
puts "== Almost Sinatra has taken the stage on #{$port} for development with backup from Webrick"
|
65
|
+
```
|
66
|
+
|
67
|
+
|
68
|
+
**Aside - What's rack?**
|
69
|
+
|
70
|
+
Lets you mix 'n' match servers and apps.
|
71
|
+
|
72
|
+
Lets you stack apps inside apps inside apps inside apps inside apps.
|
73
|
+
|
74
|
+
Good News: A Sinatra app is a Rack app.
|
75
|
+
|
76
|
+
Learn more about Rack @ [`rack.github.io`](http://rack.github.io).
|
77
|
+
|
78
|
+
|
79
|
+
|
80
|
+
**Aside - What's tilt?**
|
81
|
+
|
82
|
+
|
83
|
+
Tilt offers a standard "generic" interface for template engines.
|
84
|
+
|
85
|
+
Let's check-up what formats and template engines tilt includes out-of-the-box:
|
86
|
+
|
87
|
+
``` ruby
|
88
|
+
require 'tilt'
|
89
|
+
|
90
|
+
Tilt.mappings.each do |ext, engines|
|
91
|
+
puts "#{ext.ljust(12)} : #{engines.inspect}"
|
92
|
+
end
|
93
|
+
```
|
94
|
+
|
95
|
+
Will result in:
|
96
|
+
|
97
|
+
``` ruby
|
98
|
+
str : [Tilt::StringTemplate]
|
99
|
+
erb : [Tilt::ErubisTemplate, Tilt::ERBTemplate]
|
100
|
+
rhtml : [Tilt::ErubisTemplate, Tilt::ERBTemplate]
|
101
|
+
erubis : [Tilt::ErubisTemplate]
|
102
|
+
etn : [Tilt::EtanniTemplate]
|
103
|
+
etanni : [Tilt::EtanniTemplate]
|
104
|
+
haml : [Tilt::HamlTemplate]
|
105
|
+
sass : [Tilt::SassTemplate]
|
106
|
+
scss : [Tilt::ScssTemplate]
|
107
|
+
less : [Tilt::LessTemplate]
|
108
|
+
rcsv : [Tilt::CSVTemplate]
|
109
|
+
coffee : [Tilt::CoffeeScriptTemplate]
|
110
|
+
nokogiri : [Tilt::NokogiriTemplate]
|
111
|
+
builder : [Tilt::BuilderTemplate]
|
112
|
+
mab : [Tilt::MarkabyTemplate]
|
113
|
+
liquid : [Tilt::LiquidTemplate]
|
114
|
+
radius : [Tilt::RadiusTemplate]
|
115
|
+
markdown : [Tilt::RedcarpetTemplate, Tilt::RedcarpetTemplate::Redcarpet2, Tilt::RedcarpetTemplate::Redcarpet1, Tilt::RDiscountTemplate, Tilt::BlueClothTemplate, Tilt::KramdownTemplate, Tilt::MarukuTemplate]
|
116
|
+
mkd : [Tilt::RedcarpetTemplate, Tilt::RedcarpetTemplate::Redcarpet2, Tilt::RedcarpetTemplate::Redcarpet1, Tilt::RDiscountTemplate, Tilt::BlueClothTemplate, Tilt::KramdownTemplate, Tilt::MarukuTemplate]
|
117
|
+
md : [Tilt::RedcarpetTemplate, Tilt::RedcarpetTemplate::Redcarpet2, Tilt::RedcarpetTemplate::Redcarpet1, Tilt::RDiscountTemplate, Tilt::BlueClothTemplate, Tilt::KramdownTemplate, Tilt::MarukuTemplate]
|
118
|
+
textile : [Tilt::RedClothTemplate]
|
119
|
+
rdoc : [Tilt::RDocTemplate]
|
120
|
+
wiki : [Tilt::WikiClothTemplate, Tilt::CreoleTemplate]
|
121
|
+
creole : [Tilt::CreoleTemplate]
|
122
|
+
mediawiki : [Tilt::WikiClothTemplate]
|
123
|
+
mw : [Tilt::WikiClothTemplate]
|
124
|
+
yajl : [Tilt::YajlTemplate]
|
125
|
+
ad : [Tilt::AsciidoctorTemplate]
|
126
|
+
adoc : [Tilt::AsciidoctorTemplate]
|
127
|
+
asciidoc : [Tilt::AsciidoctorTemplate]
|
128
|
+
html : [Tilt::PlainTemplate]
|
129
|
+
```
|
130
|
+
|
131
|
+
|
132
|
+
### Line 2/6
|
133
|
+
|
134
|
+
Line 2:
|
135
|
+
|
136
|
+
``` ruby
|
137
|
+
$n=Module.new{extend Rack;a,D,S,q=Rack::Builder.new,Object.method(:define_method),/@@ *([^\n]+)\n(((?!@@)[^\n]*\n)*)/m
|
138
|
+
´´´
|
139
|
+
|
140
|
+
Breakdown:
|
141
|
+
|
142
|
+
´´´ ruby
|
143
|
+
$n = Module.new do
|
144
|
+
app = Rack::Builder.new # rename a to app
|
145
|
+
req = nil # rename q to req
|
146
|
+
´´´
|
147
|
+
|
148
|
+
|
149
|
+
### Line 3/6
|
150
|
+
|
151
|
+
Line 3:
|
152
|
+
|
153
|
+
``` ruby
|
154
|
+
%w[get post put delete].map{|m|D.(m){|u,&b|a.map(u){run->(e){[200,{"Content-Type"=>"text/html"},[a.instance_eval(&b)]]}}}}
|
155
|
+
```
|
156
|
+
|
157
|
+
Breakdown:
|
158
|
+
|
159
|
+
```
|
160
|
+
['get','post','put','delete'].each do |method|
|
161
|
+
define_method method do |path, &block|
|
162
|
+
app.map( path ) do
|
163
|
+
run ->(env){ [200, {'Content-Type'=>'text/html'}, [app.instance_eval( &block )]]}
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
```
|
168
|
+
|
169
|
+
|
170
|
+
### Line 4/6
|
171
|
+
|
172
|
+
Line 4:
|
173
|
+
|
174
|
+
``` ruby
|
175
|
+
Tilt.mappings.map{|k,v|D.(k){|n,*o|$t||=(h=$u._jisx0301("hash, please");File.read(caller[0][/^[^:]+/]).scan(S){|a,b|h[a]=b};h);v[0].new(*o){n=="#{n}"?n:$t[n.to_s]}.render(a,o[0].try(:[],:locals)||{})}}
|
176
|
+
```
|
177
|
+
|
178
|
+
Breakdown:
|
179
|
+
|
180
|
+
``` ruby
|
181
|
+
Tilt.mappings.each do |ext, engines| # rename k to ext and v to engines
|
182
|
+
define_method ext do |text, *args| # rename n to text and o to args
|
183
|
+
template = engines[0].new(*args) do
|
184
|
+
text
|
185
|
+
end
|
186
|
+
locals = (args[0].respond_to?(:[]) ? args[0][:locals] : nil) || {} # was o[0].try(:[],:locals)||{}
|
187
|
+
template.render( app, locals )
|
188
|
+
end
|
189
|
+
end
|
190
|
+
```
|
191
|
+
|
192
|
+
Commentary: Almost Sinatra will define a method for every format so you can use, for example:
|
193
|
+
|
194
|
+
```
|
195
|
+
markdown "Strong emphasis, aka bold, with **asterisks** or __underscores__."
|
196
|
+
```
|
197
|
+
|
198
|
+
or
|
199
|
+
|
200
|
+
```
|
201
|
+
erb "Hello <%= name %>!", locals: { name: params['name'] }
|
202
|
+
```
|
203
|
+
|
204
|
+
|
205
|
+
|
206
|
+
### Line 5/6
|
207
|
+
|
208
|
+
Line 5:
|
209
|
+
|
210
|
+
``` ruby
|
211
|
+
%w[set enable disable configure helpers use register].map{|m|D.(m){|*_,&b|b.try :[]}};END{Rack::Handler.get("webrick").run(a,Port:$z){|s|$r=s}}
|
212
|
+
```
|
213
|
+
|
214
|
+
Breakdown:
|
215
|
+
|
216
|
+
```
|
217
|
+
# was END { ... }; change to run! method
|
218
|
+
define_method 'run!' do
|
219
|
+
Rack::Handler.get('webrick').run( app, Port:$port ) {|server| $server=server }
|
220
|
+
end
|
221
|
+
```
|
222
|
+
|
223
|
+
|
224
|
+
### Line 6/6
|
225
|
+
|
226
|
+
Line 6:
|
227
|
+
|
228
|
+
``` ruby
|
229
|
+
%w[params session].map{|m|D.(m){q.send m}};a.use Rack::Session::Cookie;a.use Rack::Lock;D.(:before){|&b|a.use Rack::Config,&b};before{|e|q=Rack::Request.new e;q.params.dup.map{|k,v|params[k.to_sym]=v}}}
|
230
|
+
```
|
231
|
+
|
232
|
+
Breakdown:
|
233
|
+
|
234
|
+
``` ruby
|
235
|
+
['params','session'].each do |method|
|
236
|
+
define_method method do
|
237
|
+
req.send method
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
app.use Rack::Session::Cookie
|
242
|
+
app.use Rack::Lock
|
243
|
+
app.use Rack::Config do |env|
|
244
|
+
req = Rack::Request.new( env )
|
245
|
+
end
|
246
|
+
end # Module.new
|
247
|
+
```
|
248
|
+
|
249
|
+
|
250
|
+
## The Proof of the Pudding - hello.rb
|
251
|
+
|
252
|
+
`samples/hello.rb`:
|
253
|
+
|
254
|
+
``` ruby
|
255
|
+
require 'almost-sinatra'
|
256
|
+
|
257
|
+
include $n # include "anonymous" Almost Sinatra DSL module
|
258
|
+
|
259
|
+
get '/hello' do
|
260
|
+
erb "Hello <%%= name %>!", locals: { name: params['name'] }
|
261
|
+
end
|
262
|
+
|
263
|
+
get '/' do
|
264
|
+
markdown <<EOS
|
265
|
+
## Welcome to Almost Sinatra
|
266
|
+
|
267
|
+
A six line ruby hack by Konstantin Haase.
|
268
|
+
|
269
|
+
Try:
|
270
|
+
- [Say hello!](/hello?name=Nancy)
|
271
|
+
|
272
|
+
Powered by Almost Sinatra (#{Time.now})
|
273
|
+
EOS
|
274
|
+
end
|
275
|
+
|
276
|
+
|
277
|
+
run!
|
278
|
+
```
|
279
|
+
|
280
|
+
Use
|
281
|
+
|
282
|
+
```
|
283
|
+
$ ruby -I ./lib ./samples/hello.rb
|
284
|
+
```
|
285
|
+
|
286
|
+
|
287
|
+
## Got Inspired? Build Your Own Microframework
|
288
|
+
|
289
|
+
- New York, New York
|
290
|
+
- Nancy
|
291
|
+
- Rum
|
292
|
+
- Cuba
|
293
|
+
- Roda
|
294
|
+
- and many more
|
295
|
+
|
296
|
+
|
297
|
+
## Real World Case Study - webservice gem - (Yet Another) HTTP JSON API (Web Service) Builder
|
298
|
+
|
299
|
+
Micro "framework" for building HTTP JSON APIs (about 100 lines of code).
|
300
|
+
Example:
|
301
|
+
|
302
|
+
``` ruby
|
303
|
+
get '/beer/:key' do
|
304
|
+
Beer.find_by_key!( params[ :key ] )
|
305
|
+
end
|
306
|
+
|
307
|
+
get '/brewery/:key' do
|
308
|
+
Brewery.find_by_key!( params[ :key ] )
|
309
|
+
end
|
310
|
+
```
|
311
|
+
|
312
|
+
|
313
|
+
## Links, Links, Links
|
314
|
+
|
315
|
+
- Article :: [Decoding Almost Sinatra](https://robm.me.uk/2013/12/13/decoding-almost-sinatra.html), by Rob Miller
|
316
|
+
- Article :: [Code Safari: Almost Sinatra, Almost Readable](http://www.sitepoint.com/code-safari-almost-sinatra-almost-readable/), by Xavier Shay
|
317
|
+
- Article :: [tilt gem - let's build (yet another) micro web framework in less than 33 lines of code](http://planetruby.github.io/gems/tilt.html), by Gerald Bauer
|
318
|
+
|
319
|
+
|
320
|
+
|
321
|
+
## Bonus: Fun Almost Sinatra Obfuscation Hacks
|
322
|
+
|
323
|
+
"Calculate" the Sinatra Port 4567:
|
324
|
+
|
325
|
+
```
|
326
|
+
(Date.new.year + 145).abs # Date.new.year always returns -4712, the default value for years
|
327
|
+
# => 4567
|
328
|
+
```
|
329
|
+
|
330
|
+
"Get" empty Hash (e.g. `{}`):
|
331
|
+
|
332
|
+
```
|
333
|
+
Date._jisx0301("hash, please")
|
334
|
+
# => {}
|
335
|
+
```
|
data/Rakefile
CHANGED
@@ -2,7 +2,7 @@ require 'hoe'
|
|
2
2
|
|
3
3
|
Hoe.spec 'almost-sinatra' do
|
4
4
|
|
5
|
-
self.version = '
|
5
|
+
self.version = '1.0.0'
|
6
6
|
|
7
7
|
self.summary = 'almost-sinatra - six lines of almost sinatra refactored and bundled up for easy (re)use - build your own webframework from scratch with rack and tilt'
|
8
8
|
self.description = summary
|
@@ -17,8 +17,8 @@ Hoe.spec 'almost-sinatra' do
|
|
17
17
|
self.history_file = 'HISTORY.md'
|
18
18
|
|
19
19
|
self.extra_deps = [
|
20
|
-
['rack' ],
|
21
|
-
['tilt' ],
|
20
|
+
['rack', '>= 2.0' ],
|
21
|
+
['tilt', '>= 2.0' ],
|
22
22
|
]
|
23
23
|
|
24
24
|
self.licenses = ['Public Domain']
|
data/lib/almost-sinatra.rb
CHANGED
@@ -70,9 +70,10 @@ $n = Module.new do
|
|
70
70
|
# Line 4:
|
71
71
|
# Tilt.mappings.map{|k,v|D.(k){|n,*o|$t||=(h=$u._jisx0301("hash, please");File.read(caller[0][/^[^:]+/]).scan(S){|a,b|h[a]=b};h);v[0].new(*o){n=="#{n}"?n:$t[n.to_s]}.render(a,o[0].try(:[],:locals)||{})}}
|
72
72
|
|
73
|
-
Tilt.
|
74
|
-
define_method ext do |text, *args|
|
75
|
-
|
73
|
+
Tilt.default_mapping.lazy_map.each do |ext, engines| # rename k to ext and v to engines
|
74
|
+
define_method ext do |text, *args|
|
75
|
+
# rename n to text and o to args
|
76
|
+
template = Kernel.const_get(engines[0][0]).new(*args) do
|
76
77
|
text
|
77
78
|
end
|
78
79
|
locals = (args[0].respond_to?(:[]) ? args[0][:locals] : nil) || {} # was o[0].try(:[],:locals)||{}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: almost-sinatra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Konstantin Haase
|
@@ -17,28 +17,28 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: '0'
|
20
|
+
version: '2.0'
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: '0'
|
27
|
+
version: '2.0'
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: tilt
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
32
|
- - ">="
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: '0'
|
34
|
+
version: '2.0'
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
39
|
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version: '0'
|
41
|
+
version: '2.0'
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: rdoc
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -74,10 +74,12 @@ executables: []
|
|
74
74
|
extensions: []
|
75
75
|
extra_rdoc_files:
|
76
76
|
- HISTORY.md
|
77
|
+
- LICENSE.md
|
77
78
|
- Manifest.txt
|
78
79
|
- README.md
|
79
80
|
files:
|
80
81
|
- HISTORY.md
|
82
|
+
- LICENSE.md
|
81
83
|
- Manifest.txt
|
82
84
|
- README.md
|
83
85
|
- Rakefile
|