Browse files

Use File #join and #expand_path to build file paths throughout so no …

…badly-formed paths are sent to event hooks.
  • Loading branch information...
1 parent 60a4550 commit 4d647dbc635cbc71397c2dc3a2e9a1efa5b965a7 @jcoglan committed Sep 21, 2009
Showing with 18 additions and 11 deletions.
  1. +8 −1 lib/jake.rb
  2. +5 −5 lib/jake/build.rb
  3. +4 −4 lib/jake/buildable.rb
  4. +1 −1 lib/jake/package.rb
View
9 lib/jake.rb
@@ -12,7 +12,7 @@
end
module Jake
- VERSION = '1.0.0'
+ VERSION = '1.0.1'
CONFIG_FILE = 'jake.yml'
HELPER_FILE = 'Jakefile'
@@ -30,6 +30,13 @@ def self.clear_hooks!
Build.delete_observers
end
+ # Returns a path made by joining the given pieces and removing unnecessary
+ # /. sections using expand_path.
+ def self.path(*parts)
+ parts = parts.compact.map { |p| p.to_s }
+ File.expand_path(File.join(*parts))
+ end
+
# Returns the contents of the given path, which may be missing a .js extension.
def self.read(path)
path = File.expand_path(path)
View
10 lib/jake/build.rb
@@ -18,12 +18,12 @@ def initialize(dir, options = {})
@helper = Helper.new(options)
force! if options[:force]
- path = "#{dir}/#{CONFIG_FILE}"
+ path = Jake.path(dir, CONFIG_FILE)
yaml = File.read(path)
@config = Jake.symbolize_hash( YAML.load(Jake.erb(yaml).result(@helper.scope)) )
- helpers = "#{dir}/#{HELPER_FILE}"
+ helpers = Jake.path(dir, HELPER_FILE)
load helpers if File.file?(helpers)
@builds = @config[:builds] || {:src => false, :min => @config[:packer]}
@@ -78,21 +78,21 @@ def run!
# Returns the path to the build directory, where generated files appear.
def build_directory
- "#{ @dir }/#{ @config[:build_directory] || '.' }"
+ Jake.path(@dir, @config[:build_directory] || '.')
end
alias :build_dir :build_directory
# Returns the path to the source directory, where source code is read from.
def source_directory
- "#{ @dir }/#{ @config[:source_directory] || '.' }"
+ Jake.path(@dir, @config[:source_directory] || '.')
end
alias :source_dir :source_directory
# Returns the header string used for the build, or an empty string if no
# header file has been set.
def header
@config[:header] ?
- Jake.read("#{ source_directory }/#{ @config[:header] }") :
+ Jake.read(Jake.path(source_directory, @config[:header])) :
""
end
View
8 lib/jake/buildable.rb
@@ -31,15 +31,15 @@ def parent
def directory
dir = @config[:directory]
return parent.directory if parent && !dir
- "#{ @build.source_directory }/#{ @config[:directory] }"
+ Jake.path(@build.source_directory, @config[:directory])
end
# Returns the path to the output file from this package for the given build name.
def build_path(build_name)
suffix = @build.use_suffix?(build_name) ? "-#{ build_name }" : ""
@build.layout == 'together' ?
- "#{ @build.build_directory }/#{ @name }#{ suffix }.js" :
- "#{ @build.build_directory }/#{ build_name }/#{ @name }.js"
+ Jake.path(@build.build_directory, "#{ @name }#{ suffix }.js") :
+ Jake.path(@build.build_directory, build_name, "#{ @name }.js")
end
# Returns +true+ if the build file for the given build name is out of date and
@@ -55,7 +55,7 @@ def build_needed?(name)
# Returns the header string being used for this package.
def header
content = @config[:header] ?
- Jake.read("#{ directory }/#{ @config[:header] }") :
+ Jake.read(Jake.path( directory, @config[:header])) :
(parent ? parent.header : @build.header)
Jake.erb(content).result(@build.helper.scope).strip
end
View
2 lib/jake/package.rb
@@ -5,7 +5,7 @@ class Package < Buildable
def files
base = parent ? parent.files : []
base + @config[:files].map do |path|
- path = "#{ directory }/#{ path }"
+ path = Jake.path( directory, path)
File.file?(path) ? path : "#{ path }.js"
end
end

0 comments on commit 4d647db

Please sign in to comment.