15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/translation_panel/filter.rb', line 15
def after(controller)
if controller.send(@condition) && controller.response.status == 200
case controller.response.content_type
when "text/html"
return unless page = controller.response.body
return unless page.index("</head>")
= tag :link, :href => "/assets/translation_panel.css",
:media => "screen", :rel => "stylesheet", :type => "text/css"
+= content_tag :script, "", :src => "/assets/translation_panel.js",
:type => "text/javascript"
page.insert page.index("</head>"),
body_part = content_tag :script,
"translationPanel = {translates: #{TranslationPanel.values.to_json}, action: '#{@save_url}', locale: '#{I18n.locale}'}",
{:type => "text/javascript"}, false
page+= body_part
controller.response.body = page
when "text/javascript"
return unless controller.response.body
body_part = ";$.translator.addTranslates(#{TranslationPanel.values.to_json});"
controller.response.body+= body_part
end
TranslationPanel.kill!
end
true
end
|