TwP-webby 0.9.0 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +11 -0
- data/Manifest.txt +45 -2
- data/Rakefile +1 -2
- data/examples/webby/content/css/site.css +1 -1
- data/examples/webby/content/learn/index.txt +1 -1
- data/examples/webby/content/release-notes/index.txt +21 -0
- data/examples/webby/content/release-notes/rel-0-9-0/index.txt +1 -0
- data/examples/webby/content/release-notes/rel-0-9-1/index.txt +93 -0
- data/examples/webby/content/tips_and_tricks/index.txt +14 -13
- data/examples/webby/content/tutorial/index.txt +13 -9
- data/examples/webby/content/user-manual/index.txt +8 -8
- data/examples/webby/layouts/default.txt +1 -1
- data/lib/webby/apps/main.rb +25 -13
- data/lib/webby/auto_builder.rb +2 -0
- data/lib/webby/builder.rb +2 -5
- data/lib/webby/filters.rb +5 -13
- data/lib/webby/renderer.rb +7 -5
- data/lib/webby/resources/db.rb +4 -4
- data/lib/webby/resources/layout.rb +14 -23
- data/lib/webby/resources/meta_file.rb +208 -0
- data/lib/webby/resources/page.rb +21 -58
- data/lib/webby/resources/partial.rb +10 -4
- data/lib/webby/resources/resource.rb +68 -27
- data/lib/webby/resources/static.rb +6 -22
- data/lib/webby/resources.rb +54 -14
- data/lib/webby/stelan/paginator.rb +17 -2
- data/lib/webby.rb +2 -1
- data/spec/data/Sitefile +9 -0
- data/spec/data/content/_partial.txt +10 -0
- data/spec/data/content/css/coderay.css +111 -0
- data/spec/data/content/css/site.css +67 -0
- data/spec/data/content/css/tumblog.css +308 -0
- data/spec/data/content/images/tumblog/permalink.gif +0 -0
- data/spec/data/content/images/tumblog/rss.gif +0 -0
- data/spec/data/content/index.txt +19 -0
- data/spec/data/content/photos.txt +21 -0
- data/spec/data/content/tumblog/200806/the-noble-chicken/index.txt +12 -0
- data/spec/data/content/tumblog/200807/historical-perspectives-on-the-classic-chicken-joke/index.txt +12 -0
- data/spec/data/content/tumblog/200807/mad-city-chickens/index.txt +10 -0
- data/spec/data/content/tumblog/200807/the-wisdom-of-the-dutch/index.txt +11 -0
- data/spec/data/content/tumblog/200807/up-a-tree/index.txt +13 -0
- data/spec/data/content/tumblog/index.txt +37 -0
- data/spec/data/content/tumblog/rss.txt +37 -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/layouts/default.txt +58 -0
- data/spec/data/layouts/tumblog/default.txt +44 -0
- data/spec/data/layouts/tumblog/post.txt +15 -0
- data/spec/data/lib/breadcrumbs.rb +28 -0
- data/spec/data/lib/tumblog_helper.rb +32 -0
- data/spec/data/tasks/tumblog.rake +30 -0
- data/spec/data/templates/_partial.erb +10 -0
- data/spec/data/templates/atom_feed.erb +40 -0
- data/spec/data/templates/page.erb +18 -0
- data/spec/data/templates/presentation.erb +40 -0
- data/spec/data/templates/tumblog/conversation.erb +12 -0
- data/spec/data/templates/tumblog/link.erb +10 -0
- data/spec/data/templates/tumblog/photo.erb +13 -0
- data/spec/data/templates/tumblog/post.erb +12 -0
- data/spec/data/templates/tumblog/quote.erb +11 -0
- data/spec/spec_helper.rb +37 -0
- data/spec/webby/apps/generator_spec.rb +4 -0
- data/spec/webby/apps/main_spec.rb +16 -3
- data/spec/webby/filters/textile_spec.rb +20 -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 +157 -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 +214 -0
- data/spec/webby/resources/static_spec.rb +49 -0
- data/spec/webby/resources_spec.rb +55 -3
- data/tasks/rubyforge.rake +1 -1
- metadata +64 -6
- data/lib/webby/resources/file.rb +0 -221
- data/spec/webby/resources/file_spec.rb +0 -104
data/spec/spec_helper.rb
CHANGED
@@ -5,10 +5,47 @@ WEBBY_SPEC_HELPER = true
|
|
5
5
|
|
6
6
|
require 'rubygems'
|
7
7
|
require 'fileutils'
|
8
|
+
require 'stringio'
|
8
9
|
|
9
10
|
require File.expand_path(
|
10
11
|
File.join(File.dirname(__FILE__), %w[.. lib webby]))
|
11
12
|
|
13
|
+
Spec::Runner.configure do |config|
|
14
|
+
config.before :all do
|
15
|
+
@pwd = Dir.pwd
|
16
|
+
Dir.chdir Webby.datapath
|
17
|
+
FileUtils.mkdir_p Webby.datapath(::Webby.site.output_dir)
|
18
|
+
end
|
19
|
+
|
20
|
+
config.after :all do
|
21
|
+
FileUtils.rm_rf(Webby.datapath(::Webby.cairn))
|
22
|
+
FileUtils.rm_rf(Dir.glob(Webby.datapath %w[output *]))
|
23
|
+
Dir.chdir @pwd
|
24
|
+
end
|
25
|
+
|
26
|
+
# == Mock Framework
|
27
|
+
#
|
28
|
+
# RSpec uses it's own mocking framework by default. If you prefer to
|
29
|
+
# use mocha, flexmock or RR, uncomment the appropriate line:
|
30
|
+
#
|
31
|
+
# config.mock_with :mocha
|
32
|
+
# config.mock_with :flexmock
|
33
|
+
# config.mock_with :rr
|
34
|
+
end
|
35
|
+
|
36
|
+
module Webby
|
37
|
+
DATAPATH = ::Webby.path(%w[spec data])
|
38
|
+
def self.datapath( *args )
|
39
|
+
args.empty? ? DATAPATH : ::File.join(DATAPATH, args.flatten)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
$webby_log_output = StringIO.new
|
44
|
+
|
45
|
+
logger = Logging::Logger['Webby']
|
46
|
+
logger.clear_appenders
|
47
|
+
logger.add_appenders(Logging::Appenders::IO.new('stringio', $webby_log_output))
|
48
|
+
|
12
49
|
end # unless defined?
|
13
50
|
|
14
51
|
# EOF
|
@@ -93,6 +93,10 @@ describe Webby::Apps::Generator do
|
|
93
93
|
end
|
94
94
|
|
95
95
|
it "should exit if a site is not specified" do
|
96
|
+
# we need to force an error by changing directories back to the top
|
97
|
+
# level so we no longer have a Sitefile in the current directory
|
98
|
+
Dir.chdir @pwd
|
99
|
+
|
96
100
|
lambda{@generator.parse %w[website]}.
|
97
101
|
should raise_error(SystemExit, 'exit')
|
98
102
|
@strio.to_s.split("\n").first.
|
@@ -55,11 +55,24 @@ describe Webby::Apps::Main do
|
|
55
55
|
args.page.should == "foo/bar/10-percent-inspiration-and-90-percent-perspiration"
|
56
56
|
end
|
57
57
|
|
58
|
-
# TODO: Is this desired behavior?
|
59
58
|
it "should set the title by joining the raw args, getting the basename, and titlecasing" do
|
60
|
-
page = "foo/bar/this
|
59
|
+
page = "foo/bar/this is a page.txt"
|
60
|
+
args = @main.capture_command_line_args([page])
|
61
|
+
args.title.should == "This Is a Page"
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should preserve any page extensions" do
|
65
|
+
page = "foo/bar/this is a page.txt"
|
66
|
+
args = @main.capture_command_line_args([page])
|
67
|
+
args.page.should == "foo/bar/this-is-a-page.txt"
|
68
|
+
|
69
|
+
page = "This is another page.haml"
|
70
|
+
args = @main.capture_command_line_args([page])
|
71
|
+
args.page.should == "this-is-another-page.haml"
|
72
|
+
|
73
|
+
page = "one/more/for the road"
|
61
74
|
args = @main.capture_command_line_args([page])
|
62
|
-
args.
|
75
|
+
args.page.should == "one/more/for-the-road"
|
63
76
|
end
|
64
77
|
end
|
65
78
|
|
@@ -0,0 +1,20 @@
|
|
1
|
+
|
2
|
+
require ::File.expand_path(
|
3
|
+
::File.join(::File.dirname(__FILE__), %w[.. .. spec_helper]))
|
4
|
+
|
5
|
+
# ---------------------------------------------------------------------------
|
6
|
+
describe 'Webby::Filters::Textile' do
|
7
|
+
|
8
|
+
it 'should regsiter the textile filter handler' do
|
9
|
+
Webby::Filters._handlers['textile'].should_not be_nil
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'processes textile markup into HTML' do
|
13
|
+
input = "p(foo). this is a paragraph of text"
|
14
|
+
output = Webby::Filters._handlers['textile'].call(input)
|
15
|
+
|
16
|
+
output.should == %q{<p class="foo">this is a paragraph of text</p>}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# EOF
|
@@ -0,0 +1,139 @@
|
|
1
|
+
|
2
|
+
require File.expand_path(
|
3
|
+
File.join(File.dirname(__FILE__), %w[.. spec_helper]))
|
4
|
+
|
5
|
+
# ---------------------------------------------------------------------------
|
6
|
+
describe Webby::Renderer do
|
7
|
+
before :each do
|
8
|
+
layout = Webby::Resources::Layout.
|
9
|
+
new(Webby.datapath %w[layouts tumblog default.txt])
|
10
|
+
Webby::Resources.stub!(:find_layout).and_return(layout)
|
11
|
+
|
12
|
+
@filename = File.join %w[content tumblog index.txt]
|
13
|
+
@page = Webby::Resources::Page.new(@filename)
|
14
|
+
@renderer = Webby::Renderer.new(@page)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'needs some more specs'
|
18
|
+
|
19
|
+
# -------------------------------------------------------------------------
|
20
|
+
describe 'when paginating' do
|
21
|
+
after :each do
|
22
|
+
::Webby.site.create_mode = 'page'
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'paginates a set of items' do
|
26
|
+
items = %w[one two three four five six seven eight]
|
27
|
+
output = []
|
28
|
+
|
29
|
+
@renderer.instance_variable_get(:@pager).should be_nil
|
30
|
+
|
31
|
+
# the first page of items
|
32
|
+
@renderer.paginate(items, 3) {|item| output << item}
|
33
|
+
pager = @renderer.instance_variable_get(:@pager)
|
34
|
+
|
35
|
+
pager.should_not be_nil
|
36
|
+
pager.number_of_pages.should == 3
|
37
|
+
pager.prev?.should == false
|
38
|
+
pager.next?.should == true
|
39
|
+
|
40
|
+
output.should == %w[one two three]
|
41
|
+
@page.destination.should == 'output/tumblog/index.html'
|
42
|
+
|
43
|
+
# go to the next page of items
|
44
|
+
@renderer._next_page.should == true
|
45
|
+
output.should == %w[one two three]
|
46
|
+
|
47
|
+
pager = @renderer.instance_variable_get(:@pager)
|
48
|
+
pager.should_not be_nil
|
49
|
+
pager.number_of_pages.should == 3
|
50
|
+
pager.prev?.should == true
|
51
|
+
pager.next?.should == true
|
52
|
+
|
53
|
+
@page.destination.should == 'output/tumblog/index2.html'
|
54
|
+
|
55
|
+
@renderer.paginate(items, 3) {|item| output << item}
|
56
|
+
output.should == %w[one two three four five six]
|
57
|
+
|
58
|
+
# go to the last page of items
|
59
|
+
@renderer._next_page.should == true
|
60
|
+
output.should == %w[one two three four five six]
|
61
|
+
|
62
|
+
pager = @renderer.instance_variable_get(:@pager)
|
63
|
+
pager.should_not be_nil
|
64
|
+
pager.number_of_pages.should == 3
|
65
|
+
pager.prev?.should == true
|
66
|
+
pager.next?.should == false
|
67
|
+
|
68
|
+
@page.destination.should == 'output/tumblog/index3.html'
|
69
|
+
|
70
|
+
@renderer.paginate(items, 3) {|item| output << item}
|
71
|
+
output.should == %w[one two three four five six seven eight]
|
72
|
+
|
73
|
+
# after the last page
|
74
|
+
@renderer._next_page.should == false
|
75
|
+
pager = @renderer.instance_variable_get(:@pager)
|
76
|
+
pager.should be_nil
|
77
|
+
@page.destination.should == 'output/tumblog/index.html'
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'obeys the create_mode of the site' do
|
81
|
+
::Webby.site.create_mode = 'directory'
|
82
|
+
items = %w[one two three four five six seven eight]
|
83
|
+
output = []
|
84
|
+
|
85
|
+
@renderer.instance_variable_get(:@pager).should be_nil
|
86
|
+
|
87
|
+
# the first page of items
|
88
|
+
@renderer.paginate(items, 3) {|item| output << item}
|
89
|
+
pager = @renderer.instance_variable_get(:@pager)
|
90
|
+
|
91
|
+
pager.should_not be_nil
|
92
|
+
pager.number_of_pages.should == 3
|
93
|
+
pager.prev?.should == false
|
94
|
+
pager.next?.should == true
|
95
|
+
|
96
|
+
output.should == %w[one two three]
|
97
|
+
@page.destination.should == 'output/tumblog/index.html'
|
98
|
+
|
99
|
+
# go to the next page of items
|
100
|
+
@renderer._next_page.should == true
|
101
|
+
output.should == %w[one two three]
|
102
|
+
|
103
|
+
pager = @renderer.instance_variable_get(:@pager)
|
104
|
+
pager.should_not be_nil
|
105
|
+
pager.number_of_pages.should == 3
|
106
|
+
pager.prev?.should == true
|
107
|
+
pager.next?.should == true
|
108
|
+
|
109
|
+
@page.destination.should == 'output/tumblog/2/index.html'
|
110
|
+
|
111
|
+
@renderer.paginate(items, 3) {|item| output << item}
|
112
|
+
output.should == %w[one two three four five six]
|
113
|
+
|
114
|
+
# go to the last page of items
|
115
|
+
@renderer._next_page.should == true
|
116
|
+
output.should == %w[one two three four five six]
|
117
|
+
|
118
|
+
pager = @renderer.instance_variable_get(:@pager)
|
119
|
+
pager.should_not be_nil
|
120
|
+
pager.number_of_pages.should == 3
|
121
|
+
pager.prev?.should == true
|
122
|
+
pager.next?.should == false
|
123
|
+
|
124
|
+
@page.destination.should == 'output/tumblog/3/index.html'
|
125
|
+
|
126
|
+
@renderer.paginate(items, 3) {|item| output << item}
|
127
|
+
output.should == %w[one two three four five six seven eight]
|
128
|
+
|
129
|
+
# after the last page
|
130
|
+
@renderer._next_page.should == false
|
131
|
+
pager = @renderer.instance_variable_get(:@pager)
|
132
|
+
pager.should be_nil
|
133
|
+
@page.destination.should == 'output/tumblog/index.html'
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
end # describe Webby::Renderer
|
138
|
+
|
139
|
+
# EOF
|
@@ -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[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[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
|