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::CHARSET_REGEXPS, Util::ENCODINGS_TO_CHECK, Util::RUBY_VERSION

Instance Method Summary collapse

Methods included from Util

#abstract, #ap_geq?, #ap_geq_3?, #assert_html_safe!, #av_template_class, #caller_info, #check_encoding, #check_haml_encoding, #check_sass_encoding, #def_static_method, #dump, #enum_cons, #enum_slice, #enum_with_index, #flatten, #haml_warn, #has?, #html_safe, #intersperse, #lcs, #load, #map_hash, #map_keys, #map_vals, #merge_adjacent_strings, #ord, #paths, #powerset, #rails_env, #rails_root, #rails_safe_buffer_class, #rails_xss_safe?, #restrict, #ruby1_8?, #ruby1_8_6?, #scope, #set_eql?, #set_hash, #silence_haml_warnings, #silence_warnings, #static_method_name, #strip_string_array, #substitute, #to_hash, #version_geq, #version_gt, #windows?

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
}

If a prerelease version of Haml is being used, the :string and :number fields will reflect the full version (e.g. "2.2.beta.1"), and the :teeny field will be -1. A :prerelease key will contain the name of the prerelease (e.g. "beta"), and a :prerelease_number key will contain the rerelease number. For example:

{
  :string => "3.0.beta.1",
  :number => "3.0.beta.1",
  :major => 3, :minor => 0, :teeny => -1,
  :prerelease => "beta",
  :prerelease_number => 1
}

Returns:

  • ({Symbol => String/Fixnum})

    The version hash



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/haml/version.rb', line 42

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

  numbers = File.read(scope('VERSION')).strip.split('.').
    map {|n| n =~ /^[0-9]+$/ ? n.to_i : n}
  name = File.read(scope('VERSION_NAME')).strip
  @@version = {
    :major => numbers[0],
    :minor => numbers[1],
    :teeny => numbers[2],
    :name => name
  }

  if numbers[3].is_a?(String)
    @@version[:teeny] = -1
    @@version[:prerelease] = numbers[3]
    @@version[:prerelease_number] = numbers[4]
  end

  @@version[:number] = numbers.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