Skip to content

Commit

Permalink
Removed deprecated class method ApplicationController#globalize?
Browse files Browse the repository at this point in the history
  • Loading branch information
Luca Guidi committed Jul 16, 2008
1 parent ba22d8b commit aa9a58f
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 47 deletions.
27 changes: 4 additions & 23 deletions lib/click_to_globalize.rb
Expand Up @@ -142,8 +142,7 @@ module Helpers # :nodoc:

# Render +app/views/shared/_click_to_globalize.html.erb+.
def click_to_globalize
# Note: controller.class.globalize? is deprecated.
return unless controller.globalize? && controller.class.globalize?
return unless controller.globalize?
render @@click_partial
end

Expand Down Expand Up @@ -213,33 +212,15 @@ def observe_locale
end
end
end

module SingletonMethods
# Checks if the application is in globalization mode.
#
# Override this method in your controllers for custom conditions.
#
# Example:
#
# def self.globalize?
# current_user.admin?
# end
#
# Note: this method is deprecated in favor of globalize?.
def globalize?
true
end
end
end
end

ActionView::Base.class_eval do
ActionView::Base.class_eval do #:nodoc:
include Globalize::Helpers
end

ActionController::Base.class_eval do # :nodoc:
extend Globalize::Controller::SingletonMethods
ActionController::Base.class_eval do #:nodoc:
include Globalize::Controller::InstanceMethods
include ActionView::Helpers::TextHelper
include ActionView::Helpers::SanitizeHelper
end
end
2 changes: 1 addition & 1 deletion templates/_click_to_globalize.html.erb
Expand Up @@ -5,4 +5,4 @@
// <![CDATA[
var ctg = new ClickToGlobalize('<%= authenticity_token %>', '<%= request_forgery_protection_token %>');
// ]]>
</script>
</script>
37 changes: 16 additions & 21 deletions templates/locales_controller.rb
@@ -1,51 +1,46 @@
class LocalesController < ApplicationController
before_filter :check_globalize, :clear_cache
before_filter :globalize?, :clear_cache

def set
Locale.set(params[:id]) if params[:id]
session[:locale] = Locale.active
session[:__globalize_translations] = nil
logger.debug("[#{Time.now.to_s(:db)}] - Set current Locale on #{Locale.language}")
redirect_to request.env['HTTP_REFERER'] if request.env['HTTP_REFERER']
end

def translate
if request.xhr?
Locale.set_pluralized_translation(params[:key], 1, params[:value])
@formatted_value = params[:value]
render :layout => false, :inline => "<%= #{inline} %>"
end
end

def translate_unformatted
if request.xhr?
@unformatted_value = Locale.translate(params[:key])
render :layout => false, :inline => "<%= @unformatted_value %>"
end
end

def translations
if request.xhr?
logger.debug("Translations got from the server: #{session[:__globalize_translations].inspect}")
render :json => session[:__globalize_translations].to_json, :status => 200
end
end

private
def check_globalize
# Note: self.class.globalize? is deprecated.
globalize? && self.class.globalize?
end

def clear_cache
Locale.clear_cache
end
def clear_cache
Locale.clear_cache
end

def inline
case Locale.formatting
when :textile then 'textilize_without_paragraph( @formatted_value )'
when :markdown then 'markdown( @formatted_value )'
else '@formatted_value'
def inline
case Locale.formatting
when :textile then 'textilize_without_paragraph( @formatted_value )'
when :markdown then 'markdown( @formatted_value )'
else '@formatted_value'
end
end
end
end
end
3 changes: 2 additions & 1 deletion test/click_to_globalize_test.rb
Expand Up @@ -222,8 +222,9 @@ def test_controller_observe_locale
end

### LOCALE_CONTROLLER

def test_check_globalize
assert @locales_controller.check_globalize
assert @locales_controller.globalize?
end

def test_clear_cache
Expand Down
2 changes: 1 addition & 1 deletion test/test_helper.rb
Expand Up @@ -53,7 +53,7 @@ def assert_any(collection, message = nil)
end

LocalesController.class_eval do #:nodoc:
public :check_globalize, :clear_cache, :inline
public :clear_cache, :inline
end

ApplicationHelper.class_eval do #:nodoc:
Expand Down

0 comments on commit aa9a58f

Please sign in to comment.