1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00

force :xhtml if template.mime_type == 'text/xml'

If the mime_type of the ActionView::Template template
being rendered is 'text/xml' then add the a :mime_type
key to the options hash so Haml::Engine will force a
format of xhtml.

Closes #427

Signed-off-by: Norman Clarke <norman@njclarke.com>
This commit is contained in:
Stephen Bannasch 2011-09-09 00:44:40 -04:00 committed by Norman Clarke
parent 6d91d9fb83
commit 12fdc50a94
3 changed files with 17 additions and 3 deletions

View file

@ -22,6 +22,10 @@
* Fix parser to allow lines ending with `some_method?` to be a Ruby multinline
(thanks to [Brad Ediger](https://github.com/bradediger))
* Always use :xhtml format when the mime_type of the rendered template is 'text/xml'.
(thanks to [Stephen Bannasch](https://github.com/stepheneb)).
## 3.1.5 (Unreleased)
* Respect Rails' `html_safe` flag when escaping attribute values

View file

@ -133,6 +133,10 @@ Available options are:
Other options are `:html4` and `:html5`, which are
identical to `:xhtml` except there are no self-closing tags,
the XML prolog is ignored and correct DOCTYPEs are generated.
<br/><br/> <!-- There's no better way to do a paragraph break in a dl in Maruku -->
If the mime_type of the template being rendered is `text/xml` then
a format of `:xhtml` will be used even if the global output format
is set to `:html4` or `:html5`.
{#escape_html-option} `:escape_html`
: Sets whether or not to escape HTML-sensitive characters in script.
@ -839,6 +843,10 @@ is compiled to:
<?xml version='1.0' encoding='iso-8859-1' ?>
If the mime_type of the template being rendered is `text/xml` then
a format of `:xhtml` will be used even if the global output format
is set to `:html4` or `:html5`.
## Comments
Haml supports two sorts of comments:

View file

@ -21,6 +21,8 @@ module Haml
def compile(template)
options = Haml::Template.options.dup
options[:mime_type] = template.mime_type
# template is a template object in Rails >=2.1.0,
# a source string previously
if template.respond_to? :source
@ -99,7 +101,7 @@ if defined?(ActionView::TemplateError) &&
begin
render_source = create_template_source(handler, template, render_symbol, local_assigns.keys)
line_offset = @@template_args[render_symbol].size + handler.line_offset
file_name = 'compiled-template' if file_name.blank?
CompiledTemplates.module_eval(render_source, file_name, -line_offset)
rescue Exception => e # errors from template code
@ -112,10 +114,10 @@ if defined?(ActionView::TemplateError) &&
# There's no way to tell Haml about the filename,
# so we've got to insert it ourselves.
e.backtrace[0].gsub!('(haml)', file_name) if e.is_a?(Haml::Error)
raise ActionView::TemplateError.new(extract_base_path_from(file_name) || view_paths.first, file_name || template, @assigns, template, e)
end
@@compile_time[render_symbol] = Time.now
# logger.debug "Compiled template #{file_name || template}\n ==> #{render_symbol}" if logger
end