Modularized Helpers, allows enable/disable of self-closing XHTML
tags (<link .../>) by enable :xhtml in your Application file
This commit is contained in:
parent
bd53f6ae34
commit
48c1086562
@ -3,6 +3,7 @@ require 'sinatra/url_for'
|
||||
|
||||
module Sinatra
|
||||
module StaticAssets
|
||||
module Helpers
|
||||
# In HTML <link> and <img> tags have no end tag.
|
||||
# In XHTML, on the contrary, these tags must be properly closed.
|
||||
#
|
||||
@ -35,13 +36,13 @@ module Sinatra
|
||||
|
||||
private
|
||||
|
||||
def tag(name, options = {})
|
||||
start_tag = "<#{name}#{tag_options(options) if options}"
|
||||
def tag(name, local_options = {})
|
||||
start_tag = "<#{name}#{tag_options(local_options) if local_options}"
|
||||
if block_given?
|
||||
content = yield
|
||||
"#{start_tag}>#{content}</#{name}>"
|
||||
else
|
||||
"#{start_tag}/>"
|
||||
"#{start_tag}#{"/" if options.xhtml}>"
|
||||
end
|
||||
end
|
||||
|
||||
@ -72,5 +73,11 @@ module Sinatra
|
||||
|
||||
end
|
||||
|
||||
helpers StaticAssets
|
||||
def self.registered(app)
|
||||
app.helpers StaticAssets::Helpers
|
||||
app.disable :xhtml
|
||||
end
|
||||
end
|
||||
|
||||
register StaticAssets
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user