Class: Haml::MagicTranslations::Parser
- Inherits:
-
Parser
- Object
- Parser
- Haml::MagicTranslations::Parser
- Defined in:
- lib/haml/magic_translations.rb
Instance Method Summary collapse
-
#parse_tag(line) ⇒ Object
Overriden function that parses Haml tags.
-
#plain(text, escape_html = nil) ⇒ Object
Magical translations will be also used for plain text.
Instance Method Details
#parse_tag(line) ⇒ Object
Overriden function that parses Haml tags. Injects gettext call for all plain text lines.
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/haml/magic_translations.rb', line 54 def parse_tag(line) tag_name, attributes, attributes_hashes, object_ref, nuke_outer_whitespace, nuke_inner_whitespace, action, value, last_line = super(line) if !value.empty? unless action && action == '=' || action == '!' && value[0] == ?= || action == '&' && value[0] == ?= value, interpolation_arguments = Haml::MagicTranslations.prepare_i18n_interpolation(value) value = "\#{_('#{value.gsub(/'/, "\\\\'")}') % #{interpolation_arguments}\}\n" end end [tag_name, attributes, attributes_hashes, object_ref, nuke_outer_whitespace, nuke_inner_whitespace, action, value, last_line] end |
#plain(text, escape_html = nil) ⇒ Object
Magical translations will be also used for plain text.
69 70 71 72 73 |
# File 'lib/haml/magic_translations.rb', line 69 def plain(text, escape_html = nil) value, interpolation_arguments = Haml::MagicTranslations.prepare_i18n_interpolation(text, escape_html) value = "_('#{value.gsub(/'/, "\\\\'")}') % #{interpolation_arguments}\n" script(value, !:escape_html) end |