From 5f7d1657f7e480cba699d40bfe3f5e63acbbf556 Mon Sep 17 00:00:00 2001 From: Hubert Date: Fri, 8 Oct 2010 08:34:01 +0200 Subject: [PATCH] Layout and authentication handling --- .../site_translations_controller.rb | 10 ++++++++++ lib/go_translate_yourself.rb | 14 +++----------- spec/dummy/app/views/layouts/dummy_admin.html.erb | 8 ++++++++ .../config/initializers/go_translate_yourself.rb | 11 ++++++++++- 4 files changed, 31 insertions(+), 12 deletions(-) create mode 100644 spec/dummy/app/views/layouts/dummy_admin.html.erb diff --git a/app/controllers/go_translate_yourself/site_translations_controller.rb b/app/controllers/go_translate_yourself/site_translations_controller.rb index 28fbd30..52389c2 100644 --- a/app/controllers/go_translate_yourself/site_translations_controller.rb +++ b/app/controllers/go_translate_yourself/site_translations_controller.rb @@ -1,8 +1,11 @@ module GoTranslateYourself class SiteTranslationsController < ApplicationController + before_filter :auth + def edit @keys = GoTranslateYourself.current_store.keys_without_prefix @locales = GoTranslateYourself.locales + render :layout => GoTranslateYourself.layout_name end def update @@ -13,5 +16,12 @@ def update end redirect_to site_translations_path end + + private + + def auth + GoTranslateYourself.auth_handler.bind(self).call if GoTranslateYourself.auth_handler.is_a? Proc + end end end + diff --git a/lib/go_translate_yourself.rb b/lib/go_translate_yourself.rb index 79ad65d..65f1d9d 100644 --- a/lib/go_translate_yourself.rb +++ b/lib/go_translate_yourself.rb @@ -1,16 +1,8 @@ require 'go_translate_yourself/engine' if defined?(Rails) && Rails::VERSION::MAJOR == 3 module GoTranslateYourself - def self.current_store=(store) - @store = store + class << self + attr_accessor :layout_name, :locales, :auth_handler, :current_store end - - def self.current_store; @store; end - - def self.locales=(array_of_locales) - @locales = array_of_locales - end - - def self.locales; @locales; end - end + diff --git a/spec/dummy/app/views/layouts/dummy_admin.html.erb b/spec/dummy/app/views/layouts/dummy_admin.html.erb new file mode 100644 index 0000000..349f3f2 --- /dev/null +++ b/spec/dummy/app/views/layouts/dummy_admin.html.erb @@ -0,0 +1,8 @@ + + + Testing site for GoTranslateYourself! + + + <%= yield %> + + diff --git a/spec/dummy/config/initializers/go_translate_yourself.rb b/spec/dummy/config/initializers/go_translate_yourself.rb index fff0055..4992e48 100644 --- a/spec/dummy/config/initializers/go_translate_yourself.rb +++ b/spec/dummy/config/initializers/go_translate_yourself.rb @@ -1,4 +1,13 @@ -GoTranslateYourself.current_store = GoTranslateYourself::MongoStore.new(Mongo::Connection.new.db("go_translate_yourself_test").collection("translations")) +conn = Mongo::Connection.new.db("go_translate_yourself_test").collection("translations") +GoTranslateYourself.current_store = GoTranslateYourself::MongoStore.new(conn) GoTranslateYourself.locales = [:pl, :de] I18n.backend = I18n::Backend::KeyValue.new GoTranslateYourself.current_store + +#GoTranslateYourself.auth_handler = proc { +# authenticate_or_request_with_http_basic do |user_name, password| +# user_name == 'some' && password == 'user' +# end +#} + +GoTranslateYourself.layout_name = "dummy_admin"