francois-webby 0.9.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +218 -0
- data/README.rdoc +92 -0
- data/Rakefile +62 -0
- data/bin/webby +41 -0
- data/bin/webby-gen +41 -0
- data/examples/blog/Sitefile +7 -0
- data/examples/blog/tasks/blog.rake +72 -0
- data/examples/blog/templates/atom_feed.erb +40 -0
- data/examples/blog/templates/blog/month.erb +22 -0
- data/examples/blog/templates/blog/post.erb +16 -0
- data/examples/blog/templates/blog/year.erb +22 -0
- data/examples/presentation/Sitefile +10 -0
- data/examples/presentation/content/css/uv/twilight.css +137 -0
- data/examples/presentation/content/presentation/_sample_code.txt +10 -0
- data/examples/presentation/content/presentation/index.txt +63 -0
- data/examples/presentation/content/presentation/s5/blank.gif +0 -0
- data/examples/presentation/content/presentation/s5/bodybg.gif +0 -0
- data/examples/presentation/content/presentation/s5/framing.css +23 -0
- data/examples/presentation/content/presentation/s5/iepngfix.htc +42 -0
- data/examples/presentation/content/presentation/s5/opera.css +7 -0
- data/examples/presentation/content/presentation/s5/outline.css +15 -0
- data/examples/presentation/content/presentation/s5/pretty.css +86 -0
- data/examples/presentation/content/presentation/s5/print.css +25 -0
- data/examples/presentation/content/presentation/s5/s5-core.css +9 -0
- data/examples/presentation/content/presentation/s5/slides.css +3 -0
- data/examples/presentation/content/presentation/s5/slides.js +553 -0
- data/examples/presentation/layouts/presentation.txt +43 -0
- data/examples/presentation/templates/_code_partial.erb +13 -0
- data/examples/presentation/templates/presentation.erb +40 -0
- data/examples/tumblog/Sitefile +9 -0
- data/examples/tumblog/content/css/tumblog.css +308 -0
- data/examples/tumblog/content/images/tumblog/permalink.gif +0 -0
- data/examples/tumblog/content/images/tumblog/rss.gif +0 -0
- data/examples/tumblog/content/tumblog/200806/the-noble-chicken/index.txt +12 -0
- data/examples/tumblog/content/tumblog/200807/historical-perspectives-on-the-classic-chicken-joke/index.txt +12 -0
- data/examples/tumblog/content/tumblog/200807/mad-city-chickens/index.txt +10 -0
- data/examples/tumblog/content/tumblog/200807/the-wisdom-of-the-dutch/index.txt +11 -0
- data/examples/tumblog/content/tumblog/200807/up-a-tree/index.txt +13 -0
- data/examples/tumblog/content/tumblog/index.txt +37 -0
- data/examples/tumblog/content/tumblog/rss.txt +37 -0
- data/examples/tumblog/layouts/tumblog/default.txt +44 -0
- data/examples/tumblog/layouts/tumblog/post.txt +15 -0
- data/examples/tumblog/lib/tumblog_helper.rb +32 -0
- data/examples/tumblog/tasks/tumblog.rake +30 -0
- data/examples/tumblog/templates/atom_feed.erb +40 -0
- data/examples/tumblog/templates/tumblog/conversation.erb +12 -0
- data/examples/tumblog/templates/tumblog/link.erb +10 -0
- data/examples/tumblog/templates/tumblog/photo.erb +13 -0
- data/examples/tumblog/templates/tumblog/post.erb +12 -0
- data/examples/tumblog/templates/tumblog/quote.erb +11 -0
- data/examples/webby/Sitefile +19 -0
- data/examples/webby/content/communicate/index.txt +28 -0
- data/examples/webby/content/css/background.gif +0 -0
- data/examples/webby/content/css/blueprint/print.css +76 -0
- data/examples/webby/content/css/blueprint/screen.css +696 -0
- data/examples/webby/content/css/coderay.css +96 -0
- data/examples/webby/content/css/site.css +196 -0
- data/examples/webby/content/css/uv/twilight.css +137 -0
- data/examples/webby/content/index.txt +37 -0
- data/examples/webby/content/learn/index.txt +28 -0
- data/examples/webby/content/reference/index.txt +204 -0
- data/examples/webby/content/release-notes/index.txt +21 -0
- data/examples/webby/content/release-notes/rel-0-9-0/index.txt +74 -0
- data/examples/webby/content/release-notes/rel-0-9-1/index.txt +93 -0
- data/examples/webby/content/release-notes/rel-0-9-2/index.txt +14 -0
- data/examples/webby/content/release-notes/rel-0-9-3/index.txt +47 -0
- data/examples/webby/content/robots.txt +6 -0
- data/examples/webby/content/script/jquery.corner.js +152 -0
- data/examples/webby/content/script/jquery.js +31 -0
- data/examples/webby/content/sitemap.txt +31 -0
- data/examples/webby/content/tips_and_tricks/index.txt +97 -0
- data/examples/webby/content/tutorial/index.txt +135 -0
- data/examples/webby/content/user-manual/index.txt +419 -0
- data/examples/webby/layouts/default.txt +49 -0
- data/examples/webby/templates/page.erb +10 -0
- data/examples/website/Sitefile +7 -0
- data/examples/website/content/css/blueprint/ie.css +26 -0
- data/examples/website/content/css/blueprint/plugins/buttons/icons/cross.png +0 -0
- data/examples/website/content/css/blueprint/plugins/buttons/icons/key.png +0 -0
- data/examples/website/content/css/blueprint/plugins/buttons/icons/tick.png +0 -0
- data/examples/website/content/css/blueprint/plugins/buttons/readme.txt +32 -0
- data/examples/website/content/css/blueprint/plugins/buttons/screen.css +97 -0
- data/examples/website/content/css/blueprint/plugins/fancy-type/readme.txt +14 -0
- data/examples/website/content/css/blueprint/plugins/fancy-type/screen.css +71 -0
- data/examples/website/content/css/blueprint/plugins/link-icons/icons/doc.png +0 -0
- data/examples/website/content/css/blueprint/plugins/link-icons/icons/email.png +0 -0
- data/examples/website/content/css/blueprint/plugins/link-icons/icons/external.png +0 -0
- data/examples/website/content/css/blueprint/plugins/link-icons/icons/feed.png +0 -0
- data/examples/website/content/css/blueprint/plugins/link-icons/icons/im.png +0 -0
- data/examples/website/content/css/blueprint/plugins/link-icons/icons/pdf.png +0 -0
- data/examples/website/content/css/blueprint/plugins/link-icons/icons/visited.png +0 -0
- data/examples/website/content/css/blueprint/plugins/link-icons/icons/xls.png +0 -0
- data/examples/website/content/css/blueprint/plugins/link-icons/readme.txt +18 -0
- data/examples/website/content/css/blueprint/plugins/link-icons/screen.css +40 -0
- data/examples/website/content/css/blueprint/plugins/rtl/readme.txt +10 -0
- data/examples/website/content/css/blueprint/plugins/rtl/screen.css +109 -0
- data/examples/website/content/css/blueprint/print.css +30 -0
- data/examples/website/content/css/blueprint/screen.css +251 -0
- data/examples/website/content/css/blueprint/src/forms.css +49 -0
- data/examples/website/content/css/blueprint/src/grid.css +212 -0
- data/examples/website/content/css/blueprint/src/grid.png +0 -0
- data/examples/website/content/css/blueprint/src/ie.css +59 -0
- data/examples/website/content/css/blueprint/src/print.css +85 -0
- data/examples/website/content/css/blueprint/src/reset.css +38 -0
- data/examples/website/content/css/blueprint/src/typography.css +105 -0
- data/examples/website/content/css/coderay.css +111 -0
- data/examples/website/content/css/site.css +67 -0
- data/examples/website/content/index.txt +19 -0
- data/examples/website/layouts/default.txt +61 -0
- data/examples/website/lib/breadcrumbs.rb +28 -0
- data/examples/website/templates/_partial.erb +10 -0
- data/examples/website/templates/page.erb +18 -0
- data/lib/webby/apps/generator.rb +276 -0
- data/lib/webby/apps/main.rb +258 -0
- data/lib/webby/apps.rb +12 -0
- data/lib/webby/auto_builder.rb +157 -0
- data/lib/webby/builder.rb +172 -0
- data/lib/webby/core_ext/enumerable.rb +11 -0
- data/lib/webby/core_ext/hash.rb +28 -0
- data/lib/webby/core_ext/kernel.rb +26 -0
- data/lib/webby/core_ext/string.rb +163 -0
- data/lib/webby/core_ext/time.rb +9 -0
- data/lib/webby/filters/basepath.rb +97 -0
- data/lib/webby/filters/erb.rb +9 -0
- data/lib/webby/filters/haml.rb +18 -0
- data/lib/webby/filters/markdown.rb +16 -0
- data/lib/webby/filters/maruku.rb +16 -0
- data/lib/webby/filters/outline.rb +309 -0
- data/lib/webby/filters/sass.rb +17 -0
- data/lib/webby/filters/slides.rb +56 -0
- data/lib/webby/filters/textile.rb +16 -0
- data/lib/webby/filters/tidy.rb +76 -0
- data/lib/webby/filters/wiki_words.rb +14 -0
- data/lib/webby/filters.rb +85 -0
- data/lib/webby/helpers/capture_helper.rb +141 -0
- data/lib/webby/helpers/coderay_helper.rb +69 -0
- data/lib/webby/helpers/graphviz_helper.rb +136 -0
- data/lib/webby/helpers/tag_helper.rb +65 -0
- data/lib/webby/helpers/tex_img_helper.rb +133 -0
- data/lib/webby/helpers/ultraviolet_helper.rb +63 -0
- data/lib/webby/helpers/url_helper.rb +241 -0
- data/lib/webby/helpers.rb +30 -0
- data/lib/webby/journal.rb +126 -0
- data/lib/webby/link_validator.rb +160 -0
- data/lib/webby/renderer.rb +389 -0
- data/lib/webby/resources/db.rb +251 -0
- data/lib/webby/resources/layout.rb +54 -0
- data/lib/webby/resources/meta_file.rb +211 -0
- data/lib/webby/resources/page.rb +81 -0
- data/lib/webby/resources/partial.rb +85 -0
- data/lib/webby/resources/resource.rb +201 -0
- data/lib/webby/resources/static.rb +36 -0
- data/lib/webby/resources.rb +137 -0
- data/lib/webby/stelan/mktemp.rb +135 -0
- data/lib/webby/stelan/paginator.rb +165 -0
- data/lib/webby/tasks/build.rake +27 -0
- data/lib/webby/tasks/create.rake +25 -0
- data/lib/webby/tasks/deploy.rake +22 -0
- data/lib/webby/tasks/growl.rake +16 -0
- data/lib/webby/tasks/validate.rake +19 -0
- data/lib/webby.rb +232 -0
- data/spec/core_ext/hash_spec.rb +47 -0
- data/spec/core_ext/string_spec.rb +110 -0
- data/spec/core_ext/time_spec.rb +19 -0
- data/spec/data/hooligans/bad_meta_data_1.txt +34 -0
- data/spec/data/hooligans/bad_meta_data_2.txt +34 -0
- data/spec/data/html/anchor.html +11 -0
- data/spec/data/html/external.html +10 -0
- data/spec/data/html/invalid-relative.html +10 -0
- data/spec/data/html/relative-anchor.html +10 -0
- data/spec/data/html/relative-invalid-anchor.html +10 -0
- data/spec/data/html/relative.html +10 -0
- data/spec/data/outline/basic.out +81 -0
- data/spec/data/outline/basic.txt +25 -0
- data/spec/data/outline/no_clobber.out +86 -0
- data/spec/data/outline/numbering.out +81 -0
- data/spec/data/outline/numbering_only.out +21 -0
- data/spec/data/outline/toc_range_1.out +66 -0
- data/spec/data/outline/toc_range_2.out +55 -0
- data/spec/data/outline/toc_style.out +81 -0
- data/spec/data/site/Sitefile +9 -0
- data/spec/data/site/content/_partial.txt +10 -0
- data/spec/data/site/content/css/coderay.css +111 -0
- data/spec/data/site/content/css/site.css +67 -0
- data/spec/data/site/content/css/tumblog.css +308 -0
- data/spec/data/site/content/images/tumblog/permalink.gif +0 -0
- data/spec/data/site/content/images/tumblog/rss.gif +0 -0
- data/spec/data/site/content/index.txt +19 -0
- data/spec/data/site/content/photos.txt +21 -0
- data/spec/data/site/content/tumblog/200806/the-noble-chicken/index.txt +12 -0
- data/spec/data/site/content/tumblog/200807/historical-perspectives-on-the-classic-chicken-joke/index.txt +12 -0
- data/spec/data/site/content/tumblog/200807/mad-city-chickens/index.txt +10 -0
- data/spec/data/site/content/tumblog/200807/the-wisdom-of-the-dutch/index.txt +11 -0
- data/spec/data/site/content/tumblog/200807/up-a-tree/index.txt +13 -0
- data/spec/data/site/content/tumblog/index.txt +37 -0
- data/spec/data/site/content/tumblog/rss.txt +37 -0
- data/spec/data/site/layouts/default.txt +58 -0
- data/spec/data/site/layouts/tumblog/default.txt +44 -0
- data/spec/data/site/layouts/tumblog/post.txt +15 -0
- data/spec/data/site/lib/breadcrumbs.rb +28 -0
- data/spec/data/site/lib/tumblog_helper.rb +32 -0
- data/spec/data/site/tasks/tumblog.rake +30 -0
- data/spec/data/site/templates/_partial.erb +10 -0
- data/spec/data/site/templates/atom_feed.erb +40 -0
- data/spec/data/site/templates/page.erb +18 -0
- data/spec/data/site/templates/presentation.erb +40 -0
- data/spec/data/site/templates/tumblog/conversation.erb +12 -0
- data/spec/data/site/templates/tumblog/link.erb +10 -0
- data/spec/data/site/templates/tumblog/photo.erb +13 -0
- data/spec/data/site/templates/tumblog/post.erb +12 -0
- data/spec/data/site/templates/tumblog/quote.erb +11 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +58 -0
- data/spec/webby/apps/generator_spec.rb +117 -0
- data/spec/webby/apps/main_spec.rb +88 -0
- data/spec/webby/filters/basepath_spec.rb +167 -0
- data/spec/webby/filters/maruku_spec.rb +31 -0
- data/spec/webby/filters/outline_spec.rb +92 -0
- data/spec/webby/filters/textile_spec.rb +31 -0
- data/spec/webby/helpers/capture_helper_spec.rb +56 -0
- data/spec/webby/link_validator_spec.rb +154 -0
- data/spec/webby/renderer_spec.rb +139 -0
- data/spec/webby/resources/db_spec.rb +250 -0
- data/spec/webby/resources/layout_spec.rb +83 -0
- data/spec/webby/resources/meta_file_spec.rb +171 -0
- data/spec/webby/resources/page_spec.rb +111 -0
- data/spec/webby/resources/partial_spec.rb +58 -0
- data/spec/webby/resources/resource_spec.rb +219 -0
- data/spec/webby/resources/static_spec.rb +49 -0
- data/spec/webby/resources_spec.rb +69 -0
- data/tasks/mswin32.rake +38 -0
- data/tasks/website.rake +37 -0
- metadata +372 -0
@@ -0,0 +1,81 @@
|
|
1
|
+
require Webby.libpath(*%w[webby resources resource])
|
2
|
+
|
3
|
+
module Webby::Resources
|
4
|
+
|
5
|
+
# A Page is a file in the content folder that contains YAML meta-data at
|
6
|
+
# the top of the file. Pages are processed by the Webby rendering engine
|
7
|
+
# and then inserted into the desired layout. The string resulting from
|
8
|
+
# processing and layout is then written to the output directory.
|
9
|
+
#
|
10
|
+
class Page < Resource
|
11
|
+
|
12
|
+
# call-seq:
|
13
|
+
# Resource.new( path )
|
14
|
+
#
|
15
|
+
# Creates a new page object from the full path to the page file.
|
16
|
+
#
|
17
|
+
def initialize( fn, meta_data = nil )
|
18
|
+
super(fn)
|
19
|
+
|
20
|
+
if meta_data.instance_of?(Hash)
|
21
|
+
@_meta_data = meta_data
|
22
|
+
else
|
23
|
+
@_meta_data = MetaFile.meta_data(@path)
|
24
|
+
@_meta_data ||= {}
|
25
|
+
end
|
26
|
+
@_meta_data = ::Webby.site.page_defaults.merge(@_meta_data)
|
27
|
+
@_meta_data.sanitize!
|
28
|
+
end
|
29
|
+
|
30
|
+
# call-seq:
|
31
|
+
# render => string
|
32
|
+
#
|
33
|
+
# This method is being deprecated. Please use the +Renderer#render+ method
|
34
|
+
# instead.
|
35
|
+
#
|
36
|
+
def render( renderer = nil )
|
37
|
+
Webby.deprecated "render", "it is being replaced by the Renderer#render() method"
|
38
|
+
renderer ||= ::Webby::Renderer.new(self)
|
39
|
+
renderer._render_page
|
40
|
+
end
|
41
|
+
|
42
|
+
# call-seq
|
43
|
+
# url => string or nil
|
44
|
+
#
|
45
|
+
# Returns a string suitable for use as a URL linking to this page. Nil
|
46
|
+
# is returned for layouts.
|
47
|
+
#
|
48
|
+
def url
|
49
|
+
return @url unless @url.nil?
|
50
|
+
|
51
|
+
@url = super
|
52
|
+
@url = File.dirname(@url) if filename == 'index'
|
53
|
+
@url
|
54
|
+
end
|
55
|
+
|
56
|
+
# call-seq:
|
57
|
+
# extension => string
|
58
|
+
#
|
59
|
+
# Returns the extension that will be appended to the output destination
|
60
|
+
# filename. The extension is determined by looking at the following:
|
61
|
+
#
|
62
|
+
# * this page's meta-data for an 'extension' property
|
63
|
+
# * the meta-data of this page's layout for an 'extension' property
|
64
|
+
# * the extension of this page file
|
65
|
+
#
|
66
|
+
def extension
|
67
|
+
return _meta_data['extension'] if _meta_data.has_key? 'extension'
|
68
|
+
|
69
|
+
if _meta_data.has_key? 'layout'
|
70
|
+
lyt = ::Webby::Resources.find_layout(_meta_data['layout'])
|
71
|
+
lyt_ext = lyt ? lyt.extension : nil
|
72
|
+
return lyt_ext if lyt_ext
|
73
|
+
end
|
74
|
+
|
75
|
+
ext
|
76
|
+
end
|
77
|
+
|
78
|
+
end # class Page
|
79
|
+
end # module Webby::Resources
|
80
|
+
|
81
|
+
# EOF
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require Webby.libpath(*%w[webby resources resource])
|
2
|
+
|
3
|
+
module Webby::Resources
|
4
|
+
|
5
|
+
# A Partial is a file in the content folder whose filename starts with an
|
6
|
+
# underscore "_" character. Partials contain text that can be included into
|
7
|
+
# other pages. Partials are not standalone pages, and they will never
|
8
|
+
# correspond directly to an output file.
|
9
|
+
#
|
10
|
+
# Partials can contain YAML meta-data at the top of the file. This
|
11
|
+
# information is only used to determine the filters to apply to the
|
12
|
+
# partial. If there is no meta-data, then the partial text is used "as is"
|
13
|
+
# without any processing by the Webby rendering engine.
|
14
|
+
#
|
15
|
+
class Partial < Resource
|
16
|
+
|
17
|
+
# call-seq:
|
18
|
+
# Partial.new( path )
|
19
|
+
#
|
20
|
+
# Creates a new Partial object given the full path to the partial file.
|
21
|
+
# Partial filenames start with an underscore (this is an enforced
|
22
|
+
# convention).
|
23
|
+
#
|
24
|
+
def initialize( fn )
|
25
|
+
super
|
26
|
+
|
27
|
+
@_meta_data = MetaFile.meta_data(@path)
|
28
|
+
@_meta_data ||= {}
|
29
|
+
@_meta_data.sanitize!
|
30
|
+
end
|
31
|
+
|
32
|
+
# call-seq:
|
33
|
+
# dirty? => true or false
|
34
|
+
#
|
35
|
+
# Returns +true+ if this resource is newer than its corresponding output
|
36
|
+
# product. The resource needs to be rendered (if a page or layout) or
|
37
|
+
# copied (if a static file) to the output directory.
|
38
|
+
#
|
39
|
+
def dirty?
|
40
|
+
return _meta_data['dirty'] if _meta_data.has_key? 'dirty'
|
41
|
+
|
42
|
+
# if the destination file does not exist, then we are dirty
|
43
|
+
return true unless test(?e, destination)
|
44
|
+
|
45
|
+
# if this file's mtime is larger than the destination file's
|
46
|
+
# mtime, then we are dirty
|
47
|
+
dirty = @mtime > ::File.mtime(destination)
|
48
|
+
return dirty if dirty
|
49
|
+
|
50
|
+
# if we got here, then we are not dirty
|
51
|
+
false
|
52
|
+
end
|
53
|
+
|
54
|
+
# call-seq:
|
55
|
+
# destination => string
|
56
|
+
#
|
57
|
+
# The output file destination for the partial. This is the ".cairn" file in
|
58
|
+
# the output folder. It is used to determine if the partial is newer than
|
59
|
+
# the build products.
|
60
|
+
#
|
61
|
+
def destination
|
62
|
+
::Webby.cairn
|
63
|
+
end
|
64
|
+
|
65
|
+
alias :extension :ext
|
66
|
+
|
67
|
+
# call-seq:
|
68
|
+
# url => nil
|
69
|
+
#
|
70
|
+
# Partials do not have a URL. This method will alwasy return +nil+.
|
71
|
+
#
|
72
|
+
def url
|
73
|
+
nil
|
74
|
+
end
|
75
|
+
|
76
|
+
# :stopdoc:
|
77
|
+
def _read
|
78
|
+
MetaFile.read(@path)
|
79
|
+
end
|
80
|
+
# :startdoc:
|
81
|
+
|
82
|
+
end # class Partial
|
83
|
+
end # module Webby::Resources
|
84
|
+
|
85
|
+
# EOF
|
@@ -0,0 +1,201 @@
|
|
1
|
+
unless defined? Webby::Resources::Resource
|
2
|
+
|
3
|
+
module Webby::Resources
|
4
|
+
|
5
|
+
# A Webby::Resource is any file that can be found in the content directory
|
6
|
+
# or in the layout directory. This class contains information about the
|
7
|
+
# resources available to Webby.
|
8
|
+
#
|
9
|
+
class Resource
|
10
|
+
|
11
|
+
instance_methods.each do |m|
|
12
|
+
undef_method(m) unless m =~ %r/\A__|\?$/ ||
|
13
|
+
m == 'class'
|
14
|
+
end
|
15
|
+
|
16
|
+
# The full path to the resource file
|
17
|
+
attr_reader :path
|
18
|
+
|
19
|
+
# The name of the file excluding the directory and extension
|
20
|
+
attr_reader :name
|
21
|
+
|
22
|
+
# The directory of the resource excluding the content directory
|
23
|
+
attr_reader :dir
|
24
|
+
|
25
|
+
# Extesion of the resource file
|
26
|
+
attr_reader :ext
|
27
|
+
|
28
|
+
# Resource file modification time
|
29
|
+
attr_reader :mtime
|
30
|
+
|
31
|
+
attr_reader :_meta_data #:nodoc:
|
32
|
+
|
33
|
+
# call-seq:
|
34
|
+
# Resource.new( filename ) => resource
|
35
|
+
#
|
36
|
+
# Creates a new resource object given the _filename_.
|
37
|
+
#
|
38
|
+
def initialize( fn )
|
39
|
+
@path = fn
|
40
|
+
@dir = ::Webby::Resources.dirname(@path)
|
41
|
+
@name = ::Webby::Resources.basename(@path)
|
42
|
+
@ext = ::Webby::Resources.extname(@path)
|
43
|
+
@mtime = ::File.mtime @path
|
44
|
+
|
45
|
+
@_meta_data = {}
|
46
|
+
self._reset
|
47
|
+
end
|
48
|
+
|
49
|
+
# call-seq:
|
50
|
+
# equal?( other ) => true or false
|
51
|
+
#
|
52
|
+
# Returns +true+ if the path of this resource is equivalent to the path of
|
53
|
+
# the _other_ resource. Returns +false+ if this is not the case.
|
54
|
+
#
|
55
|
+
def equal?( other )
|
56
|
+
return false unless other.kind_of? ::Webby::Resources::Resource
|
57
|
+
(self.destination == other.destination) && (self.path == other.path)
|
58
|
+
end
|
59
|
+
alias :== :equal?
|
60
|
+
alias :eql? :equal?
|
61
|
+
|
62
|
+
# call-seq:
|
63
|
+
# resource <=> other => -1, 0, +1, or nil
|
64
|
+
#
|
65
|
+
# Resource comparison operates on the full path of the resource objects
|
66
|
+
# and uses the standard String comparison operator. Returns +nil+ if
|
67
|
+
# _other_ is not a Resource instance.
|
68
|
+
#
|
69
|
+
def <=>( other )
|
70
|
+
return unless other.kind_of? ::Webby::Resources::Resource
|
71
|
+
self.destination <=> other.destination
|
72
|
+
end
|
73
|
+
|
74
|
+
# call-seq:
|
75
|
+
# resource[key] => value or nil
|
76
|
+
#
|
77
|
+
# Returns the value associated with the given meta-data key. Key is
|
78
|
+
# converted into a string.
|
79
|
+
#
|
80
|
+
def []( key )
|
81
|
+
_meta_data[key.to_s]
|
82
|
+
end
|
83
|
+
|
84
|
+
# call-seq:
|
85
|
+
# resource[key] = value
|
86
|
+
#
|
87
|
+
# Sets the given meta-data key to the value. Key is converted into a
|
88
|
+
# string.
|
89
|
+
#
|
90
|
+
def []=( key, value )
|
91
|
+
_meta_data[key.to_s] = value
|
92
|
+
end
|
93
|
+
|
94
|
+
# call-seq:
|
95
|
+
# method_missing( symbol [, *args, &block] ) => result
|
96
|
+
#
|
97
|
+
# Invoked by Ruby when a message is sent to the resource that it cannot
|
98
|
+
# handle. The default behavior is to convert _symbol_ to a string and
|
99
|
+
# search for that string in the resource's meta-data. If found, the
|
100
|
+
# meta-data item is returned; otherwise, +nil+ is returned.
|
101
|
+
#
|
102
|
+
def method_missing( name, *a, &b )
|
103
|
+
_meta_data[name.to_s]
|
104
|
+
end
|
105
|
+
|
106
|
+
# call-seq:
|
107
|
+
# dirty? => true or false
|
108
|
+
#
|
109
|
+
# Returns +true+ if this resource is newer than its corresponding output
|
110
|
+
# product. The resource needs to be rendered (if a page or layout) or
|
111
|
+
# copied (if a static file) to the output directory.
|
112
|
+
#
|
113
|
+
def dirty?
|
114
|
+
return _meta_data['dirty'] if _meta_data.has_key? 'dirty'
|
115
|
+
|
116
|
+
# if the destination file does not exist, then we are dirty
|
117
|
+
return true unless test(?e, destination)
|
118
|
+
|
119
|
+
# if this file's mtime is larger than the destination file's
|
120
|
+
# mtime, then we are dirty
|
121
|
+
dirty = @mtime > ::File.mtime(destination)
|
122
|
+
return dirty if dirty
|
123
|
+
|
124
|
+
# check to see if the layout is dirty, and if it is then we
|
125
|
+
# are dirty, too
|
126
|
+
if _meta_data.has_key? 'layout'
|
127
|
+
lyt = ::Webby::Resources.find_layout(_meta_data['layout'])
|
128
|
+
unless lyt.nil?
|
129
|
+
return true if lyt.dirty?
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
# if we got here, then we are not dirty
|
134
|
+
false
|
135
|
+
end
|
136
|
+
|
137
|
+
# The resource filename excluding path and extension. This will either be
|
138
|
+
# the name of the file or the 'filename' attribute from the meta-data if
|
139
|
+
# present.
|
140
|
+
#
|
141
|
+
def filename
|
142
|
+
return _meta_data['filename'] if _meta_data.has_key? 'filename'
|
143
|
+
name
|
144
|
+
end
|
145
|
+
|
146
|
+
# The resource file extension. This will either be the extension of the
|
147
|
+
# file or the 'extension' attribute from the meta-data if present.
|
148
|
+
#
|
149
|
+
def extension
|
150
|
+
return _meta_data['extension'] if _meta_data.has_key? 'extension'
|
151
|
+
ext
|
152
|
+
end
|
153
|
+
|
154
|
+
# The location of this resource in the directory structure. This directory
|
155
|
+
# does not include the content folder or the output folder.
|
156
|
+
#
|
157
|
+
def directory
|
158
|
+
return _meta_data['directory'] if _meta_data.has_key? 'directory'
|
159
|
+
dir
|
160
|
+
end
|
161
|
+
|
162
|
+
# Returns the path in the output directory where the resource will be
|
163
|
+
# generated. This path is used to determine if the resource is dirty
|
164
|
+
# and in need of generating.
|
165
|
+
#
|
166
|
+
def destination
|
167
|
+
return @destination unless @destination.nil?
|
168
|
+
|
169
|
+
@destination = ::File.join(::Webby.site.output_dir, directory, filename)
|
170
|
+
ext = extension
|
171
|
+
unless ext.nil? or ext.empty?
|
172
|
+
@destination << '.' << ext
|
173
|
+
end
|
174
|
+
@destination
|
175
|
+
end
|
176
|
+
|
177
|
+
# Returns a string suitable for use as a URL linking to this resource.
|
178
|
+
#
|
179
|
+
def url
|
180
|
+
return @url unless @url.nil?
|
181
|
+
@url = destination.sub(::Webby.site.output_dir, '')
|
182
|
+
end
|
183
|
+
|
184
|
+
# :stopdoc:
|
185
|
+
def _read
|
186
|
+
MetaFile.read(@path)
|
187
|
+
end
|
188
|
+
|
189
|
+
def _reset( meta_data = nil )
|
190
|
+
_meta_data.replace(meta_data) if meta_data.instance_of?(Hash)
|
191
|
+
@url = nil
|
192
|
+
@destination = nil
|
193
|
+
end
|
194
|
+
# :startdoc:
|
195
|
+
|
196
|
+
end # class Resource
|
197
|
+
end # module Webby::Resources
|
198
|
+
|
199
|
+
end # unless defined?
|
200
|
+
|
201
|
+
# EOF
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require Webby.libpath(*%w[webby resources resource])
|
2
|
+
|
3
|
+
module Webby::Resources
|
4
|
+
|
5
|
+
# A Static resource is any file in the content folder that does not
|
6
|
+
# contain YAML meta-data at the top of the file and does not start with
|
7
|
+
# and underscore "_" character (those are partials). Static resources will
|
8
|
+
# be copied as-is from the content directory to the output directory.
|
9
|
+
#
|
10
|
+
class Static < Resource
|
11
|
+
|
12
|
+
# Returns the contents of the file.
|
13
|
+
#
|
14
|
+
def render
|
15
|
+
Webby.deprecated "render", "it is being replaced by the Renderer#render() method"
|
16
|
+
self._read
|
17
|
+
end
|
18
|
+
|
19
|
+
# Returns +true+ if this static file is newer than its corresponding output
|
20
|
+
# product. The static file needs to be copied to the output directory.
|
21
|
+
#
|
22
|
+
def dirty?
|
23
|
+
return true unless test(?e, destination)
|
24
|
+
@mtime > ::File.mtime(destination)
|
25
|
+
end
|
26
|
+
|
27
|
+
# :stopdoc:
|
28
|
+
def _read
|
29
|
+
::File.read(path)
|
30
|
+
end
|
31
|
+
# :startdoc:
|
32
|
+
|
33
|
+
end # class Layout
|
34
|
+
end # module Webby::Resources
|
35
|
+
|
36
|
+
# EOF
|
@@ -0,0 +1,137 @@
|
|
1
|
+
module Webby::Resources
|
2
|
+
|
3
|
+
class << self
|
4
|
+
# Returns the pages hash object.
|
5
|
+
#
|
6
|
+
def pages
|
7
|
+
@pages ||= ::Webby::Resources::DB.new
|
8
|
+
end
|
9
|
+
|
10
|
+
# Returns the layouts hash object.
|
11
|
+
#
|
12
|
+
def layouts
|
13
|
+
@layouts ||= ::Webby::Resources::DB.new
|
14
|
+
end
|
15
|
+
|
16
|
+
# Returns the partials hash object.
|
17
|
+
#
|
18
|
+
def partials
|
19
|
+
@partials ||= ::Webby::Resources::DB.new
|
20
|
+
end
|
21
|
+
|
22
|
+
# Clear the contents of the +layouts+, +pages+ and +partials+ hash
|
23
|
+
# objects.
|
24
|
+
#
|
25
|
+
def clear
|
26
|
+
self.pages.clear
|
27
|
+
self.layouts.clear
|
28
|
+
self.partials.clear
|
29
|
+
end
|
30
|
+
|
31
|
+
# call-seq:
|
32
|
+
# Resources.new( filename )
|
33
|
+
#
|
34
|
+
#
|
35
|
+
def new( fn )
|
36
|
+
# normalize the path
|
37
|
+
fn = self.path(fn)
|
38
|
+
|
39
|
+
# see if we are dealing with a layout
|
40
|
+
if %r/\A#{::Webby.site.layout_dir}\//o =~ fn
|
41
|
+
r = ::Webby::Resources::Layout.new(fn)
|
42
|
+
self.layouts << r
|
43
|
+
return r
|
44
|
+
end
|
45
|
+
|
46
|
+
# see if we are dealing with a partial
|
47
|
+
filename = self.basename(fn)
|
48
|
+
if %r/\A_/o =~ filename
|
49
|
+
r = ::Webby::Resources::Partial.new(fn)
|
50
|
+
self.partials << r
|
51
|
+
return r
|
52
|
+
end
|
53
|
+
|
54
|
+
begin
|
55
|
+
fd = ::File.open(fn, 'r')
|
56
|
+
mf = MetaFile.new fd
|
57
|
+
|
58
|
+
# see if we are dealing with a static resource
|
59
|
+
unless mf.meta_data?
|
60
|
+
r = ::Webby::Resources::Static.new(fn)
|
61
|
+
self.pages << r
|
62
|
+
return r
|
63
|
+
end
|
64
|
+
|
65
|
+
# this is a renderable page
|
66
|
+
mf.each do |meta_data|
|
67
|
+
r = ::Webby::Resources::Page.new(fn, meta_data)
|
68
|
+
self.pages << r
|
69
|
+
r
|
70
|
+
end
|
71
|
+
rescue MetaFile::Error => err
|
72
|
+
logger.error "error loading file #{fn.inspect}"
|
73
|
+
logger.error err
|
74
|
+
ensure
|
75
|
+
fd.close if fd
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
# Returns a normalized path for the given filename.
|
80
|
+
#
|
81
|
+
def path( filename )
|
82
|
+
filename.sub(%r/\A(?:\.\/|\/)/o, '').freeze
|
83
|
+
end
|
84
|
+
|
85
|
+
# Returns the layout resource corresponding to the given _filename_ or
|
86
|
+
# +nil+ if no layout exists under that filename.
|
87
|
+
#
|
88
|
+
def find_layout( filename )
|
89
|
+
return unless filename
|
90
|
+
filename = filename.to_s
|
91
|
+
|
92
|
+
fn = self.basename(filename)
|
93
|
+
dir = ::File.dirname(filename)
|
94
|
+
dir = '.' == dir ? '' : dir
|
95
|
+
|
96
|
+
layouts.find(:filename => fn, :in_directory => dir)
|
97
|
+
|
98
|
+
rescue RuntimeError
|
99
|
+
raise Webby::Error, "could not find layout #{filename.inspect}"
|
100
|
+
end
|
101
|
+
|
102
|
+
# Returns the directory component of the _filename_ with the content
|
103
|
+
# directory removed from the beginning if it is present.
|
104
|
+
#
|
105
|
+
def dirname( filename )
|
106
|
+
rgxp = %r/\A(?:#{::Webby.site.content_dir}|#{::Webby.site.layout_dir})\//o
|
107
|
+
dirname = ::File.dirname(filename)
|
108
|
+
dirname << '/' if dirname.index(?/) == nil
|
109
|
+
dirname.sub(rgxp, '')
|
110
|
+
end
|
111
|
+
|
112
|
+
# Returns the last component of the _filename_ with any extension
|
113
|
+
# information removed.
|
114
|
+
#
|
115
|
+
def basename( filename )
|
116
|
+
::File.basename(filename, '.*')
|
117
|
+
end
|
118
|
+
|
119
|
+
# Returns the extension (the portion of file name in path after the
|
120
|
+
# period). This method excludes the period from the extension name.
|
121
|
+
#
|
122
|
+
def extname( filename )
|
123
|
+
::File.extname(filename).tr('.', '')
|
124
|
+
end
|
125
|
+
|
126
|
+
# :stopdoc:
|
127
|
+
def logger
|
128
|
+
@logger ||= ::Logging::Logger[self]
|
129
|
+
end
|
130
|
+
# :startdoc:
|
131
|
+
|
132
|
+
end # class << self
|
133
|
+
end # module Webby::Resources
|
134
|
+
|
135
|
+
Webby.require_all_libs_relative_to(__FILE__)
|
136
|
+
|
137
|
+
# EOF
|