lib/project/template.rb in project-0.9.3 vs lib/project/template.rb in project-1.0.0

- old
+ new

@@ -1,23 +1,24 @@ module Project class Template attr_accessor :subject, :replacements - REGEX = /%([a-z|A-Z]*)?/ - + REGEX = /%([a-z|A-Z|_]*)?/ + def initialize(subject, replacements) self.subject = subject self.replacements = replacements end - - def parse + + def parse! matches = self.subject.scan(REGEX) matches.flatten! - + matches.each do |match| - raise MissingTemplateVariable, "No variable named %#{match} was specified in the project #{self.key}" if replacements[match].nil? - self.subject.gsub!("%#{match}", replacements[match]) + replacement = replacements[match.to_sym] + raise MissingTemplateVariable, "No variable named %#{match} was found on the specified project." if replacement.nil? + self.subject.gsub!("%#{match}", replacement) end - + self.subject end end end