diff --git a/REFERENCE b/REFERENCE index 46315e38..c4c83405 100644 --- a/REFERENCE +++ b/REFERENCE @@ -289,6 +289,28 @@ is compiled to: +==== ? + +The question mark character creates an XML processing directive (an XML +prolog, a stylesheet link, or another format-specific directive). It's +followed by the "target" of the directive, followed by any attributes +of the directive. If the target is left out, it defaults to "xml." For +example: + + ?{ :version => "1.0", :encoding => "UTF-8" } + +is compiled to: + + + +and + + ?xml-stylesheet{ :href => "stylesheets/rss.css", :type => "text/css" } + +is compiled to: + + + ==== / The forward slash character, when placed at the beginning of a line, wraps all diff --git a/lib/haml/buffer.rb b/lib/haml/buffer.rb index 937be427..681acd8f 100644 --- a/lib/haml/buffer.rb +++ b/lib/haml/buffer.rb @@ -55,6 +55,11 @@ module Haml nil end + # Adds an XML processor direction to the buffer. + def push_proc(target, attributes, tabulation) + @buffer << "#{tabs(tabulation)}\n" + end + # Takes the various information about the opening tag for an # element, formats it, and adds it to the buffer. def open_tag(name, tabulation, atomic, try_one_line, class_id, attributes_hash, obj_ref, flattened) diff --git a/lib/haml/engine.rb b/lib/haml/engine.rb index bbd4fb61..83cef0df 100644 --- a/lib/haml/engine.rb +++ b/lib/haml/engine.rb @@ -34,6 +34,9 @@ module Haml # Designates an XHTML doctype. DOCTYPE = '!'[0] + # Designates an XML processing instruction. + PROCESS = '?'[0] + # Designates script, the result of which is output. SCRIPT = '='[0] @@ -57,6 +60,7 @@ module Haml DIV_ID, COMMENT, DOCTYPE, + PROCESS, SCRIPT, FLAT_SCRIPT, SILENT_SCRIPT @@ -210,6 +214,8 @@ module Haml render_tag(line, index) when COMMENT render_comment(line) + when PROCESS + render_process(line, index) when SCRIPT push_script(line[1..-1], false, index) when FLAT_SCRIPT @@ -404,6 +410,17 @@ module Haml push_silent "_hamlout.close_comment(#{has_conditional}, #{@tabulation})" end + # Renders an XML processing direction. + def render_process(line, index) + target, attributes = line[1..-1].split("{") + target = "xml" if target.empty? + if attributes + push_silent "_hamlout.push_proc(#{target.dump}, {#{attributes}, #{@tabulation})" + else + push_text "" + end + end + # Parses a line that will render as an XHTML tag, and adds the code that will # render that tag to @precompiled. def render_tag(line, index) diff --git a/test/results/just_stuff.xhtml b/test/results/just_stuff.xhtml index 9783cc21..0ac9ab40 100644 --- a/test/results/just_stuff.xhtml +++ b/test/results/just_stuff.xhtml @@ -1,3 +1,5 @@ + + diff --git a/test/templates/just_stuff.haml b/test/templates/just_stuff.haml index e101a717..3a7a92b0 100644 --- a/test/templates/just_stuff.haml +++ b/test/templates/just_stuff.haml @@ -1,3 +1,5 @@ +?{ :version => "1.0", :encoding => "UTF-8" } +?xml-stylesheet{ :href => "/non/existant/stylesheet.css", :type => "text/css" } !!! !!! 1.1 !!! 1.1 Strict