aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGibheer <gibheer@gmail.com>2012-11-26 21:16:34 +0100
committerGibheer <gibheer@gmail.com>2012-11-26 21:41:09 +0100
commit43a6ada2edee277bf3a3d21a27fa7f8f2c7db8cb (patch)
tree7b0fabf7bff7e7fd9376ed0d53423ca2acc734fa /lib
parentcb39d8ac909c5c7c5d564c883b6d5bf2c5e26760 (diff)
now the renderer correctly saves all templates
Before this fix the renderer was not able to save the templates and types in the correct way. It still needs some cleanup, but it works now.
Diffstat (limited to 'lib')
-rw-r--r--lib/zero/renderer.rb35
1 files changed, 15 insertions, 20 deletions
diff --git a/lib/zero/renderer.rb b/lib/zero/renderer.rb
index 473db7c..fb34d4b 100644
--- a/lib/zero/renderer.rb
+++ b/lib/zero/renderer.rb
@@ -56,13 +56,19 @@ module Zero
# the wanted template.
# @return [Self] returns the object
def read_template_path!
- @templates = Hash.new do |hash, key|
- # TODO this is just ugly
- result = []
- search_files(key).each { |file| fill_template_type_map(result, file) }
- Hash[result]
+ # TODO clean up later
+ @templates = {}
+ search_files.each do |file|
+ parts = file.gsub(/#{template_path}/, '').split('.')
+ @templates[parts[0]] ||= {}
+ if parts.count > 2 then
+ read_type(parts[1]).each do |type|
+ @templates[parts[0]][type] = file
+ end
+ else
+ @templates[parts[0]][''] = file
+ end
end
- self
end
# render a template
@@ -83,19 +89,8 @@ module Zero
# @api private
# @param template_name [String] the name of the template
# @return [#each] a list of all templates found
- def search_files(template_name)
- Dir[template_path + template_name + '**/*.*']
- end
-
- # fill the `datamap` with all variants of files and types found
- # @api private
- # @param dataset [Hash] the hash to fill with values
- # @param file [String] a filename which will be used to fill the hash
- def fill_template_type_map(dataset, file)
- parts = file.split('.')
- read_type(parts[2]).each do |type|
- dataset << [type, file]
- end
+ def search_files
+ Dir[template_path + '**/*.*']
end
# gets the type information from a file and converts it to an array of
@@ -129,7 +124,7 @@ module Zero
return Tilt.new(template)
end
end
- raise ArgumentError "No template found for '#{name}'!"
+ raise ArgumentError.new "No template found for '#{name}'!"
end
end
end