Permalink
Browse files

Replace gist-y partials with a full gem implementation that integrate…

…s with the Tilt template cache and is faster.
  • Loading branch information...
1 parent 4796c69 commit 3642f592168770c05817d34ac7a91c191904e1bc @kylev kylev committed Jul 8, 2012
Showing with 7 additions and 17 deletions.
  1. +3 −0 Gemfile.lock
  2. +1 −0 hobson.gemspec
  3. +3 −0 lib/hobson/server.rb
  4. +0 −17 lib/hobson/server/helpers.rb
View
@@ -34,6 +34,7 @@ PATH
sass
simplecov
sinatra
+ sinatra-partial
sys-proctable
thor (~> 0.14.6)
uuid
@@ -162,6 +163,8 @@ GEM
rack (~> 1.3, >= 1.3.6)
rack-protection (~> 1.2)
tilt (~> 1.3, >= 1.3.3)
+ sinatra-partial (0.3.1)
+ sinatra
sprockets (2.0.3)
hike (~> 1.2)
rack (~> 1.0)
View
@@ -39,6 +39,7 @@ Gem::Specification.new do |s|
s.add_runtime_dependency "rack", "~> 1.3.5"
s.add_runtime_dependency "vegas"
s.add_runtime_dependency "sinatra"
+ s.add_runtime_dependency "sinatra-partial"
s.add_runtime_dependency "haml"
s.add_runtime_dependency "sass"
end
View
@@ -1,6 +1,7 @@
require 'time'
require 'sinatra/base'
+require 'sinatra/partial'
require 'vegas'
require 'haml'
require 'sass'
@@ -14,6 +15,7 @@
I18n.load_path << $:.map{|path| File.join(path,'action_view/locale/en.yml') }.find{|path| File.exist?(path) }
class Hobson::Server < Sinatra::Base
+ register Sinatra::Partial
# patch Vegas::Runner to start a redis slave if the server needs to be started
# but before it forks
@@ -36,6 +38,7 @@ def self.start! options={}
set :views, root + "views"
set :public_folder, root + "public"
set :static, true
+ set :partial_underscores, true
require 'hobson/server/helpers'
helpers Hobson::Server::Helpers
@@ -255,21 +255,4 @@ def test_run_status_icon test_run, &block
end
end
- # Sam Elliott’s partials.rb
- # https://gist.github.com/119874
- 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 << haml(:"#{template}", options.merge(:layout =>
- false, :locals => {template_array[-1].to_sym => member}))
- end.join("\n")
- else
- haml(:"#{template}", options)
- end
- end
-
end

0 comments on commit 3642f59

Please sign in to comment.