mascut 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY.rdoc +3 -0
- data/Rakefile +2 -2
- data/VERSION +1 -1
- data/lib/mascut/mascut.rb +9 -3
- data/spec/mascut/hamlth_spec.rb +18 -14
- data/spec/mascut/mascut_spec.rb +5 -1
- metadata +3 -3
data/HISTORY.rdoc
CHANGED
data/Rakefile
CHANGED
@@ -24,12 +24,12 @@ end
|
|
24
24
|
|
25
25
|
require 'spec/rake/spectask'
|
26
26
|
Spec::Rake::SpecTask.new(:spec) do |spec|
|
27
|
-
spec.libs << '
|
27
|
+
spec.libs << 'spec'
|
28
28
|
spec.spec_files = FileList['spec/**/*_spec.rb']
|
29
29
|
end
|
30
30
|
|
31
31
|
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
32
|
-
spec.libs << '
|
32
|
+
spec.libs << 'spec'
|
33
33
|
spec.pattern = 'spec/**/*_spec.rb'
|
34
34
|
spec.rcov = true
|
35
35
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.7
|
data/lib/mascut/mascut.rb
CHANGED
@@ -14,8 +14,14 @@ module Mascut
|
|
14
14
|
status, headers, body = @app.call(env)
|
15
15
|
if status == 200 and headers['Content-Type'] =~ /^text\/html/
|
16
16
|
body = [ File.read(body.path) ] if body.is_a?(Rack::File)
|
17
|
-
body.
|
18
|
-
|
17
|
+
if body.kind_of?(Rack::Response)
|
18
|
+
# this code is not well considered
|
19
|
+
body.body = mascutize(body.body)
|
20
|
+
headers['Content-Length'] = body.length.to_s
|
21
|
+
else
|
22
|
+
body.map! {|html| mascutize(html) }
|
23
|
+
headers['Content-Length'] = body.to_a.inject(0) {|len, part| len + Rack::Utils.bytesize(part) }.to_s
|
24
|
+
end
|
19
25
|
end
|
20
26
|
|
21
27
|
[ status, headers, body ]
|
@@ -28,7 +34,7 @@ module Mascut
|
|
28
34
|
catch :reload do
|
29
35
|
loop do
|
30
36
|
@files.each {|file| throw(:reload, 'reload') if File.exist?(file) and now < File.mtime(file) }
|
31
|
-
sleep
|
37
|
+
sleep(@opts[:interval] || 1.0)
|
32
38
|
end
|
33
39
|
end
|
34
40
|
|
data/spec/mascut/hamlth_spec.rb
CHANGED
@@ -2,22 +2,22 @@ require File.join(File.dirname(__FILE__), %w[ .. spec_helper ])
|
|
2
2
|
|
3
3
|
shared_examples_for 'hamlize PATH_INFO' do
|
4
4
|
before do
|
5
|
-
stub(File).exist?(
|
5
|
+
stub(File).exist?(file) { true }
|
6
6
|
end
|
7
7
|
|
8
8
|
it 'should hamlize PATH_INFO' do
|
9
|
-
mock(middleware).hamlize(
|
9
|
+
mock(middleware).hamlize(file) { 'haml' }
|
10
10
|
subject
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
14
|
shared_examples_for 'sassize PATH_INFO' do
|
15
15
|
before do
|
16
|
-
stub(File).exist?(
|
16
|
+
stub(File).exist?(file) { true }
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'should hamlize PATH_INFO' do
|
20
|
-
mock(middleware).sassize(
|
20
|
+
mock(middleware).sassize(file) { 'sass' }
|
21
21
|
subject
|
22
22
|
end
|
23
23
|
end
|
@@ -26,11 +26,12 @@ describe Mascut::Hamlth, '#call' do
|
|
26
26
|
let(:app) { mock }
|
27
27
|
let(:middleware) { Mascut::Hamlth.new(app) }
|
28
28
|
let(:env) { { 'PATH_INFO' => path } }
|
29
|
+
let(:file) { path[1..-1] }
|
29
30
|
|
30
31
|
subject { middleware.call(env) }
|
31
32
|
|
32
33
|
context 'for *.html' do
|
33
|
-
let(:path) { 'hoge.html' }
|
34
|
+
let(:path) { '/hoge.html' }
|
34
35
|
|
35
36
|
context 'when *.html exists' do
|
36
37
|
it_should_behave_like 'hamlize PATH_INFO'
|
@@ -38,7 +39,7 @@ describe Mascut::Hamlth, '#call' do
|
|
38
39
|
|
39
40
|
context 'when *.haml exists' do
|
40
41
|
before do
|
41
|
-
stub(File).exist?(
|
42
|
+
stub(File).exist?(file) { false }
|
42
43
|
stub(File).exist?('hoge.haml') { true }
|
43
44
|
end
|
44
45
|
|
@@ -50,7 +51,7 @@ describe Mascut::Hamlth, '#call' do
|
|
50
51
|
|
51
52
|
context 'neighter exists' do
|
52
53
|
before do
|
53
|
-
stub(File).exist?(
|
54
|
+
stub(File).exist?(file) { false }
|
54
55
|
stub(File).exist?('hoge.haml') { false }
|
55
56
|
end
|
56
57
|
|
@@ -62,7 +63,8 @@ describe Mascut::Hamlth, '#call' do
|
|
62
63
|
end
|
63
64
|
|
64
65
|
context 'for *.haml' do
|
65
|
-
let(:path) { 'hoge.haml' }
|
66
|
+
let(:path) { '/hoge.haml' }
|
67
|
+
let(:file) { path[1..-1] }
|
66
68
|
|
67
69
|
context 'when *.haml exists' do
|
68
70
|
it_should_behave_like 'hamlize PATH_INFO'
|
@@ -70,7 +72,7 @@ describe Mascut::Hamlth, '#call' do
|
|
70
72
|
|
71
73
|
context '*.haml does not exist' do
|
72
74
|
before do
|
73
|
-
stub(File).exist?(
|
75
|
+
stub(File).exist?(file) { false }
|
74
76
|
end
|
75
77
|
|
76
78
|
it 'should move on to next app' do
|
@@ -81,7 +83,8 @@ describe Mascut::Hamlth, '#call' do
|
|
81
83
|
end
|
82
84
|
|
83
85
|
context 'for *.css' do
|
84
|
-
let(:path) { 'hoge.css' }
|
86
|
+
let(:path) { '/hoge.css' }
|
87
|
+
let(:file) { path[1..-1] }
|
85
88
|
|
86
89
|
context 'when *.css exists' do
|
87
90
|
it_should_behave_like 'sassize PATH_INFO'
|
@@ -89,7 +92,7 @@ describe Mascut::Hamlth, '#call' do
|
|
89
92
|
|
90
93
|
context 'when *.sass exists' do
|
91
94
|
before do
|
92
|
-
stub(File).exist?(
|
95
|
+
stub(File).exist?(file) { false }
|
93
96
|
stub(File).exist?('hoge.sass') { true }
|
94
97
|
end
|
95
98
|
|
@@ -101,7 +104,7 @@ describe Mascut::Hamlth, '#call' do
|
|
101
104
|
|
102
105
|
context 'neighter exists' do
|
103
106
|
before do
|
104
|
-
stub(File).exist?(
|
107
|
+
stub(File).exist?(file) { false }
|
105
108
|
stub(File).exist?('hoge.sass') { false }
|
106
109
|
end
|
107
110
|
|
@@ -113,7 +116,8 @@ describe Mascut::Hamlth, '#call' do
|
|
113
116
|
end
|
114
117
|
|
115
118
|
context 'for *.sass' do
|
116
|
-
let(:path) { 'hoge.sass' }
|
119
|
+
let(:path) { '/hoge.sass' }
|
120
|
+
let(:file) { path[1..-1] }
|
117
121
|
|
118
122
|
context 'when *.sass exists' do
|
119
123
|
it_should_behave_like 'sassize PATH_INFO'
|
@@ -121,7 +125,7 @@ describe Mascut::Hamlth, '#call' do
|
|
121
125
|
|
122
126
|
context '*.sass does not exist' do
|
123
127
|
before do
|
124
|
-
stub(File).exist?(
|
128
|
+
stub(File).exist?(file) { false }
|
125
129
|
end
|
126
130
|
|
127
131
|
it 'should move on to next app' do
|
data/spec/mascut/mascut_spec.rb
CHANGED
@@ -62,7 +62,7 @@ describe Mascut::Mascut, '#call' do
|
|
62
62
|
end
|
63
63
|
|
64
64
|
it 'should add updated content length' do
|
65
|
-
stub(middleware).mascutize
|
65
|
+
stub(middleware).mascutize { '12characters' }
|
66
66
|
subject[1].should include('Content-Length' => 12.to_s )
|
67
67
|
end
|
68
68
|
|
@@ -71,6 +71,10 @@ describe Mascut::Mascut, '#call' do
|
|
71
71
|
subject[2].should == [ 'mascutized' ]
|
72
72
|
end
|
73
73
|
end
|
74
|
+
|
75
|
+
context 'if app returns a kind of Rack::Response' do
|
76
|
+
it 'should have specs'
|
77
|
+
end
|
74
78
|
|
75
79
|
[ [ 201, { 'Content-Type' => 'text/html' }, [ 'html' ] ],
|
76
80
|
[ 200, { 'Content-Type' => 'text/css' }, [ 'css' ] ],
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 7
|
9
|
+
version: 0.0.7
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- okitan
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-05-
|
17
|
+
date: 2010-05-28 00:00:00 +09:00
|
18
18
|
default_executable: mascut
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|