jamesgolick-webby 0.9.5
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +219 -0
- data/README.rdoc +92 -0
- data/Rakefile +62 -0
- data/bin/webby +41 -0
- data/bin/webby-gen +41 -0
- data/examples/blog/Sitefile +7 -0
- data/examples/blog/tasks/blog.rake +72 -0
- data/examples/blog/templates/atom_feed.erb +40 -0
- data/examples/blog/templates/blog/month.erb +22 -0
- data/examples/blog/templates/blog/post.erb +16 -0
- data/examples/blog/templates/blog/year.erb +22 -0
- data/examples/presentation/Sitefile +10 -0
- data/examples/presentation/content/css/uv/twilight.css +137 -0
- data/examples/presentation/content/presentation/_sample_code.txt +10 -0
- data/examples/presentation/content/presentation/index.txt +63 -0
- data/examples/presentation/content/presentation/s5/blank.gif +0 -0
- data/examples/presentation/content/presentation/s5/bodybg.gif +0 -0
- data/examples/presentation/content/presentation/s5/framing.css +23 -0
- data/examples/presentation/content/presentation/s5/iepngfix.htc +42 -0
- data/examples/presentation/content/presentation/s5/opera.css +7 -0
- data/examples/presentation/content/presentation/s5/outline.css +15 -0
- data/examples/presentation/content/presentation/s5/pretty.css +86 -0
- data/examples/presentation/content/presentation/s5/print.css +25 -0
- data/examples/presentation/content/presentation/s5/s5-core.css +9 -0
- data/examples/presentation/content/presentation/s5/slides.css +3 -0
- data/examples/presentation/content/presentation/s5/slides.js +553 -0
- data/examples/presentation/layouts/presentation.txt +43 -0
- data/examples/presentation/templates/_code_partial.erb +13 -0
- data/examples/presentation/templates/presentation.erb +40 -0
- data/examples/tumblog/Sitefile +9 -0
- data/examples/tumblog/content/css/tumblog.css +308 -0
- data/examples/tumblog/content/images/tumblog/permalink.gif +0 -0
- data/examples/tumblog/content/images/tumblog/rss.gif +0 -0
- data/examples/tumblog/content/tumblog/200806/the-noble-chicken/index.txt +12 -0
- data/examples/tumblog/content/tumblog/200807/historical-perspectives-on-the-classic-chicken-joke/index.txt +12 -0
- data/examples/tumblog/content/tumblog/200807/mad-city-chickens/index.txt +10 -0
- data/examples/tumblog/content/tumblog/200807/the-wisdom-of-the-dutch/index.txt +11 -0
- data/examples/tumblog/content/tumblog/200807/up-a-tree/index.txt +13 -0
- data/examples/tumblog/content/tumblog/index.txt +37 -0
- data/examples/tumblog/content/tumblog/rss.txt +37 -0
- data/examples/tumblog/layouts/tumblog/default.txt +44 -0
- data/examples/tumblog/layouts/tumblog/post.txt +15 -0
- data/examples/tumblog/lib/tumblog_helper.rb +32 -0
- data/examples/tumblog/tasks/tumblog.rake +30 -0
- data/examples/tumblog/templates/atom_feed.erb +40 -0
- data/examples/tumblog/templates/tumblog/conversation.erb +12 -0
- data/examples/tumblog/templates/tumblog/link.erb +10 -0
- data/examples/tumblog/templates/tumblog/photo.erb +13 -0
- data/examples/tumblog/templates/tumblog/post.erb +12 -0
- data/examples/tumblog/templates/tumblog/quote.erb +11 -0
- data/examples/webby/Sitefile +19 -0
- data/examples/webby/content/communicate/index.txt +28 -0
- data/examples/webby/content/css/background.gif +0 -0
- data/examples/webby/content/css/blueprint/print.css +76 -0
- data/examples/webby/content/css/blueprint/screen.css +696 -0
- data/examples/webby/content/css/coderay.css +96 -0
- data/examples/webby/content/css/site.css +196 -0
- data/examples/webby/content/css/uv/twilight.css +137 -0
- data/examples/webby/content/index.txt +37 -0
- data/examples/webby/content/learn/index.txt +28 -0
- data/examples/webby/content/reference/index.txt +204 -0
- data/examples/webby/content/release-notes/index.txt +21 -0
- data/examples/webby/content/release-notes/rel-0-9-0/index.txt +74 -0
- data/examples/webby/content/release-notes/rel-0-9-1/index.txt +93 -0
- data/examples/webby/content/release-notes/rel-0-9-2/index.txt +14 -0
- data/examples/webby/content/release-notes/rel-0-9-3/index.txt +47 -0
- data/examples/webby/content/robots.txt +6 -0
- data/examples/webby/content/script/jquery.corner.js +152 -0
- data/examples/webby/content/script/jquery.js +31 -0
- data/examples/webby/content/sitemap.txt +31 -0
- data/examples/webby/content/tips_and_tricks/index.txt +97 -0
- data/examples/webby/content/tutorial/index.txt +135 -0
- data/examples/webby/content/user-manual/index.txt +419 -0
- data/examples/webby/layouts/default.txt +49 -0
- data/examples/webby/templates/page.erb +10 -0
- data/examples/website/Sitefile +7 -0
- data/examples/website/content/css/blueprint/ie.css +26 -0
- data/examples/website/content/css/blueprint/plugins/buttons/icons/cross.png +0 -0
- data/examples/website/content/css/blueprint/plugins/buttons/icons/key.png +0 -0
- data/examples/website/content/css/blueprint/plugins/buttons/icons/tick.png +0 -0
- data/examples/website/content/css/blueprint/plugins/buttons/readme.txt +32 -0
- data/examples/website/content/css/blueprint/plugins/buttons/screen.css +97 -0
- data/examples/website/content/css/blueprint/plugins/fancy-type/readme.txt +14 -0
- data/examples/website/content/css/blueprint/plugins/fancy-type/screen.css +71 -0
- data/examples/website/content/css/blueprint/plugins/link-icons/icons/doc.png +0 -0
- data/examples/website/content/css/blueprint/plugins/link-icons/icons/email.png +0 -0
- data/examples/website/content/css/blueprint/plugins/link-icons/icons/external.png +0 -0
- data/examples/website/content/css/blueprint/plugins/link-icons/icons/feed.png +0 -0
- data/examples/website/content/css/blueprint/plugins/link-icons/icons/im.png +0 -0
- data/examples/website/content/css/blueprint/plugins/link-icons/icons/pdf.png +0 -0
- data/examples/website/content/css/blueprint/plugins/link-icons/icons/visited.png +0 -0
- data/examples/website/content/css/blueprint/plugins/link-icons/icons/xls.png +0 -0
- data/examples/website/content/css/blueprint/plugins/link-icons/readme.txt +18 -0
- data/examples/website/content/css/blueprint/plugins/link-icons/screen.css +40 -0
- data/examples/website/content/css/blueprint/plugins/rtl/readme.txt +10 -0
- data/examples/website/content/css/blueprint/plugins/rtl/screen.css +109 -0
- data/examples/website/content/css/blueprint/print.css +30 -0
- data/examples/website/content/css/blueprint/screen.css +251 -0
- data/examples/website/content/css/blueprint/src/forms.css +49 -0
- data/examples/website/content/css/blueprint/src/grid.css +212 -0
- data/examples/website/content/css/blueprint/src/grid.png +0 -0
- data/examples/website/content/css/blueprint/src/ie.css +59 -0
- data/examples/website/content/css/blueprint/src/print.css +85 -0
- data/examples/website/content/css/blueprint/src/reset.css +38 -0
- data/examples/website/content/css/blueprint/src/typography.css +105 -0
- data/examples/website/content/css/coderay.css +111 -0
- data/examples/website/content/css/site.css +67 -0
- data/examples/website/content/index.txt +19 -0
- data/examples/website/layouts/default.txt +61 -0
- data/examples/website/lib/breadcrumbs.rb +28 -0
- data/examples/website/templates/_partial.erb +10 -0
- data/examples/website/templates/page.erb +18 -0
- data/lib/webby.rb +233 -0
- data/lib/webby/apps.rb +12 -0
- data/lib/webby/apps/generator.rb +276 -0
- data/lib/webby/apps/main.rb +258 -0
- data/lib/webby/auto_builder.rb +157 -0
- data/lib/webby/builder.rb +172 -0
- data/lib/webby/core_ext/enumerable.rb +11 -0
- data/lib/webby/core_ext/hash.rb +28 -0
- data/lib/webby/core_ext/kernel.rb +26 -0
- data/lib/webby/core_ext/string.rb +163 -0
- data/lib/webby/core_ext/time.rb +9 -0
- data/lib/webby/filters.rb +85 -0
- data/lib/webby/filters/basepath.rb +97 -0
- data/lib/webby/filters/erb.rb +9 -0
- data/lib/webby/filters/haml.rb +18 -0
- data/lib/webby/filters/markdown.rb +16 -0
- data/lib/webby/filters/maruku.rb +16 -0
- data/lib/webby/filters/outline.rb +309 -0
- data/lib/webby/filters/sass.rb +17 -0
- data/lib/webby/filters/slides.rb +56 -0
- data/lib/webby/filters/textile.rb +16 -0
- data/lib/webby/filters/tidy.rb +76 -0
- data/lib/webby/filters/wiki_words.rb +14 -0
- data/lib/webby/helpers.rb +30 -0
- data/lib/webby/helpers/capture_helper.rb +141 -0
- data/lib/webby/helpers/coderay_helper.rb +69 -0
- data/lib/webby/helpers/graphviz_helper.rb +136 -0
- data/lib/webby/helpers/tag_helper.rb +65 -0
- data/lib/webby/helpers/tex_img_helper.rb +133 -0
- data/lib/webby/helpers/ultraviolet_helper.rb +63 -0
- data/lib/webby/helpers/url_helper.rb +241 -0
- data/lib/webby/journal.rb +126 -0
- data/lib/webby/link_validator.rb +160 -0
- data/lib/webby/renderer.rb +390 -0
- data/lib/webby/resources.rb +137 -0
- data/lib/webby/resources/db.rb +251 -0
- data/lib/webby/resources/layout.rb +54 -0
- data/lib/webby/resources/meta_file.rb +211 -0
- data/lib/webby/resources/page.rb +81 -0
- data/lib/webby/resources/partial.rb +85 -0
- data/lib/webby/resources/resource.rb +201 -0
- data/lib/webby/resources/static.rb +36 -0
- data/lib/webby/stelan/mktemp.rb +135 -0
- data/lib/webby/stelan/paginator.rb +165 -0
- data/lib/webby/tasks/build.rake +27 -0
- data/lib/webby/tasks/create.rake +25 -0
- data/lib/webby/tasks/deploy.rake +22 -0
- data/lib/webby/tasks/growl.rake +16 -0
- data/lib/webby/tasks/validate.rake +19 -0
- data/spec/core_ext/hash_spec.rb +47 -0
- data/spec/core_ext/string_spec.rb +110 -0
- data/spec/core_ext/time_spec.rb +19 -0
- data/spec/data/hooligans/bad_meta_data_1.txt +34 -0
- data/spec/data/hooligans/bad_meta_data_2.txt +34 -0
- data/spec/data/html/anchor.html +11 -0
- data/spec/data/html/external.html +10 -0
- data/spec/data/html/invalid-relative.html +10 -0
- data/spec/data/html/relative-anchor.html +10 -0
- data/spec/data/html/relative-invalid-anchor.html +10 -0
- data/spec/data/html/relative.html +10 -0
- data/spec/data/outline/basic.out +81 -0
- data/spec/data/outline/basic.txt +25 -0
- data/spec/data/outline/no_clobber.out +86 -0
- data/spec/data/outline/numbering.out +81 -0
- data/spec/data/outline/numbering_only.out +21 -0
- data/spec/data/outline/toc_range_1.out +66 -0
- data/spec/data/outline/toc_range_2.out +55 -0
- data/spec/data/outline/toc_style.out +81 -0
- data/spec/data/site/Sitefile +9 -0
- data/spec/data/site/content/_partial.txt +10 -0
- data/spec/data/site/content/css/coderay.css +111 -0
- data/spec/data/site/content/css/site.css +67 -0
- data/spec/data/site/content/css/tumblog.css +308 -0
- data/spec/data/site/content/images/tumblog/permalink.gif +0 -0
- data/spec/data/site/content/images/tumblog/rss.gif +0 -0
- data/spec/data/site/content/index.txt +19 -0
- data/spec/data/site/content/photos.txt +21 -0
- data/spec/data/site/content/tumblog/200806/the-noble-chicken/index.txt +12 -0
- data/spec/data/site/content/tumblog/200807/historical-perspectives-on-the-classic-chicken-joke/index.txt +12 -0
- data/spec/data/site/content/tumblog/200807/mad-city-chickens/index.txt +10 -0
- data/spec/data/site/content/tumblog/200807/the-wisdom-of-the-dutch/index.txt +11 -0
- data/spec/data/site/content/tumblog/200807/up-a-tree/index.txt +13 -0
- data/spec/data/site/content/tumblog/index.txt +37 -0
- data/spec/data/site/content/tumblog/rss.txt +37 -0
- data/spec/data/site/layouts/default.txt +58 -0
- data/spec/data/site/layouts/tumblog/default.txt +44 -0
- data/spec/data/site/layouts/tumblog/post.txt +15 -0
- data/spec/data/site/lib/breadcrumbs.rb +28 -0
- data/spec/data/site/lib/tumblog_helper.rb +32 -0
- data/spec/data/site/tasks/tumblog.rake +30 -0
- data/spec/data/site/templates/_partial.erb +10 -0
- data/spec/data/site/templates/atom_feed.erb +40 -0
- data/spec/data/site/templates/page.erb +18 -0
- data/spec/data/site/templates/presentation.erb +40 -0
- data/spec/data/site/templates/tumblog/conversation.erb +12 -0
- data/spec/data/site/templates/tumblog/link.erb +10 -0
- data/spec/data/site/templates/tumblog/photo.erb +13 -0
- data/spec/data/site/templates/tumblog/post.erb +12 -0
- data/spec/data/site/templates/tumblog/quote.erb +11 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +58 -0
- data/spec/webby/apps/generator_spec.rb +117 -0
- data/spec/webby/apps/main_spec.rb +88 -0
- data/spec/webby/filters/basepath_spec.rb +167 -0
- data/spec/webby/filters/maruku_spec.rb +31 -0
- data/spec/webby/filters/outline_spec.rb +92 -0
- data/spec/webby/filters/textile_spec.rb +31 -0
- data/spec/webby/helpers/capture_helper_spec.rb +56 -0
- data/spec/webby/link_validator_spec.rb +154 -0
- data/spec/webby/renderer_spec.rb +139 -0
- data/spec/webby/resources/db_spec.rb +250 -0
- data/spec/webby/resources/layout_spec.rb +83 -0
- data/spec/webby/resources/meta_file_spec.rb +171 -0
- data/spec/webby/resources/page_spec.rb +111 -0
- data/spec/webby/resources/partial_spec.rb +58 -0
- data/spec/webby/resources/resource_spec.rb +219 -0
- data/spec/webby/resources/static_spec.rb +49 -0
- data/spec/webby/resources_spec.rb +69 -0
- data/tasks/mswin32.rake +38 -0
- data/tasks/website.rake +37 -0
- metadata +435 -0
@@ -0,0 +1,250 @@
|
|
1
|
+
|
2
|
+
require File.expand_path(
|
3
|
+
File.join(File.dirname(__FILE__), %w[.. .. spec_helper]))
|
4
|
+
|
5
|
+
# -------------------------------------------------------------------------
|
6
|
+
describe Webby::Resources::DB do
|
7
|
+
|
8
|
+
before :each do
|
9
|
+
layout = Webby::Resources::Layout.
|
10
|
+
new(Webby.datapath %w[site layouts tumblog default.txt])
|
11
|
+
Webby::Resources.stub!(:find_layout).and_return(layout)
|
12
|
+
|
13
|
+
@db = Webby::Resources::DB.new
|
14
|
+
Dir.glob('content/tumblog/**/*').each do |fn|
|
15
|
+
next unless test(?f, fn)
|
16
|
+
@db.add Webby::Resources::Page.new(fn)
|
17
|
+
end
|
18
|
+
@db_hash = @db.instance_variable_get(:@db)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'stores resources by directory' do
|
22
|
+
@db_hash.keys.sort.should == %w[
|
23
|
+
tumblog
|
24
|
+
tumblog/200806/the-noble-chicken
|
25
|
+
tumblog/200807/historical-perspectives-on-the-classic-chicken-joke
|
26
|
+
tumblog/200807/mad-city-chickens
|
27
|
+
tumblog/200807/the-wisdom-of-the-dutch
|
28
|
+
tumblog/200807/up-a-tree
|
29
|
+
]
|
30
|
+
@db_hash['tumblog'].length.should == 2
|
31
|
+
@db_hash['tumblog/200807/up-a-tree'].length.should == 1
|
32
|
+
@db_hash['tumblog/200807/up-a-tree'].first.filename.should == 'index'
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'replaces resources when adding' do
|
36
|
+
ary = @db_hash['tumblog/200806/the-noble-chicken']
|
37
|
+
page = ary.first
|
38
|
+
|
39
|
+
@db.add Webby::Resources::Page.
|
40
|
+
new('content/tumblog/200806/the-noble-chicken/index.txt')
|
41
|
+
|
42
|
+
ary.first.should_not equal(page)
|
43
|
+
ary.first.path.should == page.path
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'clears the stored resources' do
|
47
|
+
@db_hash.should_not be_empty
|
48
|
+
@db.clear
|
49
|
+
@db_hash.should be_empty
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'iterates over the resources in order' do
|
53
|
+
ary = []
|
54
|
+
@db.each {|page| ary << page.url}
|
55
|
+
ary.should == %w[
|
56
|
+
/tumblog
|
57
|
+
/tumblog/rss.xml
|
58
|
+
/tumblog/200806/the-noble-chicken
|
59
|
+
/tumblog/200807/historical-perspectives-on-the-classic-chicken-joke
|
60
|
+
/tumblog/200807/mad-city-chickens
|
61
|
+
/tumblog/200807/the-wisdom-of-the-dutch
|
62
|
+
/tumblog/200807/up-a-tree
|
63
|
+
]
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'returns the parent of a resource' do
|
67
|
+
page = Webby::Resources::Page.new('content/tumblog/index.txt')
|
68
|
+
parent = @db.parent_of(page)
|
69
|
+
(parent == nil).should == true
|
70
|
+
|
71
|
+
page = Webby::Resources::Page.new('content/tumblog/rss.txt')
|
72
|
+
parent = @db.parent_of(page)
|
73
|
+
parent.url.should == '/tumblog'
|
74
|
+
|
75
|
+
page = Webby::Resources::Page.new('content/tumblog/200807/up-a-tree/index.txt')
|
76
|
+
parent = @db.parent_of(page)
|
77
|
+
parent.url.should == '/tumblog'
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'returns the siblings of a resource' do
|
81
|
+
page = Webby::Resources::Page.new('content/tumblog/index.txt')
|
82
|
+
siblings = @db.siblings(page)
|
83
|
+
|
84
|
+
siblings.length.should == 1
|
85
|
+
siblings.first.path.should == 'content/tumblog/rss.txt'
|
86
|
+
|
87
|
+
page = Webby::Resources::Page.new('content/tumblog/200806/the-noble-chicken/index.txt')
|
88
|
+
siblings = @db.siblings(page)
|
89
|
+
siblings.should be_empty
|
90
|
+
end
|
91
|
+
|
92
|
+
# -----------------------------------------------------------------------
|
93
|
+
describe '.children' do
|
94
|
+
it 'returns the children of a resource' do
|
95
|
+
page = Webby::Resources::Page.new('content/tumblog/index.txt')
|
96
|
+
children = @db.children(page)
|
97
|
+
|
98
|
+
children.length.should == 5
|
99
|
+
children.map {|page| page.url}.sort.should == %w[
|
100
|
+
/tumblog/200806/the-noble-chicken
|
101
|
+
/tumblog/200807/historical-perspectives-on-the-classic-chicken-joke
|
102
|
+
/tumblog/200807/mad-city-chickens
|
103
|
+
/tumblog/200807/the-wisdom-of-the-dutch
|
104
|
+
/tumblog/200807/up-a-tree
|
105
|
+
]
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'returns them in the specified sort order' do
|
109
|
+
page = Webby::Resources::Page.new('content/tumblog/index.txt')
|
110
|
+
children = @db.children(page, :sort_by => :url)
|
111
|
+
|
112
|
+
children.length.should == 5
|
113
|
+
children.map {|page| page.url}.should == %w[
|
114
|
+
/tumblog/200806/the-noble-chicken
|
115
|
+
/tumblog/200807/historical-perspectives-on-the-classic-chicken-joke
|
116
|
+
/tumblog/200807/mad-city-chickens
|
117
|
+
/tumblog/200807/the-wisdom-of-the-dutch
|
118
|
+
/tumblog/200807/up-a-tree
|
119
|
+
]
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'returns them in the reversed sort order' do
|
123
|
+
page = Webby::Resources::Page.new('content/tumblog/index.txt')
|
124
|
+
children = @db.children(page, :sort_by => :url, :reverse => true)
|
125
|
+
|
126
|
+
children.length.should == 5
|
127
|
+
children.map {|page| page.url}.should == %w[
|
128
|
+
/tumblog/200806/the-noble-chicken
|
129
|
+
/tumblog/200807/historical-perspectives-on-the-classic-chicken-joke
|
130
|
+
/tumblog/200807/mad-city-chickens
|
131
|
+
/tumblog/200807/the-wisdom-of-the-dutch
|
132
|
+
/tumblog/200807/up-a-tree
|
133
|
+
].reverse
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
# -----------------------------------------------------------------------
|
138
|
+
describe '.find' do
|
139
|
+
it 'returns the first page if no options are given' do
|
140
|
+
page = @db.each {|p| break p}
|
141
|
+
@db.find.path.should == page.path
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'returns all pages' do
|
145
|
+
ary = []
|
146
|
+
@db.each {|p| ary << p.path}
|
147
|
+
|
148
|
+
pages = @db.find(:all)
|
149
|
+
pages.map! {|p| p.path}
|
150
|
+
pages.should == ary
|
151
|
+
|
152
|
+
pages = @db.find(:limit => :all)
|
153
|
+
pages.map! {|p| p.path}
|
154
|
+
pages.should == ary
|
155
|
+
|
156
|
+
pages = @db.find('all')
|
157
|
+
pages.map! {|p| p.path}
|
158
|
+
pages.should == ary
|
159
|
+
end
|
160
|
+
|
161
|
+
it 'returns a limited number of pages' do
|
162
|
+
ary = []
|
163
|
+
@db.each {|p| ary << p.path}
|
164
|
+
ary = ary.slice(0,3)
|
165
|
+
|
166
|
+
pages = @db.find(3)
|
167
|
+
pages.map! {|p| p.path}
|
168
|
+
pages.should == ary
|
169
|
+
|
170
|
+
pages = @db.find(:limit => 3)
|
171
|
+
pages.map! {|p| p.path}
|
172
|
+
pages.should == ary
|
173
|
+
end
|
174
|
+
|
175
|
+
it 'can sorty by a given meta-data field' do
|
176
|
+
pages = @db.find(:all, :sort_by => 'title')
|
177
|
+
pages.map! {|p| p.title}
|
178
|
+
pages.should == [
|
179
|
+
'A Mother Clucker',
|
180
|
+
'A Mother Clucker',
|
181
|
+
'Historical Perspectives on the Classic Chicken Joke',
|
182
|
+
'Mad City Chickens',
|
183
|
+
'The Noble Chicken',
|
184
|
+
'The Wisdom of the Dutch',
|
185
|
+
'Up a Tree'
|
186
|
+
]
|
187
|
+
|
188
|
+
pages = @db.find(:all, :sort_by => 'tumblog_type')
|
189
|
+
pages.map! {|p| p.tumblog_type}
|
190
|
+
pages.should == %w[conversation link photo quote regular]
|
191
|
+
end
|
192
|
+
|
193
|
+
it 'can reverse the sort order' do
|
194
|
+
pages = @db.find(:all, :sort_by => 'tumblog_type', :reverse => true)
|
195
|
+
pages.map! {|p| p.tumblog_type}
|
196
|
+
pages.should == %w[conversation link photo quote regular].reverse
|
197
|
+
|
198
|
+
pages = @db.find(3, :sort_by => 'tumblog_type', :reverse => true)
|
199
|
+
pages.map! {|p| p.tumblog_type}
|
200
|
+
pages.should == %w[regular quote photo]
|
201
|
+
end
|
202
|
+
|
203
|
+
it 'can search is a specific directory' do
|
204
|
+
pages = @db.find('all', :in_directory => 'tumblog')
|
205
|
+
pages.map! {|p| p.path}
|
206
|
+
pages.should == %w[
|
207
|
+
content/tumblog/index.txt
|
208
|
+
content/tumblog/rss.txt
|
209
|
+
]
|
210
|
+
end
|
211
|
+
|
212
|
+
it 'can recurse into directories' do
|
213
|
+
pages = @db.find('all', :in_directory => 'tumblog/200807', :recursive => true)
|
214
|
+
pages.map! {|p| p.title}
|
215
|
+
pages.should == [
|
216
|
+
'The Wisdom of the Dutch',
|
217
|
+
'Mad City Chickens',
|
218
|
+
'Historical Perspectives on the Classic Chicken Joke',
|
219
|
+
'Up a Tree'
|
220
|
+
]
|
221
|
+
end
|
222
|
+
|
223
|
+
it 'can combine all these options' do
|
224
|
+
pages = @db.find(:limit => 2,
|
225
|
+
:in_directory => 'tumblog/200807', :recursive => true,
|
226
|
+
:sort_by => 'title', :reverse => true,
|
227
|
+
:author => 'Tim Pease')
|
228
|
+
pages.map! {|p| p.title}
|
229
|
+
pages.should == [
|
230
|
+
'Up a Tree',
|
231
|
+
'Mad City Chickens'
|
232
|
+
]
|
233
|
+
end
|
234
|
+
|
235
|
+
it 'can find pages using a user supplied search block' do
|
236
|
+
pages = @db.find(:all, :sort_by => 'title') do |page|
|
237
|
+
%w[quote conversation photo].include? page.tumblog_type
|
238
|
+
end
|
239
|
+
pages.map! {|p| p.title}
|
240
|
+
pages.should == [
|
241
|
+
'Historical Perspectives on the Classic Chicken Joke',
|
242
|
+
'The Wisdom of the Dutch',
|
243
|
+
'Up a Tree'
|
244
|
+
]
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
end # describe Webby::Resources::DB
|
249
|
+
|
250
|
+
# EOF
|
@@ -0,0 +1,83 @@
|
|
1
|
+
|
2
|
+
require File.expand_path(
|
3
|
+
File.join(File.dirname(__FILE__), %w[.. .. spec_helper]))
|
4
|
+
|
5
|
+
# -------------------------------------------------------------------------
|
6
|
+
describe Webby::Resources::Layout do
|
7
|
+
before :each do
|
8
|
+
layout = Webby::Resources::Layout.
|
9
|
+
new(Webby.datapath %w[site layouts tumblog default.txt])
|
10
|
+
Webby::Resources.stub!(:find_layout).and_return(layout)
|
11
|
+
|
12
|
+
@default = File.join %w[layouts tumblog default.txt]
|
13
|
+
@post = File.join %w[layouts tumblog post.txt]
|
14
|
+
@layout = Webby::Resources::Layout.new(@default)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'parses meta-data on initialization' do
|
18
|
+
h = @layout._meta_data
|
19
|
+
|
20
|
+
h.should_not be_empty
|
21
|
+
h.should == {
|
22
|
+
'extension' => 'html',
|
23
|
+
'filter' => 'erb'
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'uses the cairn file as the destination' do
|
28
|
+
@layout.destination.should == ::Webby.cairn
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'always returns nil as the url' do
|
32
|
+
@layout.url.should be_nil
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'reads the contents of the file' do
|
36
|
+
layout = Webby::Resources::Layout.new(@post)
|
37
|
+
str = layout._read
|
38
|
+
str.split($/).first.should == '<div class="post">'
|
39
|
+
end
|
40
|
+
|
41
|
+
# -----------------------------------------------------------------------
|
42
|
+
describe '.extension' do
|
43
|
+
it 'uses the extension from the meta-data if present' do
|
44
|
+
@layout.extension.should == 'html'
|
45
|
+
end
|
46
|
+
|
47
|
+
it "returns nil if no extension is found in the meta-data" do
|
48
|
+
@layout._meta_data.delete('extension')
|
49
|
+
@layout.extension.should be_nil
|
50
|
+
end
|
51
|
+
|
52
|
+
it "uses the parent layout's extension if a parent layout is present" do
|
53
|
+
layout = Webby::Resources::Layout.new(@post)
|
54
|
+
layout.extension.should == 'html'
|
55
|
+
|
56
|
+
layout._meta_data.delete('layout')
|
57
|
+
layout.extension.should be_nil
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# -----------------------------------------------------------------------
|
62
|
+
describe '.dirty?' do
|
63
|
+
it 'overrides the dirty state based on the meta-data value' do
|
64
|
+
@layout['dirty'] = true
|
65
|
+
@layout.dirty?.should == true
|
66
|
+
|
67
|
+
@layout['dirty'] = false
|
68
|
+
@layout.dirty?.should == false
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'returns true if the output file is missing' do
|
72
|
+
@layout.dirty?.should == true
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'returns false if the cairn file is present' do
|
76
|
+
FileUtils.touch Webby.cairn
|
77
|
+
@layout.dirty?.should == false
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
end # describe Webby::Resources::Layout
|
82
|
+
|
83
|
+
# EOF
|
@@ -0,0 +1,171 @@
|
|
1
|
+
|
2
|
+
require File.expand_path(
|
3
|
+
File.join(File.dirname(__FILE__), %w[.. .. spec_helper]))
|
4
|
+
|
5
|
+
# -------------------------------------------------------------------------
|
6
|
+
describe Webby::Resources::MetaFile do
|
7
|
+
|
8
|
+
it 'raises an error when created without an IO object' do
|
9
|
+
lambda {Webby::Resources::MetaFile.new('string')}.should raise_error(
|
10
|
+
ArgumentError, 'expecting an IO stream')
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'returns the number of meta-data blocks at the top of a file' do
|
14
|
+
fn = Webby.datapath %w[site content css coderay.css]
|
15
|
+
File.open(fn, 'r') do |fd|
|
16
|
+
mf = Webby::Resources::MetaFile.new(fd)
|
17
|
+
mf.meta_count.should == 0
|
18
|
+
end
|
19
|
+
|
20
|
+
fn = Webby.datapath %w[site content index.txt]
|
21
|
+
File.open(fn, 'r') do |fd|
|
22
|
+
mf = Webby::Resources::MetaFile.new(fd)
|
23
|
+
mf.meta_count.should == 1
|
24
|
+
end
|
25
|
+
|
26
|
+
fn = Webby.datapath %w[site content photos.txt]
|
27
|
+
File.open(fn, 'r') do |fd|
|
28
|
+
mf = Webby::Resources::MetaFile.new(fd)
|
29
|
+
mf.meta_count.should == 3
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'determines the end of the final meta-data block' do
|
34
|
+
fn = Webby.datapath %w[site content index.txt]
|
35
|
+
File.open(fn, 'r') do |fd|
|
36
|
+
mf = Webby::Resources::MetaFile.new(fd)
|
37
|
+
mf.meta_end.should == 7
|
38
|
+
end
|
39
|
+
|
40
|
+
fn = Webby.datapath %w[site content photos.txt]
|
41
|
+
File.open(fn, 'r') do |fd|
|
42
|
+
mf = Webby::Resources::MetaFile.new(fd)
|
43
|
+
mf.meta_end.should == 18
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# -----------------------------------------------------------------------
|
48
|
+
describe '.each' do
|
49
|
+
it 'yields each meta-data block' do
|
50
|
+
fn = Webby.datapath %w[site content photos.txt]
|
51
|
+
output = []
|
52
|
+
File.open(fn, 'r') do |fd|
|
53
|
+
mf = Webby::Resources::MetaFile.new(fd)
|
54
|
+
mf.each {|h| output << h}
|
55
|
+
end
|
56
|
+
output.length.should == 3
|
57
|
+
output.map {|h| h['title']}.should == [
|
58
|
+
'First Photo',
|
59
|
+
'Second Photo',
|
60
|
+
'Third Photo'
|
61
|
+
]
|
62
|
+
output.map {|h| h['directory']}.should == ['photos']*3
|
63
|
+
output.map {|h| h['filename']}.should == %w[image1 image2 image3]
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'yields a single meta-data block' do
|
68
|
+
fn = Webby.datapath %w[site content index.txt]
|
69
|
+
output = []
|
70
|
+
File.open(fn, 'r') do |fd|
|
71
|
+
mf = Webby::Resources::MetaFile.new(fd)
|
72
|
+
mf.each {|h| output << h}
|
73
|
+
end
|
74
|
+
output.length.should == 1
|
75
|
+
h = output.first
|
76
|
+
h['title'].should == 'Home Page'
|
77
|
+
h['filter'].should == %w[erb textile]
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'raises an error if the meta-data is not a hash' do
|
81
|
+
fn = Webby.datapath %w[hooligans bad_meta_data_1.txt]
|
82
|
+
output = []
|
83
|
+
File.open(fn, 'r') do |fd|
|
84
|
+
mf = Webby::Resources::MetaFile.new(fd)
|
85
|
+
lambda {
|
86
|
+
mf.each {|h| output << h}
|
87
|
+
}.should raise_error(Webby::Resources::MetaFile::Error)
|
88
|
+
end
|
89
|
+
output.length.should == 1
|
90
|
+
end
|
91
|
+
|
92
|
+
it "really doesn't like YAML syntax errors" do
|
93
|
+
fn = Webby.datapath %w[hooligans bad_meta_data_2.txt]
|
94
|
+
output = []
|
95
|
+
File.open(fn, 'r') do |fd|
|
96
|
+
mf = Webby::Resources::MetaFile.new(fd)
|
97
|
+
lambda {
|
98
|
+
mf.each {|h| output << h}
|
99
|
+
}.should raise_error(Webby::Resources::MetaFile::Error)
|
100
|
+
end
|
101
|
+
output.length.should == 1
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
# -----------------------------------------------------------------------
|
106
|
+
describe '#meta_data' do
|
107
|
+
it 'returns nil for regular files' do
|
108
|
+
fn = Webby.datapath %w[site content css coderay.css]
|
109
|
+
Webby::Resources::MetaFile.meta_data(fn).should be_nil
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'returns a hash for pages' do
|
113
|
+
fn = Webby.datapath %w[site content index.txt]
|
114
|
+
h = Webby::Resources::MetaFile.meta_data(fn)
|
115
|
+
|
116
|
+
h.should be_instance_of(Hash)
|
117
|
+
h['created_at'].should be_instance_of(Time)
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'returns a hash for layouts' do
|
121
|
+
fn = Webby.datapath %w[site layouts default.txt]
|
122
|
+
h = Webby::Resources::MetaFile.meta_data(fn)
|
123
|
+
|
124
|
+
h.should be_instance_of(Hash)
|
125
|
+
h.should == {
|
126
|
+
'extension' => 'html',
|
127
|
+
'filter' => 'erb'
|
128
|
+
}
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
# -----------------------------------------------------------------------
|
133
|
+
describe "#meta_data?" do
|
134
|
+
it 'returns true for files with meta-data' do
|
135
|
+
fn = Webby.datapath %w[site content index.txt]
|
136
|
+
Webby::Resources::MetaFile.meta_data?(fn).should == true
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'returns false for files without meta-data' do
|
140
|
+
fn = Webby.datapath %w[site content css coderay.css]
|
141
|
+
Webby::Resources::MetaFile.meta_data?(fn).should == false
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
# -----------------------------------------------------------------------
|
146
|
+
describe "#read" do
|
147
|
+
it 'behaves the same as File#read for regular files' do
|
148
|
+
fn = Webby.datapath %w[site content css coderay.css]
|
149
|
+
Webby::Resources::MetaFile.read(fn).should == ::File.read(fn)
|
150
|
+
end
|
151
|
+
|
152
|
+
it 'returns only the content for pages' do
|
153
|
+
fn = Webby.datapath %w[site content index.txt]
|
154
|
+
lines = File.readlines(fn)
|
155
|
+
lines = lines[7..-1].join
|
156
|
+
|
157
|
+
Webby::Resources::MetaFile.read(fn).should == lines
|
158
|
+
end
|
159
|
+
|
160
|
+
it 'returns only the content for layouts' do
|
161
|
+
fn = Webby.datapath %w[site layouts default.txt]
|
162
|
+
lines = File.readlines(fn)
|
163
|
+
lines = lines[4..-1].join
|
164
|
+
|
165
|
+
Webby::Resources::MetaFile.read(fn).should == lines
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
end # describe Webby::Resources::MetaFile
|
170
|
+
|
171
|
+
# EOF
|