Module: StaticMatic::Helpers::UrlHelper

### Home Classes Methods

### In Files

- lib/staticmatic/helpers/url_helper.rb

### Methods

- #link
- #link_to
- #urlify

### Files

- LICENSE

### Class/Module Index

Quicksearch

- StaticMatic
- StaticMatic::Base
- StaticMatic::BuildMixin
- StaticMatic::Configuration
- StaticMatic::Error
- StaticMatic::Helpers
- StaticMatic::Helpers::AssetsHelper
- StaticMatic::Helpers::CurrentPathHelper
- StaticMatic::Helpers::FormHelper
- StaticMatic::Helpers::RenderHelper
- StaticMatic::Helpers::TagHelper
- StaticMatic::Helpers::UrlHelper
- StaticMatic::HelpersMixin
- StaticMatic::RenderMixin
- StaticMatic::RescueMixin
- StaticMatic::Server
- StaticMatic::ServerMixin
- StaticMatic::SetupMixin
- StaticMatic::TemplateError
- Compass
- Compass::AppIntegration
- Compass::AppIntegration::Staticmatic
- Compass::AppIntegration::Staticmatic::ConfigurationDefaults
- Compass::AppIntegration::Staticmatic::Installer

No matching classes.

# StaticMatic::Helpers::UrlHelper

### Public Instance Methods

link(title, href = "", options = {}) click to toggle source

Generate an HTML link

If only the title is passed, it will automatically create a link from this value:

link('Test') -> <a href="test.html">Test</a>

    # File lib/staticmatic/helpers/url_helper.rb, line 13
    def link(title, href = "", options = {})
      if href.is_a?(Hash)
        options = href
        href = ""
      end

      if href.nil? || href.strip.length < 1
        path_prefix = ''
        if title.match(/^(\.\.?)?\//)
          # starts with relative path so strip it off and prepend it to the urlified title
          path_prefix_match = title.match(/^[^\s]*\//)
          path_prefix = path_prefix_match[0] if path_prefix_match
          title = title[path_prefix.length, title.length]
        end
        href = path_prefix + urlify(title) + ".html"
      end

      options[:href] = "#{current_page_relative_path(href)}#{href}"

      local_page = (options[:href].match(/^(\#|.+?\:)/) == nil)
      unless @staticmatic.configuration.use_extensions_for_page_links || !local_page
        options[:href].chomp!(".html")
        options[:href].chomp!("index") if options[:href][-5, 5] == 'index'
      end

      tag(:a, options) { title }
    end

Also aliased as: link_to
link_to(title, href = "", options = {}) click to toggle source
Alias for: link
urlify(string) click to toggle source

Generates a URL friendly string from the value passed:

"We love Haml" -> "we_love_haml" "Elf & Ham" -> "elf_and_ham" "Stephen's gem" -> "stephens_gem"

    # File lib/staticmatic/helpers/url_helper.rb, line 48
    def urlify(string)
      string.tr(" ", "_").
             sub("&", "and").
             sub("@", "at").
             tr("^A-Za-z0-9_", "").
             sub(/_{2,}/, "_").
             downcase
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.