Sha256: 3b917b78beecdb1647587f3ef7b4a91efb8e24181c781feb6299815b69f6b297

Contents?: true

Size: 1.61 KB

Versions: 3

Compression:

Stored size: 1.61 KB

Contents

module Jekyll
  module Utils
    # https://github.com/jekyll/jekyll/blob/master/lib/jekyll/utils.rb

    # Slugify a filename or title.
    #
    # string - the filename or title to slugify
    # mode - how string is slugified
    #
    # When mode is "none", return the given string in lowercase.
    #
    # When mode is "raw", return the given string in lowercase,
    # with every sequence of spaces characters replaced with a hyphen.
    #
    # When mode is "default" or nil, non-alphabetic characters are
    # replaced with a hyphen too.
    #
    # When mode is "pretty", some non-alphabetic characters (._~!$&'()+,;=@)
    # are not replaced with hyphen.
    #
    # Examples:
    #   slugify("The _config.yml file")
    #   # => "the-config-yml-file"
    #
    #   slugify("The _config.yml file", "pretty")
    #   # => "the-_config.yml-file"
    #
    # Returns the slugified string.

    def slugify(string, mode=nil, delimiter="_")
      mode ||= 'default'
      return nil if string.nil?
      return string.downcase unless SLUGIFY_MODES.include?(mode)

      # Replace each character sequence with a hyphen
      re = case mode
      when 'raw'
        SLUGIFY_RAW_REGEXP
      when 'default'
        SLUGIFY_DEFAULT_REGEXP
      when 'pretty'
        # "._~!$&'()+,;=@" is human readable (not URI-escaped) in URL
        # and is allowed in both extN and NTFS.
        SLUGIFY_PRETTY_REGEXP
      end

      string.
        # Strip according to the mode
        gsub(re, delimiter).
        # Remove leading/trailing hyphen
        gsub(/^#{delimiter}|#{delimiter}$/i, '').
        # Downcase
        downcase
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
jekyll-slugify_underscore-0.0.3 lib/jekyll/slugify_underscore.rb
jekyll-slugify_underscore-0.0.2 lib/jekyll/slugify_underscore.rb
jekyll-slugify_underscore-0.0.1 lib/jekyll/slugify_underscore.rb