Skip to content

Commit

Permalink
Refactoring, fixed a weird behaviour (bug?).
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakub Šťastný aka Botanicus committed Feb 17, 2011
1 parent cb50ebf commit cba2239
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
16 changes: 12 additions & 4 deletions lib/template-inheritance.rb
Expand Up @@ -67,7 +67,7 @@ def initialize(path, scope = Object.new)
def fullpath
@fullpath ||= begin
if self.path.match(/^(\/|\.)/) # /foo or ./foo
Dir[self.path, "#{self.path}.*"].find {|file| !File.directory?(file)}
find_file(self.path, "#{self.path}.*")
else
self.find_in_paths
end
Expand Down Expand Up @@ -104,12 +104,20 @@ def render(context = Hash.new)

protected
def find_in_paths
self.class.paths.each do |directory|
path = File.join(directory, self.path)
return Dir[path, "#{path}.*"].find {|file| !File.directory?(file)}
self.class.paths.inject(nil) do |real, directory|
if real.nil?
path = File.join(directory, self.path)
find_file(path, "#{path}.*")
else
real
end
end
end

def find_file(one, other)
alternatives.find { |file| File.file?(file) }
end

def snake_case(string)
return string.downcase if string =~ /^[A-Z]+$/
string.gsub(/([A-Z]+)(?=[A-Z][a-z]?)|\B[A-Z]/, '_\&') =~ /_*(.*)/
Expand Down
2 changes: 1 addition & 1 deletion template-inheritance.gemspec
Expand Up @@ -5,7 +5,7 @@ require "base64"

Gem::Specification.new do |s|
s.name = "template-inheritance"
s.version = "0.1.1"
s.version = "0.1.2"
s.authors = ["Jakub Šťastný aka Botanicus"]
s.homepage = "http://github.com/botanicus/template-inheritance"
s.summary = ""
Expand Down

0 comments on commit cba2239

Please sign in to comment.