Class: Jekyll::URL

### Home Classes Methods

### In Files

- lib/jekyll/url.rb

### Parent

Object

### Methods

- ::new
- #generate_url
- #sanitize_url
- #to_s

### Files

- LICENSE

### Class/Module Index

Quicksearch

- Jekyll
- Jekyll::Command
- Jekyll::Commands
- Jekyll::Commands::Build
- Jekyll::Commands::Doctor
- Jekyll::Commands::New
- Jekyll::Commands::Serve
- Jekyll::Configuration
- Jekyll::Converter
- Jekyll::Converters
- Jekyll::Converters::Identity
- Jekyll::Converters::Markdown
- Jekyll::Converters::Markdown::KramdownParser
- Jekyll::Converters::Markdown::MarukuParser
- Jekyll::Converters::Markdown::RDiscountParser
- Jekyll::Converters::Markdown::RedcarpetParser
- Jekyll::Converters::Markdown::RedcarpetParser::CommonMethods
- Jekyll::Converters::Markdown::RedcarpetParser::WithPygments
- Jekyll::Converters::Markdown::RedcarpetParser::WithoutPygments
- Jekyll::Converters::Textile
- Jekyll::Convertible
- Jekyll::Deprecator
- Jekyll::Draft
- Jekyll::Excerpt
- Jekyll::FatalException
- Jekyll::Filters
- Jekyll::Generator
- Jekyll::Generators
- Jekyll::Generators::Pagination
- Jekyll::GistTag
- Jekyll::Layout
- Jekyll::Page
- Jekyll::Pager
- Jekyll::Plugin
- Jekyll::Post
- Jekyll::RelatedPosts
- Jekyll::Site
- Jekyll::Site::Cleaner
- Jekyll::StaticFile
- Jekyll::Stevenson
- Jekyll::Tags
- Jekyll::Tags::HighlightBlock
- Jekyll::Tags::IncludeTag
- Jekyll::Tags::PostComparer
- Jekyll::Tags::PostUrl
- Jekyll::URL
- Date
- Enumerable
- Hash
- Object

No matching classes.

# Jekyll::URL

### Public Class Methods

new(options) click to toggle source

options - One of :permalink or :template must be supplied.

    :template     - The String used as template for URL generation,
                    for example "/:path/:basename:output_ext", where
                    a placeholder is prefixed with a colon.
    :placeholders - A hash containing the placeholders which will be
                    replaced when used inside the template. E.g.
                    { "year" => Time.now.strftime("%Y") } would replace
                    the placeholder ":year" with the current year.
    :permalink    - If supplied, no URL will be generated from the
                    template. Instead, the given permalink will be
                    used as URL.

    # File lib/jekyll/url.rb, line 24
    def initialize(options)
      @template = options[:template]
      @placeholders = options[:placeholders] || {}
      @permalink = options[:permalink]

      if (@template || @permalink).nil?
        raise ArgumentError, "One of :template or :permalink must be supplied."
      end
    end

### Public Instance Methods

generate_url() click to toggle source

Internal: Generate the URL by replacing all placeholders with their respective values

Returns the unsanitizied String URL

    # File lib/jekyll/url.rb, line 45
    def generate_url
      @placeholders.inject(@template) do |result, token|
        result.gsub(/:#{token.first}/, token.last)
      end
    end

sanitize_url(in_url) click to toggle source

Returns a sanitized String URL

    # File lib/jekyll/url.rb, line 52
    def sanitize_url(in_url)
      # Remove all double slashes
      url = in_url.gsub(/\/\//, "/")

      # Remove every URL segment that consists solely of dots
      url = url.split('/').reject{ |part| part =~ /^\.+$/ }.join('/')

      # Append a trailing slash to the URL if the unsanitized URL had one
      url += "/" if in_url =~ /\/$/

      # Always add a leading slash
      url.gsub!(/\A([^\/])/, '/\1')
      url
    end

to_s() click to toggle source

The generated relative URL of the resource

Returns the String URL

    # File lib/jekyll/url.rb, line 37
    def to_s
      sanitize_url(@permalink || generate_url)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.