lib/webby/filters/basepath.rb
# call-seq:
#    filter    => html
#
# Process the original html document passed to the filter when it was
# created. The document will be scanned and the basepath for certain
# elements will be modified.
#
# For example, if a document contains the following line:
# 
#    <a href="/link/to/another/page.html">Page</a>
#
# and the user has requested for the base path to be some other directory
# on the webserver -- <tt>/some/other/directory</tt>. The result of the
# BasePath filter would be:
#
#     <a href="/some/other/directory/link/to/another/page.html">Page</a>
#
call-seq:
filter    => html

Process the original html document passed to the filter when it was
created. The document will be scanned and the basepath for certain
elements will be modified.

For example, if a document contains the following line.

Page

and the user has requested for the base path to be some other directory
on the webserver -- /some/other/directory. The result of the
BasePath filter would be.

Page
call - seq : filter = > html Process the original html document passed to the filter when it was created . The document will be scanned and the basepath for certain elements will be modified . For example if a document contains the following line . Page and the user has requested for the base path to be some other directory on the webserver -- / some / other / directory . The result of the BasePath filter would be . Page
def filter
    doc = @mode == :xml ? Hpricot.XML(@str) : Hpricot(@str)
    base_path = ::Webby.site.base
    attr_rgxp = %r/\[@(\w+)\]$/o
    sub_rgxp = %r/\A(?=\/)/o
    ::Webby.site.xpaths.each do |xpath|
      @attr_name = nil
      doc.search(xpath).each do |element|
        @attr_name ||= attr_rgxp.match(xpath)[1]
        a = element.get_attribute(@attr_name)
        element.set_attribute(@attr_name, a) if a.sub!(sub_rgxp, base_path)
      end
    end
    doc.to_html
  end
def filter doc = @mode == :xml ? Hpricot . XML ( @str ) : Hpricot ( @str ) base_path = :: Webby . site . base attr_rgxp = %r/ \[ @( \w +) \] $ /o sub_rgxp = %r/ \A (?= \/ ) /o :: Webby . site . xpaths . each do | xpath | @attr_name = nil doc . search ( xpath ) . each do | element | @attr_name ||= attr_rgxp . match ( xpath ) [ 1 ] a = element . get_attribute ( @attr_name ) element . set_attribute ( @attr_name , a ) if a . sub! ( sub_rgxp , base_path ) end end doc . to_html end
call-seq:
filter    => html
call - seq : filter = > html