flatrack 1.3.3 → 1.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.ruby-version +1 -1
- data/.travis.yml +3 -6
- data/flatrack.gemspec +4 -3
- data/lib/custom-extensions/sprockets-sass.rb +32 -0
- data/lib/flatrack.rb +123 -11
- data/lib/flatrack/asset_extensions.rb +7 -1
- data/lib/flatrack/cli.rb +9 -1
- data/lib/flatrack/domain_parser.rb +13 -0
- data/lib/flatrack/middleware.rb +32 -0
- data/lib/flatrack/redirector.rb +63 -0
- data/lib/flatrack/request.rb +16 -2
- data/lib/flatrack/response.rb +7 -8
- data/lib/flatrack/rewriter.rb +32 -0
- data/lib/flatrack/sass/functions.rb +6 -6
- data/lib/flatrack/sass/importer.rb +7 -7
- data/lib/flatrack/sass/sass_template.rb +6 -6
- data/lib/flatrack/site.rb +2 -27
- data/lib/flatrack/template.rb +27 -8
- data/lib/flatrack/template/erubis.rb +2 -2
- data/lib/flatrack/template/html.rb +2 -2
- data/lib/flatrack/template/rb.rb +2 -2
- data/lib/flatrack/version.rb +1 -1
- data/lib/flatrack/view.rb +1 -1
- data/lib/flatrack/view/capture_helper.rb +1 -2
- data/lib/flatrack/view/link_helper.rb +8 -1
- data/lib/flatrack/view/render_helper.rb +1 -1
- data/lib/flatrack/view/request_helper.rb +23 -2
- data/lib/flatrack/view/tag_helper.rb +19 -11
- data/spec/lib/flatrack/cli_spec.rb +28 -2
- data/spec/lib/flatrack/middleware_spec.rb +55 -0
- data/spec/lib/flatrack/site_spec.rb +3 -5
- data/spec/lib/flatrack/view/render_helper_spec.rb +4 -0
- data/spec/lib/flatrack/view/set_layout_spec.rb +1 -1
- data/spec/lib/flatrack/view/tag_helper_spec.rb +9 -0
- data/spec/lib/flatrack/view_spec.rb +1 -1
- data/spec/lib/flatrack_spec.rb +73 -0
- data/spec/lib/rake/asset_tasks_spec.rb +2 -2
- data/spec/spec_helper.rb +1 -0
- data/spec/support/fixture_helper.rb +1 -1
- data/spec/support/site_helper.rb +3 -1
- metadata +32 -9
@@ -25,12 +25,13 @@ describe Flatrack::CLI do
|
|
25
25
|
retries = 0
|
26
26
|
begin
|
27
27
|
Net::HTTP.get URI.parse 'http://localhost:5959'
|
28
|
-
thread.kill
|
29
28
|
rescue Errno::ECONNREFUSED => error
|
30
29
|
retries += 1
|
31
30
|
sleep 0.1
|
32
31
|
retry unless retries > 100
|
33
32
|
raise error
|
33
|
+
ensure
|
34
|
+
thread.kill
|
34
35
|
end
|
35
36
|
end
|
36
37
|
end.to_not raise_error
|
@@ -45,16 +46,41 @@ describe Flatrack::CLI do
|
|
45
46
|
retries = 0
|
46
47
|
begin
|
47
48
|
Net::HTTP.get URI.parse 'http://localhost:8282'
|
48
|
-
thread.kill
|
49
49
|
rescue Errno::ECONNREFUSED => error
|
50
50
|
retries += 1
|
51
51
|
sleep 0.1
|
52
52
|
retry unless retries > 100
|
53
53
|
raise error
|
54
|
+
ensure
|
55
|
+
thread.kill
|
54
56
|
end
|
55
57
|
end
|
56
58
|
end.to_not raise_error
|
57
59
|
end
|
60
|
+
|
61
|
+
context 'without a boot.rb' do
|
62
|
+
it 'should start the rack server' do
|
63
|
+
expect do
|
64
|
+
site do
|
65
|
+
FileUtils.rm 'boot.rb'
|
66
|
+
thread = Thread.new do
|
67
|
+
Flatrack::CLI.start(%w(start --port 8283 --verbose false))
|
68
|
+
end
|
69
|
+
retries = 0
|
70
|
+
begin
|
71
|
+
Net::HTTP.get URI.parse 'http://localhost:8283'
|
72
|
+
rescue Errno::ECONNREFUSED => error
|
73
|
+
retries += 1
|
74
|
+
sleep 0.1
|
75
|
+
retry unless retries > 100
|
76
|
+
raise error
|
77
|
+
ensure
|
78
|
+
thread.kill
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end.to_not raise_error
|
82
|
+
end
|
83
|
+
end
|
58
84
|
end
|
59
85
|
|
60
86
|
describe '--version' do
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Flatrack::Middleware do
|
4
|
+
include Flatrack::SiteHelper
|
5
|
+
|
6
|
+
def request(path)
|
7
|
+
url = URI.parse 'http://example.com'
|
8
|
+
url.path = File.join '/', path
|
9
|
+
env = Rack::MockRequest.env_for url.to_s
|
10
|
+
middleware.call env
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:flatrack_app) { Flatrack::Site }
|
14
|
+
let(:app) { ->(_) { [200, {}, ['OK']] } }
|
15
|
+
let(:middleware) { described_class.new app, flatrack_app: flatrack_app }
|
16
|
+
|
17
|
+
context 'given a status of 404' do
|
18
|
+
it 'should call the original app' do
|
19
|
+
site do
|
20
|
+
expect(app).to receive(:call)
|
21
|
+
request '/nothing_here'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'when a NotFound error is raised' do
|
27
|
+
it 'should call the original app' do
|
28
|
+
site do
|
29
|
+
Flatrack.config { |site| site.raise_errors = true }
|
30
|
+
expect(app).to receive(:call)
|
31
|
+
request '/nothing_here'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'when the response is 200' do
|
37
|
+
it 'should not call the original app' do
|
38
|
+
site do
|
39
|
+
expect(app).to_not receive(:call)
|
40
|
+
request '/'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'when the response is 500' do
|
46
|
+
it 'should not call the original app' do
|
47
|
+
site do
|
48
|
+
write :page, 'bad_render.html.ggr', ''
|
49
|
+
expect(app).to_not receive(:call)
|
50
|
+
request '/bad_render'
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Flatrack::Site do
|
4
4
|
let(:mock_app) { ->(env) { [200, {}, ['ok']] } }
|
5
|
-
let(:mock_env) {
|
5
|
+
let(:mock_env) { Flatrack.mock_env_for('example.org', {}) }
|
6
6
|
|
7
7
|
it 'should be a rack app' do
|
8
8
|
expect(described_class).to respond_to :call
|
@@ -26,9 +26,7 @@ describe Flatrack::Site do
|
|
26
26
|
Flatrack.config do |site|
|
27
27
|
middlewares.each do |middleware|
|
28
28
|
expect_any_instance_of(middleware)
|
29
|
-
|
30
|
-
.with(mock_env)
|
31
|
-
.and_call_original
|
29
|
+
.to receive(:call).with(mock_env).and_call_original
|
32
30
|
site.use middleware
|
33
31
|
end
|
34
32
|
end
|
@@ -38,7 +36,7 @@ describe Flatrack::Site do
|
|
38
36
|
|
39
37
|
it 'should formulate a proper response' do
|
40
38
|
expect(Flatrack::Request).to receive(:new).and_call_original
|
41
|
-
expect_any_instance_of(Flatrack::Request).to receive(:response)
|
39
|
+
expect_any_instance_of(Flatrack::Request).to receive(:response).and_call_original
|
42
40
|
Flatrack::Site.call(mock_env)
|
43
41
|
end
|
44
42
|
end
|
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe Flatrack::View do
|
4
4
|
def render_template(fixture)
|
5
5
|
path = File.join Flatrack.gem_root, '../spec/fixtures/templates', fixture
|
6
|
-
env =
|
6
|
+
env = Flatrack.mock_env_for 'http://example.com'
|
7
7
|
req = Flatrack::Request.new env
|
8
8
|
_, _, body = Flatrack::Response.new(req).render(file: path)
|
9
9
|
body.first.lines.map(&:strip).join
|
@@ -20,6 +20,15 @@ describe Flatrack::View::TagHelper do
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
+
context 'with in invalid number of arguments' do
|
24
|
+
it 'should raise an error' do
|
25
|
+
mock = double
|
26
|
+
mock.extend Flatrack::View::TagHelper
|
27
|
+
expect { mock.html_tag :foo, 'bar', { baz: :raz }, false, true }
|
28
|
+
.to raise_error ArgumentError
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
23
32
|
end
|
24
33
|
|
25
34
|
describe '#image_tag' do
|
@@ -4,7 +4,7 @@ describe Flatrack::View do
|
|
4
4
|
include Flatrack::SiteHelper
|
5
5
|
|
6
6
|
let(:uri) { URI.parse 'http://example.org/index.html' }
|
7
|
-
let(:env) {
|
7
|
+
let(:env) { Flatrack.mock_env_for uri.to_s }
|
8
8
|
let(:request) { Flatrack::Request.new env }
|
9
9
|
let(:response) { Flatrack::Response.new request }
|
10
10
|
subject(:view) { described_class.new response }
|
data/spec/lib/flatrack_spec.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Flatrack do
|
4
|
+
include Flatrack::SiteHelper
|
4
5
|
|
5
6
|
describe '.gem_root' do
|
6
7
|
it 'should be the root of the gem' do
|
@@ -25,4 +26,76 @@ describe Flatrack do
|
|
25
26
|
end
|
26
27
|
end
|
27
28
|
|
29
|
+
describe '.redirect' do
|
30
|
+
it 'should redirect requests with a 301' do
|
31
|
+
site do
|
32
|
+
Flatrack.config do |site|
|
33
|
+
site.redirect '/foo', to: '/bar'
|
34
|
+
end
|
35
|
+
status, headers, _ = get_page_response '/foo'
|
36
|
+
expect(status).to eq 301
|
37
|
+
expect(headers['location']).to eq '/bar'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'when an argument is not a string' do
|
42
|
+
it 'should raise an error' do
|
43
|
+
Flatrack.config do |site|
|
44
|
+
expect { site.redirect :bar, to: '/' }
|
45
|
+
.to raise_error ArgumentError
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'with type :permanent' do
|
51
|
+
it 'should redirect requests with a 301' do
|
52
|
+
site do
|
53
|
+
Flatrack.config do |site|
|
54
|
+
site.redirect '/foo', to: '/bar', type: :permanent
|
55
|
+
end
|
56
|
+
status, headers, _ = get_page_response '/foo'
|
57
|
+
expect(status).to eq 301
|
58
|
+
expect(headers['location']).to eq '/bar'
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'with type :temporary' do
|
64
|
+
it 'should redirect requests with a 302' do
|
65
|
+
site do
|
66
|
+
Flatrack.config do |site|
|
67
|
+
site.redirect '/foo', to: '/bar', type: :temporary
|
68
|
+
end
|
69
|
+
status, headers, _ = get_page_response '/foo'
|
70
|
+
expect(status).to eq 302
|
71
|
+
expect(headers['location']).to eq '/bar'
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe '.rewrite' do
|
78
|
+
it 'should rewrite a path' do
|
79
|
+
site do
|
80
|
+
write :page, 'bar.html.rb', '"page is #{current_page}"'
|
81
|
+
Flatrack.config do |site|
|
82
|
+
site.raise_errors = true
|
83
|
+
site.rewrite '/foo', to: '/bar.html'
|
84
|
+
end
|
85
|
+
status, _, body = get_page_response '/foo'
|
86
|
+
expect(status).to eq 200
|
87
|
+
expect(body.body.first).to include 'page is /bar.html'
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
context 'when an argument is not a string' do
|
92
|
+
it 'should raise an error' do
|
93
|
+
Flatrack.config do |site|
|
94
|
+
expect { site.rewrite :bar, to: '/' }
|
95
|
+
.to raise_error ArgumentError
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
28
101
|
end
|
@@ -6,7 +6,7 @@ describe Rake::AssetTasks do
|
|
6
6
|
include FileUtils
|
7
7
|
include Flatrack::SiteHelper
|
8
8
|
|
9
|
-
before(:
|
9
|
+
before(:each) do
|
10
10
|
@sha = site(clean: false) do
|
11
11
|
@rake = Rake::Application.new
|
12
12
|
Rake.application = @rake
|
@@ -21,7 +21,7 @@ describe Rake::AssetTasks do
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
after(:
|
24
|
+
after(:each) do
|
25
25
|
Rake.application = nil
|
26
26
|
cleanup(@sha)
|
27
27
|
rm_rf(@dir)
|
data/spec/spec_helper.rb
CHANGED
data/spec/support/site_helper.rb
CHANGED
@@ -33,7 +33,9 @@ class Flatrack
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def get_page_response(page)
|
36
|
-
|
36
|
+
url = URI.parse 'http://example.org'
|
37
|
+
url.path = File.join '', page
|
38
|
+
env = Rack::MockRequest.env_for url.to_s
|
37
39
|
Flatrack::Site.call(env)
|
38
40
|
end
|
39
41
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flatrack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Waldrip
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.4'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rack-contrib
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.2'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: erubis
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -61,7 +75,7 @@ dependencies:
|
|
61
75
|
version: '3.2'
|
62
76
|
- - "<"
|
63
77
|
- !ruby/object:Gem::Version
|
64
|
-
version: '
|
78
|
+
version: '5.0'
|
65
79
|
type: :runtime
|
66
80
|
prerelease: false
|
67
81
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -71,21 +85,21 @@ dependencies:
|
|
71
85
|
version: '3.2'
|
72
86
|
- - "<"
|
73
87
|
- !ruby/object:Gem::Version
|
74
|
-
version: '
|
88
|
+
version: '5.0'
|
75
89
|
- !ruby/object:Gem::Dependency
|
76
90
|
name: sass
|
77
91
|
requirement: !ruby/object:Gem::Requirement
|
78
92
|
requirements:
|
79
93
|
- - "~>"
|
80
94
|
- !ruby/object:Gem::Version
|
81
|
-
version: 3.2
|
95
|
+
version: '3.2'
|
82
96
|
type: :runtime
|
83
97
|
prerelease: false
|
84
98
|
version_requirements: !ruby/object:Gem::Requirement
|
85
99
|
requirements:
|
86
100
|
- - "~>"
|
87
101
|
- !ruby/object:Gem::Version
|
88
|
-
version: 3.2
|
102
|
+
version: '3.2'
|
89
103
|
- !ruby/object:Gem::Dependency
|
90
104
|
name: sprockets-sass
|
91
105
|
requirement: !ruby/object:Gem::Requirement
|
@@ -137,7 +151,7 @@ dependencies:
|
|
137
151
|
version: 0.8.7
|
138
152
|
- - "<"
|
139
153
|
- !ruby/object:Gem::Version
|
140
|
-
version: '10.
|
154
|
+
version: '10.4'
|
141
155
|
type: :runtime
|
142
156
|
prerelease: false
|
143
157
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -147,7 +161,7 @@ dependencies:
|
|
147
161
|
version: 0.8.7
|
148
162
|
- - "<"
|
149
163
|
- !ruby/object:Gem::Version
|
150
|
-
version: '10.
|
164
|
+
version: '10.4'
|
151
165
|
- !ruby/object:Gem::Dependency
|
152
166
|
name: bundler
|
153
167
|
requirement: !ruby/object:Gem::Requirement
|
@@ -328,6 +342,7 @@ files:
|
|
328
342
|
- error_pages/404.html
|
329
343
|
- error_pages/500.html
|
330
344
|
- flatrack.gemspec
|
345
|
+
- lib/custom-extensions/sprockets-sass.rb
|
331
346
|
- lib/flatrack.rb
|
332
347
|
- lib/flatrack/asset_extensions.rb
|
333
348
|
- lib/flatrack/cli.rb
|
@@ -342,8 +357,12 @@ files:
|
|
342
357
|
- lib/flatrack/cli/templates/logo.png
|
343
358
|
- lib/flatrack/cli/templates/page.html.erb
|
344
359
|
- lib/flatrack/cli/templates/stylesheet.css.scss
|
360
|
+
- lib/flatrack/domain_parser.rb
|
361
|
+
- lib/flatrack/middleware.rb
|
362
|
+
- lib/flatrack/redirector.rb
|
345
363
|
- lib/flatrack/request.rb
|
346
364
|
- lib/flatrack/response.rb
|
365
|
+
- lib/flatrack/rewriter.rb
|
347
366
|
- lib/flatrack/sass.rb
|
348
367
|
- lib/flatrack/sass/functions.rb
|
349
368
|
- lib/flatrack/sass/importer.rb
|
@@ -390,10 +409,12 @@ files:
|
|
390
409
|
- spec/fixtures/templates/stylesheet_tag.html.rb
|
391
410
|
- spec/lib/flatrack/asset_extensions_spec.rb
|
392
411
|
- spec/lib/flatrack/cli_spec.rb
|
412
|
+
- spec/lib/flatrack/middleware_spec.rb
|
393
413
|
- spec/lib/flatrack/request_spec.rb
|
394
414
|
- spec/lib/flatrack/response_spec.rb
|
395
415
|
- spec/lib/flatrack/site_spec.rb
|
396
416
|
- spec/lib/flatrack/view/link_helper_spec.rb
|
417
|
+
- spec/lib/flatrack/view/render_helper_spec.rb
|
397
418
|
- spec/lib/flatrack/view/set_layout_spec.rb
|
398
419
|
- spec/lib/flatrack/view/tag_helper_spec.rb
|
399
420
|
- spec/lib/flatrack/view_spec.rb
|
@@ -422,7 +443,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
422
443
|
version: '0'
|
423
444
|
requirements: []
|
424
445
|
rubyforge_project:
|
425
|
-
rubygems_version: 2.
|
446
|
+
rubygems_version: 2.4.5
|
426
447
|
signing_key:
|
427
448
|
specification_version: 4
|
428
449
|
summary: Deliver static files with style.
|
@@ -450,10 +471,12 @@ test_files:
|
|
450
471
|
- spec/fixtures/templates/stylesheet_tag.html.rb
|
451
472
|
- spec/lib/flatrack/asset_extensions_spec.rb
|
452
473
|
- spec/lib/flatrack/cli_spec.rb
|
474
|
+
- spec/lib/flatrack/middleware_spec.rb
|
453
475
|
- spec/lib/flatrack/request_spec.rb
|
454
476
|
- spec/lib/flatrack/response_spec.rb
|
455
477
|
- spec/lib/flatrack/site_spec.rb
|
456
478
|
- spec/lib/flatrack/view/link_helper_spec.rb
|
479
|
+
- spec/lib/flatrack/view/render_helper_spec.rb
|
457
480
|
- spec/lib/flatrack/view/set_layout_spec.rb
|
458
481
|
- spec/lib/flatrack/view/tag_helper_spec.rb
|
459
482
|
- spec/lib/flatrack/view_spec.rb
|