akki 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore CHANGED
@@ -4,3 +4,5 @@ Gemfile.lock
4
4
  pkg/*
5
5
  articles/*
6
6
  templates/*
7
+ views/*
8
+ *.swp
@@ -0,0 +1 @@
1
+ rvm: 1.9.2
data/Rakefile CHANGED
@@ -1 +1,11 @@
1
+ require 'bundler/setup'
1
2
  require 'bundler/gem_tasks'
3
+ require 'rspec/core/rake_task'
4
+ require 'cucumber/rake/task'
5
+
6
+ task :default => [:spec, :cucumber]
7
+
8
+ RSpec::Core::RakeTask.new(:spec) do |task|
9
+ task.rspec_opts = ["--color"]
10
+ end
11
+ Cucumber::Rake::Task.new(:cucumber)
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
18
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
19
  s.add_dependency 'sinatra'
20
20
  s.add_dependency 'haml'
21
+ s.add_development_dependency 'rake'
21
22
  s.add_development_dependency 'rspec'
22
23
  s.add_development_dependency 'cucumber'
23
24
  s.add_development_dependency 'capybara'
@@ -0,0 +1,29 @@
1
+ Feature: Archives
2
+ In order to list all current articles
3
+ As a developer
4
+ I need a list of all articles
5
+
6
+ Scenario: View articles sorted by date
7
+ Given I have the article file "1991-04-23-article.txt"
8
+ """
9
+ title: Article 3
10
+ date: 2008/04/23
11
+ """
12
+ And I have the article file "1993-04-23-article.txt"
13
+ """
14
+ title: Article 2
15
+ date: 2008/04/23
16
+ """
17
+ And I have the article file "2008-04-23-article.txt"
18
+ """
19
+ title: Article 1
20
+ date: 2008/04/23
21
+ """
22
+ And I have an archive template that shows the article title
23
+ When I visit "/archives"
24
+ Then I should see:
25
+ """
26
+ <p>Article 1</p>
27
+ <p>Article 2</p>
28
+ <p>Article 3</p>
29
+ """
@@ -1,38 +1,18 @@
1
- Feature: Article
2
- In order to display articles on
1
+ Feature: Article Page
2
+ In order to display articles
3
3
  As a user
4
- I want to be render blog pages
4
+ I want to be able to view an article
5
5
 
6
6
  Scenario: Simple Article
7
- Given I have the article file "1983-10-23-simple-article.txt"
7
+ Given I have the article file "1983-05-23-simple-article.txt"
8
8
  """
9
9
  title: Simple Article
10
- date: 23/10/1983
10
+ date: 1983/05/23
11
11
 
12
12
  %p article content
13
13
  """
14
- And the layout template:
15
- """
16
- %html
17
- %head
18
- %title= article.title
19
- %body
20
- = yield
21
- """
22
- And the article template:
23
- """
24
- %div.article= article.render
25
- """
26
- When I visit "1983/10/23/simple-article"
14
+ When I visit "/1983/05/23/simple-article"
27
15
  Then I should see:
28
16
  """
29
- <html>
30
- <head>
31
- <title>Simple Article</title>
32
- </head>
33
- <body>
34
- <div class='article'><p>article content</p></div>
35
- </body>
36
- </html>
37
-
17
+ <div class='article'><p>article content</p></div>
38
18
  """
@@ -0,0 +1,2 @@
1
+ - articles.each do |article|
2
+ %p= article.title
@@ -0,0 +1 @@
1
+ %div.article= article.render
@@ -0,0 +1 @@
1
+ %p This is the example page
@@ -0,0 +1,5 @@
1
+ %html
2
+ %head
3
+ %title= article.title if defined? article
4
+ %body
5
+ = yield
@@ -0,0 +1,12 @@
1
+ Feature: Pages
2
+ In order to display custom pages
3
+ As a user
4
+ I want to display custom pages
5
+
6
+ Scenario: About page
7
+ Given I have the page "example-page"
8
+ When I visit "/example-page"
9
+ Then I should see:
10
+ """
11
+ <p>This is the example page</p>
12
+ """
@@ -1,7 +1,10 @@
1
1
  $:.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
2
2
 
3
+ ENV['RACK_ENV'] = 'test'
4
+
3
5
  require 'capybara/cucumber'
4
6
  require 'akki'
7
+ require 'fileutils'
5
8
 
6
9
  Capybara.app = Akki::Application
7
10
  Akki::Application.set :environment, :test
@@ -1,31 +1,29 @@
1
- Given /^I have the article file "([^"]*)"$/ do |article_file, article_contents|
2
- articles_path = File.join(File.dirname(__FILE__), '..', '..', 'articles')
3
- FileUtils.mkdir_p(articles_path)
4
- File.open(File.join(articles_path, article_file), 'w') do |file|
5
- file.write(article_contents)
6
- end
1
+ Before do
2
+ @articles_path = File.join(File.dirname(__FILE__), '..', '..', 'articles')
3
+ FileUtils.mkdir_p(@articles_path)
4
+ Akki::Application.set :views, "features/fixtures/views"
7
5
  end
8
6
 
9
- Given /^the layout template:$/ do |contents|
10
- templates_path = File.join(File.dirname(__FILE__), '..', '..', 'templates')
11
- FileUtils.mkdir_p(templates_path)
12
- File.open(File.join(templates_path, 'layout.haml'), 'w') do |file|
13
- file.write(contents)
14
- end
7
+ After do
8
+ FileUtils.rm_rf @articles_path if File.exist?(@articles_path)
15
9
  end
16
10
 
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)
11
+ Given /^I have the article file "([^"]*)"$/ do |article_file, article_contents|
12
+ File.open(File.join(@articles_path, article_file), 'w') do |file|
13
+ file.write(article_contents)
22
14
  end
23
15
  end
24
16
 
17
+ Given /^I have the page "example-page"$/ do
18
+ end
19
+
25
20
  Given /^I visit "([^"]*)"$/ do |url|
26
- visit "/#{url}"
21
+ visit url
27
22
  end
28
23
 
29
24
  Then /^I should see:$/ do |content|
30
- page.source.should == content
25
+ page.source.should include content
26
+ end
27
+
28
+ Given /^I have an archive template that shows the article title$/ do
31
29
  end
@@ -1,3 +1,7 @@
1
1
  $:.unshift(File.dirname(__FILE__))
2
+
3
+ require "rubygems"
4
+ require "bundler/setup"
5
+
2
6
  require "akki/version"
3
7
  require "akki/application"
@@ -5,23 +5,18 @@ require 'akki/article'
5
5
 
6
6
  module Akki
7
7
  class Application < Sinatra::Base
8
+
8
9
  get "/:year/:month/:day/:slug/?" do
9
- year = params[:year]
10
- month = params[:month]
11
- day = params[:day]
10
+ year = params[:year].to_i
11
+ month = params[:month].to_i
12
+ day = params[:day].to_i
12
13
  slug = params[:slug]
13
- render(Article::from_file(year, month, day, slug))
14
+ article = Article::find(year, month, day, slug)
15
+ haml :article, :locals => { :article => article }
14
16
  end
15
17
 
16
- def render article
17
- scope = OpenStruct.new
18
- scope.article = article
19
- layout = File.read('templates/layout.haml')
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
+ get "/:page/?" do
19
+ haml params[:page].to_sym, :locals => { :articles => Article.all }
25
20
  end
26
21
  end
27
22
  end
@@ -2,22 +2,38 @@ require 'haml'
2
2
 
3
3
  module Akki
4
4
  class Article
5
- attr_accessor :title, :date, :content
5
+ attr_accessor :title, :slug, :date, :content
6
6
 
7
- def initialize(title, date, content)
7
+ def initialize(title, date, content, slug)
8
8
  @title = title
9
9
  @date = date
10
10
  @content = content
11
+ @slug = slug
11
12
  end
12
13
 
13
- def self.from_file year, month, day, slug
14
- path = "articles/#{year}-#{month}-#{day}-#{slug}.txt"
15
- parts = File.read(path).split("\n\n", 2)
16
- yaml = YAML.parse(parts[0])
17
- content = parts[1]
18
- title = yaml['title'].value
19
- date = Date.strptime(yaml['date'].value, '%Y/%m/%d')
20
- Article.new(title, date, content)
14
+ def self.find year, month, day, slug
15
+ article = all.select { |article|
16
+ article.date.year == year &&
17
+ article.date.month == month &&
18
+ article.date.day == day &&
19
+ article.slug == slug
20
+ }.first
21
+ end
22
+
23
+ def self.all
24
+ articles = Dir.glob("articles/*").map do |path|
25
+ parts = File.read(path).split("\n\n", 2)
26
+ yaml = YAML.load(parts[0])
27
+ content = parts[1]
28
+ title = yaml['title']
29
+ date = Date.strptime(yaml['date'], '%Y/%m/%d')
30
+ slug = File.basename(path).split("-", 4).last.gsub(".txt", "")
31
+ Article.new(title, date, content, slug)
32
+ end
33
+
34
+ articles = articles.sort do |a, b|
35
+ a.date <=> b.date
36
+ end.reverse
21
37
  end
22
38
 
23
39
  def render
@@ -1,3 +1,3 @@
1
1
  module Akki
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -1,5 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
+ Akki::Application.set :reload_templates, true
4
+
3
5
  module Akki
4
6
  describe Application do
5
7
  include Rack::Test::Methods
@@ -8,35 +10,67 @@ module Akki
8
10
  Application
9
11
  end
10
12
 
13
+ before do
14
+ @views_path = File.join(File.dirname(__FILE__), '..', 'views')
15
+ FileUtils.mkdir_p @views_path
16
+ end
17
+
18
+ after do
19
+ FileUtils.rm_rf @views_path
20
+ end
21
+
22
+ def create_view name, contents
23
+ File.open(File.join(@views_path, name), 'w') do |file|
24
+ file.write(contents)
25
+ end
26
+ end
27
+
11
28
  describe "GET /23/10/2011/simple-article" do
12
29
  before do
13
30
  @article = mock :article
14
31
  @article.stub!(:render).and_return 'article content'
15
32
  @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'
18
- Article.stub!(:from_file).and_return @article
33
+ Article.stub!(:find).and_return @article
19
34
  end
20
35
 
21
- it "is successful" do
36
+ it "loads an article" do
37
+ create_view "article.haml", ""
38
+ Article.should_receive(:find).with(2011, 10, 23, "simple-article")
22
39
  get '/2011/10/23/simple-article'
23
- last_response.should be_ok
24
40
  end
25
41
 
26
- it "loads an article" do
27
- Article.should_receive(:from_file).with("2011", "10", "23", 'simple-article')
42
+ it "passes the article through to the view" do
43
+ create_view "article.haml", "= article.render"
28
44
  get '/2011/10/23/simple-article'
45
+ last_response.body.should include "article content"
29
46
  end
30
47
 
31
- it "renders the article inside an article template" do
48
+ it "renders the article" do
49
+ create_view 'article.haml', '= article.render'
32
50
  get '/2011/10/23/simple-article'
33
- last_response.body.should include '<div><p>article content</p></div>'
51
+ last_response.body.should include "article content"
34
52
  end
53
+ end
35
54
 
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'
55
+ describe "GET /page_name" do
56
+ it "renders a custom page" do
57
+ Article.stub!(:all).and_return []
58
+ create_view 'page_name.haml', 'this is my page!'
59
+ get '/page_name'
60
+ last_response.body.should include 'this is my page!'
61
+ end
62
+ end
63
+
64
+ describe "GET a page that lists articles" do
65
+ it "lists all articles" do
66
+ Article.stub!(:all).and_return([
67
+ Article.new("article 1", nil, "article 1 content", "article1"),
68
+ Article.new("article 2", nil, "article 2 content", "article2")
69
+ ])
70
+ create_view 'archives.haml', "- articles.each do |a|\n %p= a.title"
71
+ get '/archives'
72
+ last_response.body.should include "article 1"
73
+ last_response.body.should include "article 2"
40
74
  end
41
75
  end
42
76
  end
@@ -3,43 +3,50 @@ require 'akki/article'
3
3
 
4
4
  module Akki
5
5
  describe Article do
6
- before do
7
- File.stub!(:read).and_return <<-ARTICLE
8
- title: the article title
9
- date: 1983/10/23
10
-
11
- article content
12
- ARTICLE
6
+ it "renders the content" do
7
+ article = Article.new("an article", Date.new(2011, 10, 10), "%p article content", "an-article")
8
+ article.render.should include '<p>article content</p>'
13
9
  end
14
10
 
15
- it "reads article content from a file" do
16
- File.should_receive(:read).with('articles/2011-10-23-article-slug.txt')
17
- Article.from_file(2011, 10, 23, 'article-slug')
11
+ def article_should_match article, title, date, content, slug
12
+ article.title.should == title
13
+ article.date.should == date
14
+ article.content.should == content
15
+ article.slug.should == slug
18
16
  end
19
17
 
20
- it "loads the title" do
21
- article = Article.from_file(2011, 10, 23, 'article-slug')
22
- article.title.should == 'the article title'
23
- end
18
+ it "loads all articles" do
19
+ articles = [
20
+ "articles/2012-10-23-article1.txt",
21
+ "articles/2011-11-25-article2.txt"
22
+ ]
23
+ Dir.stub!(:glob).with("articles/*").and_return(articles)
24
+ File.stub!(:read).with(articles.first).and_return("title: article 1\ndate: 2012/10/23\n\narticle 1 content")
25
+ File.stub!(:read).with(articles.last).and_return("title: article 2\ndate: 2011/11/25\n\narticle 2 content")
24
26
 
25
- it "loads the date" do
26
- article = Article.from_file(2011, 10, 23, 'article-slug')
27
- article.date.year.should == 1983
28
- article.date.month.should == 10
29
- article.date.day.should == 23
27
+ article_should_match(Article.all.first, "article 1", Date.new(2012, 10, 23), "article 1 content", "article1")
28
+ article_should_match(Article.all.last, "article 2", Date.new(2011, 11, 25), "article 2 content", "article2")
30
29
  end
31
30
 
32
- it "loads the article content" do
33
- article = Article.from_file(2011, 10, 23, 'article-slug')
34
- article.content.should include 'article content'
31
+ it "sorts articles by date" do
32
+ articles = [
33
+ "articles/2009-10-23-article1.txt",
34
+ "articles/2011-11-25-article2.txt"
35
+ ]
36
+ Dir.stub!(:glob).with("articles/*").and_return(articles)
37
+ File.stub!(:read).with(articles.first).and_return("title: article 1\ndate: 2009/10/23\n\narticle 1 content")
38
+ File.stub!(:read).with(articles.last).and_return("title: article 2\ndate: 2011/11/25\n\narticle 2 content")
39
+ Article.all.first.title.should == "article 2"
40
+ Article.all.last.title.should == "article 1"
35
41
  end
36
42
 
37
- it "renders the content" do
38
- engine = mock :engine
39
- engine.stub!(:render).and_return 'rendered content'
40
- Haml::Engine.stub!(:new).and_return(engine)
41
- article = Article.from_file(2011, 10, 23, 'article-slug')
42
- article.render.should == 'rendered content'
43
+ it "finds an article" do
44
+ articles = [
45
+ Article.new("an article", Date.new(2011, 10, 10), "article 1 content", "an-article"),
46
+ Article.new("Some Article", Date.new(2033, 4, 3), "article 2 content", "some-article")
47
+ ]
48
+ Article.stub!(:all).and_return(articles)
49
+ Article.find(2033, 4, 3, "some-article").should == articles.last
43
50
  end
44
51
  end
45
52
  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.3
4
+ version: 0.0.4
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-15 00:00:00.000000000 +01:00
12
+ date: 2011-08-17 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: &70103560445100 !ruby/object:Gem::Requirement
17
+ requirement: &70144102831020 !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: *70103560445100
25
+ version_requirements: *70144102831020
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: haml
28
- requirement: &70103560444680 !ruby/object:Gem::Requirement
28
+ requirement: &70144102830340 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,21 @@ dependencies:
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *70103560444680
36
+ version_requirements: *70144102830340
37
+ - !ruby/object:Gem::Dependency
38
+ name: rake
39
+ requirement: &70144102829540 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *70144102829540
37
48
  - !ruby/object:Gem::Dependency
38
49
  name: rspec
39
- requirement: &70103560444260 !ruby/object:Gem::Requirement
50
+ requirement: &70144102828720 !ruby/object:Gem::Requirement
40
51
  none: false
41
52
  requirements:
42
53
  - - ! '>='
@@ -44,10 +55,10 @@ dependencies:
44
55
  version: '0'
45
56
  type: :development
46
57
  prerelease: false
47
- version_requirements: *70103560444260
58
+ version_requirements: *70144102828720
48
59
  - !ruby/object:Gem::Dependency
49
60
  name: cucumber
50
- requirement: &70103560443840 !ruby/object:Gem::Requirement
61
+ requirement: &70144102827700 !ruby/object:Gem::Requirement
51
62
  none: false
52
63
  requirements:
53
64
  - - ! '>='
@@ -55,10 +66,10 @@ dependencies:
55
66
  version: '0'
56
67
  type: :development
57
68
  prerelease: false
58
- version_requirements: *70103560443840
69
+ version_requirements: *70144102827700
59
70
  - !ruby/object:Gem::Dependency
60
71
  name: capybara
61
- requirement: &70103560443420 !ruby/object:Gem::Requirement
72
+ requirement: &70144102826640 !ruby/object:Gem::Requirement
62
73
  none: false
63
74
  requirements:
64
75
  - - ! '>='
@@ -66,7 +77,7 @@ dependencies:
66
77
  version: '0'
67
78
  type: :development
68
79
  prerelease: false
69
- version_requirements: *70103560443420
80
+ version_requirements: *70144102826640
70
81
  description: ''
71
82
  email:
72
83
  - andrew.vos@gmail.com
@@ -76,11 +87,18 @@ extra_rdoc_files: []
76
87
  files:
77
88
  - .gitignore
78
89
  - .rvmrc
90
+ - .travis.yml
79
91
  - Gemfile
80
92
  - Rakefile
81
93
  - akki.gemspec
82
94
  - config.ru
95
+ - features/archives.feature
83
96
  - features/articles.feature
97
+ - features/fixtures/views/archives.haml
98
+ - features/fixtures/views/article.haml
99
+ - features/fixtures/views/example-page.haml
100
+ - features/fixtures/views/layout.haml
101
+ - features/pages.feature
84
102
  - features/step_definitions/env.rb
85
103
  - features/step_definitions/steps.rb
86
104
  - lib/akki.rb
@@ -103,12 +121,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
103
121
  - - ! '>='
104
122
  - !ruby/object:Gem::Version
105
123
  version: '0'
124
+ segments:
125
+ - 0
126
+ hash: -3256136502332795362
106
127
  required_rubygems_version: !ruby/object:Gem::Requirement
107
128
  none: false
108
129
  requirements:
109
130
  - - ! '>='
110
131
  - !ruby/object:Gem::Version
111
132
  version: '0'
133
+ segments:
134
+ - 0
135
+ hash: -3256136502332795362
112
136
  requirements: []
113
137
  rubyforge_project: akki
114
138
  rubygems_version: 1.6.2
@@ -116,7 +140,13 @@ signing_key:
116
140
  specification_version: 3
117
141
  summary: ''
118
142
  test_files:
143
+ - features/archives.feature
119
144
  - features/articles.feature
145
+ - features/fixtures/views/archives.haml
146
+ - features/fixtures/views/article.haml
147
+ - features/fixtures/views/example-page.haml
148
+ - features/fixtures/views/layout.haml
149
+ - features/pages.feature
120
150
  - features/step_definitions/env.rb
121
151
  - features/step_definitions/steps.rb
122
152
  - spec/application_spec.rb