diff --git a/lib/haml.rb b/lib/haml.rb index 0e9c8b29..99d06426 100644 --- a/lib/haml.rb +++ b/lib/haml.rb @@ -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, diff --git a/lib/haml/version.rb b/lib/haml/version.rb new file mode 100644 index 00000000..163183f8 --- /dev/null +++ b/lib/haml/version.rb @@ -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 diff --git a/lib/sass.rb b/lib/sass.rb index 19e59b5d..4dc392e4 100644 --- a/lib/sass.rb +++ b/lib/sass.rb @@ -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 :template_location 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'