Method: YARD::Templates::Helpers::HtmlHelper#charset

Defined in:
lib/yard/templates/helpers/html_helper.rb

#charsetString

Returns the current character set. The default value can be overridden by setting the LANG environment variable or by overriding this method. In Ruby 1.9 you can also modify this value by setting Encoding.default_external.

Returns:

  • (String)

    the current character set

Since:

  • 0.5.4


467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
# File 'lib/yard/templates/helpers/html_helper.rb', line 467

def charset
  if @file && RUBY19
    lang = @file.contents.encoding.to_s
  else
    return 'utf-8' unless RUBY19 || lang = ENV['LANG']
    if RUBY19
      lang = ::Encoding.default_external.name.downcase
    else
      lang = lang.downcase.split('.').last
    end
  end
  case lang
  when "ascii-8bit", "us-ascii", "ascii-7bit"; 'iso-8859-1'
  when "utf8"; 'utf-8'
  else; lang
  end
end