flatrack 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/lib/flatrack/cli.rb +2 -1
- data/lib/flatrack/renderer.rb +9 -10
- data/lib/flatrack/response.rb +6 -6
- data/lib/flatrack/response/view_context.rb +4 -0
- data/lib/flatrack/version.rb +1 -1
- data/spec/lib/flatrack/response/view_context_spec.rb +17 -0
- data/spec/renderers/erb_spec.rb +1 -1
- data/spec/renderers/html_spec.rb +1 -1
- data/spec/renderers/rb_spec.rb +1 -1
- data/spec/support/site_helper.rb +2 -2
- metadata +3 -4
- data/spec/lib/flatrack/renderer_spec.rb +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c19e4a9f13cab919d16beac789e1030adc8484ef
|
4
|
+
data.tar.gz: e28d6c79ef1c3fde4e1a117c160d0c339b4b9f52
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ccafe9a3cfc1b91d6cbce338062f6d71767e8840cbcc81a0fb5aa15b0aec8a114b27f1a7a10a26aa2e5604de61976f91b8af32b1d6ca370c6e11c0a586484fa0
|
7
|
+
data.tar.gz: 5de8c2db8beea1d99f89db153f38b0c4ebe4ea573da2a879bbb2a082a32cb3fed458265f2a9d7ff1f293679c5481b2f5c53b8aff3bdfc10425d3041841eec29f
|
data/CHANGELOG.md
ADDED
data/lib/flatrack/cli.rb
CHANGED
data/lib/flatrack/renderer.rb
CHANGED
@@ -4,11 +4,10 @@ class Flatrack
|
|
4
4
|
|
5
5
|
autoload :Base
|
6
6
|
|
7
|
-
def find(file)
|
8
|
-
template =
|
7
|
+
def find(type, file)
|
8
|
+
template = find_by_type type, file
|
9
9
|
fail FileNotFound, "could not find #{file}" unless template
|
10
10
|
ext = File.extname(template).sub(/\./, '')
|
11
|
-
|
12
11
|
renderer = Base.descendants.find do |descendant|
|
13
12
|
descendant.renders?(ext)
|
14
13
|
end || fail(RendererNotFound, "could not find a renderer for #{file}")
|
@@ -18,14 +17,14 @@ class Flatrack
|
|
18
17
|
|
19
18
|
private
|
20
19
|
|
21
|
-
def
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
20
|
+
def find_by_type(type, file)
|
21
|
+
if File.exists?(file)
|
22
|
+
file
|
23
|
+
else
|
24
|
+
Dir[File.join type.to_s.pluralize, "#{file}*"].first
|
25
|
+
end
|
27
26
|
end
|
28
27
|
|
29
|
-
module_function :find, :
|
28
|
+
module_function :find, :find_by_type
|
30
29
|
end
|
31
30
|
end
|
data/lib/flatrack/response.rb
CHANGED
@@ -23,10 +23,10 @@ class Flatrack
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def render(file: file_for(request.path), status: 200, layout: :layout)
|
26
|
-
page_content = proc {
|
26
|
+
page_content = proc { renderer_for_page(file).render(view_context) }
|
27
27
|
set_content_type
|
28
28
|
body << begin
|
29
|
-
|
29
|
+
renderer_for_layout(layout).render(view_context, &page_content)
|
30
30
|
rescue Flatrack::FileNotFound
|
31
31
|
page_content.call
|
32
32
|
end
|
@@ -47,12 +47,12 @@ class Flatrack
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
-
def
|
51
|
-
Renderer.find file
|
50
|
+
def renderer_for_page(file)
|
51
|
+
Renderer.find :page, file
|
52
52
|
end
|
53
53
|
|
54
|
-
def
|
55
|
-
Renderer.find File.join("#{file}.#{request.format}")
|
54
|
+
def renderer_for_layout(file)
|
55
|
+
Renderer.find :layout, File.join("#{file}.#{request.format}")
|
56
56
|
end
|
57
57
|
|
58
58
|
def view_context
|
@@ -46,6 +46,10 @@ class Flatrack
|
|
46
46
|
@response.request.path
|
47
47
|
end
|
48
48
|
|
49
|
+
def render(file)
|
50
|
+
Renderer.find(:partial, file.to_s).render(self)
|
51
|
+
end
|
52
|
+
|
49
53
|
def stylesheet_tag(uri)
|
50
54
|
uri = asset_path(uri) + '.css' if uri.is_a? Symbol
|
51
55
|
html_tag(:link, rel: 'stylesheet', type: 'text/css', href: uri)
|
data/lib/flatrack/version.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Flatrack::Response::ViewContext do
|
4
|
+
include SiteHelper
|
4
5
|
|
5
6
|
let(:uri) { URI.parse 'http://example.org/index.html' }
|
6
7
|
let(:env){ Rack::MockRequest.env_for uri.to_s }
|
@@ -66,6 +67,22 @@ describe Flatrack::Response::ViewContext do
|
|
66
67
|
end
|
67
68
|
end
|
68
69
|
|
70
|
+
describe '#render' do
|
71
|
+
let(:template) do
|
72
|
+
<<-ERB
|
73
|
+
<%= 'Hello World'.reverse %>
|
74
|
+
ERB
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'should properly render a partial' do
|
78
|
+
site do
|
79
|
+
write(:partial, 'sample.erb', template)
|
80
|
+
result = view.render(:sample)
|
81
|
+
expect(result).to include 'Hello World'.reverse
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
69
86
|
describe '#stylesheet_tag' do
|
70
87
|
it 'should be a proper stylesheet tag' do
|
71
88
|
expect(view.stylesheet_tag :test)
|
data/spec/renderers/erb_spec.rb
CHANGED
@@ -12,7 +12,7 @@ describe Flatrack::Renderer::ERB do
|
|
12
12
|
it 'should render properly' do
|
13
13
|
sha = SecureRandom.hex
|
14
14
|
site do
|
15
|
-
|
15
|
+
write(:page, "#{sha}.html.erb", template)
|
16
16
|
status, headers, body = get_page_response(sha)
|
17
17
|
expect(body.first).to include 'Hello World'.reverse
|
18
18
|
end
|
data/spec/renderers/html_spec.rb
CHANGED
@@ -12,7 +12,7 @@ describe Flatrack::Renderer::Html do
|
|
12
12
|
it 'should render properly' do
|
13
13
|
sha = SecureRandom.hex
|
14
14
|
site do
|
15
|
-
|
15
|
+
write(:page, "#{sha}.html.html", template)
|
16
16
|
status, headers, body = get_page_response(sha)
|
17
17
|
expect(body.first).to include template
|
18
18
|
end
|
data/spec/renderers/rb_spec.rb
CHANGED
@@ -12,7 +12,7 @@ describe Flatrack::Renderer::Rb do
|
|
12
12
|
it 'should render properly' do
|
13
13
|
sha = SecureRandom.hex
|
14
14
|
site do
|
15
|
-
|
15
|
+
write(:page, "#{sha}.html.rb", template)
|
16
16
|
status, headers, body = get_page_response(sha)
|
17
17
|
expect(body.first).to include 'Hello World'.reverse
|
18
18
|
end
|
data/spec/support/site_helper.rb
CHANGED
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.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Waldrip
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -236,6 +236,7 @@ files:
|
|
236
236
|
- ".rubocop.yml"
|
237
237
|
- ".ruby-version"
|
238
238
|
- ".travis.yml"
|
239
|
+
- CHANGELOG.md
|
239
240
|
- Gemfile
|
240
241
|
- Guardfile
|
241
242
|
- LICENSE.txt
|
@@ -263,7 +264,6 @@ files:
|
|
263
264
|
- spec/lib/flatrack/asset_extensions_spec.rb
|
264
265
|
- spec/lib/flatrack/cli_spec.rb
|
265
266
|
- spec/lib/flatrack/renderer/base_spec.rb
|
266
|
-
- spec/lib/flatrack/renderer_spec.rb
|
267
267
|
- spec/lib/flatrack/request_spec.rb
|
268
268
|
- spec/lib/flatrack/response/view_context_spec.rb
|
269
269
|
- spec/lib/flatrack/response_spec.rb
|
@@ -316,7 +316,6 @@ test_files:
|
|
316
316
|
- spec/lib/flatrack/asset_extensions_spec.rb
|
317
317
|
- spec/lib/flatrack/cli_spec.rb
|
318
318
|
- spec/lib/flatrack/renderer/base_spec.rb
|
319
|
-
- spec/lib/flatrack/renderer_spec.rb
|
320
319
|
- spec/lib/flatrack/request_spec.rb
|
321
320
|
- spec/lib/flatrack/response/view_context_spec.rb
|
322
321
|
- spec/lib/flatrack/response_spec.rb
|