akki 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -17,9 +17,13 @@ Feature: Article
17
17
  %head
18
18
  %title= article.title
19
19
  %body
20
- = article.render
20
+ = yield
21
21
  """
22
- And I visit "1983/10/23/simple-article"
22
+ And the article template:
23
+ """
24
+ %div.article= article.render
25
+ """
26
+ When I visit "1983/10/23/simple-article"
23
27
  Then I should see:
24
28
  """
25
29
  <html>
@@ -27,7 +31,7 @@ Feature: Article
27
31
  <title>Simple Article</title>
28
32
  </head>
29
33
  <body>
30
- <p>article content</p>
34
+ <div class='article'><p>article content</p></div>
31
35
  </body>
32
36
  </html>
33
37
 
@@ -14,6 +14,14 @@ Given /^the layout template:$/ do |contents|
14
14
  end
15
15
  end
16
16
 
17
+ Given /^the article template:$/ do |contents|
18
+ templates_path = File.join(File.dirname(__FILE__), '..', '..', 'templates')
19
+ FileUtils.mkdir_p(templates_path)
20
+ File.open(File.join(templates_path, 'article.haml'), 'w') do |file|
21
+ file.write(contents)
22
+ end
23
+ end
24
+
17
25
  Given /^I visit "([^"]*)"$/ do |url|
18
26
  visit "/#{url}"
19
27
  end
@@ -1,5 +1,6 @@
1
1
  require 'sinatra/base'
2
2
  require 'yaml'
3
+ require 'ostruct'
3
4
  require 'akki/article'
4
5
 
5
6
  module Akki
@@ -13,8 +14,14 @@ module Akki
13
14
  end
14
15
 
15
16
  def render article
17
+ scope = OpenStruct.new
18
+ scope.article = article
16
19
  layout = File.read('templates/layout.haml')
17
- Haml::Engine.new(layout).render(binding)
20
+ article_layout = File.read('templates/article.haml')
21
+
22
+ Haml::Engine.new(layout).render(scope) do
23
+ Haml::Engine.new(article_layout).render(binding)
24
+ end
18
25
  end
19
26
  end
20
27
  end
@@ -1,3 +1,3 @@
1
1
  module Akki
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -12,7 +12,9 @@ module Akki
12
12
  before do
13
13
  @article = mock :article
14
14
  @article.stub!(:render).and_return 'article content'
15
- @article.stub!(:title)
15
+ @article.stub!(:title).and_return 'article title'
16
+ File.stub!(:read).with('templates/layout.haml').and_return '%div= yield'
17
+ File.stub!(:read).with('templates/article.haml').and_return '%p= article.render'
16
18
  Article.stub!(:from_file).and_return @article
17
19
  end
18
20
 
@@ -26,10 +28,15 @@ module Akki
26
28
  get '/2011/10/23/simple-article'
27
29
  end
28
30
 
29
- it "returns a template" do
30
- File.stub!(:read).and_return '%p hello'
31
+ it "renders the article inside an article template" do
31
32
  get '/2011/10/23/simple-article'
32
- last_response.body.should include '<p>hello</p>'
33
+ last_response.body.should include '<div><p>article content</p></div>'
34
+ end
35
+
36
+ it "passes the article through through to the layout when rendering" do
37
+ File.stub!(:read).with('templates/layout.haml').and_return '= article.title'
38
+ get '/2011/10/23/simple-article'
39
+ last_response.body.should include 'article title'
33
40
  end
34
41
  end
35
42
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: akki
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-14 00:00:00.000000000 +01:00
12
+ date: 2011-08-15 00:00:00.000000000 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: sinatra
17
- requirement: &70309988133600 !ruby/object:Gem::Requirement
17
+ requirement: &70103560445100 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70309988133600
25
+ version_requirements: *70103560445100
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: haml
28
- requirement: &70309988133180 !ruby/object:Gem::Requirement
28
+ requirement: &70103560444680 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *70309988133180
36
+ version_requirements: *70103560444680
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: rspec
39
- requirement: &70309988132760 !ruby/object:Gem::Requirement
39
+ requirement: &70103560444260 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: '0'
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *70309988132760
47
+ version_requirements: *70103560444260
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: cucumber
50
- requirement: &70309988132340 !ruby/object:Gem::Requirement
50
+ requirement: &70103560443840 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ! '>='
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: '0'
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *70309988132340
58
+ version_requirements: *70103560443840
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: capybara
61
- requirement: &70309988131920 !ruby/object:Gem::Requirement
61
+ requirement: &70103560443420 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ! '>='
@@ -66,7 +66,7 @@ dependencies:
66
66
  version: '0'
67
67
  type: :development
68
68
  prerelease: false
69
- version_requirements: *70309988131920
69
+ version_requirements: *70103560443420
70
70
  description: ''
71
71
  email:
72
72
  - andrew.vos@gmail.com