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"]
path = vendor/sinatra-content-for
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,37 +12,22 @@ require File.join(File.dirname(__FILE__), '..', 'vendor', 'sinatra-maruku', 'lib
# Include content_for support
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
set :app_file, __FILE__
set :static, true
set :root, Dir.pwd
set :environment, defined?(MIDDLEMAN_BUILDER) ? :build : :development
helpers Sinatra::Markaby
helpers Sinatra::Maruku
helpers Sinatra::ContentFor
helpers do
def link_to(title, url="#", params={})
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
helpers Sinatra::Helpers::Haml::Forms
helpers Sinatra::Helpers::Haml::Links
helpers Sinatra::Helpers::Haml::Partials
def self.run!(options={}, &block)
set options
handler = detect_rack_handler
@ -106,4 +91,6 @@ class Middleman < Sinatra::Base
result || pass
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