francois-webby 0.9.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (233) hide show
  1. data/History.txt +218 -0
  2. data/README.rdoc +92 -0
  3. data/Rakefile +62 -0
  4. data/bin/webby +41 -0
  5. data/bin/webby-gen +41 -0
  6. data/examples/blog/Sitefile +7 -0
  7. data/examples/blog/tasks/blog.rake +72 -0
  8. data/examples/blog/templates/atom_feed.erb +40 -0
  9. data/examples/blog/templates/blog/month.erb +22 -0
  10. data/examples/blog/templates/blog/post.erb +16 -0
  11. data/examples/blog/templates/blog/year.erb +22 -0
  12. data/examples/presentation/Sitefile +10 -0
  13. data/examples/presentation/content/css/uv/twilight.css +137 -0
  14. data/examples/presentation/content/presentation/_sample_code.txt +10 -0
  15. data/examples/presentation/content/presentation/index.txt +63 -0
  16. data/examples/presentation/content/presentation/s5/blank.gif +0 -0
  17. data/examples/presentation/content/presentation/s5/bodybg.gif +0 -0
  18. data/examples/presentation/content/presentation/s5/framing.css +23 -0
  19. data/examples/presentation/content/presentation/s5/iepngfix.htc +42 -0
  20. data/examples/presentation/content/presentation/s5/opera.css +7 -0
  21. data/examples/presentation/content/presentation/s5/outline.css +15 -0
  22. data/examples/presentation/content/presentation/s5/pretty.css +86 -0
  23. data/examples/presentation/content/presentation/s5/print.css +25 -0
  24. data/examples/presentation/content/presentation/s5/s5-core.css +9 -0
  25. data/examples/presentation/content/presentation/s5/slides.css +3 -0
  26. data/examples/presentation/content/presentation/s5/slides.js +553 -0
  27. data/examples/presentation/layouts/presentation.txt +43 -0
  28. data/examples/presentation/templates/_code_partial.erb +13 -0
  29. data/examples/presentation/templates/presentation.erb +40 -0
  30. data/examples/tumblog/Sitefile +9 -0
  31. data/examples/tumblog/content/css/tumblog.css +308 -0
  32. data/examples/tumblog/content/images/tumblog/permalink.gif +0 -0
  33. data/examples/tumblog/content/images/tumblog/rss.gif +0 -0
  34. data/examples/tumblog/content/tumblog/200806/the-noble-chicken/index.txt +12 -0
  35. data/examples/tumblog/content/tumblog/200807/historical-perspectives-on-the-classic-chicken-joke/index.txt +12 -0
  36. data/examples/tumblog/content/tumblog/200807/mad-city-chickens/index.txt +10 -0
  37. data/examples/tumblog/content/tumblog/200807/the-wisdom-of-the-dutch/index.txt +11 -0
  38. data/examples/tumblog/content/tumblog/200807/up-a-tree/index.txt +13 -0
  39. data/examples/tumblog/content/tumblog/index.txt +37 -0
  40. data/examples/tumblog/content/tumblog/rss.txt +37 -0
  41. data/examples/tumblog/layouts/tumblog/default.txt +44 -0
  42. data/examples/tumblog/layouts/tumblog/post.txt +15 -0
  43. data/examples/tumblog/lib/tumblog_helper.rb +32 -0
  44. data/examples/tumblog/tasks/tumblog.rake +30 -0
  45. data/examples/tumblog/templates/atom_feed.erb +40 -0
  46. data/examples/tumblog/templates/tumblog/conversation.erb +12 -0
  47. data/examples/tumblog/templates/tumblog/link.erb +10 -0
  48. data/examples/tumblog/templates/tumblog/photo.erb +13 -0
  49. data/examples/tumblog/templates/tumblog/post.erb +12 -0
  50. data/examples/tumblog/templates/tumblog/quote.erb +11 -0
  51. data/examples/webby/Sitefile +19 -0
  52. data/examples/webby/content/communicate/index.txt +28 -0
  53. data/examples/webby/content/css/background.gif +0 -0
  54. data/examples/webby/content/css/blueprint/print.css +76 -0
  55. data/examples/webby/content/css/blueprint/screen.css +696 -0
  56. data/examples/webby/content/css/coderay.css +96 -0
  57. data/examples/webby/content/css/site.css +196 -0
  58. data/examples/webby/content/css/uv/twilight.css +137 -0
  59. data/examples/webby/content/index.txt +37 -0
  60. data/examples/webby/content/learn/index.txt +28 -0
  61. data/examples/webby/content/reference/index.txt +204 -0
  62. data/examples/webby/content/release-notes/index.txt +21 -0
  63. data/examples/webby/content/release-notes/rel-0-9-0/index.txt +74 -0
  64. data/examples/webby/content/release-notes/rel-0-9-1/index.txt +93 -0
  65. data/examples/webby/content/release-notes/rel-0-9-2/index.txt +14 -0
  66. data/examples/webby/content/release-notes/rel-0-9-3/index.txt +47 -0
  67. data/examples/webby/content/robots.txt +6 -0
  68. data/examples/webby/content/script/jquery.corner.js +152 -0
  69. data/examples/webby/content/script/jquery.js +31 -0
  70. data/examples/webby/content/sitemap.txt +31 -0
  71. data/examples/webby/content/tips_and_tricks/index.txt +97 -0
  72. data/examples/webby/content/tutorial/index.txt +135 -0
  73. data/examples/webby/content/user-manual/index.txt +419 -0
  74. data/examples/webby/layouts/default.txt +49 -0
  75. data/examples/webby/templates/page.erb +10 -0
  76. data/examples/website/Sitefile +7 -0
  77. data/examples/website/content/css/blueprint/ie.css +26 -0
  78. data/examples/website/content/css/blueprint/plugins/buttons/icons/cross.png +0 -0
  79. data/examples/website/content/css/blueprint/plugins/buttons/icons/key.png +0 -0
  80. data/examples/website/content/css/blueprint/plugins/buttons/icons/tick.png +0 -0
  81. data/examples/website/content/css/blueprint/plugins/buttons/readme.txt +32 -0
  82. data/examples/website/content/css/blueprint/plugins/buttons/screen.css +97 -0
  83. data/examples/website/content/css/blueprint/plugins/fancy-type/readme.txt +14 -0
  84. data/examples/website/content/css/blueprint/plugins/fancy-type/screen.css +71 -0
  85. data/examples/website/content/css/blueprint/plugins/link-icons/icons/doc.png +0 -0
  86. data/examples/website/content/css/blueprint/plugins/link-icons/icons/email.png +0 -0
  87. data/examples/website/content/css/blueprint/plugins/link-icons/icons/external.png +0 -0
  88. data/examples/website/content/css/blueprint/plugins/link-icons/icons/feed.png +0 -0
  89. data/examples/website/content/css/blueprint/plugins/link-icons/icons/im.png +0 -0
  90. data/examples/website/content/css/blueprint/plugins/link-icons/icons/pdf.png +0 -0
  91. data/examples/website/content/css/blueprint/plugins/link-icons/icons/visited.png +0 -0
  92. data/examples/website/content/css/blueprint/plugins/link-icons/icons/xls.png +0 -0
  93. data/examples/website/content/css/blueprint/plugins/link-icons/readme.txt +18 -0
  94. data/examples/website/content/css/blueprint/plugins/link-icons/screen.css +40 -0
  95. data/examples/website/content/css/blueprint/plugins/rtl/readme.txt +10 -0
  96. data/examples/website/content/css/blueprint/plugins/rtl/screen.css +109 -0
  97. data/examples/website/content/css/blueprint/print.css +30 -0
  98. data/examples/website/content/css/blueprint/screen.css +251 -0
  99. data/examples/website/content/css/blueprint/src/forms.css +49 -0
  100. data/examples/website/content/css/blueprint/src/grid.css +212 -0
  101. data/examples/website/content/css/blueprint/src/grid.png +0 -0
  102. data/examples/website/content/css/blueprint/src/ie.css +59 -0
  103. data/examples/website/content/css/blueprint/src/print.css +85 -0
  104. data/examples/website/content/css/blueprint/src/reset.css +38 -0
  105. data/examples/website/content/css/blueprint/src/typography.css +105 -0
  106. data/examples/website/content/css/coderay.css +111 -0
  107. data/examples/website/content/css/site.css +67 -0
  108. data/examples/website/content/index.txt +19 -0
  109. data/examples/website/layouts/default.txt +61 -0
  110. data/examples/website/lib/breadcrumbs.rb +28 -0
  111. data/examples/website/templates/_partial.erb +10 -0
  112. data/examples/website/templates/page.erb +18 -0
  113. data/lib/webby/apps/generator.rb +276 -0
  114. data/lib/webby/apps/main.rb +258 -0
  115. data/lib/webby/apps.rb +12 -0
  116. data/lib/webby/auto_builder.rb +157 -0
  117. data/lib/webby/builder.rb +172 -0
  118. data/lib/webby/core_ext/enumerable.rb +11 -0
  119. data/lib/webby/core_ext/hash.rb +28 -0
  120. data/lib/webby/core_ext/kernel.rb +26 -0
  121. data/lib/webby/core_ext/string.rb +163 -0
  122. data/lib/webby/core_ext/time.rb +9 -0
  123. data/lib/webby/filters/basepath.rb +97 -0
  124. data/lib/webby/filters/erb.rb +9 -0
  125. data/lib/webby/filters/haml.rb +18 -0
  126. data/lib/webby/filters/markdown.rb +16 -0
  127. data/lib/webby/filters/maruku.rb +16 -0
  128. data/lib/webby/filters/outline.rb +309 -0
  129. data/lib/webby/filters/sass.rb +17 -0
  130. data/lib/webby/filters/slides.rb +56 -0
  131. data/lib/webby/filters/textile.rb +16 -0
  132. data/lib/webby/filters/tidy.rb +76 -0
  133. data/lib/webby/filters/wiki_words.rb +14 -0
  134. data/lib/webby/filters.rb +85 -0
  135. data/lib/webby/helpers/capture_helper.rb +141 -0
  136. data/lib/webby/helpers/coderay_helper.rb +69 -0
  137. data/lib/webby/helpers/graphviz_helper.rb +136 -0
  138. data/lib/webby/helpers/tag_helper.rb +65 -0
  139. data/lib/webby/helpers/tex_img_helper.rb +133 -0
  140. data/lib/webby/helpers/ultraviolet_helper.rb +63 -0
  141. data/lib/webby/helpers/url_helper.rb +241 -0
  142. data/lib/webby/helpers.rb +30 -0
  143. data/lib/webby/journal.rb +126 -0
  144. data/lib/webby/link_validator.rb +160 -0
  145. data/lib/webby/renderer.rb +389 -0
  146. data/lib/webby/resources/db.rb +251 -0
  147. data/lib/webby/resources/layout.rb +54 -0
  148. data/lib/webby/resources/meta_file.rb +211 -0
  149. data/lib/webby/resources/page.rb +81 -0
  150. data/lib/webby/resources/partial.rb +85 -0
  151. data/lib/webby/resources/resource.rb +201 -0
  152. data/lib/webby/resources/static.rb +36 -0
  153. data/lib/webby/resources.rb +137 -0
  154. data/lib/webby/stelan/mktemp.rb +135 -0
  155. data/lib/webby/stelan/paginator.rb +165 -0
  156. data/lib/webby/tasks/build.rake +27 -0
  157. data/lib/webby/tasks/create.rake +25 -0
  158. data/lib/webby/tasks/deploy.rake +22 -0
  159. data/lib/webby/tasks/growl.rake +16 -0
  160. data/lib/webby/tasks/validate.rake +19 -0
  161. data/lib/webby.rb +232 -0
  162. data/spec/core_ext/hash_spec.rb +47 -0
  163. data/spec/core_ext/string_spec.rb +110 -0
  164. data/spec/core_ext/time_spec.rb +19 -0
  165. data/spec/data/hooligans/bad_meta_data_1.txt +34 -0
  166. data/spec/data/hooligans/bad_meta_data_2.txt +34 -0
  167. data/spec/data/html/anchor.html +11 -0
  168. data/spec/data/html/external.html +10 -0
  169. data/spec/data/html/invalid-relative.html +10 -0
  170. data/spec/data/html/relative-anchor.html +10 -0
  171. data/spec/data/html/relative-invalid-anchor.html +10 -0
  172. data/spec/data/html/relative.html +10 -0
  173. data/spec/data/outline/basic.out +81 -0
  174. data/spec/data/outline/basic.txt +25 -0
  175. data/spec/data/outline/no_clobber.out +86 -0
  176. data/spec/data/outline/numbering.out +81 -0
  177. data/spec/data/outline/numbering_only.out +21 -0
  178. data/spec/data/outline/toc_range_1.out +66 -0
  179. data/spec/data/outline/toc_range_2.out +55 -0
  180. data/spec/data/outline/toc_style.out +81 -0
  181. data/spec/data/site/Sitefile +9 -0
  182. data/spec/data/site/content/_partial.txt +10 -0
  183. data/spec/data/site/content/css/coderay.css +111 -0
  184. data/spec/data/site/content/css/site.css +67 -0
  185. data/spec/data/site/content/css/tumblog.css +308 -0
  186. data/spec/data/site/content/images/tumblog/permalink.gif +0 -0
  187. data/spec/data/site/content/images/tumblog/rss.gif +0 -0
  188. data/spec/data/site/content/index.txt +19 -0
  189. data/spec/data/site/content/photos.txt +21 -0
  190. data/spec/data/site/content/tumblog/200806/the-noble-chicken/index.txt +12 -0
  191. data/spec/data/site/content/tumblog/200807/historical-perspectives-on-the-classic-chicken-joke/index.txt +12 -0
  192. data/spec/data/site/content/tumblog/200807/mad-city-chickens/index.txt +10 -0
  193. data/spec/data/site/content/tumblog/200807/the-wisdom-of-the-dutch/index.txt +11 -0
  194. data/spec/data/site/content/tumblog/200807/up-a-tree/index.txt +13 -0
  195. data/spec/data/site/content/tumblog/index.txt +37 -0
  196. data/spec/data/site/content/tumblog/rss.txt +37 -0
  197. data/spec/data/site/layouts/default.txt +58 -0
  198. data/spec/data/site/layouts/tumblog/default.txt +44 -0
  199. data/spec/data/site/layouts/tumblog/post.txt +15 -0
  200. data/spec/data/site/lib/breadcrumbs.rb +28 -0
  201. data/spec/data/site/lib/tumblog_helper.rb +32 -0
  202. data/spec/data/site/tasks/tumblog.rake +30 -0
  203. data/spec/data/site/templates/_partial.erb +10 -0
  204. data/spec/data/site/templates/atom_feed.erb +40 -0
  205. data/spec/data/site/templates/page.erb +18 -0
  206. data/spec/data/site/templates/presentation.erb +40 -0
  207. data/spec/data/site/templates/tumblog/conversation.erb +12 -0
  208. data/spec/data/site/templates/tumblog/link.erb +10 -0
  209. data/spec/data/site/templates/tumblog/photo.erb +13 -0
  210. data/spec/data/site/templates/tumblog/post.erb +12 -0
  211. data/spec/data/site/templates/tumblog/quote.erb +11 -0
  212. data/spec/spec.opts +1 -0
  213. data/spec/spec_helper.rb +58 -0
  214. data/spec/webby/apps/generator_spec.rb +117 -0
  215. data/spec/webby/apps/main_spec.rb +88 -0
  216. data/spec/webby/filters/basepath_spec.rb +167 -0
  217. data/spec/webby/filters/maruku_spec.rb +31 -0
  218. data/spec/webby/filters/outline_spec.rb +92 -0
  219. data/spec/webby/filters/textile_spec.rb +31 -0
  220. data/spec/webby/helpers/capture_helper_spec.rb +56 -0
  221. data/spec/webby/link_validator_spec.rb +154 -0
  222. data/spec/webby/renderer_spec.rb +139 -0
  223. data/spec/webby/resources/db_spec.rb +250 -0
  224. data/spec/webby/resources/layout_spec.rb +83 -0
  225. data/spec/webby/resources/meta_file_spec.rb +171 -0
  226. data/spec/webby/resources/page_spec.rb +111 -0
  227. data/spec/webby/resources/partial_spec.rb +58 -0
  228. data/spec/webby/resources/resource_spec.rb +219 -0
  229. data/spec/webby/resources/static_spec.rb +49 -0
  230. data/spec/webby/resources_spec.rb +69 -0
  231. data/tasks/mswin32.rake +38 -0
  232. data/tasks/website.rake +37 -0
  233. metadata +372 -0
@@ -0,0 +1,135 @@
1
+ # :stopdoc:
2
+ # Skeleton module for the 'mktemp' routine.
3
+ #
4
+ # Ideally, one would do this in their code to import the "mktemp" call
5
+ # directly into their current namespace:
6
+ #
7
+ # require 'mktemp'
8
+ # include MkTemp
9
+ # # do something with mktemp()
10
+ #
11
+ #
12
+ # It is recommended that you look at the documentation for the mktemp()
13
+ # call directly for specific usage.
14
+ #
15
+ #--
16
+ #
17
+ # The compilation of software known as mktemp.rb is distributed under the
18
+ # following terms:
19
+ # Copyright (C) 2005-2006 Erik Hollensbe. All rights reserved.
20
+ #
21
+ # Redistribution and use in source form, with or without
22
+ # modification, are permitted provided that the following conditions
23
+ # are met:
24
+ # 1. Redistributions of source code must retain the above copyright
25
+ # notice, this list of conditions and the following disclaimer.
26
+ #
27
+ # THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
28
+ # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30
+ # ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
31
+ # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32
+ # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33
+ # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34
+ # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35
+ # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36
+ # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37
+ # SUCH DAMAGE.
38
+ #
39
+ #++
40
+
41
+ module Webby
42
+ module MkTemp
43
+ VALID_TMPNAM_CHARS = (?a..?z).to_a + (?A..?Z).to_a
44
+
45
+ #
46
+ # This routine just generates a temporary file similar to the
47
+ # routines from 'mktemp'. A trailing series of 'X' characters will
48
+ # be transformed into a randomly-generated set of alphanumeric
49
+ # characters.
50
+ #
51
+ # This routine performs no file testing, at all. It is not suitable
52
+ # for anything beyond that.
53
+ #
54
+
55
+ def tmpnam(filename)
56
+ m = filename.match(/(X*)$/)
57
+
58
+ retnam = filename.dup
59
+
60
+ if m[1]
61
+ mask = ""
62
+ m[1].length.times { mask += VALID_TMPNAM_CHARS[rand(52)].chr }
63
+ retnam.sub!(/(X*)$/, mask)
64
+ end
65
+
66
+ return retnam
67
+ end
68
+
69
+ module_function :tmpnam
70
+
71
+ #
72
+ # This routine works similarly to mkstemp(3) in that it gets a new
73
+ # file, and returns a file handle for that file. The mask parameter
74
+ # determines whether or not to process the filename as a mask by
75
+ # calling the tmpnam() routine in this module. This routine will
76
+ # continue until it finds a valid filename, which may not do what
77
+ # you expect.
78
+ #
79
+ # While all attempts have been made to keep this as secure as
80
+ # possible, due to a few problems with Ruby's file handling code, we
81
+ # are required to allow a few concessions. If a 0-length file is
82
+ # created before we attempt to create ours, we have no choice but to
83
+ # accept it. Do not rely on this code for any expected level of
84
+ # security, even though we have taken all the measures we can to
85
+ # handle that situation.
86
+ #
87
+
88
+ def mktemp(filename, mask=true)
89
+ fh = nil
90
+
91
+ begin
92
+ loop do
93
+ fn = mask ? tmpnam(filename) : filename
94
+
95
+ if File.exist? fn
96
+ fail "Unable to create a temporary filename" unless mask
97
+ next
98
+ end
99
+
100
+ fh = File.new(fn, "a", 0600)
101
+ fh.seek(0, IO::SEEK_END)
102
+ break if fh.pos == 0
103
+
104
+ fail "Unable to create a temporary filename" unless mask
105
+ fh.close
106
+ end
107
+ rescue Exception => e
108
+ # in the case that we hit a locked file...
109
+ fh.close if fh
110
+ raise e unless mask
111
+ end
112
+
113
+ return fh
114
+ end
115
+
116
+ module_function :mktemp
117
+
118
+ #
119
+ # Create a directory. If mask is true (default), it will use the
120
+ # random name generation rules from the tmpnam() call in this
121
+ # module.
122
+ #
123
+
124
+ def mktempdir(filename, mask=true)
125
+ fn = mask ? tmpnam(filename) : filename
126
+ Dir.mkdir(fn)
127
+ return fn
128
+ end
129
+
130
+ module_function :mktempdir
131
+ end # module MkTemp
132
+ end # module Webby
133
+
134
+ # :startdoc:
135
+ # EOF
@@ -0,0 +1,165 @@
1
+ # This code was originally written by Bruce Williams, and it is available
2
+ # as the Paginator gem. I've added a few helper methods and modifications so
3
+ # it plays a little more nicely with Webby. Specifically, a Webby::Resource
4
+ # can be given to the Page and used to generate links to the previous and
5
+ # next pages.
6
+ #
7
+ # Many thanks to Bruce Williams for letting me use his work. Drop him a note
8
+ # of praise scribbled on the back of a $100 bill. He'd appreciate it.
9
+
10
+ require 'forwardable'
11
+
12
+ module Webby
13
+ class Paginator
14
+
15
+ include Enumerable
16
+
17
+ class ArgumentError < ::ArgumentError; end
18
+ class MissingCountError < ArgumentError; end
19
+ class MissingSelectError < ArgumentError; end
20
+
21
+ attr_reader :per_page, :count, :resource, :filename, :directory
22
+
23
+ # Instantiate a new Paginator object
24
+ #
25
+ # Provide:
26
+ # * A total count of the number of objects to paginate
27
+ # * The number of objects in each page
28
+ # * A block that returns the array of items
29
+ # * The block is passed the item offset
30
+ # (and the number of items to show per page, for
31
+ # convenience, if the arity is 2)
32
+ def initialize(count, per_page, resource, &select)
33
+ @count, @per_page, @resource = count, per_page, resource
34
+ @meta_data = @resource._meta_data.dup
35
+ @filename = @resource.filename
36
+ @directory = @resource.directory
37
+ unless select
38
+ raise MissingSelectError, "Must provide block to select data for each page"
39
+ end
40
+ @select = select
41
+ end
42
+
43
+ # Total number of pages
44
+ def number_of_pages
45
+ (@count / @per_page).to_i + (@count % @per_page > 0 ? 1 : 0)
46
+ end
47
+
48
+ # First page object
49
+ def first
50
+ page 1
51
+ end
52
+
53
+ # Last page object
54
+ def last
55
+ page number_of_pages
56
+ end
57
+
58
+ def each
59
+ 1.upto(number_of_pages) do |number|
60
+ yield page(number)
61
+ end
62
+ end
63
+
64
+ # Retrieve page object by number
65
+ def page(number)
66
+ number = (n = number.to_i) > 0 ? n : 1
67
+ Page.new(self, number, lambda {
68
+ offset = (number - 1) * @per_page
69
+ args = [offset]
70
+ args << @per_page if @select.arity == 2
71
+ @select.call(*args)
72
+ })
73
+ end
74
+
75
+ # Finalizer method that should be called when the paginator is finished
76
+ def reset
77
+ resource._reset(@meta_data)
78
+ end
79
+
80
+ # Page object
81
+ #
82
+ # Retrieves items for a page and provides metadata about the position
83
+ # of the page in the paginator
84
+ class Page
85
+
86
+ include Enumerable
87
+
88
+ attr_reader :number, :pager, :url
89
+
90
+ def initialize(pager, number, select) #:nodoc:
91
+ @pager, @number = pager, number
92
+ @offset = (number - 1) * pager.per_page
93
+ @select = select
94
+
95
+ @pager.reset
96
+ if number > 1
97
+ if ::Webby.site.create_mode == 'directory'
98
+ @pager.resource['directory'] = File.join(@pager.directory, number.to_s)
99
+ else
100
+ @pager.resource['filename'] = @pager.filename + number.to_s
101
+ end
102
+ end
103
+ @url = @pager.resource.url
104
+ end
105
+
106
+ # Retrieve the items for this page
107
+ # * Caches
108
+ def items
109
+ @items ||= @select.call
110
+ end
111
+
112
+ # Checks to see if there's a page before this one
113
+ def prev?
114
+ @number > 1
115
+ end
116
+
117
+ # Get previous page (if possible)
118
+ def prev
119
+ @pager.page(@number - 1) if prev?
120
+ end
121
+
122
+ # Checks to see if there's a page after this one
123
+ def next?
124
+ @number < @pager.number_of_pages
125
+ end
126
+
127
+ # Get next page (if possible)
128
+ def next
129
+ @pager.page(@number + 1) if next?
130
+ end
131
+
132
+ # The "item number" of the first item on this page
133
+ def first_item_number
134
+ 1 + @offset
135
+ end
136
+
137
+ # The "item number" of the last item on this page
138
+ def last_item_number
139
+ if next?
140
+ @offset + @pager.per_page
141
+ else
142
+ @pager.count
143
+ end
144
+ end
145
+
146
+ def ==(other) #:nodoc:
147
+ @pager == other.pager && self.number == other.number
148
+ end
149
+
150
+ def each(&block)
151
+ items.each(&block)
152
+ end
153
+
154
+ def method_missing(meth, *args, &block) #:nodoc:
155
+ if @pager.respond_to?(meth)
156
+ @pager.__send__(meth, *args, &block)
157
+ else
158
+ super
159
+ end
160
+ end
161
+
162
+ end
163
+
164
+ end # class Paginator
165
+ end # module Webby
@@ -0,0 +1,27 @@
1
+
2
+ task :configure_basepath do
3
+ Webby.site.base = ENV['BASE'] if ENV.has_key?('BASE')
4
+ end
5
+
6
+ desc "Build the website"
7
+ task :build => :configure_basepath do |t|
8
+ Webby::Builder.run
9
+ end
10
+
11
+ desc "Rebuild the website"
12
+ task :rebuild => :configure_basepath do |t|
13
+ Webby::Builder.run :rebuild => true
14
+ end
15
+
16
+ desc "Continuously build the website"
17
+ task :autobuild => :configure_basepath do |t|
18
+ Webby::AutoBuilder.run
19
+ end
20
+
21
+ desc "Delete the website"
22
+ task :clobber do |t|
23
+ rm_rf Webby.site.output_dir
24
+ mkdir Webby.site.output_dir
25
+ end
26
+
27
+ # EOF
@@ -0,0 +1,25 @@
1
+
2
+ namespace :create do
3
+
4
+ FileList["#{Webby.site.template_dir}/*"].each do |template|
5
+ next unless test(?f, template)
6
+ name = template.pathmap '%n'
7
+
8
+ # if the file is a partial template
9
+ name = $1 if name =~ %r/^_(.*)/
10
+
11
+ desc "Create a new #{name}"
12
+ task name do |t|
13
+ page, title, dir = Webby::Builder.new_page_info
14
+ page = Webby::Builder.create(page, :from => template,
15
+ :locals => {:title => title, :directory => dir})
16
+ unless ::Webby.editor.nil?
17
+ args = [::Webby.editor.split, page].flatten
18
+ exec(*args)
19
+ end
20
+ end
21
+ end # each
22
+
23
+ end # namespace :create
24
+
25
+ # EOF
@@ -0,0 +1,22 @@
1
+
2
+ require 'rake/contrib/sshpublisher'
3
+
4
+ namespace :deploy do
5
+
6
+ desc 'Deploy to the server using rsync'
7
+ task :rsync do
8
+ cmd = "rsync #{SITE.rsync_args.join(' ')} "
9
+ cmd << "#{SITE.output_dir}/ #{SITE.user}@#{SITE.host}:#{SITE.remote_dir}"
10
+ sh cmd
11
+ end
12
+
13
+ desc 'Deploy to the server using ssh'
14
+ task :ssh do
15
+ Rake::SshDirPublisher.new(
16
+ "#{SITE.user}@#{SITE.host}", SITE.remote_dir, SITE.output_dir
17
+ ).upload
18
+ end
19
+
20
+ end # deploy
21
+
22
+ # EOF
@@ -0,0 +1,16 @@
1
+
2
+ unless WINDOWS
3
+
4
+ task :growl do
5
+ growl = Logging::Appenders::Growl.new('growl',
6
+ :layout => Logging::Layouts::Pattern.new(:pattern => "%5l - Webby\000%m"),
7
+ :coalesce => true,
8
+ :separator => "\000"
9
+ )
10
+ Logging::Logger['Webby'].add_appenders(growl)
11
+ Logging::Logger['Webby::Journal'].add_appenders(growl)
12
+ end
13
+
14
+ end # unless WINDOWS
15
+
16
+ # EOF
@@ -0,0 +1,19 @@
1
+
2
+ namespace :validate do
3
+
4
+ desc 'Validate hyperlinks (exclude external sites)'
5
+ task :internal => :build do
6
+ Webby::LinkValidator.validate(:external => false)
7
+ end
8
+
9
+ desc 'Validate hyperlinks (include external sites)'
10
+ task :external => :build do
11
+ Webby::LinkValidator.validate(:external => true)
12
+ end
13
+
14
+ end # validate
15
+
16
+ desc 'Alias to validate:internal'
17
+ task :validate => 'validate:internal'
18
+
19
+ # EOF
data/lib/webby.rb ADDED
@@ -0,0 +1,232 @@
1
+ # Equivalent to a header guard in C/C++
2
+ # Used to prevent the spec helper from being loaded more than once
3
+ unless defined? ::Webby
4
+
5
+ require 'rubygems'
6
+ require 'logging'
7
+ require 'ostruct'
8
+ require 'date'
9
+
10
+ module Webby
11
+
12
+ # :stopdoc:
13
+ VERSION = '0.9.4.1' # :nodoc:
14
+ LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
15
+ PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
16
+ YAML_SEP = '---'
17
+ # :startdoc:
18
+
19
+ class Error < StandardError; end # :nodoc:
20
+
21
+ # call-seq:
22
+ # Webby.site => struct
23
+ #
24
+ # Returns a struct containing the configuration parameters for the
25
+ # Webby site. These defaults should be overridden as needed in the
26
+ # site specific Rakefile.
27
+ #
28
+ def self.site
29
+ return @site if defined? @site
30
+ @site = OpenStruct.new(
31
+ :output_dir => 'output',
32
+ :content_dir => 'content',
33
+ :layout_dir => 'layouts',
34
+ :template_dir => 'templates',
35
+ :exclude => %w(tmp$ bak$ ~$ CVS \.svn),
36
+ :page_defaults => {
37
+ 'layout' => 'default'
38
+ },
39
+ :find_by => 'title',
40
+ :base => nil,
41
+ :create_mode => 'page',
42
+ :blog_dir => 'blog',
43
+ :tumblog_dir => 'tumblog',
44
+
45
+ # Items for running the embedded webserver
46
+ :use_web_server => true,
47
+ :web_port => 4331,
48
+
49
+ # Items used to deploy the website
50
+ :user => ENV['USER'] || ENV['USERNAME'],
51
+ :host => 'example.com',
52
+ :remote_dir => '/not/a/valid/dir',
53
+ :rsync_args => %w(-av),
54
+
55
+ # Global options for HAML and SASS
56
+ :haml_options => {},
57
+ :sass_options => {},
58
+
59
+ # Options passed to the 'tidy' program when the tidy filter is used
60
+ :tidy_options => '-indent -wrap 80',
61
+
62
+ # List of valid URIs (these automatically pass validation)
63
+ :valid_uris => [],
64
+
65
+ # Options for coderay processing
66
+ :coderay => {
67
+ :lang => :ruby,
68
+ :line_numbers => nil,
69
+ :line_number_start => 1,
70
+ :bold_every => 10,
71
+ :tab_width => 8
72
+ },
73
+
74
+ # Options for graphviz processing
75
+ :graphviz => {
76
+ :path => nil,
77
+ :cmd => 'dot',
78
+ :type => 'png'
79
+ },
80
+
81
+ # Options for tex2img processing
82
+ :tex2img => {
83
+ :path => nil,
84
+ :type => 'png',
85
+ :bg => 'white',
86
+ :fg => 'black',
87
+ :resolution => '150x150'
88
+ },
89
+
90
+ # Options for ultraviolet syntax highlighting
91
+ :uv => {
92
+ :lang => 'ruby',
93
+ :line_numbers => false,
94
+ :theme => 'mac_classic'
95
+ },
96
+
97
+ # XPath identifiers used by the basepath filter
98
+ :xpaths => %w(
99
+ /html/head//base[@href]
100
+ /html/head//link[@href]
101
+ //script[@src]
102
+ /html/body[@background]
103
+ /html/body//a[@href]
104
+ /html/body//object[@data]
105
+ /html/body//img[@src]
106
+ /html/body//area[@href]
107
+ /html/body//form[@action]
108
+ /html/body//input[@src]
109
+ )
110
+ # other possible XPaths to include for base path substitution
111
+ # /html/body//object[@usemap]
112
+ # /html/body//img[@usemap]
113
+ # /html/body//input[@usemap]
114
+ )
115
+ end
116
+
117
+ # call-seq
118
+ # Webby.exclude => regexp
119
+ #
120
+ # Returns a regular expression used to exclude resources from the content
121
+ # directory from being processed by Webby. This same regular expression is
122
+ # also used to exclude layouts.
123
+ #
124
+ def self.exclude
125
+ @exclude ||= Regexp.new(site.exclude.join('|'))
126
+ end
127
+
128
+ # call-seq:
129
+ # Webby.editor => string or nil
130
+ #
131
+ # Returns the default editor to use when creating new pages. This editor
132
+ # will be spawned to allow the user to edit the newly created page.
133
+ #
134
+ def self.editor
135
+ return @editor if defined? @editor
136
+
137
+ @editor = if ENV['EDITOR'].nil? or ENV['EDITOR'].empty? then nil
138
+ else ENV['EDITOR'] end
139
+ end
140
+
141
+ # call-seq:
142
+ # cairn => filename
143
+ #
144
+ # The Webby _cairn_ file is used to mark the last time the content was
145
+ # built into the output directory. It is an empty file; only the
146
+ # modification time of the file is important.
147
+ #
148
+ def self.cairn
149
+ @cairn ||= ::File.join(site.output_dir, '.cairn')
150
+ end
151
+
152
+ # Returns the library path for Webby. If any arguments are given,
153
+ # they will be joined to the end of the libray path using
154
+ # <tt>File.join</tt>.
155
+ #
156
+ def self.libpath( *args )
157
+ args.empty? ? LIBPATH : ::File.join(LIBPATH, args.flatten)
158
+ end
159
+
160
+ # Returns the path for Webby. If any arguments are given,
161
+ # they will be joined to the end of the path using
162
+ # <tt>File.join</tt>.
163
+ #
164
+ def self.path( *args )
165
+ args.empty? ? PATH : ::File.join(PATH, args.flatten)
166
+ end
167
+
168
+ # call-seq:
169
+ # Webby.require_all_libs_relative_to( filename, directory = nil )
170
+ #
171
+ # Utility method used to rquire all files ending in .rb that lie in the
172
+ # directory below this file that has the same name as the filename passed
173
+ # in. Optionally, a specific _directory_ name can be passed in such that
174
+ # the _filename_ does not have to be equivalent to the directory.
175
+ #
176
+ def self.require_all_libs_relative_to( fname, dir = nil )
177
+ dir ||= ::File.basename(fname, '.*')
178
+ search_me = ::File.expand_path(
179
+ ::File.join(::File.dirname(fname), dir, '*.rb'))
180
+
181
+ Dir.glob(search_me).sort.each {|rb| require rb}
182
+ end
183
+
184
+ # Prints a deprecation warning using the logger. The message states that
185
+ # the given method is being deprecated. An optional message can be give to
186
+ # -- somthing nice and fuzzy about a new method or why this one has to go
187
+ # away; sniff, we'll miss you little buddy.
188
+ #
189
+ def self.deprecated( method, message = nil )
190
+ msg = "'#{method}' has been deprecated"
191
+ msg << "\n\t#{message}" unless message.nil?
192
+ Logging::Logger['Webby'].warn msg
193
+ end
194
+
195
+ # Scan the <code>layouts/</code> folder and the <code>content/</code>
196
+ # folder and create a new Resource object for each file found there.
197
+ #
198
+ def self.load_files
199
+ ::Find.find(site.layout_dir, site.content_dir) do |path|
200
+ next unless test ?f, path
201
+ next if path =~ ::Webby.exclude
202
+ Resources.new path
203
+ end
204
+ end
205
+
206
+ end # module Webby
207
+
208
+
209
+ # call-seq:
210
+ # try_require( library, gemname = nil ) => true or false
211
+ #
212
+ # Try to laod the given _library_ using the built-in require, but do not
213
+ # raise a LoadError if unsuccessful. Returns +true+ if the _library_ was
214
+ # successfully loaded; returns +false+ otherwise.
215
+ #
216
+ # If a _gemname_ is given, then the "gem gemname" command will be called
217
+ # before the library is loaded.
218
+ #
219
+ def try_require( lib, gemname = nil )
220
+ gem gemname unless gemname.nil?
221
+ require lib
222
+ true
223
+ rescue LoadError
224
+ false
225
+ end
226
+
227
+ Webby.require_all_libs_relative_to(__FILE__, ::File.join(%w[webby core_ext]))
228
+ Webby.require_all_libs_relative_to(__FILE__)
229
+
230
+ end # unless defined?
231
+
232
+ # EOF