Module: Haml::Version

Includes:
Util
Included in:
Haml, Sass
Defined in:
lib/haml/version.rb

Overview

Handles Haml version-reporting. Haml not only reports the standard three version numbers, but its Git revision hash as well, if it was installed from Git.

Constant Summary

Constants included from Util

Util::RUBY_VERSION

Instance Method Summary collapse

Methods included from Util

#assert_html_safe!, #av_template_class, #caller_info, #check_encoding, #def_static_method, #enum_with_index, #has?, #html_safe, #map_hash, #map_keys, #map_vals, #merge_adjacent_strings, #powerset, #rails_env, #rails_root, #rails_safe_buffer_class, #rails_xss_safe?, #restrict, #ruby1_8?, #scope, #silence_warnings, #static_method_name, #to_hash

Instance Method Details

#version{Symbol => String/Fixnum}

Returns a hash representing the version of Haml. The :major, :minor, and :teeny keys have their respective numbers as Fixnums. The :name key has the name of the version. The :string key contains a human-readable string representation of the version. The :number key is the major, minor, and teeny keys separated by periods. If Haml is checked out from Git, the :rev key will have the revision hash. For example:

{
  :string => "2.1.0.9616393",
  :rev    => "9616393b8924ef36639c7e82aa88a51a24d16949",
  :number => "2.1.0",
  :major  => 2, :minor => 1, :teeny => 0
}

Returns:

  • ({Symbol => String/Fixnum})

    The version hash



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/haml/version.rb', line 27

def version
  return @@version if defined?(@@version)

  numbers = File.read(scope('VERSION')).strip.split('.').map { |n| n.to_i }
  name = File.read(scope('VERSION_NAME')).strip
  @@version = {
    :major => numbers[0],
    :minor => numbers[1],
    :teeny => numbers[2],
    :name => name
  }
  @@version[:number] = [:major, :minor, :teeny].map { |comp| @@version[comp] }.compact.join('.')
  @@version[:string] = @@version[:number].dup

  if rev = revision_number
    @@version[:rev] = rev
    unless rev[0] == ?(
      @@version[:string] << "." << rev[0...7]
    end
  end

  @@version[:string] << " (#{name})"
  @@version
end