Sha256: fc23113afdc3ae0428aca87db846a099246eb83b19fb996b058cfe0792b21cf3

Contents?: true

Size: 1 KB

Versions: 12

Compression:

Stored size: 1 KB

Contents

# encoding: utf-8

module Nanoc3::StringExtensions

  # Transforms string into an actual identifier
  #
  # @return [String] The identifier generated from the receiver
  def cleaned_identifier
    "/#{self}/".gsub(/^\/+|\/+$/, '/')
  end

  # Replaces Unicode characters with their ASCII decompositions if the
  # environment does not support Unicode.
  #
  # This method is not suited for general usage. If you need similar
  # functionality, consider using the Iconv library instead.
  #
  # @return [String] The decomposed string
  def make_compatible_with_env
    # Check whether environment supports Unicode
    # TODO this is ugly, and there most likely are better ways to do this
    is_unicode_supported = %w( LC_ALL LC_CTYPE LANG ).any? { |e| ENV[e] =~ /UTF/ }
    return self if is_unicode_supported

    # Decompose if necessary
    # TODO this decomposition is not generally usable
    self.gsub(/“|”/, '"').gsub(/‘|’/, '\'').gsub('…', '...')
  end

end

class String
  include Nanoc3::StringExtensions
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
nanoc3-3.1.9 lib/nanoc3/base/core_ext/string.rb
nanoc3-3.1.8 lib/nanoc3/base/core_ext/string.rb
nanoc3-3.1.7 lib/nanoc3/base/core_ext/string.rb
nanoc3-3.1.6 lib/nanoc3/base/core_ext/string.rb
nanoc3-3.1.5 lib/nanoc3/base/core_ext/string.rb
nanoc3-3.1.4 lib/nanoc3/base/core_ext/string.rb
nanoc3-3.1.3 lib/nanoc3/base/core_ext/string.rb
nanoc3-3.1.2 lib/nanoc3/base/core_ext/string.rb
nanoc3-3.1.1 lib/nanoc3/base/core_ext/string.rb
nanoc3-3.1.0 lib/nanoc3/base/core_ext/string.rb
nanoc3-3.1.0rc1 lib/nanoc3/base/core_ext/string.rb
nanoc3-3.1.0b2 lib/nanoc3/base/core_ext/string.rb