sinatra helpers

This commit is contained in:
tdreyno 2009-07-31 09:35:12 -07:00
parent 09973aef67
commit bc904074a2
4 changed files with 31 additions and 24 deletions

3
.gitmodules vendored
View file

@ -10,3 +10,6 @@
[submodule "vendor/sinatra-content-for"] [submodule "vendor/sinatra-content-for"]
path = vendor/sinatra-content-for path = vendor/sinatra-content-for
url = git://github.com/foca/sinatra-content-for.git url = git://github.com/foca/sinatra-content-for.git
[submodule "vendor/sinatra-helpers"]
path = vendor/sinatra-helpers
url = git://github.com/sbfaulkner/sinatra-helpers.git

View file

@ -12,6 +12,9 @@ require File.join(File.dirname(__FILE__), '..', 'vendor', 'sinatra-maruku', 'lib
# Include content_for support # Include content_for support
require File.join(File.dirname(__FILE__), '..', 'vendor', 'sinatra-content-for', 'lib', 'sinatra', 'content_for') require File.join(File.dirname(__FILE__), '..', 'vendor', 'sinatra-content-for', 'lib', 'sinatra', 'content_for')
# Include common haml/html helper support
require File.join(File.dirname(__FILE__), '..', 'vendor', 'sinatra-helpers', 'lib', 'sinatra-helpers', 'haml')
class Middleman < Sinatra::Base class Middleman < Sinatra::Base
set :app_file, __FILE__ set :app_file, __FILE__
set :static, true set :static, true
@ -21,27 +24,9 @@ class Middleman < Sinatra::Base
helpers Sinatra::Markaby helpers Sinatra::Markaby
helpers Sinatra::Maruku helpers Sinatra::Maruku
helpers Sinatra::ContentFor helpers Sinatra::ContentFor
helpers Sinatra::Helpers::Haml::Forms
helpers do helpers Sinatra::Helpers::Haml::Links
def link_to(title, url="#", params={}) helpers Sinatra::Helpers::Haml::Partials
params = params.map { |k,v| %Q{#{k}="#{v}"}}.join(' ')
%Q{<a href="#{url}" #{params}>#{title}</a>}
end
def page_classes(*additional)
classes = []
parts = @full_request_path.split('.')[0].split('/')
parts.each_with_index { |path, i| classes << parts.first(i+1).join('_') }
classes << "index" if classes.empty?
classes += additional unless additional.empty?
classes.join(' ')
end
def sprite(name)
image_tag("spacer.gif", :class => "#{name}-img")
end
end
def self.run!(options={}, &block) def self.run!(options={}, &block)
set options set options
@ -107,3 +92,5 @@ class Middleman < Sinatra::Base
result || pass result || pass
end end
end end
require File.join(File.dirname(__FILE__), 'middleman', 'helpers')

16
lib/middleman/helpers.rb Normal file
View file

@ -0,0 +1,16 @@
Middleman.helpers do
def link_to(title, url="#", params={ :href => url })
params = params.map { |k,v| %Q{#{k}="#{v}"}}.join(' ')
%Q{<a #{params}>#{title}</a>}
end
def page_classes(*additional)
classes = []
parts = @full_request_path.split('.')[0].split('/')
parts.each_with_index { |path, i| classes << parts.first(i+1).join('_') }
classes << "index" if classes.empty?
classes += additional unless additional.empty?
classes.join(' ')
end
end

1
vendor/sinatra-helpers vendored Submodule

@ -0,0 +1 @@
Subproject commit 65d5060ad8cdff6b12631878d97486114d195376