Module: Webby::Resources
- Defined in:
- lib/webby/resources.rb,
lib/webby/resources/db.rb,
lib/webby/resources/page.rb,
lib/webby/resources/layout.rb,
lib/webby/resources/static.rb,
lib/webby/resources/partial.rb,
lib/webby/resources/resource.rb,
lib/webby/resources/meta_file.rb
Defined Under Namespace
Classes: DB, Layout, MetaFile, Page, Partial, Resource, Static
Class Method Summary collapse
-
.basename(filename) ⇒ Object
Returns the last component of the filename with any extension information removed.
-
.clear ⇒ Object
Clear the contents of the
layouts
,pages
andpartials
hash objects. -
.dirname(filename) ⇒ Object
Returns the directory component of the filename with the content directory removed from the beginning if it is present.
-
.extname(filename) ⇒ Object
Returns the extension (the portion of file name in path after the period).
-
.find_layout(filename) ⇒ Object
Returns the layout resource corresponding to the given filename or
nil
if no layout exists under that filename. -
.layouts ⇒ Object
Returns the layouts hash object.
-
.logger ⇒ Object
:stopdoc:.
-
.new(fn) ⇒ Object
call-seq: Resources.new( filename ).
-
.pages ⇒ Object
Returns the pages hash object.
-
.partials ⇒ Object
Returns the partials hash object.
-
.path(filename) ⇒ Object
Returns a normalized path for the given filename.
Class Method Details
.basename(filename) ⇒ Object
Returns the last component of the filename with any extension information removed.
115 116 117 |
# File 'lib/webby/resources.rb', line 115 def basename( filename ) ::File.basename(filename, '.*') end |
.clear ⇒ Object
Clear the contents of the layouts
, pages
and partials
hash objects.
25 26 27 28 29 |
# File 'lib/webby/resources.rb', line 25 def clear self.pages.clear self.layouts.clear self.partials.clear end |
.dirname(filename) ⇒ Object
Returns the directory component of the filename with the content directory removed from the beginning if it is present.
105 106 107 108 109 110 |
# File 'lib/webby/resources.rb', line 105 def dirname( filename ) rgxp = %r/\A(?:#{::Webby.site.content_dir}|#{::Webby.site.layout_dir})\//o dirname = ::File.dirname(filename) dirname << '/' if dirname.index(?/) == nil dirname.sub(rgxp, '') end |
.extname(filename) ⇒ Object
Returns the extension (the portion of file name in path after the period). This method excludes the period from the extension name.
122 123 124 |
# File 'lib/webby/resources.rb', line 122 def extname( filename ) ::File.extname(filename).tr('.', '') end |
.find_layout(filename) ⇒ Object
Returns the layout resource corresponding to the given filename or nil
if no layout exists under that filename.
88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/webby/resources.rb', line 88 def find_layout( filename ) return unless filename filename = filename.to_s fn = self.basename(filename) dir = ::File.dirname(filename) dir = '.' == dir ? '' : dir layouts.find(:filename => fn, :in_directory => dir) rescue RuntimeError raise Webby::Error, "could not find layout #{filename.inspect}" end |
.layouts ⇒ Object
Returns the layouts hash object.
12 13 14 |
# File 'lib/webby/resources.rb', line 12 def layouts @layouts ||= ::Webby::Resources::DB.new end |
.logger ⇒ Object
:stopdoc:
127 128 129 |
# File 'lib/webby/resources.rb', line 127 def logger @logger ||= ::Logging::Logger[self] end |
.new(fn) ⇒ Object
call-seq:
Resources.new( filename )
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/webby/resources.rb', line 35 def new( fn ) # normalize the path fn = self.path(fn) # see if we are dealing with a layout if %r/\A#{::Webby.site.layout_dir}\//o =~ fn r = ::Webby::Resources::Layout.new(fn) self.layouts << r return r end # see if we are dealing with a partial filename = self.basename(fn) if %r/\A_/o =~ filename r = ::Webby::Resources::Partial.new(fn) self.partials << r return r end begin fd = ::File.open(fn, 'r') mf = MetaFile.new fd # see if we are dealing with a static resource unless mf. r = ::Webby::Resources::Static.new(fn) self.pages << r return r end # this is a renderable page mf.each do || r = ::Webby::Resources::Page.new(fn, ) self.pages << r r end rescue MetaFile::Error => err logger.error "error loading file #{fn.inspect}" logger.error err ensure fd.close if fd end end |
.pages ⇒ Object
Returns the pages hash object.
6 7 8 |
# File 'lib/webby/resources.rb', line 6 def pages @pages ||= ::Webby::Resources::DB.new end |
.partials ⇒ Object
Returns the partials hash object.
18 19 20 |
# File 'lib/webby/resources.rb', line 18 def partials @partials ||= ::Webby::Resources::DB.new end |
.path(filename) ⇒ Object
Returns a normalized path for the given filename.
81 82 83 |
# File 'lib/webby/resources.rb', line 81 def path( filename ) filename.sub(%r/\A(?:\.\/|\/)/o, '').freeze end |