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,165 @@
|
|
1
|
+
require 'zenweb'
|
2
|
+
|
3
|
+
task :default => :generate
|
4
|
+
|
5
|
+
def website
|
6
|
+
$website = Zenweb::Site.new
|
7
|
+
$website.scan
|
8
|
+
$website.wire
|
9
|
+
$website
|
10
|
+
rescue RuntimeError => e
|
11
|
+
p e
|
12
|
+
puts e.backtrace.join "\n"
|
13
|
+
raise e
|
14
|
+
end
|
15
|
+
|
16
|
+
desc "Generate the website."
|
17
|
+
task :generate do
|
18
|
+
site = website
|
19
|
+
|
20
|
+
site.generate
|
21
|
+
|
22
|
+
found = Dir[".site/**/*"].select { |f| File.file? f }.sort
|
23
|
+
known = site.pages.values.map { |p| p.url_path }.sort
|
24
|
+
rm found - known
|
25
|
+
end
|
26
|
+
|
27
|
+
desc "Print out possible orphans (html pages w/o parent pages)"
|
28
|
+
task :orphans do
|
29
|
+
site = website
|
30
|
+
puts "Possible Orphans (HTML pages w/o parents):"
|
31
|
+
puts
|
32
|
+
site.pages.values.reject(&:parent).sort_by(&:clean_url).each do |page|
|
33
|
+
next unless page.url =~ /html$/
|
34
|
+
puts page
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
desc "Push changes to the site. (you need to define this)"
|
39
|
+
task :push
|
40
|
+
|
41
|
+
desc "Publish your website: clean, generate, push."
|
42
|
+
task :publish => [:clean, :generate, :push]
|
43
|
+
|
44
|
+
desc "Remove junk files."
|
45
|
+
task :clean do
|
46
|
+
rm_rf Dir["**/*~"]
|
47
|
+
end
|
48
|
+
|
49
|
+
desc "Remove generated .site directory."
|
50
|
+
task :realclean => :clean do
|
51
|
+
rm_rf ".site"
|
52
|
+
end
|
53
|
+
|
54
|
+
def new_file title, dated = false
|
55
|
+
path = "#{title.strip.downcase.gsub(/\W+/, '-')}.html.md"
|
56
|
+
|
57
|
+
if dated then
|
58
|
+
today = Time.now.strftime '%Y-%m-%d'
|
59
|
+
path = "#{today}-#{path}"
|
60
|
+
end
|
61
|
+
|
62
|
+
open path, 'w' do |post|
|
63
|
+
post.puts "---"
|
64
|
+
post.puts "title: \"#{title}\""
|
65
|
+
post.puts "date: #{Time.now.iso8601}"
|
66
|
+
post.puts "..."
|
67
|
+
post.puts
|
68
|
+
end
|
69
|
+
|
70
|
+
path
|
71
|
+
end
|
72
|
+
|
73
|
+
desc "Begin a new dated post: rake new_post['title']"
|
74
|
+
task :new_post, :title do |t, args|
|
75
|
+
title = args[:title] || "new-post"
|
76
|
+
|
77
|
+
path = new_file title, true
|
78
|
+
|
79
|
+
warn "Created new post: #{path}"
|
80
|
+
end
|
81
|
+
|
82
|
+
desc "Begin a new dated post: rake new_page['title']"
|
83
|
+
task :new_page, :title do |t, args|
|
84
|
+
title = args[:title] || "new-post"
|
85
|
+
|
86
|
+
path = new_file title
|
87
|
+
|
88
|
+
warn "Created new file: #{path}"
|
89
|
+
end
|
90
|
+
|
91
|
+
desc "Run a webserver and build on the fly."
|
92
|
+
task :run do
|
93
|
+
require 'zenweb/extensions'
|
94
|
+
require 'webrick'
|
95
|
+
require 'thread'
|
96
|
+
|
97
|
+
module Rake
|
98
|
+
class FileTask
|
99
|
+
def clear_timestamp
|
100
|
+
@timestamp = nil
|
101
|
+
prerequisite_tasks.each(&:clear_timestamp)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
# TODO: implement a watcher or something... this is annoying
|
107
|
+
class ZenwebBuilder < WEBrick::HTTPServlet::FileHandler
|
108
|
+
@@semaphore = Mutex.new
|
109
|
+
|
110
|
+
def service req, res
|
111
|
+
@@site ||= @@semaphore.synchronize { website }
|
112
|
+
|
113
|
+
url = req.path
|
114
|
+
target_path = File.join(".site", url)
|
115
|
+
|
116
|
+
target_path = File.join target_path, "index.html" if
|
117
|
+
File.directory? target_path
|
118
|
+
|
119
|
+
task = Rake.application[target_path] rescue nil
|
120
|
+
|
121
|
+
warn "NOTE: No file found for #{url}" unless task
|
122
|
+
|
123
|
+
newer = task && task.needed?
|
124
|
+
|
125
|
+
if newer then
|
126
|
+
system "rake clean generate"
|
127
|
+
end
|
128
|
+
|
129
|
+
if task && newer then
|
130
|
+
@@site = nil
|
131
|
+
Rake.application = Rake::Application.new # reset
|
132
|
+
end
|
133
|
+
|
134
|
+
task.clear_timestamp if task && target_path =~ /(html|css|js)$/
|
135
|
+
|
136
|
+
super
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
server = WEBrick::HTTPServer.new :Port => 8000
|
141
|
+
server.mount '/', ZenwebBuilder, ".site"
|
142
|
+
|
143
|
+
trap 'INT' do
|
144
|
+
server.shutdown
|
145
|
+
end
|
146
|
+
|
147
|
+
server.start
|
148
|
+
end
|
149
|
+
|
150
|
+
website if ENV['DEBUG']
|
151
|
+
|
152
|
+
desc "Debug the generation of a file. Takes a PATH arg."
|
153
|
+
task :debug => ".site" do
|
154
|
+
site = website
|
155
|
+
|
156
|
+
path = ENV['PAGE'] || ENV['F'] || ENV['FILE'] || "index.html.erb"
|
157
|
+
|
158
|
+
if path then
|
159
|
+
page = site.pages[path]
|
160
|
+
page.generate
|
161
|
+
|
162
|
+
puts
|
163
|
+
puts File.read page.url_path
|
164
|
+
end
|
165
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
class MiniTest::Unit::TestCase
|
2
|
+
def self.ChdirTest path
|
3
|
+
Module.new do
|
4
|
+
define_method :setup do
|
5
|
+
super()
|
6
|
+
@old_dir = Dir.pwd
|
7
|
+
Dir.chdir path
|
8
|
+
end
|
9
|
+
|
10
|
+
define_method :teardown do
|
11
|
+
super()
|
12
|
+
Dir.chdir @old_dir
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def assert_task name, deps = nil, type = Rake::FileTask
|
18
|
+
@tasks << name
|
19
|
+
assert_operator Rake::Task, :task_defined?, name
|
20
|
+
|
21
|
+
task = Rake.application[name]
|
22
|
+
assert_kind_of type, task
|
23
|
+
assert_equal deps, task.prerequisites.sort, name if deps
|
24
|
+
end
|
25
|
+
|
26
|
+
def assert_tasks
|
27
|
+
@tasks = []
|
28
|
+
yield
|
29
|
+
assert_empty Rake.application.tasks.map(&:name) - @tasks
|
30
|
+
end
|
31
|
+
|
32
|
+
def build_fake_site(*paths)
|
33
|
+
paths.flatten.compact.each do |path|
|
34
|
+
page = Zenweb::Page.new(site, path)
|
35
|
+
page.content = "Content for #{path}"
|
36
|
+
page.config = Zenweb::Config.new site, path
|
37
|
+
page.config.h = {
|
38
|
+
"title" => "Title for #{path}"
|
39
|
+
}
|
40
|
+
site.pages[path] = page
|
41
|
+
end
|
42
|
+
|
43
|
+
site.fix_subpages
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
class Zenweb::Page
|
48
|
+
attr_writer :content, :config
|
49
|
+
end
|
50
|
+
|
51
|
+
class Zenweb::Config
|
52
|
+
attr_writer :h
|
53
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
|
3
|
+
require "rubygems"
|
4
|
+
|
5
|
+
gem "rake"
|
6
|
+
require "rake"
|
7
|
+
require "minitest/autorun"
|
8
|
+
|
9
|
+
require "zenweb/site"
|
10
|
+
require "test/helper"
|
11
|
+
|
12
|
+
class TestZenwebConfig < MiniTest::Unit::TestCase
|
13
|
+
include ChdirTest("example-site")
|
14
|
+
|
15
|
+
attr_accessor :site, :config
|
16
|
+
|
17
|
+
def setup
|
18
|
+
super
|
19
|
+
|
20
|
+
self.site = Zenweb::Site.new
|
21
|
+
page = Zenweb::Page.new site, "blog/2012-01-02-page1.html.md"
|
22
|
+
self.config = page.config
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_h
|
26
|
+
exp = {"title"=>"Example Page 1"}
|
27
|
+
assert_equal exp, config.h
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_index
|
31
|
+
assert_equal "Example Page 1", config["title"]
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_inspect
|
35
|
+
exp = ['Config["blog/2012-01-02-page1.html.md"',
|
36
|
+
'Config["blog/_config.yml"',
|
37
|
+
'Config["_config.yml"',
|
38
|
+
'Config::Null]]]'
|
39
|
+
].join ", "
|
40
|
+
assert_equal exp, config.inspect
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_inspect_trace
|
44
|
+
exp = ['Config["blog/2012-01-02-page1.html.md"',
|
45
|
+
'Config["blog/_config.yml"',
|
46
|
+
'Config["_config.yml"',
|
47
|
+
'Config::Null',
|
48
|
+
'"exclude" => ["Rakefile", "tmp"]',
|
49
|
+
'"google_ua" => "UA-1234567-8"',
|
50
|
+
'"header" => "Example Website"]',
|
51
|
+
'"layout" => "post"]',
|
52
|
+
'"title" => "Example Page 1"]'].join ", "
|
53
|
+
|
54
|
+
assert_nil Rake.application.options.trace
|
55
|
+
Rake.application.options.trace = true
|
56
|
+
assert_equal exp, config.inspect
|
57
|
+
ensure
|
58
|
+
Rake.application.options.trace = nil
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_parent
|
62
|
+
assert_equal site.configs["blog/_config.yml"], config.parent
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_path
|
66
|
+
assert_equal "blog/2012-01-02-page1.html.md", config.path
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_site
|
70
|
+
assert_equal site, config.site
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_to_s
|
74
|
+
assert_equal "Config[\"blog/2012-01-02-page1.html.md\"]", config.to_s
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_wire
|
78
|
+
Rake.application = Rake::Application.new
|
79
|
+
site.scan
|
80
|
+
self.config = site.pages["blog/2012-01-02-page1.html.md"].config
|
81
|
+
|
82
|
+
config.wire
|
83
|
+
|
84
|
+
assert_tasks do
|
85
|
+
assert_task "_config.yml"
|
86
|
+
assert_task "blog/_config.yml", %w[_config.yml]
|
87
|
+
assert_task config.path, %w[blog/_config.yml]
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
|
3
|
+
require "rubygems"
|
4
|
+
require "minitest/autorun"
|
5
|
+
require "zenweb/extensions"
|
6
|
+
|
7
|
+
class TestFile < MiniTest::Unit::TestCase
|
8
|
+
def test_class_each_parent
|
9
|
+
a = []
|
10
|
+
|
11
|
+
Dir.chdir "example-site" do
|
12
|
+
File.each_parent "blog/index.html.erb", "_config.yml" do |f|
|
13
|
+
a << f
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
assert_equal %w[blog/_config.yml _config.yml], a
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class TestTime < MiniTest::Unit::TestCase
|
22
|
+
def test_date
|
23
|
+
assert_equal "1969-12-31", Time.at(0).date
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_datetime
|
27
|
+
assert_equal "1969-12-31 @ 16:00", Time.at(0).datetime
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_time
|
31
|
+
assert_equal "16:00", Time.at(0).time
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,381 @@
|
|
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 TestZenwebPage < 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 setup_deps
|
22
|
+
Rake.application = Rake::Application.new
|
23
|
+
site.scan
|
24
|
+
|
25
|
+
assert_empty Rake.application.tasks
|
26
|
+
|
27
|
+
p1 = site.pages["blog/2012-01-02-page1.html.md"]
|
28
|
+
p2 = site.pages["blog/2012-01-03-page2.html.md"]
|
29
|
+
|
30
|
+
return p1, p2
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_body
|
34
|
+
assert_equal "Not really much here to see.", page.body
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_breadcrumbs
|
38
|
+
site.scan
|
39
|
+
self.page = site.pages[page.path]
|
40
|
+
|
41
|
+
exp = %w[/index.html /blog/index.html]
|
42
|
+
|
43
|
+
assert_equal exp, page.breadcrumbs.map(&:url)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_clean_url
|
47
|
+
act = page.clean_url
|
48
|
+
exp = "/blog/2012/01/02/page1.html"
|
49
|
+
|
50
|
+
assert_equal exp, act
|
51
|
+
|
52
|
+
page = Zenweb::Page.new site, "a/b/index.html"
|
53
|
+
act = page.clean_url
|
54
|
+
exp = "/a/b/"
|
55
|
+
|
56
|
+
assert_equal exp, act
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_config
|
60
|
+
exp = {"title" => "Example Page 1"}
|
61
|
+
|
62
|
+
assert_kind_of Zenweb::Config, page.config
|
63
|
+
assert_equal exp, page.config.h
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_content
|
67
|
+
assert_equal File.read(page.path), page.content
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_date
|
71
|
+
assert_equal Time.local(2012, 1, 2), page.date
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_date_from_path
|
75
|
+
assert_equal Time.local(2012, 1, 2), page.date_from_path
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_depends_on
|
79
|
+
p1, p2 = setup_deps
|
80
|
+
|
81
|
+
p1.depends_on p2
|
82
|
+
|
83
|
+
assert_tasks do
|
84
|
+
assert_task p1.url_path, [p2.url_path]
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_depends_on_string
|
89
|
+
p1, _ = setup_deps
|
90
|
+
|
91
|
+
p1.depends_on "somethingelse"
|
92
|
+
|
93
|
+
# TODO: double check that this should be p1.path and not p1.url_path
|
94
|
+
assert_tasks do
|
95
|
+
assert_task p1.path, ["somethingelse"]
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_filetype
|
100
|
+
assert_equal "md", page.filetype
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_filetypes
|
104
|
+
assert_equal %w[md], page.filetypes
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_filetypes_odd
|
108
|
+
page = Zenweb::Page.new site, "blah.wtf"
|
109
|
+
assert_equal %w[], page.filetypes
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_generate
|
113
|
+
page = Zenweb::Page.new site, "blah"
|
114
|
+
|
115
|
+
def page.render
|
116
|
+
"woot"
|
117
|
+
end
|
118
|
+
|
119
|
+
def page.open path, mode
|
120
|
+
yield $stdout
|
121
|
+
end
|
122
|
+
|
123
|
+
out = "woot\n"
|
124
|
+
err = "Rendering .site/blah\n"
|
125
|
+
|
126
|
+
assert_output out, err do
|
127
|
+
page.generate
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_generate_via_invoke
|
132
|
+
Rake.application = Rake::Application.new
|
133
|
+
site.scan
|
134
|
+
site.wire
|
135
|
+
self.page = site.pages["blog/2012-01-02-page1.html.md"]
|
136
|
+
Rake.application[page.url_path].clear_prerequisites # no mkdir, thanks
|
137
|
+
|
138
|
+
def page.generate
|
139
|
+
raise "no generate"
|
140
|
+
end
|
141
|
+
|
142
|
+
e = assert_raises RuntimeError do
|
143
|
+
Rake.application[page.url_path].invoke
|
144
|
+
end
|
145
|
+
|
146
|
+
assert_equal "no generate", e.message
|
147
|
+
ensure
|
148
|
+
FileUtils.rm_rf ".site"
|
149
|
+
end
|
150
|
+
|
151
|
+
def test_html_eh
|
152
|
+
assert page.html?
|
153
|
+
|
154
|
+
site.scan
|
155
|
+
refute site.pages["js/site.js"].html?
|
156
|
+
end
|
157
|
+
|
158
|
+
def test_include
|
159
|
+
# test via a layout page so we can test indirect access of page vars
|
160
|
+
layout = Zenweb::Page.new(site, "_layouts/site.erb")
|
161
|
+
fragment = layout.include("analytics.html.erb", page)
|
162
|
+
assert_match(/UA-\d+/, site.config["google_ua"])
|
163
|
+
assert_match site.config["google_ua"], fragment
|
164
|
+
end
|
165
|
+
|
166
|
+
def test_include_page_var
|
167
|
+
# test via a layout page so we can test indirect access of page vars
|
168
|
+
layout = Zenweb::Page.new(site, "_layouts/site.erb")
|
169
|
+
fragment = layout.include("header.html.erb", page)
|
170
|
+
assert_match "Example Page 1 ~ Example Website", fragment
|
171
|
+
end
|
172
|
+
|
173
|
+
def test_index
|
174
|
+
assert_equal page.config["title"], page["title"]
|
175
|
+
end
|
176
|
+
|
177
|
+
def test_inspect
|
178
|
+
assert_equal 'Page["blog/2012-01-02-page1.html.md"]', page.inspect
|
179
|
+
end
|
180
|
+
|
181
|
+
def test_layout
|
182
|
+
assert_equal site.layout("post"), page.layout
|
183
|
+
end
|
184
|
+
|
185
|
+
def test_link_html
|
186
|
+
exp = "<a href=\"/blog/2012/01/02/page1.html\">Example Page 1</a>"
|
187
|
+
assert_equal exp, page.link_html
|
188
|
+
|
189
|
+
exp = "<a href=\"/blog/2012/01/02/page1.html\">blah</a>"
|
190
|
+
assert_equal exp, page.link_html("blah")
|
191
|
+
end
|
192
|
+
|
193
|
+
def test_method_missing
|
194
|
+
assert_equal page["title"], page.method_missing("title")
|
195
|
+
end
|
196
|
+
|
197
|
+
def test_meta
|
198
|
+
exp = '<meta name="title" content="Example Page 1">'
|
199
|
+
assert_equal exp, page.meta("title")
|
200
|
+
end
|
201
|
+
|
202
|
+
def test_method_missing_odd
|
203
|
+
err = "Page[\"blog/2012-01-02-page1.html.md\"] does not define \"wtf\"\n"
|
204
|
+
assert_output "", err do
|
205
|
+
assert_nil page.method_missing("wtf")
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
def test_method_missing_render
|
210
|
+
e = assert_raises NoMethodError do
|
211
|
+
assert_nil page.render_wtf
|
212
|
+
end
|
213
|
+
err = "undefined method `render_wtf' for Page"
|
214
|
+
assert_includes e.message, err
|
215
|
+
end
|
216
|
+
|
217
|
+
def test_parent
|
218
|
+
site.scan
|
219
|
+
self.page = site.pages[page.path]
|
220
|
+
|
221
|
+
assert_equal site.pages["blog/index.html.erb"], page.parent
|
222
|
+
end
|
223
|
+
|
224
|
+
def test_parent_top
|
225
|
+
build_fake_site %w[index.html]
|
226
|
+
|
227
|
+
page = site.pages["index.html"]
|
228
|
+
|
229
|
+
assert_nil page.parent
|
230
|
+
end
|
231
|
+
|
232
|
+
def test_parent_url
|
233
|
+
assert_equal "/blog/2012/01/02/page1.html", page.url
|
234
|
+
assert_equal "/blog/2012/01/02/index.html", page.parent_url
|
235
|
+
|
236
|
+
page = Zenweb::Page.new(site, "a/b/c.html")
|
237
|
+
assert_equal "/a/b/index.html", page.parent_url
|
238
|
+
|
239
|
+
page = Zenweb::Page.new(site, "a/b/index.html")
|
240
|
+
assert_equal "/a/index.html", page.parent_url
|
241
|
+
end
|
242
|
+
|
243
|
+
def test_path
|
244
|
+
assert_equal "blog/2012-01-02-page1.html.md", page.path
|
245
|
+
end
|
246
|
+
|
247
|
+
def test_render
|
248
|
+
assert_equal "<p>Not really much here to see.</p>\n", page.render
|
249
|
+
end
|
250
|
+
|
251
|
+
def test_render_image
|
252
|
+
self.page = Zenweb::Page.new site, "img/bg.png"
|
253
|
+
assert_equal File.binread("img/bg.png"), page.render
|
254
|
+
end
|
255
|
+
|
256
|
+
def test_run_js_script
|
257
|
+
exp = <<-EOM.gsub(/^ {6}/, '')
|
258
|
+
<script type=\"text/javascript\">
|
259
|
+
(function() {
|
260
|
+
var s = document.createElement('script');
|
261
|
+
s.type = 'text/javascript';
|
262
|
+
s.async = true;
|
263
|
+
s.src = 'my_url';
|
264
|
+
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(s);
|
265
|
+
})();
|
266
|
+
</script>
|
267
|
+
EOM
|
268
|
+
|
269
|
+
assert_equal exp, page.run_js_script("my_url")
|
270
|
+
end
|
271
|
+
|
272
|
+
def test_site
|
273
|
+
assert_equal site, page.site
|
274
|
+
end
|
275
|
+
|
276
|
+
def test_subpages
|
277
|
+
site.scan
|
278
|
+
|
279
|
+
page = site.pages["blog/index.html.erb"]
|
280
|
+
act = page.subpages
|
281
|
+
exp = [site.pages["blog/2012-01-04-page3.html.md"],
|
282
|
+
site.pages["blog/2012-01-03-page2.html.md"],
|
283
|
+
site.pages["blog/2012-01-02-page1.html.md"]]
|
284
|
+
|
285
|
+
assert_equal exp, act
|
286
|
+
end
|
287
|
+
|
288
|
+
def test_subpages_subdirs
|
289
|
+
build_fake_site %w[index.html
|
290
|
+
a/index.html
|
291
|
+
a/a.html
|
292
|
+
a/b.html
|
293
|
+
a/c.html
|
294
|
+
b/index.html
|
295
|
+
b/2012-01-02-p1.html
|
296
|
+
b/2012-01-03-p2.html
|
297
|
+
b/2012-01-04-p3.html
|
298
|
+
c/index.html
|
299
|
+
c/a.html
|
300
|
+
c/b.html
|
301
|
+
c/c.html
|
302
|
+
c/d/e.html
|
303
|
+
c/d/f.html
|
304
|
+
c/d/g.html
|
305
|
+
d/index.html
|
306
|
+
d/2012-01-02-p1.html
|
307
|
+
d/2012-01-03-p2.html
|
308
|
+
d/2012-01-04-p3.html
|
309
|
+
some_random_page.html
|
310
|
+
]
|
311
|
+
|
312
|
+
urls = %w[a/index.html
|
313
|
+
b/index.html
|
314
|
+
c/index.html
|
315
|
+
d/index.html
|
316
|
+
some_random_page.html]
|
317
|
+
|
318
|
+
exp = urls.map { |url| site.pages[url] }
|
319
|
+
|
320
|
+
page = site.pages["index.html"]
|
321
|
+
assert_equal exp, page.subpages
|
322
|
+
end
|
323
|
+
|
324
|
+
def test_subrender
|
325
|
+
assert_equal "<p>Not really much here to see.</p>\n", page.subrender
|
326
|
+
end
|
327
|
+
|
328
|
+
def test_to_s
|
329
|
+
assert_equal 'Page["blog/2012-01-02-page1.html.md"]', page.to_s
|
330
|
+
end
|
331
|
+
|
332
|
+
def test_url
|
333
|
+
assert_equal "/blog/2012/01/02/page1.html", page.url
|
334
|
+
end
|
335
|
+
|
336
|
+
def test_url_date_fmt
|
337
|
+
page.config.h["date_fmt"] = "%Y/%m"
|
338
|
+
assert_equal "/blog/2012/01/page1.html", page.url
|
339
|
+
end
|
340
|
+
|
341
|
+
def test_url_regular_page
|
342
|
+
page = Zenweb::Page.new site, "pages/blah.html"
|
343
|
+
assert_equal "/pages/blah.html", page.url
|
344
|
+
end
|
345
|
+
|
346
|
+
def test_url_dir
|
347
|
+
assert_equal ".site/blog/2012/01/02", page.url_dir
|
348
|
+
end
|
349
|
+
|
350
|
+
def test_url_path
|
351
|
+
assert_equal ".site/blog/2012/01/02/page1.html", page.url_path
|
352
|
+
end
|
353
|
+
|
354
|
+
def test_wire
|
355
|
+
Rake.application = Rake::Application.new
|
356
|
+
site.scan
|
357
|
+
self.page = site.pages["blog/2012-01-02-page1.html.md"]
|
358
|
+
|
359
|
+
page.wire
|
360
|
+
|
361
|
+
assert_tasks do
|
362
|
+
# dirs
|
363
|
+
assert_task ".site"
|
364
|
+
assert_task ".site/blog"
|
365
|
+
assert_task ".site/blog/2012"
|
366
|
+
assert_task ".site/blog/2012/01"
|
367
|
+
assert_task ".site/blog/2012/01/02"
|
368
|
+
|
369
|
+
# aux
|
370
|
+
assert_task "_layouts/post.erb", %w[_config.yml _layouts/site.erb]
|
371
|
+
assert_task "_layouts/site.erb", %w[_config.yml]
|
372
|
+
assert_task "blog/_config.yml", %w[_config.yml]
|
373
|
+
assert_task "_config.yml"
|
374
|
+
|
375
|
+
# page down to site
|
376
|
+
assert_task page.path, %w[_layouts/post.erb blog/_config.yml]
|
377
|
+
assert_task page.url_path, [page.url_dir, page.path]
|
378
|
+
assert_task "site", [page.url_path], Rake::Task
|
379
|
+
end
|
380
|
+
end
|
381
|
+
end
|