zorglub 0.0.3 → 0.0.4
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.
- data/Changelog +2 -1
- data/lib/zorglub/config.rb +10 -11
- data/lib/zorglub/engines/file.rb +20 -0
- data/lib/zorglub/node.rb +13 -4
- data/lib/zorglub.rb +1 -1
- data/spec/data/view/node0/plain_file.txt +1 -0
- data/spec/data/view/node0/xml_file.xml +1 -0
- data/spec/node_spec.rb +11 -4
- data/spec/spec_helper.rb +32 -17
- metadata +13 -9
data/Changelog
CHANGED
@@ -11,7 +11,8 @@
|
|
11
11
|
* update test application and write specs
|
12
12
|
|
13
13
|
2012-01-05 Jérémy Zurcher <jeremy@asynk.ch>
|
14
|
-
* haml
|
14
|
+
* haml, file engines
|
15
|
+
* view/layout extention overriding at methode level
|
15
16
|
* optional engine cache
|
16
17
|
* optional engine proc mime-type definition
|
17
18
|
* optional static page generation/cache
|
data/lib/zorglub/config.rb
CHANGED
@@ -50,19 +50,18 @@ module Zorglub
|
|
50
50
|
#
|
51
51
|
def register_engine name, ext, proc
|
52
52
|
return unless name
|
53
|
-
|
53
|
+
if ext.nil? or ext.empty?
|
54
|
+
x = nil
|
55
|
+
else
|
56
|
+
x = (ext[0]=='.' ? (ext.length==1 ? nil : ext) : '.'+ext)
|
57
|
+
end
|
58
|
+
@engines[name]=[ proc, x ]
|
54
59
|
end
|
55
60
|
#
|
56
|
-
def
|
57
|
-
|
58
|
-
return '' if
|
59
|
-
x
|
60
|
-
( x.nil? ? '' : '.'+x )
|
61
|
-
end
|
62
|
-
#
|
63
|
-
def engine_proc engine
|
64
|
-
e = @engines[engine]
|
65
|
-
( e.nil? ? nil : e[1] )
|
61
|
+
def engine_proc_ext engine, ext
|
62
|
+
p,x = @engines[engine]
|
63
|
+
return [nil, ''] if p.nil?
|
64
|
+
[ p, (x.nil? ? ext : x ) ]
|
66
65
|
end
|
67
66
|
#
|
68
67
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- coding: UTF-8 -*-
|
2
|
+
#
|
3
|
+
require 'haml/util'
|
4
|
+
require 'haml/engine'
|
5
|
+
#
|
6
|
+
module Zorglub
|
7
|
+
module Engines
|
8
|
+
module File
|
9
|
+
def self.proc path,obj
|
10
|
+
content = ::File.open(path,'r'){|f| f.read }
|
11
|
+
ext = path.sub /.*\.(.+)$/,'\1'
|
12
|
+
return content, "text/#{ext}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
#
|
18
|
+
Zorglub::Config.register_engine :file, nil, Zorglub::Engines::File.method(:proc)
|
19
|
+
#
|
20
|
+
# EOF
|
data/lib/zorglub/node.rb
CHANGED
@@ -150,7 +150,8 @@ module Zorglub
|
|
150
150
|
end
|
151
151
|
#
|
152
152
|
def compile!
|
153
|
-
|
153
|
+
e, @options[:ext] = Config.engine_proc_ext @options[:engine], @options[:ext]
|
154
|
+
v, l = view, layout
|
154
155
|
state (@options[:layout].nil? ? :partial : :view)
|
155
156
|
@content, mime = e.call v, self if e and File.exists? v
|
156
157
|
@mime = mime unless mime.nil?
|
@@ -183,7 +184,7 @@ module Zorglub
|
|
183
184
|
def layout layout=nil
|
184
185
|
@options[:layout] = layout unless layout.nil? or layout.empty?
|
185
186
|
return '' if @options[:layout].nil?
|
186
|
-
File.join(Config.layout_base_path, @options[:layout])+
|
187
|
+
File.join(Config.layout_base_path, @options[:layout])+ext
|
187
188
|
end
|
188
189
|
#
|
189
190
|
def no_layout
|
@@ -193,13 +194,21 @@ module Zorglub
|
|
193
194
|
def static val=nil
|
194
195
|
@options[:static] = val if (val==true or val==false)
|
195
196
|
return nil if not @options[:static] or @options[:view].nil?
|
196
|
-
File.join(Config.static_base_path, @options[:view])+
|
197
|
+
File.join(Config.static_base_path, @options[:view])+ext
|
197
198
|
end
|
198
199
|
#
|
199
200
|
def view view=nil
|
200
201
|
@options[:view] = view unless view.nil? or view.empty?
|
201
202
|
return '' if @options[:view].nil?
|
202
|
-
File.join(Config.view_base_path, @options[:view])+
|
203
|
+
File.join(Config.view_base_path, @options[:view])+ext
|
204
|
+
end
|
205
|
+
#
|
206
|
+
def ext ext=nil
|
207
|
+
if ext.nil? or ext.empty?
|
208
|
+
@options[:ext]||''
|
209
|
+
else
|
210
|
+
@options[:ext] = (ext[0]=='.' ? (ext.length==1 ? nil : ext) : '.'+ext)
|
211
|
+
end
|
203
212
|
end
|
204
213
|
#
|
205
214
|
def inherited_var sym, *args
|
data/lib/zorglub.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
plain file
|
@@ -0,0 +1 @@
|
|
1
|
+
<xml>file</xml>
|
data/spec/node_spec.rb
CHANGED
@@ -152,16 +152,16 @@ describe Zorglub do
|
|
152
152
|
end
|
153
153
|
#
|
154
154
|
it "static pages should be generated" do
|
155
|
-
r =
|
155
|
+
r = Node6.my_call '/do_static'
|
156
156
|
r.body[0].should == 'VAL 1'
|
157
157
|
r.header['Content-type'].should == 'text/static'
|
158
|
-
r =
|
158
|
+
r = Node6.my_call '/do_static'
|
159
159
|
r.body[0].should == 'VAL 1'
|
160
160
|
r.header['Content-type'].should == 'text/static'
|
161
|
-
r =
|
161
|
+
r = Node6.my_call '/do_static'
|
162
162
|
r.body[0].should == 'VAL 1'
|
163
163
|
r.header['Content-type'].should == 'text/static'
|
164
|
-
r =
|
164
|
+
r = Node6.my_call '/no_static'
|
165
165
|
r.body[0].should == 'VAL 4'
|
166
166
|
r.header['Content-type'].should == 'text/static'
|
167
167
|
end
|
@@ -192,6 +192,13 @@ describe Zorglub do
|
|
192
192
|
vars.should == ['js0','js1']
|
193
193
|
vars[2].should be_nil
|
194
194
|
end
|
195
|
+
#
|
196
|
+
it "ext definition and file engine should work" do
|
197
|
+
r = Node0.my_call '/xml_file'
|
198
|
+
r.body[0]='<xml>file</xml>'
|
199
|
+
r = Node0.my_call '/plain_file'
|
200
|
+
r.body[0]='plain text'
|
201
|
+
end
|
195
202
|
end
|
196
203
|
#
|
197
204
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -11,6 +11,7 @@ end
|
|
11
11
|
require 'yaml'
|
12
12
|
#
|
13
13
|
require 'zorglub'
|
14
|
+
require 'zorglub/engines/file'
|
14
15
|
#
|
15
16
|
HASH_PROC = Proc.new { |path,obj| {:path=>path,:layout=>obj.layout,:view=>obj.view,:args=>obj.args,:map=>obj.map}.to_yaml }
|
16
17
|
STATIC_PROC = Proc.new { |path,obj| ["VAL #{obj.value}",'text/static'] }
|
@@ -45,10 +46,6 @@ class Temp < Zorglub::Node
|
|
45
46
|
end
|
46
47
|
#
|
47
48
|
class Node0 < Zorglub::Node
|
48
|
-
@static_cpt=0
|
49
|
-
class << self
|
50
|
-
attr_accessor :static_cpt
|
51
|
-
end
|
52
49
|
# default
|
53
50
|
def index
|
54
51
|
html
|
@@ -72,20 +69,15 @@ class Node0 < Zorglub::Node
|
|
72
69
|
def do_redirect
|
73
70
|
redirect r(:do_partial,1,2,3)
|
74
71
|
end
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
view r('do_render')
|
80
|
-
Node0.static_cpt+=1
|
81
|
-
@value = Node0.static_cpt
|
72
|
+
def xml_file
|
73
|
+
no_layout
|
74
|
+
engine :file
|
75
|
+
ext 'xml'
|
82
76
|
end
|
83
|
-
def
|
84
|
-
|
85
|
-
engine
|
86
|
-
|
87
|
-
Node0.static_cpt+=1
|
88
|
-
@value = Node0.static_cpt
|
77
|
+
def plain_file
|
78
|
+
no_layout
|
79
|
+
engine :file
|
80
|
+
ext 'txt'
|
89
81
|
end
|
90
82
|
end
|
91
83
|
#
|
@@ -144,12 +136,35 @@ class Node5 < Node4
|
|
144
136
|
end
|
145
137
|
end
|
146
138
|
#
|
139
|
+
class Node6 < Zorglub::Node
|
140
|
+
@static_cpt=0
|
141
|
+
class << self
|
142
|
+
attr_accessor :static_cpt
|
143
|
+
end
|
144
|
+
attr_reader :value
|
145
|
+
static true
|
146
|
+
def no_static
|
147
|
+
static false
|
148
|
+
engine 'static'
|
149
|
+
view Node0.r('do_render')
|
150
|
+
Node6.static_cpt+=1
|
151
|
+
@value = Node6.static_cpt
|
152
|
+
end
|
153
|
+
def do_static
|
154
|
+
engine 'static'
|
155
|
+
view Node0.r('do_render')
|
156
|
+
Node6.static_cpt+=1
|
157
|
+
@value = Node6.static_cpt
|
158
|
+
end
|
159
|
+
end
|
160
|
+
#
|
147
161
|
APP = Zorglub::App.new do
|
148
162
|
map '/node0', Node0
|
149
163
|
map '/node1', Node1
|
150
164
|
map '/node3', Node3
|
151
165
|
map '/node4', Node4
|
152
166
|
map '/node5', Node5
|
167
|
+
map '/node6', Node6
|
153
168
|
end
|
154
169
|
class Node2
|
155
170
|
map APP, '/node2'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zorglub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-01-05 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|
16
|
-
requirement: &
|
16
|
+
requirement: &20000040 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 1.4.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *20000040
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake
|
27
|
-
requirement: &
|
27
|
+
requirement: &19999520 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 0.8.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *19999520
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rake
|
38
|
-
requirement: &
|
38
|
+
requirement: &19998860 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 0.8.7
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *19998860
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: bones
|
49
|
-
requirement: &
|
49
|
+
requirement: &19998120 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,13 +54,14 @@ dependencies:
|
|
54
54
|
version: 3.7.3
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *19998120
|
58
58
|
description: a nano web application framework based on rack[http://rack.rubyforge.org/]
|
59
59
|
email: jeremy@asynk.ch
|
60
60
|
executables: []
|
61
61
|
extensions: []
|
62
62
|
extra_rdoc_files:
|
63
63
|
- README.rdoc
|
64
|
+
- spec/data/view/node0/plain_file.txt
|
64
65
|
files:
|
65
66
|
- Changelog
|
66
67
|
- MIT-LICENSE
|
@@ -69,6 +70,7 @@ files:
|
|
69
70
|
- lib/zorglub.rb
|
70
71
|
- lib/zorglub/app.rb
|
71
72
|
- lib/zorglub/config.rb
|
73
|
+
- lib/zorglub/engines/file.rb
|
72
74
|
- lib/zorglub/engines/haml.rb
|
73
75
|
- lib/zorglub/node.rb
|
74
76
|
- lib/zorglub/rack_session.rb
|
@@ -78,6 +80,8 @@ files:
|
|
78
80
|
- spec/data/layout/main.spec
|
79
81
|
- spec/data/view/node0/do_partial
|
80
82
|
- spec/data/view/node0/do_render
|
83
|
+
- spec/data/view/node0/plain_file.txt
|
84
|
+
- spec/data/view/node0/xml_file.xml
|
81
85
|
- spec/node_spec.rb
|
82
86
|
- spec/spec_helper.rb
|
83
87
|
- tasks/ann.rake
|