Revisions
-
sax revised this gist
Apr 6, 2010 . 1 changed file with 20 additions and 13 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,19 +2,26 @@ # and made a lot more robust by me # this implementation uses erb by default. if you want to use any other template mechanism # then replace `erb` on line 13 and line 17 with `haml` or whatever require 'sinatra/base' module Sinatra module Partials def partial(template, *args) template_array = template.to_s.split('/') template = template_array[0..-2].join('/') + "/_#{template_array[-1]}" options = args.last.is_a?(Hash) ? args.pop : {} options.merge!(:layout => false) if collection = options.delete(:collection) then collection.inject([]) do |buffer, member| buffer << erb(:"#{template}", options.merge(:layout => false, :locals => {template_array[-1].to_sym => member})) end.join("\n") else erb(:"#{template}", options) end end end helpers Partials end -
lenary revised this gist
Jun 2, 2009 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ # stolen from http://github.com/cschneid/irclogger/blob/master/lib/partials.rb # and made a lot more robust by me # this implementation uses erb by default. if you want to use any other template mechanism # then replace `erb` on line 13 and line 17 with `haml` or whatever module Sinatra::Partials def partial(template, *args) template_array = template.to_s.split('/') -
lenary revised this gist
Jun 2, 2009 . 1 changed file with 7 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,16 +1,19 @@ # stolen from http://github.com/cschneid/irclogger/blob/master/lib/partials.rb # and made a lot more robust by me # this implementation uses erb by default. if you want to use any other template mechanism # then replace `erb` on line 14 and line 18 with `haml` or whatever module Sinatra::Partials def partial(template, *args) template_array = template.to_s.split('/') template = template_array[0..-2].join('/') + "/_#{template_array[-1]}" options = args.last.is_a?(Hash) ? args.pop : {} options.merge!(:layout => false) if collection = options.delete(:collection) then collection.inject([]) do |buffer, member| buffer << erb(:"#{template}", options.merge(:layout => false, :locals => {template_array[-1].to_sym => member})) end.join("\n") else erb(:"#{template}", options) end end -
lenary revised this gist
May 29, 2009 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,7 +9,8 @@ def partial(template, *args) false, :locals => {template.to_sym => member})) end.join("\n") else template_array = template.to_s.split('/') template = template_array[0..-2].join('/') + "/_#{template_array[-1]}" erb(:"#{template}", options) end end -
lenary revised this gist
May 29, 2009 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,7 +9,7 @@ def partial(template, *args) false, :locals => {template.to_sym => member})) end.join("\n") else template = template.to_s.split('/')[0..-2].join('/') + "/_#{template.to_s.split('/')[-1]}" erb(:"#{template}", options) end end -
lenary revised this gist
May 29, 2009 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -13,4 +13,4 @@ def partial(template, *args) erb(:"#{template}", options) end end end -
lenary revised this gist
May 29, 2009 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,7 +9,7 @@ def partial(template, *args) false, :locals => {template.to_sym => member})) end.join("\n") else template = template.split('/')[0..-2].join('/') + "/_#{template.split('/')[-1]}" erb(:"#{template}", options) end end -
lenary created this gist
May 29, 2009 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ # stolen from http://github.com/cschneid/irclogger/blob/master/lib/partials.rb module Sinatra::Partials def partial(template, *args) options = args.last.is_a?(Hash) ? args.pop : {} options.merge!(:layout => false) if collection = options.delete(:collection) then collection.inject([]) do |buffer, member| buffer << erb(template, options.merge(:layout => false, :locals => {template.to_sym => member})) end.join("\n") else template = template.split('/')[0..-2] + "_#{template.split('/')[-1]}" erb(:"#{template}", options) end end en