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 Sinatra
|
||||||
module StaticAssets
|
module StaticAssets
|
||||||
|
module Helpers
|
||||||
# In HTML <link> and <img> tags have no end tag.
|
# In HTML <link> and <img> tags have no end tag.
|
||||||
# In XHTML, on the contrary, these tags must be properly closed.
|
# In XHTML, on the contrary, these tags must be properly closed.
|
||||||
#
|
#
|
||||||
|
@ -35,13 +36,13 @@ module Sinatra
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def tag(name, options = {})
|
def tag(name, local_options = {})
|
||||||
start_tag = "<#{name}#{tag_options(options) if options}"
|
start_tag = "<#{name}#{tag_options(local_options) if local_options}"
|
||||||
if block_given?
|
if block_given?
|
||||||
content = yield
|
content = yield
|
||||||
"#{start_tag}>#{content}</#{name}>"
|
"#{start_tag}>#{content}</#{name}>"
|
||||||
else
|
else
|
||||||
"#{start_tag}/>"
|
"#{start_tag}#{"/" if options.xhtml}>"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -72,5 +73,11 @@ module Sinatra
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
helpers StaticAssets
|
def self.registered(app)
|
||||||
|
app.helpers StaticAssets::Helpers
|
||||||
|
app.disable :xhtml
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
register StaticAssets
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue