akki 0.0.1

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.
@@ -0,0 +1,6 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ articles/*
6
+ templates/*
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm ruby-1.9.2@akki
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in akki.gemspec
4
+ gemspec
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "akki/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "akki"
7
+ s.version = Akki::VERSION
8
+ s.authors = ["Andrew Vos"]
9
+ s.email = ["andrew.vos@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{}
12
+ s.description = %q{}
13
+
14
+ s.rubyforge_project = "akki"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.add_dependency 'sinatra'
20
+ s.add_dependency 'haml'
21
+ s.add_development_dependency 'rspec'
22
+ s.add_development_dependency 'cucumber'
23
+ s.add_development_dependency 'capybara'
24
+ s.require_paths = ["lib"]
25
+ end
@@ -0,0 +1,2 @@
1
+ require File.join(File.dirname(__FILE__), 'lib', 'akki')
2
+ run Akki::Application
@@ -0,0 +1,34 @@
1
+ Feature: Article
2
+ In order to display articles on
3
+ As a user
4
+ I want to be render blog pages
5
+
6
+ Scenario: Simple Article
7
+ Given I have the article file "1983-10-23-simple-article.txt"
8
+ """
9
+ title: Simple Article
10
+ date: 23/10/1983
11
+
12
+ %p article content
13
+ """
14
+ And the layout template:
15
+ """
16
+ %html
17
+ %head
18
+ %title= article.title
19
+ %body
20
+ = article.render
21
+ """
22
+ And I visit "1983/10/23/simple-article"
23
+ Then I should see:
24
+ """
25
+ <html>
26
+ <head>
27
+ <title>Simple Article</title>
28
+ </head>
29
+ <body>
30
+ <p>article content</p>
31
+ </body>
32
+ </html>
33
+
34
+ """
@@ -0,0 +1,7 @@
1
+ $:.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
2
+
3
+ require 'capybara/cucumber'
4
+ require 'akki'
5
+
6
+ Capybara.app = Akki::Application
7
+ Akki::Application.set :environment, :test
@@ -0,0 +1,23 @@
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
7
+ end
8
+
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
15
+ end
16
+
17
+ Given /^I visit "([^"]*)"$/ do |url|
18
+ visit "/#{url}"
19
+ end
20
+
21
+ Then /^I should see:$/ do |content|
22
+ page.source.should == content
23
+ end
@@ -0,0 +1,3 @@
1
+ $:.unshift(File.dirname(__FILE__))
2
+ require "akki/version"
3
+ require "akki/application"
@@ -0,0 +1,20 @@
1
+ require 'sinatra/base'
2
+ require 'yaml'
3
+ require 'akki/article'
4
+
5
+ module Akki
6
+ class Application < Sinatra::Base
7
+ get "/:year/:month/:day/:slug/?" do
8
+ year = params[:year]
9
+ month = params[:month]
10
+ day = params[:day]
11
+ slug = params[:slug]
12
+ render(Article::from_file(year, month, day, slug))
13
+ end
14
+
15
+ def render article
16
+ layout = File.read('templates/layout.haml')
17
+ Haml::Engine.new(layout).render(binding)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,27 @@
1
+ require 'haml'
2
+
3
+ module Akki
4
+ class Article
5
+ attr_accessor :title, :date, :content
6
+
7
+ def initialize(title, date, content)
8
+ @title = title
9
+ @date = date
10
+ @content = content
11
+ end
12
+
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, '%d/%m/%Y')
20
+ Article.new(title, date, content)
21
+ end
22
+
23
+ def render
24
+ Haml::Engine.new(content).render
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module Akki
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ module Akki
4
+ describe Application do
5
+ include Rack::Test::Methods
6
+
7
+ def app
8
+ Application
9
+ end
10
+
11
+ describe "GET /23/10/2011/simple-article" do
12
+ before do
13
+ @article = mock :article
14
+ @article.stub!(:render).and_return 'article content'
15
+ @article.stub!(:title)
16
+ Article.stub!(:from_file).and_return @article
17
+ end
18
+
19
+ it "is successful" do
20
+ get '/2011/10/23/simple-article'
21
+ last_response.should be_ok
22
+ end
23
+
24
+ it "loads an article" do
25
+ Article.should_receive(:from_file).with("2011", "10", "23", 'simple-article')
26
+ get '/2011/10/23/simple-article'
27
+ end
28
+
29
+ it "returns a template" do
30
+ File.stub!(:read).and_return '%p hello'
31
+ get '/2011/10/23/simple-article'
32
+ last_response.body.should include '<p>hello</p>'
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+ require 'akki/article'
3
+
4
+ module Akki
5
+ describe Article do
6
+ before do
7
+ File.stub!(:read).and_return <<-ARTICLE
8
+ title: the article title
9
+ date: 23/10/1983
10
+
11
+ article content
12
+ ARTICLE
13
+ end
14
+
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')
18
+ end
19
+
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
24
+
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
30
+ end
31
+
32
+ it "loads the article content" do
33
+ article = Article.from_file(2011, 10, 23, 'article-slug')
34
+ article.content.should include 'article content'
35
+ end
36
+
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
+ end
44
+ end
45
+ end
@@ -0,0 +1,5 @@
1
+ $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ require 'akki'
3
+ require 'rack/test'
4
+
5
+ Akki::Application::set :environment, :test
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: akki
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Andrew Vos
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-08-14 00:00:00.000000000 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: sinatra
17
+ requirement: &70211798428040 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *70211798428040
26
+ - !ruby/object:Gem::Dependency
27
+ name: haml
28
+ requirement: &70211798427620 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: *70211798427620
37
+ - !ruby/object:Gem::Dependency
38
+ name: rspec
39
+ requirement: &70211798427200 !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: *70211798427200
48
+ - !ruby/object:Gem::Dependency
49
+ name: cucumber
50
+ requirement: &70211798426780 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: *70211798426780
59
+ - !ruby/object:Gem::Dependency
60
+ name: capybara
61
+ requirement: &70211798426360 !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ type: :development
68
+ prerelease: false
69
+ version_requirements: *70211798426360
70
+ description: ''
71
+ email:
72
+ - andrew.vos@gmail.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - .gitignore
78
+ - .rvmrc
79
+ - Gemfile
80
+ - Rakefile
81
+ - akki.gemspec
82
+ - config.ru
83
+ - features/articles.feature
84
+ - features/step_definitions/env.rb
85
+ - features/step_definitions/steps.rb
86
+ - lib/akki.rb
87
+ - lib/akki/application.rb
88
+ - lib/akki/article.rb
89
+ - lib/akki/version.rb
90
+ - spec/application_spec.rb
91
+ - spec/article_spec.rb
92
+ - spec/spec_helper.rb
93
+ has_rdoc: true
94
+ homepage: ''
95
+ licenses: []
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ! '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project: akki
114
+ rubygems_version: 1.6.2
115
+ signing_key:
116
+ specification_version: 3
117
+ summary: ''
118
+ test_files:
119
+ - features/articles.feature
120
+ - features/step_definitions/env.rb
121
+ - features/step_definitions/steps.rb
122
+ - spec/application_spec.rb
123
+ - spec/article_spec.rb
124
+ - spec/spec_helper.rb