engine_of_war 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/.rbenv-version +1 -0
- data/.yardopts +2 -0
- data/Gemfile +4 -0
- data/Rakefile +10 -0
- data/Readme.textile +0 -0
- data/engine_of_war.gemspec +34 -0
- data/lib/engine_of_war.rb +24 -0
- data/lib/engine_of_war/app.rb +67 -0
- data/lib/engine_of_war/extensions/string.rb +10 -0
- data/lib/engine_of_war/layout.rb +29 -0
- data/lib/engine_of_war/my_red_cloth_template.rb +78 -0
- data/lib/engine_of_war/page.rb +68 -0
- data/lib/engine_of_war/page_collection.rb +47 -0
- data/lib/engine_of_war/recommendation.rb +34 -0
- data/lib/engine_of_war/version.rb +3 -0
- data/spec/assets_spec.rb +59 -0
- data/spec/atom_spec.rb +55 -0
- data/spec/blog_spec.rb +140 -0
- data/spec/code_filter_spec.rb +46 -0
- data/spec/frontmatter_spec.rb +41 -0
- data/spec/image_filter_spec.rb +73 -0
- data/spec/page_collection_spec.rb +67 -0
- data/spec/page_spec.rb +129 -0
- data/spec/recommendations_spec.rb +44 -0
- data/spec/rendering_spec.rb +49 -0
- data/spec/root_spec.rb +25 -0
- data/spec/spec_helper.rb +71 -0
- metadata +246 -0
data/spec/assets_spec.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "given a layout and some assets" do
|
4
|
+
before do
|
5
|
+
create_template("layouts/application.html.haml", "%h1 Layout\n= yield")
|
6
|
+
create_template("one.css.scss", ".foo {color: red}")
|
7
|
+
create_template("nested/file.css.scss", ".foo {color: yellow}")
|
8
|
+
create_template("two.js.coffee", 'alert "Coffee"')
|
9
|
+
create_template("three.css.sass", ".foo\n :clear both\n")
|
10
|
+
end
|
11
|
+
|
12
|
+
it "doesn't render the layout when getting a CSS file" do
|
13
|
+
visit "/one.css"
|
14
|
+
page.should_not have_selector('h1:contains("Layout")')
|
15
|
+
end
|
16
|
+
|
17
|
+
it "doesn't render the layout when getting a JS file" do
|
18
|
+
visit "/two.js"
|
19
|
+
page.should_not have_selector('h1:contains("Layout")')
|
20
|
+
end
|
21
|
+
|
22
|
+
it "renders the scss as css" do
|
23
|
+
visit "/one.css"
|
24
|
+
page.source.should match(%r{color: red;})
|
25
|
+
page.response_headers['Content-Type'].should match(%r{text/css})
|
26
|
+
end
|
27
|
+
|
28
|
+
it "renders the sass as css" do
|
29
|
+
visit "/three.css"
|
30
|
+
page.source.should match(%r{clear: both;})
|
31
|
+
end
|
32
|
+
|
33
|
+
it "renders the coffeescript as js" do
|
34
|
+
visit "/two.js"
|
35
|
+
page.source.should match(%r{alert\("Coffee"\)})
|
36
|
+
end
|
37
|
+
|
38
|
+
it "renders a template if a cachebuster is used" do
|
39
|
+
visit "/two.js?2348347"
|
40
|
+
page.source.should match(%r{alert\("Coffee"\)})
|
41
|
+
end
|
42
|
+
|
43
|
+
it "renders the nested asset without issue" do
|
44
|
+
visit "/nested/file.css"
|
45
|
+
page.source.should match(%r{color: yellow;})
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "An asset in /public" do
|
50
|
+
before do
|
51
|
+
create_asset("straight.js", 'javascript!')
|
52
|
+
end
|
53
|
+
|
54
|
+
it "is rendered without processing" do
|
55
|
+
visit "/straight.js"
|
56
|
+
page.source.should == "javascript!"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
data/spec/atom_spec.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
#!/bin/env rspec
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
describe "Given some blog posts" do
|
6
|
+
before do
|
7
|
+
create_template("posts/a_post.html.haml",
|
8
|
+
<<-EOF)
|
9
|
+
---
|
10
|
+
title: First post
|
11
|
+
date: 1997-07-01
|
12
|
+
---
|
13
|
+
%blockquote This is the first post.
|
14
|
+
EOF
|
15
|
+
|
16
|
+
create_template("posts/another_post.html.haml",
|
17
|
+
<<-EOF)
|
18
|
+
---
|
19
|
+
title: Second post
|
20
|
+
date: 2011-01-10
|
21
|
+
---
|
22
|
+
This is the second post.
|
23
|
+
EOF
|
24
|
+
|
25
|
+
create_template("posts/textile_post.html.textile",
|
26
|
+
<<-EOF)
|
27
|
+
---
|
28
|
+
title: Textile post
|
29
|
+
date: 2010-01-10
|
30
|
+
---
|
31
|
+
|
32
|
+
bq. Textile post.
|
33
|
+
EOF
|
34
|
+
end
|
35
|
+
|
36
|
+
context "GET /posts.atom" do
|
37
|
+
before { visit "/posts.atom" }
|
38
|
+
|
39
|
+
it "renders the feed as rss" do
|
40
|
+
page.should have_selector("rss[version='2.0']")
|
41
|
+
page.should have_selector("rss title")
|
42
|
+
page.response_headers['Content-Type'].should == "application/rss+xml"
|
43
|
+
end
|
44
|
+
|
45
|
+
it "renders xml for the first post" do
|
46
|
+
page.should have_selector('rss channel item title:contains("First post")')
|
47
|
+
page.source.should include("http://www.example.com/posts/a_post")
|
48
|
+
end
|
49
|
+
|
50
|
+
it "renders xml for the second post" do
|
51
|
+
page.should have_selector('rss channel item title:contains("Second post")')
|
52
|
+
page.source.should include("http://www.example.com/posts/another_post")
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/spec/blog_spec.rb
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
#!/bin/env rspec
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
describe "Given some blog posts" do
|
6
|
+
before do
|
7
|
+
create_template("layouts/application.html.haml",
|
8
|
+
<<-EOF)
|
9
|
+
%h1 Layout
|
10
|
+
= yield
|
11
|
+
EOF
|
12
|
+
|
13
|
+
create_template("layouts/posts.html.haml",
|
14
|
+
<<-EOF)
|
15
|
+
%h1 Post Layout
|
16
|
+
= yield
|
17
|
+
EOF
|
18
|
+
|
19
|
+
create_template("posts.html.haml",
|
20
|
+
<<-EOF)
|
21
|
+
This is the Blog!
|
22
|
+
- collection("posts").each do |post|
|
23
|
+
%h2= post.meta[:title]
|
24
|
+
= render_page(post)
|
25
|
+
EOF
|
26
|
+
|
27
|
+
create_template("posts/a_post.html.haml",
|
28
|
+
<<-EOF)
|
29
|
+
---
|
30
|
+
title: First post
|
31
|
+
date: 1997-07-01
|
32
|
+
---
|
33
|
+
%blockquote This is the first post.
|
34
|
+
EOF
|
35
|
+
|
36
|
+
create_template("posts/another_post.html.haml",
|
37
|
+
<<-EOF)
|
38
|
+
---
|
39
|
+
title: Second post
|
40
|
+
date: 2011-01-10
|
41
|
+
---
|
42
|
+
This is the second post.
|
43
|
+
EOF
|
44
|
+
|
45
|
+
create_template("posts/textile_post.html.textile",
|
46
|
+
<<-EOF)
|
47
|
+
---
|
48
|
+
title: Textile post
|
49
|
+
date: 2010-01-10
|
50
|
+
---
|
51
|
+
|
52
|
+
bq. Textile post.
|
53
|
+
EOF
|
54
|
+
end
|
55
|
+
|
56
|
+
context "GET /posts" do
|
57
|
+
before { visit "/posts" }
|
58
|
+
|
59
|
+
it "renders the page" do
|
60
|
+
page.source.should =~ /This is the Blog/
|
61
|
+
end
|
62
|
+
|
63
|
+
it "renders the layout" do
|
64
|
+
page.should have_selector('h1:contains("Layout")')
|
65
|
+
end
|
66
|
+
|
67
|
+
it "renders the first post title" do
|
68
|
+
page.should have_selector('h2:contains("First post")')
|
69
|
+
end
|
70
|
+
|
71
|
+
it "renders the second post title" do
|
72
|
+
page.should have_selector('h2:contains("Second post")')
|
73
|
+
end
|
74
|
+
|
75
|
+
it "renders the body of the haml post" do
|
76
|
+
page.should have_selector('blockquote:contains("first post")')
|
77
|
+
end
|
78
|
+
|
79
|
+
it "renders the body of the textile post" do
|
80
|
+
page.should have_selector('blockquote:contains("Textile post")')
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "Given a blog post" do
|
86
|
+
before do
|
87
|
+
create_template("layouts/application.html.haml",
|
88
|
+
<<-EOF)
|
89
|
+
%h1 Layout
|
90
|
+
= yield
|
91
|
+
EOF
|
92
|
+
|
93
|
+
create_template("layouts/posts.html.haml",
|
94
|
+
<<-EOF)
|
95
|
+
%h1 Post Layout
|
96
|
+
%h2= meta[:title]
|
97
|
+
= yield
|
98
|
+
EOF
|
99
|
+
|
100
|
+
create_template("posts/a_post.html.haml",
|
101
|
+
<<-EOF)
|
102
|
+
---
|
103
|
+
title: First post
|
104
|
+
date: 1997-07-01
|
105
|
+
foo: bar
|
106
|
+
---
|
107
|
+
%blockquote This is the first post.
|
108
|
+
EOF
|
109
|
+
end
|
110
|
+
|
111
|
+
context "navigating to that post" do
|
112
|
+
before { visit "/posts/a_post" }
|
113
|
+
|
114
|
+
it "renders the post layout" do
|
115
|
+
page.should have_selector('h1:contains("Post Layout")')
|
116
|
+
end
|
117
|
+
|
118
|
+
it "renders the post title" do
|
119
|
+
page.should have_selector('h2:contains("First post")')
|
120
|
+
end
|
121
|
+
|
122
|
+
it "renders the post body" do
|
123
|
+
page.should have_selector('blockquote:contains("This is the first post.")')
|
124
|
+
end
|
125
|
+
|
126
|
+
it "doesn't attempt to render the frontmatter" do
|
127
|
+
page.source.should_not match("foo")
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
context "navigating to that post with a trailing /" do
|
132
|
+
before { visit "/posts/a_post/" }
|
133
|
+
|
134
|
+
it "renders the post body" do
|
135
|
+
page.should have_selector('blockquote:contains("This is the first post.")')
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "given a textile template with a code sample" do
|
4
|
+
before do
|
5
|
+
create_template("layouts/application.html.haml", <<-EOS)
|
6
|
+
%h1 Layout
|
7
|
+
.content
|
8
|
+
~ yield
|
9
|
+
EOS
|
10
|
+
create_template("index.html.haml", <<-EOF)
|
11
|
+
This is the Blog!
|
12
|
+
- collection("posts").each do |post|
|
13
|
+
%h2= post.meta[:title]
|
14
|
+
~ render_page(post)
|
15
|
+
EOF
|
16
|
+
create_template("posts/bar.html.textile", <<-EOS)
|
17
|
+
@@@ ruby
|
18
|
+
[branch "master"]
|
19
|
+
remote = origin
|
20
|
+
merge = refs/heads/master
|
21
|
+
@@@
|
22
|
+
EOS
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
context "the rendered page" do
|
27
|
+
before { visit "/posts/bar" }
|
28
|
+
subject { page }
|
29
|
+
|
30
|
+
it { should have_selector('pre code.ruby') }
|
31
|
+
it "should not fuck up the indenting" do
|
32
|
+
page.source.should match(%r{\S remote = origin})
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "the posts index" do
|
37
|
+
before { visit "/" }
|
38
|
+
subject { page }
|
39
|
+
|
40
|
+
it { should have_selector('pre code.ruby') }
|
41
|
+
it "should not fuck up the indenting" do
|
42
|
+
page.source.should match(%r{\S remote = origin})
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
@@ -0,0 +1,41 @@
|
|
1
|
+
#!/bin/env rspec
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
describe "Given a page with frontmatter" do
|
6
|
+
before do
|
7
|
+
create_template("layouts/application.html.haml",
|
8
|
+
<<-EOF)
|
9
|
+
%head
|
10
|
+
%title= meta[:title]
|
11
|
+
%h1 Layout
|
12
|
+
= yield
|
13
|
+
EOF
|
14
|
+
|
15
|
+
create_template("page_with_frontmatter.html.haml",
|
16
|
+
<<-EOF)
|
17
|
+
---
|
18
|
+
title: Title for this post.
|
19
|
+
---
|
20
|
+
This is a post.
|
21
|
+
EOF
|
22
|
+
end
|
23
|
+
|
24
|
+
context "GET /page_with_frontmatter" do
|
25
|
+
before { visit "/page_with_frontmatter" }
|
26
|
+
|
27
|
+
it "renders the page" do
|
28
|
+
page.source.should =~ /This is a post/
|
29
|
+
end
|
30
|
+
|
31
|
+
it "renders the layout" do
|
32
|
+
page.should have_selector('h1:contains("Layout")')
|
33
|
+
end
|
34
|
+
|
35
|
+
it "hands the frontmatter to the layout" do
|
36
|
+
page.should have_selector('title:contains("Title for this post.")')
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "given a textile template with an image link " do
|
4
|
+
before { create_template("layouts/application.html.haml", "%h1 Layout\n= yield") }
|
5
|
+
|
6
|
+
describe "and an image link" do
|
7
|
+
before do
|
8
|
+
create_asset("images/file/original.jpg", "image data")
|
9
|
+
create_template("posts/bar.html.textile", "%file.jpg large%")
|
10
|
+
end
|
11
|
+
|
12
|
+
context "the rendered page" do
|
13
|
+
before { visit "/posts/bar" }
|
14
|
+
subject { page }
|
15
|
+
|
16
|
+
it { should have_selector('img[src="/images/file/large.jpg"]') }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "and an image link with metadata" do
|
21
|
+
before do
|
22
|
+
create_template("posts/bar.html.textile", "%file.jpg%")
|
23
|
+
create_asset("images/file/original.jpg", "image data")
|
24
|
+
create_asset("images/file/meta.yml", <<-EOS)
|
25
|
+
---
|
26
|
+
:description: Me Speaking
|
27
|
+
:source_url: ""
|
28
|
+
EOS
|
29
|
+
end
|
30
|
+
|
31
|
+
context "the rendered page" do
|
32
|
+
before { visit "/posts/bar" }
|
33
|
+
subject { page }
|
34
|
+
|
35
|
+
it { should have_selector('img[alt="Me Speaking"]') }
|
36
|
+
it { should_not have_selector('a img') }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "and an image link with metadata that includes a url" do
|
41
|
+
before do
|
42
|
+
create_template("posts/bar.html.textile", "%file.jpg%")
|
43
|
+
create_asset("images/file/original.jpg", "image data")
|
44
|
+
create_asset("images/file/meta.yml", <<-EOS)
|
45
|
+
---
|
46
|
+
:description: ""
|
47
|
+
:source_url: http://google.com
|
48
|
+
EOS
|
49
|
+
end
|
50
|
+
|
51
|
+
context "the rendered page" do
|
52
|
+
before { visit "/posts/bar" }
|
53
|
+
subject { page }
|
54
|
+
|
55
|
+
it { should_not have_selector('img[alt]') }
|
56
|
+
it { should have_selector('a[href="http://google.com"] img') }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "and an image link without a file" do
|
61
|
+
before { create_template("posts/bar.html.textile", "%bad_file.jpg%") }
|
62
|
+
|
63
|
+
context "the rendered page" do
|
64
|
+
before { visit "/posts/bar" }
|
65
|
+
subject { page }
|
66
|
+
|
67
|
+
it { should_not have_selector('img') }
|
68
|
+
it { should have_selector('.warning') }
|
69
|
+
it { page.source.should match("unknown") }
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
@@ -0,0 +1,67 @@
|
|
1
|
+
#!/bin/env rspec
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
describe "Given some drafts" do
|
6
|
+
before do
|
7
|
+
create_template("drafts/a_post.html.haml",
|
8
|
+
<<-EOF)
|
9
|
+
---
|
10
|
+
title: First draft
|
11
|
+
date: 1997-07-01
|
12
|
+
---
|
13
|
+
This is the first post.
|
14
|
+
EOF
|
15
|
+
|
16
|
+
create_template("drafts/another_post.html.haml",
|
17
|
+
<<-EOF)
|
18
|
+
---
|
19
|
+
title: Second draft
|
20
|
+
date: 2011-01-10
|
21
|
+
---
|
22
|
+
This is the second post.
|
23
|
+
EOF
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "PageCollection.new('drafts')" do
|
27
|
+
before { @collection = EngineOfWar::PageCollection.new('drafts')}
|
28
|
+
subject { @collection }
|
29
|
+
|
30
|
+
it { should_not be_empty }
|
31
|
+
it "should return the newest draft first" do
|
32
|
+
@collection.first.meta[:title].should == "Second draft"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "Given some posts" do
|
38
|
+
before do
|
39
|
+
create_template("posts/a_post.html.haml",
|
40
|
+
<<-EOF)
|
41
|
+
---
|
42
|
+
title: First post
|
43
|
+
date: 1997-07-01
|
44
|
+
---
|
45
|
+
This is the first post.
|
46
|
+
EOF
|
47
|
+
|
48
|
+
create_template("posts/another_post.html.haml",
|
49
|
+
<<-EOF)
|
50
|
+
---
|
51
|
+
title: Second post
|
52
|
+
date: 2011-01-10
|
53
|
+
---
|
54
|
+
This is the second post.
|
55
|
+
EOF
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "PageCollection.new('posts')" do
|
59
|
+
before { @collection = EngineOfWar::PageCollection.new('posts')}
|
60
|
+
subject { @collection }
|
61
|
+
|
62
|
+
it { should_not be_empty }
|
63
|
+
it "should return the newest post first" do
|
64
|
+
@collection.first.meta[:title].should == "Second post"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|