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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 02f38974206178dab428bdc7d4b7a0c2aa92dc03
4
- data.tar.gz: b6b70a1a6ea5ddd2a9a4c344c547228715d499c3
3
+ metadata.gz: c19e4a9f13cab919d16beac789e1030adc8484ef
4
+ data.tar.gz: e28d6c79ef1c3fde4e1a117c160d0c339b4b9f52
5
5
  SHA512:
6
- metadata.gz: 4a2cd97cdcdcd578d7a3af3278ef743c7fbd838eb1d195e7233e406c4cf9a74d0a26c932852fc4c04cf402cdb2a3f55af753911487325de9cfdf6d11c6e32888
7
- data.tar.gz: 22a927232f2f038a3297ef20e78dd5a605950a032ec411b5cb8796720c461a7faefd9be9c152518f25f345c58c1c2c52d12c2ddda12bcbe9363213ff82f5d3f7
6
+ metadata.gz: ccafe9a3cfc1b91d6cbce338062f6d71767e8840cbcc81a0fb5aa15b0aec8a114b27f1a7a10a26aa2e5604de61976f91b8af32b1d6ca370c6e11c0a586484fa0
7
+ data.tar.gz: 5de8c2db8beea1d99f89db153f38b0c4ebe4ea573da2a879bbb2a082a32cb3fed458265f2a9d7ff1f293679c5481b2f5c53b8aff3bdfc10425d3041841eec29f
data/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ # Flatrack 1.1.0 (March 05, 2014)
2
+
3
+ * Added support for rendering partials in views
4
+
5
+ *Jason Waldrip*
6
+
7
+ # Flatrack 1.0.0 (March 04, 2014)
8
+
9
+ * Initial Release
10
+
11
+ *Jason Waldrip*
data/lib/flatrack/cli.rb CHANGED
@@ -18,7 +18,8 @@ class Flatrack
18
18
  'assets/javascripts',
19
19
  'assets/images',
20
20
  'pages',
21
- 'layouts'
21
+ 'layouts',
22
+ 'partials'
22
23
  ]
23
24
 
24
25
  FILES = {
@@ -4,11 +4,10 @@ class Flatrack
4
4
 
5
5
  autoload :Base
6
6
 
7
- def find(file)
8
- template = File.exists?(file) ? file : [*pages(file), *layouts(file)][0]
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 pages(file)
22
- Dir[File.join 'pages', "#{file}*"]
23
- end
24
-
25
- def layouts(file)
26
- Dir[File.join 'layouts', "#{file}*"]
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, :pages, :layouts
28
+ module_function :find, :find_by_type
30
29
  end
31
30
  end
@@ -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 { renderer_for(file).render(view_context) }
26
+ page_content = proc { renderer_for_page(file).render(view_context) }
27
27
  set_content_type
28
28
  body << begin
29
- layout_for(layout).render(view_context, &page_content)
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 renderer_for(file)
51
- Renderer.find file
50
+ def renderer_for_page(file)
51
+ Renderer.find :page, file
52
52
  end
53
53
 
54
- def layout_for(file)
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)
@@ -1,3 +1,3 @@
1
1
  class Flatrack
2
- VERSION = '1.0.0'
2
+ VERSION = '1.1.0'
3
3
  end
@@ -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)
@@ -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
- write_page("#{sha}.html.erb", template)
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
@@ -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
- write_page("#{sha}.html.html", template)
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
@@ -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
- write_page("#{sha}.html.rb", template)
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
@@ -27,8 +27,8 @@ module SiteHelper
27
27
  end
28
28
  end
29
29
 
30
- def write_page(filename, contents)
31
- Dir.chdir('pages') do
30
+ def write(type, filename, contents)
31
+ Dir.chdir(type.to_s.pluralize) do
32
32
  File.open(filename, 'w') do |file|
33
33
  file.write(contents)
34
34
  end
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.0.0
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-05 00:00:00.000000000 Z
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
@@ -1,4 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Flatrack::Renderer do
4
- end