zorglub 0.0.9 → 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.
- checksums.yaml +5 -5
- data/Gemfile.lock +49 -34
- data/lib/zorglub.rb +4 -4
- data/lib/zorglub/app.rb +27 -31
- data/lib/zorglub/engines/file.rb +3 -3
- data/lib/zorglub/engines/haml.rb +3 -3
- data/lib/zorglub/engines/sass.rb +3 -3
- data/lib/zorglub/node.rb +75 -77
- data/lib/zorglub/rack_session.rb +1 -5
- data/lib/zorglub/session.rb +27 -31
- data/spec/app_spec.rb +21 -21
- data/spec/node_spec.rb +162 -154
- data/spec/spec_helper.rb +30 -25
- data/zorglub.gemspec +4 -4
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: '0219f50bb07d3009172295d5a5dab9c055cd379475d9a4d292f4938459c4fb8f'
|
4
|
+
data.tar.gz: 224611e8b174fcf26fbd27e2e72beb80adb8562ce9d945a699bbc76fbd976e73
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f532761158fdb87b7dbd38eb12882158bbab72a4551861c02a7c88a2776f25ecc455c026ec675198853aee6423bcdfcaeca7f3e17a323fc82deff4a629362251
|
7
|
+
data.tar.gz: 660122838f1de84f1ab75ae0788ea8160ba47be3fa3d3f8d3bf9d7fce3ae12270cc704a6b2eae3669a154aac9d33809d1e7a466669eac7d6e6256c22b70e3e9b
|
data/Gemfile.lock
CHANGED
@@ -1,46 +1,58 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
zorglub (0.0
|
4
|
+
zorglub (0.1.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: http://rubygems.org/
|
8
8
|
specs:
|
9
|
-
coveralls (0.
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
diff-lcs (1.
|
16
|
-
docile (1.1
|
17
|
-
|
9
|
+
coveralls (0.8.22)
|
10
|
+
json (>= 1.8, < 3)
|
11
|
+
simplecov (~> 0.16.1)
|
12
|
+
term-ansicolor (~> 1.3)
|
13
|
+
thor (~> 0.19.4)
|
14
|
+
tins (~> 1.6)
|
15
|
+
diff-lcs (1.3)
|
16
|
+
docile (1.3.1)
|
17
|
+
ffi (1.9.25)
|
18
|
+
haml (5.0.4)
|
19
|
+
temple (>= 0.8.0)
|
18
20
|
tilt
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
rspec (
|
26
|
-
rspec-core (~>
|
27
|
-
rspec-expectations (~>
|
28
|
-
rspec-mocks (~>
|
29
|
-
rspec-core (
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
21
|
+
json (2.1.0)
|
22
|
+
rack (2.0.6)
|
23
|
+
rake (12.3.2)
|
24
|
+
rb-fsevent (0.10.3)
|
25
|
+
rb-inotify (0.10.0)
|
26
|
+
ffi (~> 1.0)
|
27
|
+
rspec (3.8.0)
|
28
|
+
rspec-core (~> 3.8.0)
|
29
|
+
rspec-expectations (~> 3.8.0)
|
30
|
+
rspec-mocks (~> 3.8.0)
|
31
|
+
rspec-core (3.8.0)
|
32
|
+
rspec-support (~> 3.8.0)
|
33
|
+
rspec-expectations (3.8.2)
|
34
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
35
|
+
rspec-support (~> 3.8.0)
|
36
|
+
rspec-mocks (3.8.0)
|
37
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
38
|
+
rspec-support (~> 3.8.0)
|
39
|
+
rspec-support (3.8.0)
|
40
|
+
sass (3.7.2)
|
41
|
+
sass-listen (~> 4.0.0)
|
42
|
+
sass-listen (4.0.0)
|
43
|
+
rb-fsevent (~> 0.9, >= 0.9.4)
|
44
|
+
rb-inotify (~> 0.9, >= 0.9.7)
|
45
|
+
simplecov (0.16.1)
|
46
|
+
docile (~> 1.1)
|
47
|
+
json (>= 1.8, < 3)
|
48
|
+
simplecov-html (~> 0.10.0)
|
49
|
+
simplecov-html (0.10.2)
|
50
|
+
temple (0.8.0)
|
51
|
+
term-ansicolor (1.7.0)
|
40
52
|
tins (~> 1.0)
|
41
|
-
thor (0.
|
42
|
-
tilt (2.0.
|
43
|
-
tins (1.
|
53
|
+
thor (0.19.4)
|
54
|
+
tilt (2.0.9)
|
55
|
+
tins (1.20.2)
|
44
56
|
|
45
57
|
PLATFORMS
|
46
58
|
ruby
|
@@ -53,3 +65,6 @@ DEPENDENCIES
|
|
53
65
|
rspec
|
54
66
|
sass
|
55
67
|
zorglub!
|
68
|
+
|
69
|
+
BUNDLED WITH
|
70
|
+
1.17.3
|
data/lib/zorglub.rb
CHANGED
data/lib/zorglub/app.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# -*- coding: UTF-8 -*-
|
2
|
-
|
2
|
+
|
3
3
|
require 'rack'
|
4
|
-
|
4
|
+
|
5
5
|
module Zorglub
|
6
|
-
|
6
|
+
|
7
7
|
class App < Rack::URLMap
|
8
|
-
|
8
|
+
|
9
9
|
def initialize map={}, &block
|
10
10
|
super
|
11
11
|
@map = map
|
@@ -22,7 +22,6 @@ module Zorglub
|
|
22
22
|
:engines => { },
|
23
23
|
:haml_options => {
|
24
24
|
:format => :html5,
|
25
|
-
:ugly => false,
|
26
25
|
:encoding => 'utf-8'
|
27
26
|
},
|
28
27
|
:sass_options => {
|
@@ -40,9 +39,9 @@ module Zorglub
|
|
40
39
|
instance_eval &block if block_given?
|
41
40
|
remap @map
|
42
41
|
end
|
43
|
-
|
42
|
+
|
44
43
|
attr_reader :engines_cache
|
45
|
-
|
44
|
+
|
46
45
|
def map location, object
|
47
46
|
return unless location and object
|
48
47
|
raise Exception.new "#{@map[location]} already mapped to #{location}" if @map.has_key? location
|
@@ -50,67 +49,64 @@ module Zorglub
|
|
50
49
|
@map.merge! location.to_s=>object
|
51
50
|
remap @map
|
52
51
|
end
|
53
|
-
|
52
|
+
|
54
53
|
def delete location
|
55
54
|
@map.delete location
|
56
55
|
remap @map
|
57
56
|
end
|
58
|
-
|
57
|
+
|
59
58
|
def at location
|
60
59
|
@map[location]
|
61
60
|
end
|
62
|
-
|
61
|
+
|
63
62
|
def to object
|
64
63
|
@map.invert[object]
|
65
64
|
end
|
66
|
-
|
65
|
+
|
67
66
|
def to_hash
|
68
67
|
@map.dup
|
69
68
|
end
|
70
|
-
|
69
|
+
|
71
70
|
# OPTIONS @options
|
72
|
-
|
71
|
+
|
73
72
|
def opt sym
|
74
73
|
@options[sym]
|
75
74
|
end
|
76
|
-
|
75
|
+
|
77
76
|
def opt! sym, val
|
78
77
|
@options[sym] = val
|
79
78
|
end
|
80
|
-
|
79
|
+
|
81
80
|
def register_engine! name, ext, proc
|
82
|
-
return unless name
|
83
81
|
if ext.nil? or ext.empty?
|
84
82
|
x = nil
|
85
83
|
else
|
86
|
-
x = (ext[0]=='.' ? (ext.length==1 ? nil : ext) : '.'+ext)
|
84
|
+
x = (ext[0]=='.' ? (ext.length==1 ? nil : ext) : '.' + ext)
|
87
85
|
end
|
88
86
|
@options[:engines][name]=[ proc, x ]
|
89
87
|
end
|
90
|
-
|
88
|
+
|
91
89
|
def engine_proc_ext engine, ext
|
92
90
|
p,x = @options[:engines][engine]
|
93
91
|
return [nil, ''] if p.nil?
|
94
92
|
[ p, ((ext.nil? or ext.empty?) ? x : ext ) ]
|
95
93
|
end
|
96
|
-
|
94
|
+
|
97
95
|
def view_base_path
|
98
|
-
|
99
|
-
( p.nil? ? File.join(@options[:root], @options[:view_dir]) : p )
|
96
|
+
_base_path @options[:view_path], :view_dir
|
100
97
|
end
|
101
|
-
|
98
|
+
|
102
99
|
def layout_base_path
|
103
|
-
|
104
|
-
( p.nil? ? File.join(@options[:root], @options[:layout_dir]) : p )
|
100
|
+
_base_path @options[:layout_path], :layout_dir
|
105
101
|
end
|
106
|
-
|
102
|
+
|
107
103
|
def static_base_path
|
108
|
-
|
109
|
-
|
104
|
+
_base_path @options[:static_path], :static_dir
|
105
|
+
end
|
106
|
+
|
107
|
+
private
|
108
|
+
def _base_path p, sym
|
109
|
+
( p.nil? ? File.join(@options[:root], @options[sym]) : p )
|
110
110
|
end
|
111
|
-
#
|
112
111
|
end
|
113
|
-
#
|
114
112
|
end
|
115
|
-
#
|
116
|
-
# EOF
|
data/lib/zorglub/engines/file.rb
CHANGED
data/lib/zorglub/engines/haml.rb
CHANGED
data/lib/zorglub/engines/sass.rb
CHANGED
data/lib/zorglub/node.rb
CHANGED
@@ -1,175 +1,175 @@
|
|
1
1
|
# -*- coding: UTF-8 -*-
|
2
|
-
|
2
|
+
|
3
3
|
require 'fileutils'
|
4
|
-
|
4
|
+
|
5
5
|
module Zorglub
|
6
|
-
|
6
|
+
|
7
7
|
class Node
|
8
|
-
|
8
|
+
|
9
9
|
UNDEFINED=-1
|
10
|
-
|
10
|
+
|
11
11
|
# class level engine, layout, static, layout_base_path, view_base_path configuration
|
12
|
-
|
12
|
+
|
13
13
|
class << self
|
14
|
-
|
14
|
+
|
15
15
|
attr_reader :static, :cache_lifetime
|
16
|
-
|
16
|
+
|
17
17
|
def engine! engine
|
18
18
|
@engine = engine
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
def engine
|
22
22
|
@engine = @app.opt(:engine) if @engine==UNDEFINED and @app
|
23
23
|
@engine
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
def no_layout!
|
27
27
|
layout! nil
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
def layout! layout
|
31
31
|
@layout = layout
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
def layout
|
35
35
|
@layout = @app.opt(:layout) if @layout==UNDEFINED and @app
|
36
36
|
@layout
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
def static! val, lifetime=0
|
40
40
|
@static = ( (val==true or val==false) ? val : false )
|
41
41
|
@cache_lifetime = lifetime
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
def layout_base_path! path
|
45
45
|
@layout_base_path = path
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
def layout_base_path
|
49
49
|
@layout_base_path ||= @app.layout_base_path
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
def view_base_path! path
|
53
53
|
@view_base_path = path
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
def view_base_path
|
57
57
|
@view_base_path ||= @app.view_base_path
|
58
58
|
end
|
59
59
|
end
|
60
|
-
|
60
|
+
|
61
61
|
# instance level engine, layout, view, static configuration
|
62
|
-
|
62
|
+
|
63
63
|
def engine! engine
|
64
64
|
@engine = engine
|
65
65
|
end
|
66
|
-
|
66
|
+
|
67
67
|
def no_layout!
|
68
68
|
layout! nil
|
69
69
|
end
|
70
|
-
|
70
|
+
|
71
71
|
def layout! layout
|
72
72
|
@layout = layout
|
73
73
|
end
|
74
|
-
|
74
|
+
|
75
75
|
def layout
|
76
76
|
return nil if @layout.nil?
|
77
|
-
File.join(self.class.layout_base_path, @layout)+ext
|
77
|
+
File.join(self.class.layout_base_path, @layout) + ext
|
78
78
|
end
|
79
|
-
|
79
|
+
|
80
80
|
def no_view!
|
81
81
|
view! nil
|
82
82
|
end
|
83
|
-
|
83
|
+
|
84
84
|
def view! view
|
85
85
|
@view = view
|
86
86
|
end
|
87
|
-
|
87
|
+
|
88
88
|
def view
|
89
89
|
return nil if @view.nil?
|
90
|
-
File.join(self.class.view_base_path, @view)+ext
|
90
|
+
File.join(self.class.view_base_path, @view) + ext
|
91
91
|
end
|
92
|
-
|
92
|
+
|
93
93
|
def static! val, lifetime=0
|
94
94
|
@static = ( (val==true or val==false) ? val : false )
|
95
95
|
@cache_lifetime = lifetime
|
96
96
|
end
|
97
|
-
|
97
|
+
|
98
98
|
def static
|
99
99
|
return nil if not @static or @view.nil?
|
100
|
-
File.join(app.static_base_path, @view)+ext
|
100
|
+
File.join(app.static_base_path, @view) + ext
|
101
101
|
end
|
102
|
-
|
102
|
+
|
103
103
|
def ext! ext
|
104
|
-
@ext = ( (ext.nil? or ext.empty?) ? nil : (ext[0]=='.' ? (ext.length==1 ? nil : ext) : '.'+ext) )
|
104
|
+
@ext = ( (ext.nil? or ext.empty?) ? nil : (ext[0]=='.' ? (ext.length==1 ? nil : ext) : '.' + ext) )
|
105
105
|
end
|
106
|
-
|
106
|
+
|
107
107
|
def ext
|
108
108
|
@ext || ''
|
109
109
|
end
|
110
|
-
|
110
|
+
|
111
111
|
def mime! mime
|
112
112
|
@mime = mime
|
113
113
|
end
|
114
|
-
|
114
|
+
|
115
115
|
# class level basic node functions
|
116
|
-
|
116
|
+
|
117
117
|
class << self
|
118
|
-
|
118
|
+
|
119
119
|
attr_accessor :app
|
120
120
|
def map app, location
|
121
121
|
@app = app
|
122
122
|
@app.map location, self
|
123
123
|
end
|
124
|
-
|
124
|
+
|
125
125
|
def r *args
|
126
126
|
@r ||= @app.to self
|
127
127
|
(args.empty? ? @r : File.join( @r, args.map { |x| x.to_s } ) )
|
128
128
|
end
|
129
|
-
|
129
|
+
|
130
130
|
end
|
131
|
-
|
131
|
+
|
132
132
|
# instance level basic node functions
|
133
|
-
|
133
|
+
|
134
134
|
def app
|
135
135
|
self.class.app
|
136
136
|
end
|
137
|
-
|
137
|
+
|
138
138
|
def map
|
139
139
|
self.class.r
|
140
140
|
end
|
141
|
-
|
141
|
+
|
142
142
|
def r *args
|
143
143
|
File.join map, (args.empty? ? meth : args.map { |x| x.to_s } )
|
144
144
|
end
|
145
|
-
|
145
|
+
|
146
146
|
def html
|
147
147
|
[ :map, :r, :args, :engine, :layout, :view ].inject('') { |s,sym| s+="<p>#{sym} => #{self.send sym}</p>"; s }
|
148
148
|
end
|
149
|
-
|
149
|
+
|
150
150
|
def redirect target, options={}, &block
|
151
151
|
status = options[:status] || 302
|
152
152
|
body = options[:body] || redirect_body(target)
|
153
153
|
header = response.header.merge('Location' => target.to_s)
|
154
154
|
throw :stop_realize, Rack::Response.new(body, status, header, &block)
|
155
155
|
end
|
156
|
-
|
156
|
+
|
157
157
|
def redirect_body target
|
158
158
|
"You are being redirected, please follow this link to: <a href='#{target}'>#{target}</a>!"
|
159
159
|
end
|
160
|
-
|
160
|
+
|
161
161
|
# class level inherited values are key=>array, copied at inheritance
|
162
162
|
# so they can be extanded at class level
|
163
163
|
# values are copied from class into instance at object creation
|
164
164
|
# so that can be extanded without modifying class level values
|
165
165
|
# typical usage are css or js inclusions
|
166
|
-
|
166
|
+
|
167
167
|
@cli_vals = { }
|
168
|
-
|
168
|
+
|
169
169
|
class << self
|
170
|
-
|
170
|
+
|
171
171
|
attr_reader :cli_vals
|
172
|
-
|
172
|
+
|
173
173
|
def cli_val sym, *args
|
174
174
|
vals = @cli_vals[sym] ||= []
|
175
175
|
unless args.empty?
|
@@ -178,9 +178,9 @@ module Zorglub
|
|
178
178
|
end
|
179
179
|
vals
|
180
180
|
end
|
181
|
-
|
181
|
+
|
182
182
|
end
|
183
|
-
|
183
|
+
|
184
184
|
def cli_val sym, *args
|
185
185
|
vals = @cli_vals[sym] ||= []
|
186
186
|
unless args.empty?
|
@@ -189,44 +189,44 @@ module Zorglub
|
|
189
189
|
end
|
190
190
|
vals
|
191
191
|
end
|
192
|
-
|
192
|
+
|
193
193
|
# before_all and after_all hooks
|
194
|
-
|
194
|
+
|
195
195
|
@cli_vals[:before_all] = []
|
196
196
|
@cli_vals[:after_all] = []
|
197
197
|
class << self
|
198
|
-
|
198
|
+
|
199
199
|
def call_before_hooks obj
|
200
200
|
@cli_vals[:before_all].each do |blk| blk.call obj end
|
201
201
|
end
|
202
|
-
|
202
|
+
|
203
203
|
def before_all meth=nil, &blk
|
204
204
|
@cli_vals[:before_all]<< ( meth.nil? ? blk : meth )
|
205
205
|
@cli_vals[:before_all].uniq!
|
206
206
|
end
|
207
|
-
|
207
|
+
|
208
208
|
def call_after_hooks obj
|
209
209
|
@cli_vals[:after_all].each do |blk| blk.call obj end
|
210
210
|
end
|
211
|
-
|
211
|
+
|
212
212
|
def after_all meth=nil, &blk
|
213
213
|
@cli_vals[:after_all]<< ( meth.nil? ? blk : meth )
|
214
214
|
@cli_vals[:after_all].uniq!
|
215
215
|
end
|
216
|
-
|
216
|
+
|
217
217
|
end
|
218
|
-
|
218
|
+
|
219
219
|
# rack entry point, page computation methods
|
220
|
-
|
220
|
+
|
221
221
|
class << self
|
222
|
-
|
222
|
+
|
223
223
|
def inherited sub
|
224
224
|
sub.engine! ( engine || (self==Zorglub::Node ? UNDEFINED : nil ) )
|
225
225
|
sub.layout! ( layout || (self==Zorglub::Node ? UNDEFINED : nil ) )
|
226
226
|
sub.instance_variable_set :@cli_vals, {}
|
227
227
|
@cli_vals.each do |s,v| sub.cli_val s, *v end
|
228
228
|
end
|
229
|
-
|
229
|
+
|
230
230
|
def call env
|
231
231
|
meth, *args = env['PATH_INFO'].sub(/^\/+/,'').split(/\//)
|
232
232
|
meth ||= 'index'
|
@@ -235,14 +235,14 @@ module Zorglub
|
|
235
235
|
return error_404 node, meth if not node.respond_to? meth
|
236
236
|
node.realize!
|
237
237
|
end
|
238
|
-
|
238
|
+
|
239
239
|
def partial env, meth, *args
|
240
240
|
node = self.new env, meth.to_s, args, true
|
241
241
|
return error_404 node, meth if not node.respond_to? meth
|
242
242
|
node.feed! env[:no_hooks]
|
243
243
|
node.content
|
244
244
|
end
|
245
|
-
|
245
|
+
|
246
246
|
def error_404 node, meth
|
247
247
|
$stderr << " !! #{node.class.name}::#{meth} not found\n" if app.opt :debug
|
248
248
|
resp = node.response
|
@@ -251,11 +251,11 @@ module Zorglub
|
|
251
251
|
resp.write "%s mapped at %p can't respond to : %p" % [ node.class.name, node.map, node.meth ]
|
252
252
|
resp
|
253
253
|
end
|
254
|
-
|
254
|
+
|
255
255
|
end
|
256
|
-
|
256
|
+
|
257
257
|
attr_reader :request, :response, :content, :mime, :state, :engine, :meth, :args
|
258
|
-
|
258
|
+
|
259
259
|
def initialize env, meth, args, partial=false
|
260
260
|
@meth = meth
|
261
261
|
@args = args
|
@@ -271,7 +271,7 @@ module Zorglub
|
|
271
271
|
@cache_lifetime = self.class.cache_lifetime
|
272
272
|
self.class.cli_vals.each do |s,v| cli_val s, *v end
|
273
273
|
end
|
274
|
-
|
274
|
+
|
275
275
|
def realize!
|
276
276
|
catch(:stop_realize) {
|
277
277
|
feed!
|
@@ -281,7 +281,7 @@ module Zorglub
|
|
281
281
|
response
|
282
282
|
}
|
283
283
|
end
|
284
|
-
|
284
|
+
|
285
285
|
def feed! no_hooks=false
|
286
286
|
@state = :pre_cb
|
287
287
|
self.class.call_before_hooks self unless no_hooks
|
@@ -298,7 +298,7 @@ module Zorglub
|
|
298
298
|
@state = :finished
|
299
299
|
return @content, @mime
|
300
300
|
end
|
301
|
-
|
301
|
+
|
302
302
|
def static_page! path
|
303
303
|
if File.exists?(path) and ( @cache_lifetime.nil? or @cache_lifetime==0 or ( (Time.now-File.stat(path).mtime) < @cache_lifetime ) )
|
304
304
|
$stderr << " * use cache file : #{path}\n" if @debug
|
@@ -312,7 +312,7 @@ module Zorglub
|
|
312
312
|
$stderr << " * cache file created : #{path}\n" if @debug
|
313
313
|
end
|
314
314
|
end
|
315
|
-
|
315
|
+
|
316
316
|
def compile_page!
|
317
317
|
e, @ext = app.engine_proc_ext @engine, @ext
|
318
318
|
v, l = view, layout
|
@@ -328,9 +328,7 @@ module Zorglub
|
|
328
328
|
@content, mime = e.call l, self if e and l and File.exists? l
|
329
329
|
@mime = mime if @mime.nil? and not mime.nil?
|
330
330
|
end
|
331
|
-
|
331
|
+
|
332
332
|
end
|
333
|
-
|
333
|
+
|
334
334
|
end
|
335
|
-
#
|
336
|
-
# EOF
|