Class: Haml::MagicTranslations::Compiler

Inherits:
Compiler
  • Object
show all
Defined in:
lib/haml/magic_translations.rb

Class Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.magic_translations_helpersObject

Returns the value of attribute magic_translations_helpers.



78
79
80
# File 'lib/haml/magic_translations.rb', line 78

def magic_translations_helpers
  @magic_translations_helpers
end

Instance Method Details

#compile_filterObject



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/haml/magic_translations.rb', line 81

def compile_filter
  case @node.value[:name]
    when 'markdown', 'maruku'
      @node.value[:text] = "\#{_(<<-'END_OF_TRANSLATABLE_MARKDOWN'.rstrip
#{@node.value[:text].rstrip.gsub(/\n/, '\n')}
END_OF_TRANSLATABLE_MARKDOWN
)}"
    when 'javascript'
      @node.value[:text].gsub!(/_\(('(([^']|\\')+)'|"(([^"]|\\")+)")\)/) do |m|
        to_parse = $1[1..-2].gsub(/"/, '\"')
        parsed_string = JSON.parse("[\"#{to_parse}\"]")[0]
        parsed_string.gsub!(/'/, "\\\\'")
        "\#{_('#{parsed_string}').to_json}"
      end
  end
  super
end

#compile_rootObject



99
100
101
102
# File 'lib/haml/magic_translations.rb', line 99

def compile_root
  @precompiled << "extend #{Compiler.magic_translations_helpers};"
  super
end