Was ist der richtige Weg, xml-stylesheet Handhabung: xmlns: blah mit haml?
Frage
Ich versuche, ein Blog mit einigem XML-Namespaces und XML-Stylesheets zu anschließen.
Die hässliche Art und Weise, dass ich tue dies sieht derzeit wie folgt:
!!! XML
= partial('xmlstyle')
%channel
......blah.....
= partial('xmlend')
Dabei steht
_xmlstyle.xml.erb sieht aus wie:
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?>
<?xml-stylesheet type="text/css" media="screen"
href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">
_xmlend.xml.erb sieht aus wie:
</rss>
Soll ich nur mit erb-Stick jetzt? Es muss ein Weg, dies zu tun in haml Recht sein?
Lösung
Haml haben keine Syntax für XML-Stylesheet-Richtlinien, aber es gibt keinen Grund, warum Sie sie nicht direkt aufnehmen können. Was die xmlns:blah
Attribute, können Sie entweder Strings als die Attributnamen, etwa so:
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?>
<?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?>
%rss{"xmlns:content" => "http://purl.org/rss/1.0/modules/content/",
"xmlns:wfw" => "http://wellformedweb.org/CommentAPI/",
"xmlns:dc" => "http://purl.org/dc/elements/1.1/",
"xmlns:atom" => "http://www.w3.org/2005/Atom",
"xmlns:sy" => "http://purl.org/rss/1.0/modules/syndication/",
"xmlns:slash" => "http://purl.org/rss/1.0/modules/slash/",
"xmlns:feedburner" => "http://rssnamespace.org/feedburner/ext/1.0",
:version => "2.0"}
%channel
blah
Sie können auch verwenden, um HTML-Style-Attribute mit ()
:
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?>
<?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?>
%rss(xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0"
version="2.0")
%channel
blah
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow