mascut 0.0.5 → 0.0.6
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 -0
- data/VERSION +1 -1
- data/bin/mascut +1 -0
- data/lib/mascut.rb +2 -1
- data/lib/mascut/hamlth.rb +33 -0
- data/spec/mascut/hamlth_spec.rb +133 -0
- metadata +24 -7
data/HISTORY.rdoc
CHANGED
data/Rakefile
CHANGED
@@ -11,6 +11,8 @@ begin
|
|
11
11
|
gem.homepage = 'http://github.com/okitan/mascut'
|
12
12
|
gem.authors = %w[ okitan ]
|
13
13
|
|
14
|
+
gem.add_dependency 'haml', '>= 3.0.6'
|
15
|
+
|
14
16
|
gem.add_development_dependency 'rr', '>= 0.10.11'
|
15
17
|
gem.add_development_dependency 'rspec', '>= 1.3.0'
|
16
18
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.6
|
data/bin/mascut
CHANGED
data/lib/mascut.rb
CHANGED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'haml'
|
2
|
+
require 'sass'
|
3
|
+
|
4
|
+
module Mascut
|
5
|
+
class Hamlth
|
6
|
+
def initialize(app)
|
7
|
+
@app = app
|
8
|
+
end
|
9
|
+
|
10
|
+
def call(env)
|
11
|
+
case path = env['PATH_INFO'][1..-1] # remove / and path is now relative
|
12
|
+
when /\.(html|haml)$/
|
13
|
+
data = ( File.exist?(path) or File.exist?(path.sub!(/html$/, 'haml')) ) ? hamlize(path) : raise
|
14
|
+
[ 200, { 'Content-Type' => 'text/html', 'Content-Length' => Rack::Utils.bytesize(data).to_s }, [ data ] ]
|
15
|
+
when /\.(css|sass)$/
|
16
|
+
data = ( File.exist?(path) or File.exist?(path.sub!(/css$/, 'sass')) ) ? sassize(path) : raise
|
17
|
+
[ 200, { 'Content- type' => 'text/css', 'Content-Length' => Rack::Utils.bytesize(data).to_s }, [ data ] ]
|
18
|
+
else
|
19
|
+
raise # all raise jumps to app.call
|
20
|
+
end
|
21
|
+
rescue => e
|
22
|
+
@app.call(env)
|
23
|
+
end
|
24
|
+
|
25
|
+
def hamlize(path)
|
26
|
+
Haml::Engine.new(File.read(path)).to_html
|
27
|
+
end
|
28
|
+
|
29
|
+
def sassize(path)
|
30
|
+
Sass::Engine.new(File.read(path)).to_css
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), %w[ .. spec_helper ])
|
2
|
+
|
3
|
+
shared_examples_for 'hamlize PATH_INFO' do
|
4
|
+
before do
|
5
|
+
stub(File).exist?(path) { true }
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should hamlize PATH_INFO' do
|
9
|
+
mock(middleware).hamlize(path) { 'haml' }
|
10
|
+
subject
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
shared_examples_for 'sassize PATH_INFO' do
|
15
|
+
before do
|
16
|
+
stub(File).exist?(path) { true }
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should hamlize PATH_INFO' do
|
20
|
+
mock(middleware).sassize(path) { 'sass' }
|
21
|
+
subject
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe Mascut::Hamlth, '#call' do
|
26
|
+
let(:app) { mock }
|
27
|
+
let(:middleware) { Mascut::Hamlth.new(app) }
|
28
|
+
let(:env) { { 'PATH_INFO' => path } }
|
29
|
+
|
30
|
+
subject { middleware.call(env) }
|
31
|
+
|
32
|
+
context 'for *.html' do
|
33
|
+
let(:path) { 'hoge.html' }
|
34
|
+
|
35
|
+
context 'when *.html exists' do
|
36
|
+
it_should_behave_like 'hamlize PATH_INFO'
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'when *.haml exists' do
|
40
|
+
before do
|
41
|
+
stub(File).exist?(path) { false }
|
42
|
+
stub(File).exist?('hoge.haml') { true }
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should hamlize *.haml' do
|
46
|
+
mock(middleware).hamlize('hoge.haml') { 'haml' }
|
47
|
+
subject
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'neighter exists' do
|
52
|
+
before do
|
53
|
+
stub(File).exist?(path) { false }
|
54
|
+
stub(File).exist?('hoge.haml') { false }
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should move on to next app' do
|
58
|
+
mock(app).call(env)
|
59
|
+
subject
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context 'for *.haml' do
|
65
|
+
let(:path) { 'hoge.haml' }
|
66
|
+
|
67
|
+
context 'when *.haml exists' do
|
68
|
+
it_should_behave_like 'hamlize PATH_INFO'
|
69
|
+
end
|
70
|
+
|
71
|
+
context '*.haml does not exist' do
|
72
|
+
before do
|
73
|
+
stub(File).exist?(path) { false }
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'should move on to next app' do
|
77
|
+
mock(app).call(env)
|
78
|
+
subject
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
context 'for *.css' do
|
84
|
+
let(:path) { 'hoge.css' }
|
85
|
+
|
86
|
+
context 'when *.css exists' do
|
87
|
+
it_should_behave_like 'sassize PATH_INFO'
|
88
|
+
end
|
89
|
+
|
90
|
+
context 'when *.sass exists' do
|
91
|
+
before do
|
92
|
+
stub(File).exist?(path) { false }
|
93
|
+
stub(File).exist?('hoge.sass') { true }
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'should sassize *.sass' do
|
97
|
+
mock(middleware).sassize('hoge.sass') { 'sass' }
|
98
|
+
subject
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context 'neighter exists' do
|
103
|
+
before do
|
104
|
+
stub(File).exist?(path) { false }
|
105
|
+
stub(File).exist?('hoge.sass') { false }
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'should move on to next app' do
|
109
|
+
mock(app).call(env)
|
110
|
+
subject
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
context 'for *.sass' do
|
116
|
+
let(:path) { 'hoge.sass' }
|
117
|
+
|
118
|
+
context 'when *.sass exists' do
|
119
|
+
it_should_behave_like 'sassize PATH_INFO'
|
120
|
+
end
|
121
|
+
|
122
|
+
context '*.sass does not exist' do
|
123
|
+
before do
|
124
|
+
stub(File).exist?(path) { false }
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'should move on to next app' do
|
128
|
+
mock(app).call(env)
|
129
|
+
subject
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
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
|
+
- 6
|
9
|
+
version: 0.0.6
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- okitan
|
@@ -14,13 +14,27 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-05-
|
17
|
+
date: 2010-05-25 00:00:00 +09:00
|
18
18
|
default_executable: mascut
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
|
-
name:
|
21
|
+
name: haml
|
22
22
|
prerelease: false
|
23
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 3
|
29
|
+
- 0
|
30
|
+
- 6
|
31
|
+
version: 3.0.6
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: rr
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
24
38
|
requirements:
|
25
39
|
- - ">="
|
26
40
|
- !ruby/object:Gem::Version
|
@@ -30,11 +44,11 @@ dependencies:
|
|
30
44
|
- 11
|
31
45
|
version: 0.10.11
|
32
46
|
type: :development
|
33
|
-
version_requirements: *
|
47
|
+
version_requirements: *id002
|
34
48
|
- !ruby/object:Gem::Dependency
|
35
49
|
name: rspec
|
36
50
|
prerelease: false
|
37
|
-
requirement: &
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
38
52
|
requirements:
|
39
53
|
- - ">="
|
40
54
|
- !ruby/object:Gem::Version
|
@@ -44,7 +58,7 @@ dependencies:
|
|
44
58
|
- 0
|
45
59
|
version: 1.3.0
|
46
60
|
type: :development
|
47
|
-
version_requirements: *
|
61
|
+
version_requirements: *id003
|
48
62
|
description: instant comet-like server in order to debug web pages
|
49
63
|
email: okitakunio@gmail.com
|
50
64
|
executables:
|
@@ -64,8 +78,10 @@ files:
|
|
64
78
|
- VERSION
|
65
79
|
- bin/mascut
|
66
80
|
- lib/mascut.rb
|
81
|
+
- lib/mascut/hamlth.rb
|
67
82
|
- lib/mascut/mascut.rb
|
68
83
|
- lib/mascut/option.rb
|
84
|
+
- spec/mascut/hamlth_spec.rb
|
69
85
|
- spec/mascut/mascut_spec.rb
|
70
86
|
- spec/mascut/option_spec.rb
|
71
87
|
- spec/mascut_spec.rb
|
@@ -102,6 +118,7 @@ signing_key:
|
|
102
118
|
specification_version: 3
|
103
119
|
summary: instant comet-like server in order to debug web pages
|
104
120
|
test_files:
|
121
|
+
- spec/mascut/hamlth_spec.rb
|
105
122
|
- spec/mascut/mascut_spec.rb
|
106
123
|
- spec/mascut/option_spec.rb
|
107
124
|
- spec/spec_helper.rb
|