Skip to content

Commit

Permalink
Add default value for default templates
Browse files Browse the repository at this point in the history
If a template has no type specifcation in it's name, then we use
'default' as map name now.
  • Loading branch information
Stormwind committed Nov 29, 2012
1 parent c6623d4 commit eccd314
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/zero/renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,16 @@ def read_template_path!
search_files.each do |file|
parts = file.gsub(/#{template_path}/, '').split('.')
@templates[parts[0]] ||= {}

# Set default value
types = 'default'
# Overwrite default value, if it's set in template path
if parts.count > 2 then
read_type(parts[1]).each do |type|
@templates[parts[0]][type] = file
end
else
@templates[parts[0]][''] = file
types = parts[1]
end

read_type(types).each do |type|
@templates[parts[0]][type] = file
end
end
end
Expand Down
11 changes: 11 additions & 0 deletions spec/unit/renderer/read_template_path_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,15 @@

it_behaves_like 'a template loader'
end

context 'with default template' do
let(:file_list) {['foo/welcome/index.erb']}
let(:type_map) { {'default' => ['text/html', 'text/xml'] } }
let(:result) { {
'text/html' => 'foo/welcome/index.erb',
'text/xml' => 'foo/welcome/index.erb'
} }

it_behaves_like 'a template loader'
end
end

0 comments on commit eccd314

Please sign in to comment.