From 0fae457e2f818ecd907ef28262878ecdf696c655 Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Thu, 10 Apr 2008 21:39:48 -0700 Subject: [PATCH] Add a method to the Haml module to scope file paths. --- lib/haml.rb | 7 ++++++- lib/haml/template.rb | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/haml.rb b/lib/haml.rb index 0f5f26bd..61840d68 100644 --- a/lib/haml.rb +++ b/lib/haml.rb @@ -884,7 +884,7 @@ module Haml def self.version return @@version if defined?(@@version) - numbers = File.read(File.dirname(__FILE__) + '/../VERSION').strip.split('.').map { |n| n.to_i } + numbers = File.read(scope('VERSION')).strip.split('.').map { |n| n.to_i } @@version = { :major => numbers[0], :minor => numbers[1], @@ -892,6 +892,11 @@ module Haml } end + # Returns the path of file relative to the Haml root. + def self.scope(file) # :nodoc: + File.join(File.dirname(__FILE__), '..', file) + end + # A string representing the version of Haml. # A more fine-grained representation is generated by Haml.version. VERSION = [:major, :minor, :teeny].map { |comp| version[comp] }.compact.join('.') unless defined?(Haml::VERSION) diff --git a/lib/haml/template.rb b/lib/haml/template.rb index 789ff0c1..0b5fa0c4 100644 --- a/lib/haml/template.rb +++ b/lib/haml/template.rb @@ -35,7 +35,7 @@ if defined?(RAILS_ROOT) # because the new init file is sufficiently flexible # to not need updating. rails_init_file = File.join(RAILS_ROOT, 'vendor', 'plugins', 'haml', 'init.rb') - haml_init_file = File.join(File.dirname(__FILE__), '..', '..', 'init.rb') + haml_init_file = Haml.scope('init.rb') if File.exists?(rails_init_file) require 'fileutils' FileUtils.cp(haml_init_file, rails_init_file) unless FileUtils.cmp(rails_init_file, haml_init_file)