Merge branch 'stable'

* stable:
  Change the versioning approach to use a module so it can be accessed from Haml.version or Sass.version.
This commit is contained in:
Chris Eppstein 2009-01-25 15:33:12 -08:00
commit e35f99a132
3 changed files with 61 additions and 44 deletions

View File

@ -1,6 +1,8 @@
dir = File.dirname(__FILE__)
$LOAD_PATH.unshift dir unless $LOAD_PATH.include?(dir)
require 'haml/version'
# = Haml (XHTML Abstraction Markup Language)
#
# Haml is a markup language
@ -1001,52 +1003,11 @@ $LOAD_PATH.unshift dir unless $LOAD_PATH.include?(dir)
# See also Whitespace Preservation, above.
#
module Haml
# Returns a hash representing the version of Haml.
# The :major, :minor, and :teeny keys have their respective numbers.
# The :string key contains a human-readable string representation of the version.
# If Haml is checked out from Git,
# the :rev key will have the revision hash.
def self.version
return @@version if defined?(@@version)
numbers = File.read(scope('VERSION')).strip.split('.').map { |n| n.to_i }
@@version = {
:major => numbers[0],
:minor => numbers[1],
:teeny => numbers[2]
}
@@version[:string] = [:major, :minor, :teeny].map { |comp| @@version[comp] }.compact.join('.')
if File.exists?(scope('REVISION'))
rev = File.read(scope('REVISION')).strip
rev = nil if rev !~ /^([a-f0-9]+|\(.*\))$/
end
if rev.nil? && File.exists?(scope('.git/HEAD'))
rev = File.read(scope('.git/HEAD')).strip
if rev =~ /^ref: (.*)$/
rev = File.read(scope(".git/#{$1}")).strip
end
end
if rev
@@version[:rev] = rev
unless rev[0] == ?(
@@version[:string] << "."
@@version[:string] << rev[0...7]
end
end
@@version
end
# Returns the path of file relative to the Haml root.
def self.scope(file) # :nodoc:
File.join(File.dirname(__FILE__), '..', file)
end
extend Haml::Version
# A string representing the version of Haml.
# A more fine-grained representation is generated by Haml.version.
# A more fine-grained representation is available from Haml.version.
VERSION = version[:string] unless defined?(Haml::VERSION)
# This method is called by init.rb,

47
lib/haml/version.rb Normal file
View File

@ -0,0 +1,47 @@
module Haml
module Version
# Returns a hash representing the version of Haml.
# The :major, :minor, and :teeny keys have their respective numbers.
# The :string key contains a human-readable string representation of the version.
# If Haml is checked out from Git,
# the :rev key will have the revision hash.
def version
return @@version if defined?(@@version)
numbers = File.read(scope('VERSION')).strip.split('.').map { |n| n.to_i }
@@version = {
:major => numbers[0],
:minor => numbers[1],
:teeny => numbers[2]
}
@@version[:string] = [:major, :minor, :teeny].map { |comp| @@version[comp] }.compact.join('.')
if File.exists?(scope('REVISION'))
rev = File.read(scope('REVISION')).strip
rev = nil if rev !~ /^([a-f0-9]+|\(.*\))$/
end
if rev.nil? && File.exists?(scope('.git/HEAD'))
rev = File.read(scope('.git/HEAD')).strip
if rev =~ /^ref: (.*)$/
rev = File.read(scope(".git/#{$1}")).strip
end
end
if rev
@@version[:rev] = rev
unless rev[0] == ?(
@@version[:string] << "."
@@version[:string] << rev[0...7]
end
end
@@version
end
# Returns the path of file relative to the Haml root.
def scope(file) # :nodoc:
File.expand_path File.join(File.dirname(__FILE__), '..', '..', file)
end
end
end

View File

@ -1,6 +1,8 @@
dir = File.dirname(__FILE__)
$LOAD_PATH.unshift dir unless $LOAD_PATH.include?(dir)
require 'haml/version'
# = Sass (Syntactically Awesome StyleSheets)
#
# Sass is a meta-language on top of CSS
@ -989,7 +991,14 @@ $LOAD_PATH.unshift dir unless $LOAD_PATH.include?(dir)
# This defaults to the working directory and, in Rails or Merb,
# whatever <tt>:template_location</tt> is.
#
module Sass; end
module Sass
extend Haml::Version
# A string representing the version of Sass.
# A more fine-grained representation is available from Sass.version.
VERSION = version[:string] unless defined?(Sass::VERSION)
end
require 'haml/util'
require 'sass/engine'