Webby::Resources

Public Class Methods

basename( filename ) click to toggle source

Returns the last component of the filename with any extension information removed.

# File lib/webby/resources.rb, line 115
def basename( filename )
  ::File.basename(filename, '.*')
end
clear() click to toggle source

Clear the contents of the layouts, pages and partials hash objects.

# File lib/webby/resources.rb, line 25
def clear
  self.pages.clear
  self.layouts.clear
  self.partials.clear
end
dirname( filename ) click to toggle source

Returns the directory component of the filename with the content directory removed from the beginning if it is present.

# File lib/webby/resources.rb, line 105
def dirname( filename )
  rgxp = /\A(?:#{::Webby.site.content_dir}|#{::Webby.site.layout_dir})\//
  dirname = ::File.dirname(filename)
  dirname << '/' if dirname.index(//) == nil
  dirname.sub(rgxp, '')
end
extname( filename ) click to toggle source

Returns the extension (the portion of file name in path after the period). This method excludes the period from the extension name.

# File lib/webby/resources.rb, line 122
def extname( filename )
  ::File.extname(filename).tr('.', '')
end
find_layout( filename ) click to toggle source

Returns the layout resource corresponding to the given filename or nil if no layout exists under that filename.

# 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() click to toggle source

Returns the layouts hash object.

# File lib/webby/resources.rb, line 12
def layouts
  @layouts ||= ::Webby::Resources::DB.new
end
new( filename ) click to toggle source
# 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 /\A#{::Webby.site.layout_dir}\// =~ 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 /\A_/ =~ 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.meta_data?
      r = ::Webby::Resources::Static.new(fn)
      self.pages << r
      return r
    end

    # this is a renderable page
    mf.each do |meta_data|
      r = ::Webby::Resources::Page.new(fn, meta_data)
      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() click to toggle source

Returns the pages hash object.

# File lib/webby/resources.rb, line 6
def pages
  @pages ||= ::Webby::Resources::DB.new
end
partials() click to toggle source

Returns the partials hash object.

# File lib/webby/resources.rb, line 18
def partials
  @partials ||= ::Webby::Resources::DB.new
end
path( filename ) click to toggle source

Returns a normalized path for the given filename.

# File lib/webby/resources.rb, line 81
def path( filename )
  filename.sub(/\A(?:\.\/|\/)/, '').freeze
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.