zenweb 2.18.1 → 3.0.0.b1
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/.autotest +18 -0
- data/.gemtest +0 -0
- data/History.txt +6 -0
- data/Manifest.txt +52 -50
- data/README.txt +27 -22
- data/Rakefile +8 -9
- data/example-site/.isolate.rb +8 -0
- data/example-site/Rakefile +32 -0
- data/example-site/_config.yml +3 -0
- data/example-site/_includes/analytics.html.erb +11 -0
- data/example-site/_includes/header.html.erb +3 -0
- data/example-site/_includes/page_list_item.html +5 -0
- data/example-site/_includes/post_list_item.html +5 -0
- data/example-site/_layouts/post.erb +13 -0
- data/example-site/_layouts/project.erb +39 -0
- data/example-site/_layouts/site.erb +62 -0
- data/example-site/about/index.html.md +8 -0
- data/example-site/atom.xml.erb +43 -0
- data/example-site/blog/2012-01-02-page1.html.md +5 -0
- data/example-site/blog/2012-01-03-page2.html.md +5 -0
- data/example-site/blog/2012-01-04-page3.html.md +5 -0
- data/example-site/blog/_config.yml +1 -0
- data/example-site/blog/index.html.erb +19 -0
- data/example-site/config.ru +33 -0
- data/example-site/css/colors.css.less +71 -0
- data/example-site/css/styles.css +223 -0
- data/example-site/css/syntax.css +171 -0
- data/example-site/img/bg.png +0 -0
- data/example-site/index.html.erb +27 -0
- data/example-site/js/jquery.js +154 -0
- data/example-site/js/site.js +37 -0
- data/example-site/pages/index.html.erb +17 -0
- data/example-site/pages/nonblogpage.html.md +8 -0
- data/example-site/projects/index.html.erb +18 -0
- data/example-site/projects/zenweb.html.erb +9 -0
- data/example-site/sitemap.xml.erb +24 -0
- data/lib/zenweb.rb +12 -0
- data/lib/zenweb/config.rb +126 -0
- data/lib/zenweb/extensions.rb +51 -0
- data/lib/zenweb/page.rb +409 -0
- data/lib/zenweb/plugins/disqus.rb +18 -0
- data/lib/zenweb/plugins/erb.rb +43 -0
- data/lib/zenweb/plugins/google.rb +20 -0
- data/lib/zenweb/plugins/less.rb +10 -0
- data/lib/zenweb/plugins/markdown.rb +121 -0
- data/lib/zenweb/site.rb +237 -0
- data/lib/zenweb/tasks.rake +165 -0
- data/test/helper.rb +53 -0
- data/test/test_zenweb_config.rb +90 -0
- data/test/test_zenweb_extensions.rb +33 -0
- data/test/test_zenweb_page.rb +381 -0
- data/test/test_zenweb_plugins_disqus.rb +41 -0
- data/test/test_zenweb_plugins_erb.rb +60 -0
- data/test/test_zenweb_plugins_google.rb +38 -0
- data/test/test_zenweb_plugins_less.rb +33 -0
- data/test/test_zenweb_plugins_markdown.rb +227 -0
- data/test/test_zenweb_site.rb +294 -0
- metadata +230 -86
- metadata.gz.sig +0 -0
- data/bin/zenweb +0 -27
- data/bin/zenwebpage +0 -66
- data/bin/zenwebsite +0 -39
- data/design/REQUIREMENTS.txt +0 -52
- data/design/ZENWEB_2.txt +0 -69
- data/design/heirarchy.png +0 -0
- data/design/heirarchy.tgif +0 -311
- data/docs/Customizing +0 -76
- data/docs/FAQ +0 -12
- data/docs/Features +0 -128
- data/docs/Presentation +0 -88
- data/docs/QuickStart +0 -32
- data/docs/Renderers +0 -85
- data/docs/SiteMap +0 -13
- data/docs/YourOwnWebsite +0 -32
- data/docs/index +0 -14
- data/docs/metadata.txt +0 -10
- data/lib/ZenWeb.rb +0 -850
- data/lib/ZenWeb/CalendarRenderer.rb +0 -162
- data/lib/ZenWeb/CompactRenderer.rb +0 -45
- data/lib/ZenWeb/CompositeRenderer.rb +0 -63
- data/lib/ZenWeb/FileAttachmentRenderer.rb +0 -57
- data/lib/ZenWeb/FooterRenderer.rb +0 -38
- data/lib/ZenWeb/GenericRenderer.rb +0 -143
- data/lib/ZenWeb/HeaderRenderer.rb +0 -52
- data/lib/ZenWeb/HtmlRenderer.rb +0 -81
- data/lib/ZenWeb/HtmlTableRenderer.rb +0 -94
- data/lib/ZenWeb/HtmlTemplateRenderer.rb +0 -173
- data/lib/ZenWeb/MetadataRenderer.rb +0 -83
- data/lib/ZenWeb/RelativeRenderer.rb +0 -97
- data/lib/ZenWeb/RubyCodeRenderer.rb +0 -56
- data/lib/ZenWeb/SitemapRenderer.rb +0 -56
- data/lib/ZenWeb/StandardRenderer.rb +0 -40
- data/lib/ZenWeb/StupidRenderer.rb +0 -91
- data/lib/ZenWeb/SubpageRenderer.rb +0 -45
- data/lib/ZenWeb/TextToHtmlRenderer.rb +0 -219
- data/lib/ZenWeb/TocRenderer.rb +0 -60
- data/lib/ZenWeb/XXXRenderer.rb +0 -32
- data/test/SiteMap +0 -14
- data/test/Something +0 -4
- data/test/include.txt +0 -3
- data/test/index +0 -8
- data/test/metadata.txt +0 -10
- data/test/ryand/SiteMap +0 -10
- data/test/ryand/blah +0 -4
- data/test/ryand/blah-blah +0 -4
- data/test/ryand/index +0 -52
- data/test/ryand/metadata.txt +0 -2
- data/test/ryand/stuff/index +0 -4
- data/test/test_zenweb.rb +0 -1619
@@ -0,0 +1,41 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
|
3
|
+
require "rubygems"
|
4
|
+
require "minitest/autorun"
|
5
|
+
|
6
|
+
require "zenweb/site"
|
7
|
+
require "test/helper"
|
8
|
+
|
9
|
+
class TestZenwebPageDisqus < MiniTest::Unit::TestCase
|
10
|
+
attr_accessor :site, :page
|
11
|
+
|
12
|
+
def setup
|
13
|
+
super
|
14
|
+
|
15
|
+
self.site = Zenweb::Site.new
|
16
|
+
self.page = Zenweb::Page.new site, "blog/2012-01-02-page1.html.md"
|
17
|
+
end
|
18
|
+
|
19
|
+
def js name
|
20
|
+
<<-EOM.gsub(/^ {6}/, '')
|
21
|
+
<script type=\"text/javascript\">
|
22
|
+
(function() {
|
23
|
+
var s = document.createElement('script');
|
24
|
+
s.type = 'text/javascript';
|
25
|
+
s.async = true;
|
26
|
+
s.src = 'http://myshortname.disqus.com/#{name}.js';
|
27
|
+
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(s);
|
28
|
+
})();
|
29
|
+
</script>
|
30
|
+
EOM
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_render_disqus
|
34
|
+
div = "<div id=\"disqus_thread\"></div>"
|
35
|
+
assert_equal div + js("embed"), page.disqus("myshortname")
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_render_disqus_counts
|
39
|
+
assert_equal js("count"), page.disqus_counts("myshortname")
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
|
3
|
+
require "rubygems"
|
4
|
+
require "minitest/autorun"
|
5
|
+
|
6
|
+
require "zenweb/site"
|
7
|
+
require "test/helper"
|
8
|
+
|
9
|
+
class TestZenwebPageErb < MiniTest::Unit::TestCase
|
10
|
+
include ChdirTest("example-site")
|
11
|
+
|
12
|
+
attr_accessor :site, :page
|
13
|
+
|
14
|
+
def setup
|
15
|
+
super
|
16
|
+
|
17
|
+
self.site = Zenweb::Site.new
|
18
|
+
self.page = Zenweb::Page.new site, "blog/2012-01-02-page1.html.md"
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_render_erb
|
22
|
+
act = page.render_erb page, nil
|
23
|
+
exp = "Not really much here to see."
|
24
|
+
|
25
|
+
assert_equal exp, act
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_erb
|
29
|
+
act = page.erb "this is some content", page
|
30
|
+
exp = "this is some content"
|
31
|
+
|
32
|
+
assert_equal exp, act
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_erb_embedded
|
36
|
+
act = page.erb "this is {{ 1 + 1 }} content", page
|
37
|
+
exp = "this is 2 content"
|
38
|
+
|
39
|
+
assert_equal exp, act
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_erb_other_error
|
43
|
+
e = assert_raises RuntimeError do
|
44
|
+
page.erb "this is {{ raise 'no' }} content", page
|
45
|
+
end
|
46
|
+
|
47
|
+
assert_equal "no", e.message
|
48
|
+
|
49
|
+
assert e.backtrace.grep('Page["blog/2012-01-02-page1.html.md"]:1')
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_erb_syntax_error
|
53
|
+
e = assert_raises SyntaxError do
|
54
|
+
page.erb "this is {{ 1 + }} content", page
|
55
|
+
end
|
56
|
+
|
57
|
+
assert_includes e.message, "concat(( 1 + ).to_s)"
|
58
|
+
assert e.backtrace.grep('Page["blog/2012-01-02-page1.html.md"]:1')
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
|
3
|
+
require "rubygems"
|
4
|
+
require "minitest/autorun"
|
5
|
+
|
6
|
+
require "zenweb/site"
|
7
|
+
require "test/helper"
|
8
|
+
|
9
|
+
class TestZenwebPageGoogle < MiniTest::Unit::TestCase
|
10
|
+
include ChdirTest("example-site")
|
11
|
+
|
12
|
+
attr_accessor :site, :page
|
13
|
+
|
14
|
+
def setup
|
15
|
+
super
|
16
|
+
|
17
|
+
self.site = Zenweb::Site.new
|
18
|
+
self.page = Zenweb::Page.new site, "blog/2012-01-02-page1.html.md"
|
19
|
+
|
20
|
+
site.config.h["google_ad_client"] = "mygooglethingy"
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_render_google_ad
|
24
|
+
exp = <<-EOM.gsub(/^ {6}/, '')
|
25
|
+
<script><!--
|
26
|
+
google_ad_client = "mygooglethingy";
|
27
|
+
google_ad_slot = "myslot";
|
28
|
+
google_ad_width = 1;
|
29
|
+
google_ad_height = 2;
|
30
|
+
//-->
|
31
|
+
</script>
|
32
|
+
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
|
33
|
+
</script>
|
34
|
+
EOM
|
35
|
+
|
36
|
+
assert_equal exp, page.google_ad("myslot", 1, 2)
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
|
3
|
+
require "rubygems"
|
4
|
+
require "minitest/autorun"
|
5
|
+
|
6
|
+
require "zenweb/site"
|
7
|
+
require "test/helper"
|
8
|
+
|
9
|
+
class TestZenwebPageLess < MiniTest::Unit::TestCase
|
10
|
+
include ChdirTest("example-site")
|
11
|
+
|
12
|
+
attr_accessor :site, :page
|
13
|
+
|
14
|
+
def setup
|
15
|
+
super
|
16
|
+
|
17
|
+
self.site = Zenweb::Site.new
|
18
|
+
self.page = Zenweb::Page.new site, "blog/2012-01-02-page1.html.md"
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_render_less
|
22
|
+
skip "soooo fucking slow!" unless ENV["RCOV"]
|
23
|
+
css = "h1 {color: red}"
|
24
|
+
act = nil
|
25
|
+
|
26
|
+
capture_io do # TODO: why?
|
27
|
+
act = page.render_less page, css
|
28
|
+
end
|
29
|
+
exp = "h1 { color: red; }\n"
|
30
|
+
|
31
|
+
assert_equal exp, act
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,227 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
|
3
|
+
require "rubygems"
|
4
|
+
require "minitest/autorun"
|
5
|
+
|
6
|
+
require "zenweb/site"
|
7
|
+
require "test/helper"
|
8
|
+
|
9
|
+
class TestZenwebPageMarkdown < MiniTest::Unit::TestCase
|
10
|
+
include ChdirTest("example-site")
|
11
|
+
|
12
|
+
attr_accessor :site, :page
|
13
|
+
|
14
|
+
def setup
|
15
|
+
super
|
16
|
+
|
17
|
+
self.site = Zenweb::Site.new
|
18
|
+
self.page = Zenweb::Page.new site, "blog/2012-01-02-page1.html.md"
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_attr_h
|
22
|
+
assert_equal "{:blah=\"42\"}", page.attr("blah" => 42)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_attr_name
|
26
|
+
assert_equal "{:blah}", page.attr("blah")
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_css_class
|
30
|
+
assert_equal "{:.blah}", page.css_class("blah")
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_css_id
|
34
|
+
assert_equal "{:#blah}", page.css_id("blah")
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_link
|
38
|
+
assert_equal "[mytitle](myurl)", page.link("myurl", "mytitle")
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_image
|
42
|
+
assert_equal "![myurl](myurl)", page.image("myurl")
|
43
|
+
assert_equal "![myalt](myurl)", page.image("myurl", "myalt")
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_render_md
|
47
|
+
act = page.render_md page, nil
|
48
|
+
exp = "<p>Not really much here to see.</p>\n"
|
49
|
+
|
50
|
+
assert_equal exp, act
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_render_md_content
|
54
|
+
skip "not yet"
|
55
|
+
act = page.render_md page, "woot"
|
56
|
+
exp = "<p>Not really much here to see.</p>\n"
|
57
|
+
|
58
|
+
assert_equal exp, act
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_markdown
|
62
|
+
act = page.markdown "woot"
|
63
|
+
exp = "<p>woot</p>\n"
|
64
|
+
|
65
|
+
assert_equal exp, act
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_sitemap
|
69
|
+
build_fake_site %w[a/index.html
|
70
|
+
a/b/index.html
|
71
|
+
a/b/2012-01-02-p1.html
|
72
|
+
a/b/2012-02-03-p2.html
|
73
|
+
a/b/2012-03-04-p3.html]
|
74
|
+
|
75
|
+
page = site.pages["a/index.html"]
|
76
|
+
act = page.sitemap
|
77
|
+
exp = <<-END.cleanup
|
78
|
+
* [Title for a/b/index.html](/a/b/)
|
79
|
+
* 2012-03:
|
80
|
+
* [Title for a/b/2012-03-04-p3.html](/a/b/2012/03/04/p3.html)
|
81
|
+
* 2012-02:
|
82
|
+
* [Title for a/b/2012-02-03-p2.html](/a/b/2012/02/03/p2.html)
|
83
|
+
* 2012-01:
|
84
|
+
* [Title for a/b/2012-01-02-p1.html](/a/b/2012/01/02/p1.html)
|
85
|
+
END
|
86
|
+
|
87
|
+
assert_equal exp, act
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_sitemap_multidir
|
91
|
+
build_fake_site %w[a/index.html
|
92
|
+
a/b/index.html
|
93
|
+
a/b/p1.html
|
94
|
+
a/b/p2.html
|
95
|
+
a/b/p3.html]
|
96
|
+
|
97
|
+
page = site.pages["a/index.html"]
|
98
|
+
act = page.sitemap
|
99
|
+
exp = <<-END.cleanup
|
100
|
+
* [Title for a/b/index.html](/a/b/)
|
101
|
+
* [Title for a/b/p1.html](/a/b/p1.html)
|
102
|
+
* [Title for a/b/p2.html](/a/b/p2.html)
|
103
|
+
* [Title for a/b/p3.html](/a/b/p3.html)
|
104
|
+
END
|
105
|
+
|
106
|
+
assert_equal exp, act
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_sitemap_subdir
|
110
|
+
build_fake_site %w[a/index.html
|
111
|
+
a/b/index.html
|
112
|
+
a/b/p1.html
|
113
|
+
a/b/p2.html
|
114
|
+
a/b/p3.html]
|
115
|
+
|
116
|
+
page = site.pages["a/b/index.html"]
|
117
|
+
act = page.sitemap
|
118
|
+
exp = <<-END.cleanup
|
119
|
+
* [Title for a/b/p1.html](/a/b/p1.html)
|
120
|
+
* [Title for a/b/p2.html](/a/b/p2.html)
|
121
|
+
* [Title for a/b/p3.html](/a/b/p3.html)
|
122
|
+
END
|
123
|
+
|
124
|
+
assert_equal exp, act
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_sitemap_subdir_mixed
|
128
|
+
build_fake_site %w[index.html
|
129
|
+
a/index.html
|
130
|
+
a/a.html
|
131
|
+
a/b.html
|
132
|
+
a/c.html
|
133
|
+
a/2012-01-02-p1.html
|
134
|
+
a/2012-01-03-p2.html
|
135
|
+
a/2012-01-04-p3.html
|
136
|
+
a/2012-02-02-p1.html
|
137
|
+
a/2012-02-03-p2.html
|
138
|
+
a/2012-02-04-p3.html
|
139
|
+
c/index.html
|
140
|
+
c/a.html
|
141
|
+
c/b.html
|
142
|
+
c/c.html
|
143
|
+
c/d/index.html
|
144
|
+
c/d/e.html
|
145
|
+
c/d/f.html
|
146
|
+
c/d/g.html
|
147
|
+
d/index.html
|
148
|
+
d/2012-01-02-p1.html
|
149
|
+
d/2012-01-03-p2.html
|
150
|
+
d/2012-01-04-p3.html
|
151
|
+
some_random_page.html
|
152
|
+
]
|
153
|
+
|
154
|
+
page = site.pages["index.html"]
|
155
|
+
act = page.sitemap
|
156
|
+
exp = <<-END.cleanup
|
157
|
+
* [Title for a/index.html](/a/)
|
158
|
+
* [Title for a/a.html](/a/a.html)
|
159
|
+
* [Title for a/b.html](/a/b.html)
|
160
|
+
* [Title for a/c.html](/a/c.html)
|
161
|
+
* 2012-02:
|
162
|
+
* [Title for a/2012-02-04-p3.html](/a/2012/02/04/p3.html)
|
163
|
+
* [Title for a/2012-02-03-p2.html](/a/2012/02/03/p2.html)
|
164
|
+
* [Title for a/2012-02-02-p1.html](/a/2012/02/02/p1.html)
|
165
|
+
* 2012-01:
|
166
|
+
* [Title for a/2012-01-04-p3.html](/a/2012/01/04/p3.html)
|
167
|
+
* [Title for a/2012-01-03-p2.html](/a/2012/01/03/p2.html)
|
168
|
+
* [Title for a/2012-01-02-p1.html](/a/2012/01/02/p1.html)
|
169
|
+
* [Title for c/index.html](/c/)
|
170
|
+
* [Title for c/a.html](/c/a.html)
|
171
|
+
* [Title for c/b.html](/c/b.html)
|
172
|
+
* [Title for c/c.html](/c/c.html)
|
173
|
+
* [Title for c/d/index.html](/c/d/)
|
174
|
+
* [Title for c/d/e.html](/c/d/e.html)
|
175
|
+
* [Title for c/d/f.html](/c/d/f.html)
|
176
|
+
* [Title for c/d/g.html](/c/d/g.html)
|
177
|
+
* [Title for d/index.html](/d/)
|
178
|
+
* 2012-01:
|
179
|
+
* [Title for d/2012-01-04-p3.html](/d/2012/01/04/p3.html)
|
180
|
+
* [Title for d/2012-01-03-p2.html](/d/2012/01/03/p2.html)
|
181
|
+
* [Title for d/2012-01-02-p1.html](/d/2012/01/02/p1.html)
|
182
|
+
* [Title for some_random_page.html](/some_random_page.html)
|
183
|
+
END
|
184
|
+
|
185
|
+
assert_equal exp, act
|
186
|
+
end
|
187
|
+
|
188
|
+
def test_sitemap_subdir_bloggish
|
189
|
+
build_fake_site %w[index.html
|
190
|
+
2012-01-02-p1.html
|
191
|
+
2012-01-03-p2.html
|
192
|
+
2012-01-04-p3.html
|
193
|
+
2012-02-02-p1.html
|
194
|
+
2012-02-03-p2.html
|
195
|
+
2012-02-04-p3.html
|
196
|
+
sitemap.html
|
197
|
+
some_random_page.html
|
198
|
+
]
|
199
|
+
|
200
|
+
page = site.pages["index.html"]
|
201
|
+
act = page.sitemap
|
202
|
+
exp = <<-END.cleanup
|
203
|
+
* [Title for sitemap.html](/sitemap.html)
|
204
|
+
* [Title for some_random_page.html](/some_random_page.html)
|
205
|
+
* 2012-02:
|
206
|
+
* [Title for 2012-02-04-p3.html](/2012/02/04/p3.html)
|
207
|
+
* [Title for 2012-02-03-p2.html](/2012/02/03/p2.html)
|
208
|
+
* [Title for 2012-02-02-p1.html](/2012/02/02/p1.html)
|
209
|
+
* 2012-01:
|
210
|
+
* [Title for 2012-01-04-p3.html](/2012/01/04/p3.html)
|
211
|
+
* [Title for 2012-01-03-p2.html](/2012/01/03/p2.html)
|
212
|
+
* [Title for 2012-01-02-p1.html](/2012/01/02/p1.html)
|
213
|
+
END
|
214
|
+
|
215
|
+
assert_equal exp, act
|
216
|
+
end
|
217
|
+
|
218
|
+
def test_toc
|
219
|
+
assert_equal "* \n{:toc}\n", page.toc
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
class String
|
224
|
+
def cleanup indent = 4
|
225
|
+
self.gsub(/^\ {#{indent}}/, '').chomp
|
226
|
+
end
|
227
|
+
end
|
@@ -0,0 +1,294 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
|
3
|
+
require "rubygems"
|
4
|
+
require "minitest/autorun"
|
5
|
+
|
6
|
+
require "zenweb/site"
|
7
|
+
require "test/helper"
|
8
|
+
|
9
|
+
class Zenweb::Site
|
10
|
+
attr_writer :layouts
|
11
|
+
end
|
12
|
+
|
13
|
+
class TestZenwebSite < MiniTest::Unit::TestCase
|
14
|
+
include ChdirTest("example-site")
|
15
|
+
|
16
|
+
attr_accessor :site
|
17
|
+
|
18
|
+
def setup
|
19
|
+
super
|
20
|
+
|
21
|
+
self.site = Zenweb::Site.new
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_categories
|
25
|
+
site.scan
|
26
|
+
cats = site.categories
|
27
|
+
assert_equal %w(blog pages projects), cats.keys.sort
|
28
|
+
|
29
|
+
exp = [["blog/2012-01-02-page1.html.md",
|
30
|
+
"blog/2012-01-03-page2.html.md",
|
31
|
+
"blog/2012-01-04-page3.html.md"],
|
32
|
+
["pages/nonblogpage.html.md"],
|
33
|
+
["projects/zenweb.html.erb"]]
|
34
|
+
|
35
|
+
assert_equal exp, cats.values.map { |a| a.map(&:path).sort }.sort
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_categories_method_missing
|
39
|
+
site.scan
|
40
|
+
cats = site.categories
|
41
|
+
|
42
|
+
exp = ["blog/2012-01-02-page1.html.md",
|
43
|
+
"blog/2012-01-03-page2.html.md",
|
44
|
+
"blog/2012-01-04-page3.html.md"]
|
45
|
+
|
46
|
+
assert_equal exp, cats.blog.map(&:path).sort
|
47
|
+
|
48
|
+
assert_raises NoMethodError do
|
49
|
+
cats.wtf
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_config
|
54
|
+
assert_equal "_config.yml", site.config.path
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_configs
|
58
|
+
site.scan
|
59
|
+
|
60
|
+
exp = %w[_config.yml blog/_config.yml]
|
61
|
+
|
62
|
+
assert_equal exp, site.configs.keys.sort
|
63
|
+
|
64
|
+
exp = [Zenweb::Config]
|
65
|
+
assert_equal exp, site.configs.values.map(&:class).uniq
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_generate
|
69
|
+
Rake.application = Rake::Application.new
|
70
|
+
extend Rake::DSL
|
71
|
+
|
72
|
+
ran = false
|
73
|
+
task(:site) do
|
74
|
+
ran = true
|
75
|
+
end
|
76
|
+
|
77
|
+
site.generate
|
78
|
+
|
79
|
+
assert ran, "Site#generate needs to call the site task"
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_html_pages
|
83
|
+
Rake.application = Rake::Application.new
|
84
|
+
site.scan
|
85
|
+
|
86
|
+
exp = %w[about/index.html.md
|
87
|
+
blog/2012-01-02-page1.html.md
|
88
|
+
blog/2012-01-03-page2.html.md
|
89
|
+
blog/2012-01-04-page3.html.md
|
90
|
+
blog/index.html.erb
|
91
|
+
index.html.erb
|
92
|
+
pages/index.html.erb
|
93
|
+
pages/nonblogpage.html.md
|
94
|
+
projects/index.html.erb
|
95
|
+
projects/zenweb.html.erb]
|
96
|
+
|
97
|
+
assert_equal exp, site.html_pages.map(&:path).sort
|
98
|
+
|
99
|
+
diff = site.pages.values - site.html_pages
|
100
|
+
|
101
|
+
exp = %w[atom.xml.erb css/colors.css.less css/styles.css
|
102
|
+
css/syntax.css img/bg.png js/jquery.js js/site.js
|
103
|
+
sitemap.xml.erb]
|
104
|
+
|
105
|
+
assert_equal exp, diff.map(&:path).sort
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_inspect
|
109
|
+
assert_equal "Site[0 pages, 0 configs]", site.inspect
|
110
|
+
|
111
|
+
site.scan
|
112
|
+
|
113
|
+
assert_equal "Site[18 pages, 2 configs]", site.inspect
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_layout
|
117
|
+
site.scan
|
118
|
+
assert_equal "_layouts/post.erb", site.layout("post").path
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_method_missing
|
122
|
+
assert_equal "Example Website", site.header
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_pages
|
126
|
+
site.scan
|
127
|
+
|
128
|
+
excludes = %w[Rakefile config.ru]
|
129
|
+
|
130
|
+
exp = Dir["**/*"].
|
131
|
+
select { |p| File.file? p }.
|
132
|
+
reject! { |p| p =~ /(^|\/)_/ }.
|
133
|
+
sort - excludes
|
134
|
+
|
135
|
+
assert_equal exp, site.pages.keys.sort
|
136
|
+
|
137
|
+
exp = [Zenweb::Page]
|
138
|
+
|
139
|
+
assert_equal exp, site.pages.values.map(&:class).uniq
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_pages_by_date
|
143
|
+
site.scan
|
144
|
+
|
145
|
+
srand 42
|
146
|
+
$dates = {}
|
147
|
+
|
148
|
+
site.html_pages.sort_by(&:title).each do |x|
|
149
|
+
$dates[x.path] = rand(100)
|
150
|
+
end
|
151
|
+
|
152
|
+
site.pages.values.each do |x|
|
153
|
+
def x.date
|
154
|
+
$dates[self.path]
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
exp = [[-92, "Example Page 1"],
|
159
|
+
[-86, "example.com pages"],
|
160
|
+
[-82, "example.com"],
|
161
|
+
[-74, "example.com projects"],
|
162
|
+
[-74, "zenweb"],
|
163
|
+
[-71, "Example Page 3"],
|
164
|
+
[-60, "Example Website"],
|
165
|
+
[-51, "About example.com"],
|
166
|
+
[-20, "Some regular page"],
|
167
|
+
[-14, "Example Page 2"]]
|
168
|
+
|
169
|
+
assert_equal exp, site.pages_by_date.map { |x| [-x.date.to_i, x.title] }
|
170
|
+
end
|
171
|
+
|
172
|
+
def test_pages_by_url
|
173
|
+
site.scan
|
174
|
+
|
175
|
+
exp = Hash[site.pages.values.map { |p| [p.url, p] }]
|
176
|
+
assert_equal exp, site.pages_by_url
|
177
|
+
end
|
178
|
+
|
179
|
+
def test_scan # the rest is tested via the other tests
|
180
|
+
assert_empty site.pages
|
181
|
+
assert_empty site.configs
|
182
|
+
assert_empty site.layouts
|
183
|
+
|
184
|
+
site.scan
|
185
|
+
|
186
|
+
refute_empty site.pages
|
187
|
+
refute_empty site.configs
|
188
|
+
refute_empty site.layouts
|
189
|
+
end
|
190
|
+
|
191
|
+
def test_wire
|
192
|
+
Rake.application = Rake::Application.new
|
193
|
+
site.scan
|
194
|
+
site.wire
|
195
|
+
|
196
|
+
assert_tasks do
|
197
|
+
assert_task ".site"
|
198
|
+
assert_task ".site/about"
|
199
|
+
assert_task ".site/blog"
|
200
|
+
assert_task ".site/blog/2012"
|
201
|
+
assert_task ".site/blog/2012/01"
|
202
|
+
assert_task ".site/blog/2012/01/02"
|
203
|
+
assert_task ".site/blog/2012/01/03"
|
204
|
+
assert_task ".site/blog/2012/01/04"
|
205
|
+
assert_task ".site/css"
|
206
|
+
assert_task ".site/img"
|
207
|
+
assert_task ".site/js"
|
208
|
+
assert_task ".site/pages"
|
209
|
+
assert_task ".site/projects"
|
210
|
+
assert_task "_config.yml"
|
211
|
+
assert_task "extra_wirings", nil, Rake::Task
|
212
|
+
|
213
|
+
# stupid simple deps
|
214
|
+
assert_task "_layouts/site.erb", %w[_config.yml]
|
215
|
+
assert_task "atom.xml.erb", %w[_config.yml]
|
216
|
+
assert_task "blog/_config.yml", %w[_config.yml]
|
217
|
+
assert_task "css/colors.css.less", %w[_config.yml]
|
218
|
+
assert_task "css/styles.css", %w[_config.yml]
|
219
|
+
assert_task "css/syntax.css", %w[_config.yml]
|
220
|
+
assert_task "img/bg.png", %w[_config.yml]
|
221
|
+
assert_task "js/jquery.js", %w[_config.yml]
|
222
|
+
assert_task "js/site.js", %w[_config.yml]
|
223
|
+
assert_task "sitemap.xml.erb", %w[_config.yml]
|
224
|
+
|
225
|
+
assert_task ".site/about/index.html", %w[.site/about about/index.html.md ]
|
226
|
+
assert_task ".site/atom.xml", %w[.site atom.xml.erb ]
|
227
|
+
assert_task ".site/blog/2012/01/02/page1.html", %w[.site/blog/2012/01/02 blog/2012-01-02-page1.html.md]
|
228
|
+
assert_task ".site/blog/2012/01/03/page2.html", %w[.site/blog/2012/01/03 blog/2012-01-03-page2.html.md]
|
229
|
+
assert_task ".site/blog/2012/01/04/page3.html", %w[.site/blog/2012/01/04 blog/2012-01-04-page3.html.md]
|
230
|
+
assert_task ".site/blog/index.html", %w[.site/blog
|
231
|
+
.site/blog/2012/01/02/page1.html
|
232
|
+
.site/blog/2012/01/03/page2.html
|
233
|
+
.site/blog/2012/01/04/page3.html
|
234
|
+
blog/index.html.erb]
|
235
|
+
assert_task ".site/css/colors.css", %w[.site/css css/colors.css.less ]
|
236
|
+
assert_task ".site/css/styles.css", %w[.site/css css/styles.css ]
|
237
|
+
assert_task ".site/css/syntax.css", %w[.site/css css/syntax.css ]
|
238
|
+
assert_task ".site/img/bg.png", %w[.site/img img/bg.png ]
|
239
|
+
assert_task ".site/index.html", %w[.site
|
240
|
+
.site/about/index.html
|
241
|
+
.site/blog/2012/01/02/page1.html
|
242
|
+
.site/blog/2012/01/03/page2.html
|
243
|
+
.site/blog/2012/01/04/page3.html
|
244
|
+
.site/blog/index.html
|
245
|
+
.site/pages/index.html
|
246
|
+
.site/pages/nonblogpage.html
|
247
|
+
.site/projects/index.html
|
248
|
+
.site/projects/zenweb.html
|
249
|
+
index.html.erb]
|
250
|
+
assert_task ".site/js/jquery.js", %w[.site/js js/jquery.js ]
|
251
|
+
assert_task ".site/js/site.js", %w[.site/js js/site.js ]
|
252
|
+
assert_task ".site/pages/index.html", %w[.site/pages .site/pages/nonblogpage.html pages/index.html.erb]
|
253
|
+
assert_task ".site/pages/nonblogpage.html", %w[.site/pages pages/nonblogpage.html.md ]
|
254
|
+
assert_task ".site/projects/index.html", %w[.site/projects .site/projects/zenweb.html projects/index.html.erb]
|
255
|
+
assert_task ".site/projects/zenweb.html", %w[.site/projects projects/zenweb.html.erb ]
|
256
|
+
assert_task ".site/sitemap.xml", %w[.site sitemap.xml.erb ]
|
257
|
+
|
258
|
+
assert_task "_layouts/post.erb", %w[_config.yml _layouts/site.erb]
|
259
|
+
assert_task "_layouts/project.erb", %w[_config.yml _layouts/site.erb]
|
260
|
+
assert_task "about/index.html.md", %w[_config.yml _layouts/site.erb]
|
261
|
+
assert_task "blog/2012-01-02-page1.html.md", %w[_layouts/post.erb blog/_config.yml]
|
262
|
+
assert_task "blog/2012-01-03-page2.html.md", %w[_layouts/post.erb blog/_config.yml]
|
263
|
+
assert_task "blog/2012-01-04-page3.html.md", %w[_layouts/post.erb blog/_config.yml]
|
264
|
+
assert_task "blog/index.html.erb", %w[_layouts/site.erb blog/_config.yml]
|
265
|
+
assert_task "index.html.erb", %w[_config.yml _layouts/site.erb]
|
266
|
+
assert_task "pages/index.html.erb", %w[_config.yml _layouts/site.erb]
|
267
|
+
assert_task "pages/nonblogpage.html.md", %w[_config.yml _layouts/site.erb]
|
268
|
+
assert_task "projects/index.html.erb", %w[_config.yml _layouts/site.erb]
|
269
|
+
assert_task "projects/zenweb.html.erb", %w[_config.yml _layouts/project.erb]
|
270
|
+
|
271
|
+
deps = %w[.site
|
272
|
+
.site/about/index.html
|
273
|
+
.site/atom.xml
|
274
|
+
.site/blog/2012/01/02/page1.html
|
275
|
+
.site/blog/2012/01/03/page2.html
|
276
|
+
.site/blog/2012/01/04/page3.html
|
277
|
+
.site/blog/index.html
|
278
|
+
.site/css/colors.css
|
279
|
+
.site/css/styles.css
|
280
|
+
.site/css/syntax.css
|
281
|
+
.site/img/bg.png
|
282
|
+
.site/index.html
|
283
|
+
.site/js/jquery.js
|
284
|
+
.site/js/site.js
|
285
|
+
.site/pages/index.html
|
286
|
+
.site/pages/nonblogpage.html
|
287
|
+
.site/projects/index.html
|
288
|
+
.site/projects/zenweb.html
|
289
|
+
.site/sitemap.xml]
|
290
|
+
|
291
|
+
assert_task "site", deps, Rake::Task
|
292
|
+
end
|
293
|
+
end
|
294
|
+
end
|