sinatra helpers
This commit is contained in:
parent
09973aef67
commit
bc904074a2
3
.gitmodules
vendored
3
.gitmodules
vendored
|
@ -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
|
||||
|
|
|
@ -12,6 +12,9 @@ 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
|
||||
|
@ -21,27 +24,9 @@ class Middleman < Sinatra::Base
|
|||
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
|
||||
|
@ -107,3 +92,5 @@ class Middleman < Sinatra::Base
|
|||
result || pass
|
||||
end
|
||||
end
|
||||
|
||||
require File.join(File.dirname(__FILE__), 'middleman', 'helpers')
|
16
lib/middleman/helpers.rb
Normal file
16
lib/middleman/helpers.rb
Normal 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
1
vendor/sinatra-helpers
vendored
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit 65d5060ad8cdff6b12631878d97486114d195376
|
Loading…
Reference in a new issue