class TranslationPanel::Filter
Public Class Methods
new()
click to toggle source
# File lib/translation_panel/filter.rb, line 5 def initialize @save_url = '/translations/translations/new' @condition = :translation_panel? end
Public Instance Methods
after(controller)
click to toggle source
# 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>") header_part = tag :link, :href => "/assets/translation_panel.css", :media => "screen", :rel => "stylesheet", :type => "text/css" header_part+= content_tag :script, "", :src => "/assets/translation_panel.js", :type => "text/javascript" page.insert page.index("</head>"), header_part 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
before(controller)
click to toggle source
# File lib/translation_panel/filter.rb, line 10 def before(controller) TranslationPanel.show! if controller.send(@condition) true end