webby 0.9.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,49 @@
1
+
2
+ require File.expand_path(
3
+ File.join(File.dirname(__FILE__), %w[.. .. spec_helper]))
4
+
5
+ # -------------------------------------------------------------------------
6
+ describe Webby::Resources::Static do
7
+ before :all do
8
+ @filename = File.join %w[content css coderay.css]
9
+ @static = Webby::Resources::Static.new(@filename)
10
+ end
11
+
12
+ it 'contains no meta-data' do
13
+ @static._meta_data.should be_empty
14
+ end
15
+
16
+ it 'uses the path remounted to the output directory as the destination' do
17
+ @static.destination.should == 'output/css/coderay.css'
18
+ end
19
+
20
+ it 'returns destination without the output directory as the url' do
21
+ @static.url.should == '/css/coderay.css'
22
+ end
23
+
24
+ it 'reads the contents of the file' do
25
+ str = @static._read
26
+ str.split($/).first.should == '.CodeRay {'
27
+ end
28
+
29
+ it 'uses the file extension as the extension' do
30
+ @static.extension.should equal(@static.ext)
31
+ end
32
+
33
+ # -----------------------------------------------------------------------
34
+ describe '.dirty?' do
35
+ it 'returns true if the output file is missing' do
36
+ @static.dirty?.should == true
37
+ end
38
+
39
+ it 'returns false if the output file is present' do
40
+ dest = @static.destination
41
+ FileUtils.mkdir_p File.dirname(dest)
42
+ FileUtils.touch dest
43
+ @static.dirty?.should == false
44
+ end
45
+ end
46
+
47
+ end # describe Webby::Resources::Static
48
+
49
+ # EOF
@@ -1,9 +1,14 @@
1
1
 
2
2
 
3
- require ::File.join(::File.dirname(__FILE__), %w[.. spec_helper])
3
+ require File.expand_path(
4
+ File.join(File.dirname(__FILE__), %w[.. spec_helper]))
4
5
 
5
- # ---------------------------------------------------------------------------
6
+ # --------------------------------------------------------------------------
6
7
  describe Webby::Resources do
8
+ before :each do
9
+ Webby::Resources.clear
10
+ end
11
+
7
12
  it "should raise a useful error if there are no layouts" do
8
13
  layouts = mock("Layouts")
9
14
  Webby::Resources.stub!(:layouts).and_return(layouts)
@@ -12,6 +17,53 @@ describe Webby::Resources do
12
17
  lambda do
13
18
  Webby::Resources.find_layout("default")
14
19
  end.should raise_error(Webby::Error, 'could not find layout "default"')
15
-
16
20
  end
21
+
22
+ it "should return the directory name for a file" do
23
+ Webby::Resources.dirname('content').should == './'
24
+ Webby::Resources.dirname('layouts').should == './'
25
+
26
+ Webby::Resources.dirname('content/index.txt').should == ''
27
+ Webby::Resources.dirname('layouts/default.txt').should == ''
28
+
29
+ Webby::Resources.dirname('content/tumblog/index.txt').should == 'tumblog'
30
+ Webby::Resources.dirname('layouts/tumblog/post.txt').should == 'tumblog'
31
+
32
+ Webby::Resources.dirname('output/tumblog/index.html').should == 'output/tumblog'
33
+ Webby::Resources.dirname('templates/tumblog/post.erb').should == 'templates/tumblog'
34
+ end
35
+
36
+ it "should normalize the path for a filename" do
37
+ Webby::Resources.path('content').should == 'content'
38
+ Webby::Resources.path('/content').should == 'content'
39
+ Webby::Resources.path('./content').should == 'content'
40
+
41
+ Webby::Resources.path('./').should == ''
42
+ Webby::Resources.path('/').should == ''
43
+ Webby::Resources.path('').should == ''
44
+ end
45
+
46
+ # ------------------------------------------------------------------------
47
+ describe "#new" do
48
+ before :each do
49
+ layout = Webby::Resources::Layout.
50
+ new(Webby.datapath %w[layouts default.txt])
51
+ Webby::Resources.stub!(:find_layout).and_return(layout)
52
+ end
53
+
54
+ it "creates multiple pages for files with multiple YAML sections" do
55
+ pages = Webby::Resources.pages
56
+
57
+ fn = File.join %w[content photos.txt]
58
+ Webby::Resources.new(fn)
59
+
60
+ ary = pages.find(:all, :in_directory => 'photos')
61
+ ary.map {|page| page.title}.should == [
62
+ 'First Photo', 'Second Photo', 'Third Photo'
63
+ ]
64
+ end
65
+ end
66
+
17
67
  end
68
+
69
+ # EOF
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Pease
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-08-25 00:00:00 -06:00
12
+ date: 2008-09-10 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -50,7 +50,7 @@ dependencies:
50
50
  requirements:
51
51
  - - ">="
52
52
  - !ruby/object:Gem::Version
53
- version: 0.9.1
53
+ version: 0.9.2
54
54
  version:
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
@@ -60,7 +60,7 @@ dependencies:
60
60
  requirements:
61
61
  - - ">="
62
62
  - !ruby/object:Gem::Version
63
- version: 0.8.1
63
+ version: 0.8.2
64
64
  version:
65
65
  - !ruby/object:Gem::Dependency
66
66
  name: rspec
@@ -90,6 +90,21 @@ extra_rdoc_files:
90
90
  - lib/webby/tasks/growl.rake
91
91
  - lib/webby/tasks/heel.rake
92
92
  - lib/webby/tasks/validate.rake
93
+ - spec/data/content/_partial.txt
94
+ - spec/data/content/index.txt
95
+ - spec/data/content/photos.txt
96
+ - spec/data/content/tumblog/200806/the-noble-chicken/index.txt
97
+ - spec/data/content/tumblog/200807/historical-perspectives-on-the-classic-chicken-joke/index.txt
98
+ - spec/data/content/tumblog/200807/mad-city-chickens/index.txt
99
+ - spec/data/content/tumblog/200807/the-wisdom-of-the-dutch/index.txt
100
+ - spec/data/content/tumblog/200807/up-a-tree/index.txt
101
+ - spec/data/content/tumblog/index.txt
102
+ - spec/data/content/tumblog/rss.txt
103
+ - spec/data/hooligans/bad_meta_data_1.txt
104
+ - spec/data/hooligans/bad_meta_data_2.txt
105
+ - spec/data/layouts/default.txt
106
+ - spec/data/layouts/tumblog/default.txt
107
+ - spec/data/layouts/tumblog/post.txt
93
108
  files:
94
109
  - History.txt
95
110
  - Manifest.txt
@@ -153,7 +168,9 @@ files:
153
168
  - examples/webby/content/index.txt
154
169
  - examples/webby/content/learn/index.txt
155
170
  - examples/webby/content/reference/index.txt
171
+ - examples/webby/content/release-notes/index.txt
156
172
  - examples/webby/content/release-notes/rel-0-9-0/index.txt
173
+ - examples/webby/content/release-notes/rel-0-9-1/index.txt
157
174
  - examples/webby/content/robots.txt
158
175
  - examples/webby/content/script/jquery.corner.js
159
176
  - examples/webby/content/script/jquery.js
@@ -227,8 +244,8 @@ files:
227
244
  - lib/webby/renderer.rb
228
245
  - lib/webby/resources.rb
229
246
  - lib/webby/resources/db.rb
230
- - lib/webby/resources/file.rb
231
247
  - lib/webby/resources/layout.rb
248
+ - lib/webby/resources/meta_file.rb
232
249
  - lib/webby/resources/page.rb
233
250
  - lib/webby/resources/partial.rb
234
251
  - lib/webby/resources/resource.rb
@@ -245,12 +262,53 @@ files:
245
262
  - spec/core_ext/hash_spec.rb
246
263
  - spec/core_ext/string_spec.rb
247
264
  - spec/core_ext/time_spec.rb
265
+ - spec/data/Sitefile
266
+ - spec/data/content/_partial.txt
267
+ - spec/data/content/css/coderay.css
268
+ - spec/data/content/css/site.css
269
+ - spec/data/content/css/tumblog.css
270
+ - spec/data/content/images/tumblog/permalink.gif
271
+ - spec/data/content/images/tumblog/rss.gif
272
+ - spec/data/content/index.txt
273
+ - spec/data/content/photos.txt
274
+ - spec/data/content/tumblog/200806/the-noble-chicken/index.txt
275
+ - spec/data/content/tumblog/200807/historical-perspectives-on-the-classic-chicken-joke/index.txt
276
+ - spec/data/content/tumblog/200807/mad-city-chickens/index.txt
277
+ - spec/data/content/tumblog/200807/the-wisdom-of-the-dutch/index.txt
278
+ - spec/data/content/tumblog/200807/up-a-tree/index.txt
279
+ - spec/data/content/tumblog/index.txt
280
+ - spec/data/content/tumblog/rss.txt
281
+ - spec/data/hooligans/bad_meta_data_1.txt
282
+ - spec/data/hooligans/bad_meta_data_2.txt
283
+ - spec/data/layouts/default.txt
284
+ - spec/data/layouts/tumblog/default.txt
285
+ - spec/data/layouts/tumblog/post.txt
286
+ - spec/data/lib/breadcrumbs.rb
287
+ - spec/data/lib/tumblog_helper.rb
288
+ - spec/data/tasks/tumblog.rake
289
+ - spec/data/templates/_partial.erb
290
+ - spec/data/templates/atom_feed.erb
291
+ - spec/data/templates/page.erb
292
+ - spec/data/templates/presentation.erb
293
+ - spec/data/templates/tumblog/conversation.erb
294
+ - spec/data/templates/tumblog/link.erb
295
+ - spec/data/templates/tumblog/photo.erb
296
+ - spec/data/templates/tumblog/post.erb
297
+ - spec/data/templates/tumblog/quote.erb
248
298
  - spec/spec.opts
249
299
  - spec/spec_helper.rb
250
300
  - spec/webby/apps/generator_spec.rb
251
301
  - spec/webby/apps/main_spec.rb
302
+ - spec/webby/filters/textile_spec.rb
252
303
  - spec/webby/helpers/capture_helper_spec.rb
253
- - spec/webby/resources/file_spec.rb
304
+ - spec/webby/renderer_spec.rb
305
+ - spec/webby/resources/db_spec.rb
306
+ - spec/webby/resources/layout_spec.rb
307
+ - spec/webby/resources/meta_file_spec.rb
308
+ - spec/webby/resources/page_spec.rb
309
+ - spec/webby/resources/partial_spec.rb
310
+ - spec/webby/resources/resource_spec.rb
311
+ - spec/webby/resources/static_spec.rb
254
312
  - spec/webby/resources_spec.rb
255
313
  - tasks/ann.rake
256
314
  - tasks/bones.rake
@@ -1,221 +0,0 @@
1
- require 'yaml'
2
-
3
- module Webby::Resources
4
-
5
- # The Webby::Resources::File class is identical to the core Ruby file class
6
- # except for YAML meta-data stored at the top of the file. This meta-data
7
- # is made available through the <code>meta_data</code> and
8
- # <code>meta_data=</code> functions.
9
- #
10
- # The meta-data data must be found between two YAML block separators "---",
11
- # each on their own line.
12
- #
13
- # Example:
14
- #
15
- # ---
16
- # layout: blog
17
- # filter: markdown
18
- # tags:
19
- # - ruby
20
- # - web development
21
- # ---
22
- # This is a blog entry formatted using MarkDown and tagged as "ruby" and
23
- # "web development". The layout being used is the "blog" format.
24
- #
25
- class File < ::File
26
-
27
- META_SEP = %r/\A---\s*\r?\n\z/o # :nodoc:
28
-
29
- class << self
30
- # call-seq:
31
- # File.read( name [, length [, offset]]) => string
32
- #
33
- # Opens the file, optionally seeks to the given _offset_, then returns
34
- # _length_ bytes (defaulting to the rest of the file). +read+ ensures
35
- # the file is closed before returning.
36
- #
37
- def read( name, *args )
38
- fd = new name, 'r'
39
- fd.read(*args)
40
- ensure
41
- fd.close unless fd.nil?
42
- end
43
-
44
- # call-seq:
45
- # File.readlines( name, sep_string = $/ ) => array
46
- #
47
- # Reads the entire file specified by _name_ as individual lines, and
48
- # returns those lines in an array. Lines are separated by _sep_string_.
49
- # +readlines+ ensures the file is closed before returning.
50
- #
51
- def readlines( name, sep = $/ )
52
- fd = new name, 'r'
53
- fd.readlines sep
54
- ensure
55
- fd.close unless fd.nil?
56
- end
57
-
58
- # call-seq:
59
- # File.meta_data( name ) => object or nil
60
- #
61
- # Reads the meta-data from the file specified by _name_. +meta_data+
62
- # ensures the files is closed before returning.
63
- #
64
- def meta_data( name )
65
- fd = new name, 'r'
66
- fd.meta_data
67
- ensure
68
- fd.close unless fd.nil?
69
- end
70
-
71
- # call-seq:
72
- # File.dirname( filename ) => dir_name
73
- #
74
- # Returns all components of the _filename_ except the last one. The
75
- # filename must be formed using forward slashes ("/") regardless of the
76
- # separator used on the local file system.
77
- #
78
- def dirname( fn )
79
- ::File.dirname(fn).sub(%r/\A[^\/]+\/?/o, '')
80
- end
81
-
82
- # call-seq:
83
- # File.basename( filename ) => base_name
84
- #
85
- # Returns the last component of the _filename_, which must be formed
86
- # using forward slashes ("/"regardless of the separator used on the
87
- # local file system. The suffix is removed from the filename.
88
- #
89
- def basename( fn )
90
- ::File.basename(fn, '.*')
91
- end
92
-
93
- # call-seq:
94
- # File.extname( filename ) => ext_name
95
- #
96
- # Returns the extension (the portion of file name in path after the
97
- # period). This method excludes the period from the extension name.
98
- #
99
- def extname( fn )
100
- ::File.extname(fn).tr('.', '')
101
- end
102
- end
103
-
104
- # call-seq:
105
- # File.new( filename, mode = "r" ) => file
106
- # File.new( filename [, mode [, perm]] ) => file
107
- #
108
- # Opens the file named by _filename_ according to _mode_ (default is 'r')
109
- # and returns a new +Webby::Resources::File+ object. See the description
110
- # of class +IO+ for a description of _mode_. The file _mode_ may
111
- # optionally be specified as a +Fixnum+ by or-ing together the flags
112
- # (+O_RDONLY+ etc, again described under +IO+). Optional permission bits
113
- # may be given in _perm_. These _mode_ and permission bits are platform
114
- # dependent; on Unix systems, see +open(2)+ for details.
115
- #
116
- # f = File.new("testfile", "r")
117
- # f = File.new("newfile", "w+")
118
- # f = File.new("newfile", File::CREAT|File::TRUNC|File::RDWR, 0644)
119
- #
120
- def initialize( *args )
121
- super
122
- @meta_end = end_of_meta_data
123
- end
124
-
125
- # call-seq:
126
- # meta_data
127
- #
128
- # Returns the meta-data defined at the top of the file. Returns +nil+ if
129
- # no meta-data is defined. The meta-data is returned as Ruby objects
130
- #
131
- # Meta-data is stored in YAML format between two YAML separators "---" on
132
- # their own lines.
133
- #
134
- def meta_data
135
- return if @meta_end.nil?
136
-
137
- cur, meta_end, @meta_end = tell, @meta_end, nil
138
- seek 0
139
- return YAML.load(self)
140
-
141
- ensure
142
- @meta_end = meta_end if defined? meta_end and meta_end
143
- seek cur if defined? cur and cur
144
- end
145
-
146
- # call-seq
147
- # meta_data = object
148
- #
149
- # Stores the given _object_ as meta-data in YAML format at the top of the
150
- # file. If the _objectc_ is +nil+, then the meta-data section will be
151
- # removed from the file.
152
- #
153
- # Meta-data is stored in YAML format between two YAML separators "---" on
154
- # their own lines.
155
- #
156
- def meta_data=( data )
157
- return if data.nil? and @meta_end.nil?
158
-
159
- seek 0
160
- lines = readlines
161
-
162
- truncate 0
163
- unless data.nil?
164
- write YAML.dump(data)
165
- write "--- #$/"
166
- end
167
- lines.each {|line| write line}
168
- ensure
169
- @meta_end = end_of_meta_data
170
- seek 0, IO::SEEK_END
171
- end
172
-
173
- alias :_gets :gets
174
- private :_gets
175
-
176
- %w(getc gets read read_nonblock readbytes readchar readline readlines readpartial scanf).each do |m|
177
- self.class_eval <<-CODE
178
- def #{m}(*a)
179
- skip_meta_data
180
- super
181
- end
182
- CODE
183
- end
184
-
185
-
186
- private
187
-
188
- # Moves the file pointer to the end of the meta-data section. Does nothing
189
- # if there is no meta-data section or if the file pointer is already past
190
- # the meta-data section.
191
- #
192
- def skip_meta_data
193
- return if @meta_end.nil?
194
- return if tell >= @meta_end
195
- seek @meta_end
196
- end
197
-
198
- # Returns the position in this file where the meta-data ends and the file
199
- # data begins. If there is no meta-data in the file, returns +nil+.
200
- #
201
- def end_of_meta_data
202
- cur = tell
203
-
204
- seek 0
205
- line = _gets
206
- return unless META_SEP =~ line
207
-
208
- while line = _gets
209
- break if META_SEP =~ line
210
- end
211
- return if line.nil?
212
- tell
213
-
214
- ensure
215
- seek cur
216
- end
217
-
218
- end # class File
219
- end # module Webby::Resources
220
-
221
- # EOF