From cba2239924f40910b6d49be5db41ed09e7536ee6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C5=A0=C5=A5astn=C3=BD=20aka=20Botanicus?= Date: Thu, 17 Feb 2011 04:01:41 +0000 Subject: [PATCH] Refactoring, fixed a weird behaviour (bug?). --- lib/template-inheritance.rb | 16 ++++++++++++---- template-inheritance.gemspec | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/template-inheritance.rb b/lib/template-inheritance.rb index 2de451e..943d48e 100644 --- a/lib/template-inheritance.rb +++ b/lib/template-inheritance.rb @@ -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 @@ -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]/, '_\&') =~ /_*(.*)/ diff --git a/template-inheritance.gemspec b/template-inheritance.gemspec index f6d4f35..7e259a1 100755 --- a/template-inheritance.gemspec +++ b/template-inheritance.gemspec @@ -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 = ""