webby 0.9.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. data/History.txt +11 -0
  2. data/Manifest.txt +45 -2
  3. data/Rakefile +1 -2
  4. data/examples/webby/content/css/site.css +1 -1
  5. data/examples/webby/content/learn/index.txt +1 -1
  6. data/examples/webby/content/release-notes/index.txt +21 -0
  7. data/examples/webby/content/release-notes/rel-0-9-0/index.txt +1 -0
  8. data/examples/webby/content/release-notes/rel-0-9-1/index.txt +93 -0
  9. data/examples/webby/content/tips_and_tricks/index.txt +14 -13
  10. data/examples/webby/content/tutorial/index.txt +13 -9
  11. data/examples/webby/content/user-manual/index.txt +8 -8
  12. data/examples/webby/layouts/default.txt +1 -1
  13. data/lib/webby.rb +2 -1
  14. data/lib/webby/apps/main.rb +25 -13
  15. data/lib/webby/auto_builder.rb +2 -0
  16. data/lib/webby/builder.rb +2 -5
  17. data/lib/webby/filters.rb +5 -13
  18. data/lib/webby/renderer.rb +7 -5
  19. data/lib/webby/resources.rb +54 -14
  20. data/lib/webby/resources/db.rb +4 -4
  21. data/lib/webby/resources/layout.rb +14 -23
  22. data/lib/webby/resources/meta_file.rb +208 -0
  23. data/lib/webby/resources/page.rb +21 -58
  24. data/lib/webby/resources/partial.rb +10 -4
  25. data/lib/webby/resources/resource.rb +68 -27
  26. data/lib/webby/resources/static.rb +6 -22
  27. data/lib/webby/stelan/paginator.rb +17 -2
  28. data/spec/data/Sitefile +9 -0
  29. data/spec/data/content/_partial.txt +10 -0
  30. data/spec/data/content/css/coderay.css +111 -0
  31. data/spec/data/content/css/site.css +67 -0
  32. data/spec/data/content/css/tumblog.css +308 -0
  33. data/spec/data/content/images/tumblog/permalink.gif +0 -0
  34. data/spec/data/content/images/tumblog/rss.gif +0 -0
  35. data/spec/data/content/index.txt +19 -0
  36. data/spec/data/content/photos.txt +21 -0
  37. data/spec/data/content/tumblog/200806/the-noble-chicken/index.txt +12 -0
  38. data/spec/data/content/tumblog/200807/historical-perspectives-on-the-classic-chicken-joke/index.txt +12 -0
  39. data/spec/data/content/tumblog/200807/mad-city-chickens/index.txt +10 -0
  40. data/spec/data/content/tumblog/200807/the-wisdom-of-the-dutch/index.txt +11 -0
  41. data/spec/data/content/tumblog/200807/up-a-tree/index.txt +13 -0
  42. data/spec/data/content/tumblog/index.txt +37 -0
  43. data/spec/data/content/tumblog/rss.txt +37 -0
  44. data/spec/data/hooligans/bad_meta_data_1.txt +34 -0
  45. data/spec/data/hooligans/bad_meta_data_2.txt +34 -0
  46. data/spec/data/layouts/default.txt +58 -0
  47. data/spec/data/layouts/tumblog/default.txt +44 -0
  48. data/spec/data/layouts/tumblog/post.txt +15 -0
  49. data/spec/data/lib/breadcrumbs.rb +28 -0
  50. data/spec/data/lib/tumblog_helper.rb +32 -0
  51. data/spec/data/tasks/tumblog.rake +30 -0
  52. data/spec/data/templates/_partial.erb +10 -0
  53. data/spec/data/templates/atom_feed.erb +40 -0
  54. data/spec/data/templates/page.erb +18 -0
  55. data/spec/data/templates/presentation.erb +40 -0
  56. data/spec/data/templates/tumblog/conversation.erb +12 -0
  57. data/spec/data/templates/tumblog/link.erb +10 -0
  58. data/spec/data/templates/tumblog/photo.erb +13 -0
  59. data/spec/data/templates/tumblog/post.erb +12 -0
  60. data/spec/data/templates/tumblog/quote.erb +11 -0
  61. data/spec/spec_helper.rb +37 -0
  62. data/spec/webby/apps/generator_spec.rb +4 -0
  63. data/spec/webby/apps/main_spec.rb +16 -3
  64. data/spec/webby/filters/textile_spec.rb +20 -0
  65. data/spec/webby/renderer_spec.rb +139 -0
  66. data/spec/webby/resources/db_spec.rb +250 -0
  67. data/spec/webby/resources/layout_spec.rb +83 -0
  68. data/spec/webby/resources/meta_file_spec.rb +157 -0
  69. data/spec/webby/resources/page_spec.rb +111 -0
  70. data/spec/webby/resources/partial_spec.rb +58 -0
  71. data/spec/webby/resources/resource_spec.rb +214 -0
  72. data/spec/webby/resources/static_spec.rb +49 -0
  73. data/spec/webby/resources_spec.rb +55 -3
  74. metadata +64 -6
  75. data/lib/webby/resources/file.rb +0 -221
  76. data/spec/webby/resources/file_spec.rb +0 -104
@@ -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
@@ -0,0 +1,157 @@
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[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[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[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
+ # -----------------------------------------------------------------------
34
+ describe '.each' do
35
+ it 'yields each meta-data block' do
36
+ fn = Webby.datapath %w[content photos.txt]
37
+ output = []
38
+ File.open(fn, 'r') do |fd|
39
+ mf = Webby::Resources::MetaFile.new(fd)
40
+ mf.each {|h| output << h}
41
+ end
42
+ output.length.should == 3
43
+ output.map {|h| h['title']}.should == [
44
+ 'First Photo',
45
+ 'Second Photo',
46
+ 'Third Photo'
47
+ ]
48
+ output.map {|h| h['directory']}.should == ['photos']*3
49
+ output.map {|h| h['filename']}.should == %w[image1 image2 image3]
50
+
51
+ end
52
+
53
+ it 'yields a single meta-data block' do
54
+ fn = Webby.datapath %w[content index.txt]
55
+ output = []
56
+ File.open(fn, 'r') do |fd|
57
+ mf = Webby::Resources::MetaFile.new(fd)
58
+ mf.each {|h| output << h}
59
+ end
60
+ output.length.should == 1
61
+ h = output.first
62
+ h['title'].should == 'Home Page'
63
+ h['filter'].should == %w[erb textile]
64
+ end
65
+
66
+ it 'raises an error if the meta-data is not a hash' do
67
+ fn = Webby.datapath %w[hooligans bad_meta_data_1.txt]
68
+ output = []
69
+ File.open(fn, 'r') do |fd|
70
+ mf = Webby::Resources::MetaFile.new(fd)
71
+ lambda {
72
+ mf.each {|h| output << h}
73
+ }.should raise_error(Webby::Resources::MetaFile::Error)
74
+ end
75
+ output.length.should == 1
76
+ end
77
+
78
+ it "really doesn't like YAML syntax errors" do
79
+ fn = Webby.datapath %w[hooligans bad_meta_data_2.txt]
80
+ output = []
81
+ File.open(fn, 'r') do |fd|
82
+ mf = Webby::Resources::MetaFile.new(fd)
83
+ lambda {
84
+ mf.each {|h| output << h}
85
+ }.should raise_error(Webby::Resources::MetaFile::Error)
86
+ end
87
+ output.length.should == 1
88
+ end
89
+ end
90
+
91
+ # -----------------------------------------------------------------------
92
+ describe '#meta_data' do
93
+ it 'returns nil for regular files' do
94
+ fn = Webby.datapath %w[content css coderay.css]
95
+ Webby::Resources::MetaFile.meta_data(fn).should be_nil
96
+ end
97
+
98
+ it 'returns a hash for pages' do
99
+ fn = Webby.datapath %w[content index.txt]
100
+ h = Webby::Resources::MetaFile.meta_data(fn)
101
+
102
+ h.should be_instance_of(Hash)
103
+ h['created_at'].should be_instance_of(Time)
104
+ end
105
+
106
+ it 'returns a hash for layouts' do
107
+ fn = Webby.datapath %w[layouts default.txt]
108
+ h = Webby::Resources::MetaFile.meta_data(fn)
109
+
110
+ h.should be_instance_of(Hash)
111
+ h.should == {
112
+ 'extension' => 'html',
113
+ 'filter' => 'erb'
114
+ }
115
+ end
116
+ end
117
+
118
+ # -----------------------------------------------------------------------
119
+ describe "#meta_data?" do
120
+ it 'returns true for files with meta-data' do
121
+ fn = Webby.datapath %w[content index.txt]
122
+ Webby::Resources::MetaFile.meta_data?(fn).should == true
123
+ end
124
+
125
+ it 'returns false for files without meta-data' do
126
+ fn = Webby.datapath %w[content css coderay.css]
127
+ Webby::Resources::MetaFile.meta_data?(fn).should == false
128
+ end
129
+ end
130
+
131
+ # -----------------------------------------------------------------------
132
+ describe "#read" do
133
+ it 'behaves the same as File#read for regular files' do
134
+ fn = Webby.datapath %w[content css coderay.css]
135
+ Webby::Resources::MetaFile.read(fn).should == ::File.read(fn)
136
+ end
137
+
138
+ it 'returns only the content for pages' do
139
+ fn = Webby.datapath %w[content index.txt]
140
+ lines = File.readlines(fn)
141
+ lines = lines[7..-1].join
142
+
143
+ Webby::Resources::MetaFile.read(fn).should == lines
144
+ end
145
+
146
+ it 'returns only the content for layouts' do
147
+ fn = Webby.datapath %w[layouts default.txt]
148
+ lines = File.readlines(fn)
149
+ lines = lines[4..-1].join
150
+
151
+ Webby::Resources::MetaFile.read(fn).should == lines
152
+ end
153
+ end
154
+
155
+ end # describe Webby::Resources::MetaFile
156
+
157
+ # EOF
@@ -0,0 +1,111 @@
1
+
2
+ require File.expand_path(
3
+ File.join(File.dirname(__FILE__), %w[.. .. spec_helper]))
4
+
5
+ # -------------------------------------------------------------------------
6
+ describe Webby::Resources::Page do
7
+ before :each do
8
+ layout = Webby::Resources::Layout.
9
+ new(Webby.datapath %w[layouts default.txt])
10
+ Webby::Resources.stub!(:find_layout).and_return(layout)
11
+
12
+ @filename = File.join %w[content index.txt]
13
+ @page = Webby::Resources::Page.new(@filename)
14
+ end
15
+
16
+ it 'parses meta-data on initialization' do
17
+ h = @page._meta_data
18
+
19
+ h.should_not be_empty
20
+ h['title'].should == 'Home Page'
21
+ h['filter'].should == ['erb', 'textile']
22
+ h['layout'].should == 'default'
23
+ end
24
+
25
+ it 'can be given a hash of meta-data on initialization' do
26
+ page = Webby::Resources::Page.new(
27
+ @filename,
28
+ 'title' => 'Not Your Average Title'
29
+ )
30
+
31
+ h = page._meta_data
32
+ h.should_not be_empty
33
+ h['title'].should == 'Not Your Average Title'
34
+ h['layout'].should == 'default'
35
+ h['created_at'].should be_nil
36
+ h['filter'].should be_nil
37
+ end
38
+
39
+ it 'reads the contents of the file' do
40
+ str = @page._read
41
+ str.split($/).first.should == "p(title). <%= @page.title %>"
42
+ end
43
+
44
+ # -----------------------------------------------------------------------
45
+ describe '.url' do
46
+ before :each do
47
+ @filename = File.join %w[content tumblog rss.txt]
48
+ @page = Webby::Resources::Page.new(@filename)
49
+ end
50
+
51
+ it 'computes the url from the destination' do
52
+ @page.url.should == '/tumblog/rss.xml'
53
+ end
54
+
55
+ it "uses only the directory name for 'index' files" do
56
+ filename = File.join %w[content tumblog index.txt]
57
+ resource = Webby::Resources::Page.new(filename)
58
+ resource.url.should == '/tumblog'
59
+ end
60
+ end
61
+
62
+ # -----------------------------------------------------------------------
63
+ describe '.extension' do
64
+ it 'uses the extension from the meta-data if present' do
65
+ @page['extension'] = 'foo'
66
+ @page.extension.should == 'foo'
67
+ end
68
+
69
+ it "uses the layout's extension if a layout is present" do
70
+ @page.extension.should == 'html'
71
+ end
72
+
73
+ it "uses the file's extension as a last ditch effort" do
74
+ @page._meta_data.delete('layout')
75
+ @page.extension.should == 'txt'
76
+ end
77
+ end
78
+
79
+ # -----------------------------------------------------------------------
80
+ describe '.dirty?' do
81
+ it 'overrides the dirty state based on the meta-data value' do
82
+ @page['dirty'] = true
83
+ @page.dirty?.should == true
84
+
85
+ @page['dirty'] = false
86
+ @page.dirty?.should == false
87
+ end
88
+
89
+ it 'returns true if the output file is missing' do
90
+ @page.dirty?.should == true
91
+ end
92
+
93
+ it 'returns true if the layout is dirty' do
94
+ dest = @page.destination
95
+ FileUtils.touch dest
96
+
97
+ @page.dirty?.should == true
98
+ end
99
+
100
+ it 'returns false if everything is up to date' do
101
+ dest = @page.destination
102
+ FileUtils.touch dest
103
+ FileUtils.touch ::Webby.cairn
104
+
105
+ @page.dirty?.should == false
106
+ end
107
+ end
108
+
109
+ end # describe Webby::Resources::Page
110
+
111
+ # EOF
@@ -0,0 +1,58 @@
1
+
2
+ require File.expand_path(
3
+ File.join(File.dirname(__FILE__), %w[.. .. spec_helper]))
4
+
5
+ # -------------------------------------------------------------------------
6
+ describe Webby::Resources::Partial do
7
+ before :each do
8
+ @filename = File.join %w[content _partial.txt]
9
+ @partial = Webby::Resources::Partial.new(@filename)
10
+ end
11
+
12
+ it 'parses meta-data on initialization' do
13
+ h = @partial._meta_data
14
+
15
+ h.should_not be_empty
16
+ h.should == {'filter' => 'erb'}
17
+ end
18
+
19
+ it 'uses the cairn file as the destination' do
20
+ @partial.destination.should == ::Webby.cairn
21
+ end
22
+
23
+ it 'always returns nil as the url' do
24
+ @partial.url.should be_nil
25
+ end
26
+
27
+ it 'reads the contents of the file' do
28
+ str = @partial._read
29
+ str.split($/).first.should == 'A partial has access to the page from which it was called. The title below will be the title of the page in which this partial is rendered.'
30
+ end
31
+
32
+ it 'uses the files extension as the extension' do
33
+ @partial.extension.should equal(@partial.ext)
34
+ end
35
+
36
+ # -----------------------------------------------------------------------
37
+ describe '.dirty?' do
38
+ it 'overrides the dirty state based on the meta-data value' do
39
+ @partial['dirty'] = true
40
+ @partial.dirty?.should == true
41
+
42
+ @partial['dirty'] = false
43
+ @partial.dirty?.should == false
44
+ end
45
+
46
+ it 'returns true if the cairn file is missing' do
47
+ @partial.dirty?.should == true
48
+ end
49
+
50
+ it 'returns false if the cairn file is present' do
51
+ FileUtils.touch Webby.cairn
52
+ @partial.dirty?.should == false
53
+ end
54
+ end
55
+
56
+ end # describe Webby::Resources::Partial
57
+
58
+ # EOF
@@ -0,0 +1,214 @@
1
+
2
+ require File.expand_path(
3
+ File.join(File.dirname(__FILE__), %w[.. .. spec_helper]))
4
+
5
+ # -------------------------------------------------------------------------
6
+ describe Webby::Resources::Resource do
7
+
8
+ before :each do
9
+ layout = Webby::Resources::Layout.
10
+ new(Webby.datapath %w[layouts default.txt])
11
+ Webby::Resources.stub!(:find_layout).and_return(layout)
12
+
13
+ @filename = File.join %w[content index.txt]
14
+ @resource = Webby::Resources::Resource.new(@filename)
15
+ end
16
+
17
+ it 'does not parse meta-data by default' do
18
+ @resource._meta_data.should be_empty
19
+ end
20
+
21
+ it 'provides the path to the file' do
22
+ @resource.path.should == @filename
23
+ end
24
+
25
+ it 'returns the bare filename' do
26
+ @resource.name.should == 'index'
27
+
28
+ resource = Webby::Resources::Resource.
29
+ new(File.join(%w[content tumblog rss.txt]))
30
+ resource.name.should == 'rss'
31
+ end
32
+
33
+ it 'returns the path-based extension' do
34
+ @resource.ext.should == 'txt'
35
+ end
36
+
37
+ it 'computes the directory of the file with the content folder removed' do
38
+ @resource.dir.should == ''
39
+
40
+ resource = Webby::Resources::Resource.
41
+ new(File.join(%w[content tumblog index.txt]))
42
+ resource.dir.should == 'tumblog'
43
+ end
44
+
45
+ it 'returns the modification time of the file' do
46
+ @resource.mtime.should be_instance_of(Time)
47
+ end
48
+
49
+ it 'determines equality from the full path' do
50
+ a = Webby::Resources::Resource.new(File.join(%w[content tumblog index.txt]))
51
+ b = Webby::Resources::Resource.new(File.join(%w[content tumblog rss.txt]))
52
+ c = Webby::Resources::Resource.new(File.join(%w[content tumblog index.txt]))
53
+
54
+ (a == b).should == false
55
+ (a == c).should == true
56
+ (b == c).should == false
57
+ (a == nil).should == false
58
+ (a == a.path).should == false
59
+ end
60
+
61
+ it 'compares two resources by path' do
62
+ a = Webby::Resources::Resource.new(File.join(%w[content tumblog index.txt]))
63
+ b = Webby::Resources::Resource.new(File.join(%w[content tumblog rss.txt]))
64
+ c = Webby::Resources::Resource.new(File.join(%w[content tumblog index.txt]))
65
+
66
+ (a <=> b).should == -1
67
+ (b <=> a).should == 1
68
+ (a <=> c).should == 0
69
+ (a <=> a).should == 0
70
+ (a <=> nil).should be_nil
71
+ (a <=> a.path).should be_nil
72
+ end
73
+
74
+ it 'can alter meta-data' do
75
+ @resource['title'].should be_nil
76
+ @resource[:title] = 'Home Page'
77
+
78
+ @resource['title'].should == 'Home Page'
79
+ @resource[:title].should == 'Home Page'
80
+ @resource[:title].should equal(@resource['title'])
81
+ end
82
+
83
+ it 'overrides the dirty state based on the meta-data value' do
84
+ @resource['dirty'] = true
85
+ @resource.dirty?.should == true
86
+
87
+ @resource['dirty'] = false
88
+ @resource.dirty?.should == false
89
+ end
90
+
91
+ it 'reads the contents of the file' do
92
+ str = @resource._read
93
+ str.split($/).first.should == "p(title). <%= @page.title %>"
94
+ end
95
+
96
+ it 'repleces the meta-data hash when reset' do
97
+ @resource._meta_data.should be_empty
98
+ oid = @resource._meta_data.object_id
99
+
100
+ @resource._reset('foo' => 'bar')
101
+ @resource._meta_data.should_not be_empty
102
+ @resource._meta_data.object_id.should == oid
103
+ @resource._meta_data['foo'].should == 'bar'
104
+ end
105
+
106
+ # -----------------------------------------------------------------------
107
+ describe '.filename' do
108
+ it 'uses the filename from the meta-data if present' do
109
+ @resource['filename'] = 'bozo'
110
+ @resource.filename.should == 'bozo'
111
+ end
112
+
113
+ it "uses the file's filename as a last ditch effort" do
114
+ @resource.filename.should == 'index'
115
+ end
116
+ end
117
+
118
+ # -----------------------------------------------------------------------
119
+ describe '.extension' do
120
+ it 'uses the extension from the meta-data if present' do
121
+ @resource['extension'] = 'foo'
122
+ @resource.extension.should == 'foo'
123
+ end
124
+
125
+ it "uses the file's extension as a last ditch effort" do
126
+ @resource.extension.should == 'txt'
127
+ end
128
+ end
129
+
130
+ # -----------------------------------------------------------------------
131
+ describe '.directory' do
132
+ it 'uses the directory from the meta-data if present' do
133
+ @resource['directory'] = 'foo'
134
+ @resource.directory.should == 'foo'
135
+ end
136
+
137
+ it "uses the file's directory as a last ditch effort" do
138
+ @resource.directory.should == ''
139
+ end
140
+ end
141
+
142
+ # -----------------------------------------------------------------------
143
+ describe '.url' do
144
+ it 'computes the url from the filename and directory' do
145
+ @resource.url.should == '/index.txt'
146
+ end
147
+
148
+ it 'caches the url' do
149
+ @resource.url.should == '/index.txt'
150
+
151
+ @resource['directory'] = 'foo/bar/baz'
152
+ @resource.url.should == '/index.txt'
153
+ end
154
+
155
+ it 'clears the cached url on reset' do
156
+ @resource.url.should == '/index.txt'
157
+
158
+ @resource['directory'] = 'foo/bar/baz'
159
+ @resource.url.should == '/index.txt'
160
+
161
+ @resource._reset
162
+ @resource.url.should == '/foo/bar/baz/index.txt'
163
+ end
164
+ end
165
+
166
+ # -----------------------------------------------------------------------
167
+ describe '.destination' do
168
+ it 'computes the destination from the filename and directory' do
169
+ @resource.destination.should == 'output/index.txt'
170
+ end
171
+
172
+ it 'caches the destination' do
173
+ @resource.destination.should == 'output/index.txt'
174
+
175
+ @resource['directory'] = 'foo/bar/baz'
176
+ @resource.destination.should == 'output/index.txt'
177
+ end
178
+
179
+ it 'clears the cached destination on reset' do
180
+ @resource.destination.should == 'output/index.txt'
181
+
182
+ @resource['directory'] = 'foo/bar/baz'
183
+ @resource.destination.should == 'output/index.txt'
184
+
185
+ @resource._reset
186
+ @resource.destination.should == 'output/foo/bar/baz/index.txt'
187
+ end
188
+ end
189
+
190
+ # -----------------------------------------------------------------------
191
+ describe '.dirty?' do
192
+ it 'overrides the dirty state based on the meta-data value' do
193
+ @resource['dirty'] = true
194
+ @resource.dirty?.should == true
195
+
196
+ @resource['dirty'] = false
197
+ @resource.dirty?.should == false
198
+ end
199
+
200
+ it 'returns true if the output file is missing' do
201
+ @resource.dirty?.should == true
202
+ end
203
+
204
+ it 'returns false if everything is up to date' do
205
+ dest = @resource.destination
206
+ FileUtils.touch dest
207
+
208
+ @resource.dirty?.should == false
209
+ end
210
+ end
211
+
212
+ end # describe Webby::Resources::Resource
213
+
214
+ # EOF