rufus-sixjo 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/lib/rufus/sixjo.rb CHANGED
@@ -65,7 +65,22 @@ module Rufus
65
65
 
66
66
  module Sixjo
67
67
 
68
- VERSION = '0.1.3'
68
+ VERSION = '0.1.4'
69
+
70
+ class << self
71
+ # View path (defaults to +views+, in the current working directory)
72
+ @@view_path = './views'
73
+
74
+ # Return the path to the views folder
75
+ def view_path
76
+ @@view_path
77
+ end
78
+
79
+ # Set the base path to the views folder
80
+ def view_path=( path )
81
+ @@view_path = path
82
+ end
83
+ end
69
84
 
70
85
  #
71
86
  # Sixjo's Rack app
@@ -204,7 +219,7 @@ module Rufus
204
219
 
205
220
  def erb (template, options = {})
206
221
 
207
- content = File.read("views/#{template}.erb")
222
+ content = File.read( Sixjo.view_path + "/#{template}.erb")
208
223
  #
209
224
  # TODO : make views/ configurable
210
225
 
@@ -314,23 +329,26 @@ module Rufus
314
329
  #
315
330
  def set_last_modified (t)
316
331
 
317
- t = Time.local(*t.to_a) # flatten milliseconds
332
+ #t = Time.local(*t.to_a) # flatten milliseconds
333
+ #@response.header['Last-Modified'] = t.httpdate
318
334
 
319
- @response.header['Last-Modified'] = t.httpdate
335
+ t = t.httpdate
336
+ @response.header['Last-Modified'] = t
320
337
 
321
338
  sin = @request.env['HTTP_IF_MODIFIED_SINCE']
322
339
 
323
340
  return unless sin
324
341
 
325
- # taken from the "Ruby Cookbook" by
326
- # Lucas Carlson and Leonard Richardson
327
- #
328
- sin = DateTime.parse(sin)
329
- sin = sin.new_offset(DateTime.now.offset - sin.offset)
330
- sin = Time.local(
331
- sin.year, sin.month, sin.day, sin.hour, sin.min, sin.sec, 0)
342
+ ## taken from the "Ruby Cookbook" by
343
+ ## Lucas Carlson and Leonard Richardson
344
+ ##
345
+ #sin = DateTime.parse(sin)
346
+ #sin = sin.new_offset(DateTime.now.offset - sin.offset)
347
+ #sin = Time.local(
348
+ # sin.year, sin.month, sin.day, sin.hour, sin.min, sin.sec, 0)
332
349
 
333
- if sin >= t
350
+ #if sin >= t
351
+ if sin == t
334
352
  throw(:done, 304) if @request.get? or @request.head?
335
353
  throw(:done, 412) # precondition failed
336
354
  end
data/test/ft_0_simple.rb CHANGED
@@ -17,12 +17,16 @@ module Simple
17
17
  extend Rufus::Sixjo
18
18
 
19
19
  get '/toto' do
20
- "toto"
20
+ 'toto'
21
21
  end
22
22
 
23
23
  get '/toto/:id' do
24
24
  "toto with id #{params[:id]} .#{request.env['_FORMAT']}"
25
25
  end
26
+
27
+ #get '/(momo|dodo)/:id' do
28
+ # "modo with id #{params[:id]}"
29
+ #end
26
30
  end
27
31
 
28
32
  class SimpleTest < Test::Unit::TestCase
@@ -37,16 +41,21 @@ class SimpleTest < Test::Unit::TestCase
37
41
  assert_equal 404, get('/nada').status
38
42
 
39
43
  assert_equal 200, get('/toto').status
40
- assert_equal "toto", @response.body
44
+ assert_equal 'toto', @response.body
41
45
 
42
46
  assert_equal 200, get('/toto/3').status
43
- assert_equal "toto with id 3 .", @response.body
47
+ assert_equal 'toto with id 3 .', @response.body
44
48
 
45
49
  assert_equal 200, get('/toto/3.json').status
46
- assert_equal "toto with id 3 .json", @response.body
50
+ assert_equal 'toto with id 3 .json', @response.body
47
51
 
48
52
  assert_equal 200, get('/toto/3.json?q=nada').status
49
- assert_equal "toto with id 3 .json", @response.body
53
+ assert_equal 'toto with id 3 .json', @response.body
50
54
  end
55
+
56
+ #def test_1
57
+ # assert_equal 200, get('/momo/2').status
58
+ # assert_equal 'modo with id 2', @response.body
59
+ #end
51
60
  end
52
61
 
data/test/ft_3_erb.rb CHANGED
@@ -36,6 +36,10 @@ module ErbApp
36
36
  get '/good3' do
37
37
  erb :view0, :whatever => true, :locals => { :life => nil }
38
38
  end
39
+
40
+ get '/nested' do
41
+ erb :nested0
42
+ end
39
43
  end
40
44
 
41
45
  class ErbTest < Test::Unit::TestCase
@@ -47,6 +51,7 @@ class ErbTest < Test::Unit::TestCase
47
51
 
48
52
  save_view('views/view0.erb', 'this is view0, life is <%= life %>')
49
53
  save_view('views/view1.erb', '<%= request.path_info %>')
54
+ save_view('views/nested/nested0.erb', 'this is nested0, obviously')
50
55
  end
51
56
 
52
57
  def test_0
@@ -68,5 +73,18 @@ class ErbTest < Test::Unit::TestCase
68
73
  assert_equal 200, get('/good3').status
69
74
  assert_equal 'this is view0, life is ', @response.body
70
75
  end
76
+
77
+ def test_2
78
+
79
+ assert_equal 500, get('/nested').status
80
+
81
+ old_view_path = Rufus::Sixjo.view_path
82
+ Rufus::Sixjo.view_path = 'views/nested'
83
+
84
+ assert_equal 200, get('/nested').status
85
+ assert_equal 'this is nested0, obviously', @response.body
86
+
87
+ Rufus::Sixjo.view_path = old_view_path
88
+ end
71
89
  end
72
90
 
data/test/testmixins.rb CHANGED
@@ -32,9 +32,8 @@ module SixjoTestMixin
32
32
  [ :post, :get, :put, :delete, :head ].each do |v|
33
33
  module_eval <<-EOS
34
34
  def #{v} (path, options={})
35
- @response = \
36
- Rack::MockRequest.new(@app).request('#{v}'.upcase, path, options)
37
- @response
35
+ @request = Rack::MockRequest.new(@app)
36
+ @response = @request.request('#{v}'.upcase, path, options)
38
37
  end
39
38
  EOS
40
39
  end
@@ -55,7 +54,7 @@ module SixjoTestMixin
55
54
 
56
55
  def save_view (filename, content)
57
56
 
58
- FileUtils.mkdir('views') unless File.exist?('views')
57
+ FileUtils.mkdir_p( File.dirname( filename ) ) unless File.exists?( File.dirname( filename ) )
59
58
 
60
59
  FileUtils.rm(filename) if File.exist?(filename)
61
60
  File.open(filename, 'w') { |f| f.write(content) }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rufus-sixjo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Mettraux
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-09-09 00:00:00 +09:00
12
+ date: 2008-12-22 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -68,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
68
68
  requirements:
69
69
  - rack
70
70
  rubyforge_project:
71
- rubygems_version: 1.2.0
71
+ rubygems_version: 1.3.1
72
72
  signing_key:
73
73
  specification_version: 2
74
74
  summary: a rack application