almost-sinatra 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e893991c5706400658705b56a665b65727bdbb4c
4
+ data.tar.gz: 6a013d524a66d24d7b065b32b8fea6a6dd56d3c4
5
+ SHA512:
6
+ metadata.gz: ad0e291fee7da826346f6c0569e3e144cd533bb373e6d1424e3e433ae6fb392c40da01fa9376e772586163631a82ba2f5fbd3d0b3d88f3c500ec150311291c44
7
+ data.tar.gz: c5431ba712ded1e434510410ed8ca8211b113dffd5c38c5bb26c10bb3e2ec4959e9be9cf8e67640f4729580c121418fd31957ceb3f4408236fee01a58295587e
@@ -0,0 +1,3 @@
1
+ ### 1.0.0 / 2017-12-05
2
+
3
+ * Everything is new. First release.
@@ -0,0 +1,5 @@
1
+ HISTORY.md
2
+ Manifest.txt
3
+ README.md
4
+ Rakefile
5
+ lib/almost-sinatra.rb
@@ -0,0 +1 @@
1
+ # Almost Sinatra
@@ -0,0 +1,30 @@
1
+ require 'hoe'
2
+
3
+ Hoe.spec 'almost-sinatra' do
4
+
5
+ self.version = '0.1.0'
6
+
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
+ self.description = summary
9
+
10
+ self.urls = ['https://github.com/rubylibs/almost-sinatra']
11
+
12
+ self.author = ['Konstantin Haase', 'Gerald Bauer']
13
+ self.email = 'ruby-talk@ruby-lang.org'
14
+
15
+ # switch extension to .markdown for gihub formatting
16
+ self.readme_file = 'README.md'
17
+ self.history_file = 'HISTORY.md'
18
+
19
+ self.extra_deps = [
20
+ ['rack' ],
21
+ ['tilt' ],
22
+ ]
23
+
24
+ self.licenses = ['Public Domain']
25
+
26
+ self.spec_extras = {
27
+ required_ruby_version: '>= 2.3'
28
+ }
29
+
30
+ end
@@ -0,0 +1,113 @@
1
+ # encoding: utf-8
2
+
3
+
4
+ ###
5
+ # almost_sinatra.rb
6
+ # -- Sinatra refactored, only six lines now. A hack by Konstantin Haase.
7
+ # see https://github.com/rkh/almost-sinatra/blob/master/almost_sinatra.rb
8
+ #
9
+ # e.g.
10
+ #
11
+ # %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"
12
+ # $n=Module.new{extend Rack;a,D,S,q=Rack::Builder.new,Object.method(:define_method),/@@ *([^\n]+)\n(((?!@@)[^\n]*\n)*)/m
13
+ # %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)]]}}}}
14
+ # 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)||{})}}
15
+ # %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}}
16
+ # %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}}}
17
+ #
18
+ #
19
+ # Why? Why? Why?
20
+ #
21
+ # > Until programmers stop acting like obfuscation is morally hazardous,
22
+ # > they're not artists, just kids who don’t want their food to touch.
23
+ # > -- \_why
24
+
25
+
26
+
27
+
28
+ # Almost Sinatra - A Breakdown - Line 1/6
29
+ #
30
+ # Line 1:
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
+
33
+ require 'rack'
34
+ require 'tilt'
35
+
36
+ trap( 'INT' ) { $server.stop } # rename $r to $server
37
+ trap( 'TERM' ) { $server.stop }
38
+
39
+ $port = 4567 # rename $z to $port
40
+
41
+ puts "== Almost Sinatra has taken the stage on #{$port} for development with backup from Webrick"
42
+
43
+
44
+ # Almost Sinatra - A Breakdown - Line 2/6
45
+ #
46
+ # Line 2:
47
+ # $n=Module.new{extend Rack;a,D,S,q=Rack::Builder.new,Object.method(:define_method),/@@ *([^\n]+)\n(((?!@@)[^\n]*\n)*)/m
48
+
49
+ $n = Module.new do
50
+ app = Rack::Builder.new # rename a to app
51
+ req = nil # rename q to req
52
+
53
+
54
+ # Almost Sinatra - A Breakdown - Line 3/6
55
+ #
56
+ # Line 3:
57
+ # %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)]]}}}}
58
+
59
+ ['get','post','put','delete'].each do |method|
60
+ define_method method do |path, &block|
61
+ app.map( path ) do
62
+ run ->(env){ [200, {'Content-Type'=>'text/html'}, [app.instance_eval( &block )]]}
63
+ end
64
+ end
65
+ end
66
+
67
+
68
+ # Almost Sinatra - A Breakdown - Line 4/6
69
+ #
70
+ # Line 4:
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
+
73
+ Tilt.mappings.each do |ext, engines| # rename k to ext and v to engines
74
+ define_method ext do |text, *args| # rename n to text and o to args
75
+ template = engines[0].new(*args) do
76
+ text
77
+ end
78
+ locals = (args[0].respond_to?(:[]) ? args[0][:locals] : nil) || {} # was o[0].try(:[],:locals)||{}
79
+ template.render( app, locals )
80
+ end
81
+ end
82
+
83
+
84
+
85
+
86
+ # Almost Sinatra - A Breakdown - Line 5/6
87
+ #
88
+ # Line 5:
89
+ # %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}}
90
+
91
+ # was END { ... }; change to run! method
92
+ define_method 'run!' do
93
+ Rack::Handler.get('webrick').run( app, Port:$port ) {|server| $server=server }
94
+ end
95
+
96
+
97
+ # Almost Sinatra - A Breakdown - Line 6/6
98
+ #
99
+ # Line 6:
100
+ # %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}}}
101
+
102
+ ['params','session'].each do |method|
103
+ define_method method do
104
+ req.send method
105
+ end
106
+ end
107
+
108
+ app.use Rack::Session::Cookie
109
+ app.use Rack::Lock
110
+ app.use Rack::Config do |env|
111
+ req = Rack::Request.new( env )
112
+ end
113
+ end # Module.new
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: almost-sinatra
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Konstantin Haase
8
+ - Gerald Bauer
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2017-12-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rack
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: tilt
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rdoc
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '4.0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '4.0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: hoe
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '3.16'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '3.16'
70
+ description: almost-sinatra - six lines of almost sinatra refactored and bundled up
71
+ for easy (re)use - build your own webframework from scratch with rack and tilt
72
+ email: ruby-talk@ruby-lang.org
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files:
76
+ - HISTORY.md
77
+ - Manifest.txt
78
+ - README.md
79
+ files:
80
+ - HISTORY.md
81
+ - Manifest.txt
82
+ - README.md
83
+ - Rakefile
84
+ - lib/almost-sinatra.rb
85
+ homepage: https://github.com/rubylibs/almost-sinatra
86
+ licenses:
87
+ - Public Domain
88
+ metadata: {}
89
+ post_install_message:
90
+ rdoc_options:
91
+ - "--main"
92
+ - README.md
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '2.3'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.5.2
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: almost-sinatra - six lines of almost sinatra refactored and bundled up for
111
+ easy (re)use - build your own webframework from scratch with rack and tilt
112
+ test_files: []