Sha256: 9acf4402d35a3ad29b950b1bf405edae806a42b6b6fa631bbea73e4f57308fd8

Contents?: true

Size: 1.05 KB

Versions: 18

Compression:

Stored size: 1.05 KB

Contents

module Plate
  # Includes basic helpers for managing URLs within your site.
  module URLHelper  
    # replace all relative links within the given content block to absolute
    # links containing the base url for this site.
    #
    # This is useful in creating RSS and/or Atom feeds that you'd like to 
    # contain links back to your site.
    #
    # href or src values that don't start with a slash are left intact.
    #
    # @example
    #     <a href="/posts/one"><img src="/images/sample.jpg"></a>
    #
    #     <!-- turns into: -->
    #
    #     <a href="http://example.com/posts/one"><img src="http://example.com/images/sample.jpg"></a>
    def absolutize_paths(content)
      content.gsub(Regexp.new("(src|href)=(\"|')/"), "\\1=\\2#{site.url}/")
    end
    alias_method :a, :absolutize_paths
  
    # Cleans up a string to make it URl-friendly, removing all special 
    # characters, spaces, and sanitizing to a dashed, lowercase string.
    def sanitize_slug(str)
      self.site.sanitize_slug(str)
    end
    alias_method :s, :sanitize_slug
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
plate-0.7.8 lib/plate/helpers/url_helper.rb
plate-0.7.7 lib/plate/helpers/url_helper.rb
plate-0.7.6 lib/plate/helpers/url_helper.rb
plate-0.7.5 lib/plate/helpers/url_helper.rb
plate-0.7.4 lib/plate/helpers/url_helper.rb
plate-0.7.3 lib/plate/helpers/url_helper.rb
plate-0.7.2 lib/plate/helpers/url_helper.rb
plate-0.7.1 lib/plate/helpers/url_helper.rb
plate-0.7.0 lib/plate/helpers/url_helper.rb
plate-0.7.0.pre5 lib/plate/helpers/url_helper.rb
plate-0.7.0.pre4 lib/plate/helpers/url_helper.rb
plate-0.7.0.pre3 lib/plate/helpers/url_helper.rb
plate-0.7.0.pre2 lib/plate/helpers/url_helper.rb
plate-0.7.0.pre lib/plate/helpers/url_helper.rb
plate-0.6.3 lib/plate/helpers/url_helper.rb
plate-0.6.2 lib/plate/helpers/url_helper.rb
plate-0.6.1 lib/plate/helpers/url_helper.rb
plate-0.6.0 lib/plate/helpers/url_helper.rb