webby 0.9.3-x86-mswin32
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.
- data/History.txt +206 -0
- data/Manifest.txt +228 -0
- data/README.txt +92 -0
- data/Rakefile +49 -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 +49 -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/License.txt +21 -0
- data/examples/website/content/css/blueprint/Readme.txt +100 -0
- data/examples/website/content/css/blueprint/compressed/print.css +76 -0
- data/examples/website/content/css/blueprint/compressed/screen.css +696 -0
- data/examples/website/content/css/blueprint/lib/forms.css +45 -0
- data/examples/website/content/css/blueprint/lib/grid.css +193 -0
- data/examples/website/content/css/blueprint/lib/grid.png +0 -0
- data/examples/website/content/css/blueprint/lib/ie.css +30 -0
- data/examples/website/content/css/blueprint/lib/reset.css +39 -0
- data/examples/website/content/css/blueprint/lib/typography.css +116 -0
- data/examples/website/content/css/blueprint/plugins/buttons/Readme +31 -0
- data/examples/website/content/css/blueprint/plugins/buttons/buttons.css +97 -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/css-classes/Readme +14 -0
- data/examples/website/content/css/blueprint/plugins/css-classes/css-classes.css +24 -0
- data/examples/website/content/css/blueprint/plugins/fancy-type/Readme +22 -0
- data/examples/website/content/css/blueprint/plugins/fancy-type/fancy-type-compressed.css +5 -0
- data/examples/website/content/css/blueprint/plugins/fancy-type/fancy-type.css +74 -0
- data/examples/website/content/css/blueprint/print.css +68 -0
- data/examples/website/content/css/blueprint/screen.css +22 -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 +58 -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.rb +221 -0
- data/lib/webby/apps.rb +12 -0
- data/lib/webby/apps/generator.rb +276 -0
- data/lib/webby/apps/main.rb +255 -0
- data/lib/webby/auto_builder.rb +157 -0
- data/lib/webby/builder.rb +180 -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.rb +83 -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/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/helpers.rb +30 -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/journal.rb +126 -0
- data/lib/webby/link_validator.rb +152 -0
- data/lib/webby/renderer.rb +386 -0
- data/lib/webby/resources.rb +136 -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/stelan/mktemp.rb +135 -0
- data/lib/webby/stelan/paginator.rb +165 -0
- data/lib/webby/stelan/spawner.rb +339 -0
- data/lib/webby/tasks/build.rake +27 -0
- data/lib/webby/tasks/create.rake +22 -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/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/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 +51 -0
- data/spec/webby/apps/generator_spec.rb +116 -0
- data/spec/webby/apps/main_spec.rb +88 -0
- data/spec/webby/filters/basepath_spec.rb +167 -0
- data/spec/webby/filters/outline_spec.rb +92 -0
- data/spec/webby/filters/textile_spec.rb +20 -0
- data/spec/webby/helpers/capture_helper_spec.rb +56 -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/ann.rake +81 -0
- data/tasks/bones.rake +21 -0
- data/tasks/gem.rake +187 -0
- data/tasks/git.rake +41 -0
- data/tasks/manifest.rake +48 -0
- data/tasks/notes.rake +28 -0
- data/tasks/post_load.rake +39 -0
- data/tasks/rdoc.rake +51 -0
- data/tasks/rubyforge.rake +55 -0
- data/tasks/setup.rb +268 -0
- data/tasks/spec.rake +55 -0
- data/tasks/website.rake +38 -0
- metadata +365 -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,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
|