Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #4 from rogercampos/isolation

Isolation
  • Loading branch information...
commit d86748961c0dba547f62277a504e3cb45f1220ed 2 parents 35e8f07 + 4d769e6
@rogercampos authored
View
3  app/assets/javascripts/interpret.js
@@ -1,3 +1,6 @@
+//= require jquery
+//= require best_in_place
+
$(document).ready(function() {
/* Activating Best In Place */
$("#interpret_container .best_in_place").best_in_place()
View
10 app/controllers/interpret/base_controller.rb
@@ -1,18 +1,24 @@
-class Interpret::BaseController < eval(Interpret.parent_controller.classify)
+class Interpret::BaseController < Interpret.parent_controller.classify.constantize
before_filter :set_locale
before_filter { authorize! :use, :interpret }
before_filter :check_authorized_language
layout 'interpret/interpret'
+ helper Interpret::InterpretHelper
protected
def current_interpret_user
- @current_interpret_user ||= eval(Interpret.current_user)
+ send(Interpret.current_user)
end
def current_ability
@current_ability ||= Interpret.ability.new(current_interpret_user)
end
+ def default_url_options(options = {})
+ options.merge({:locale => I18n.locale})
+ end
+
+
private
def set_locale
I18n.locale = params[:locale] if params[:locale]
View
16 app/controllers/interpret/translations_controller.rb
@@ -3,6 +3,10 @@ class TranslationsController < Interpret::BaseController
before_filter :get_tree, :only => :index
authorize_resource :class => "Interpret::Translation"
+ def welcome
+ redirect_to root_url
+ end
+
def index
key = params[:key]
t = Interpret::Translation.arel_table
@@ -36,15 +40,15 @@ def update
respond_to do |format|
if @translation.update_attributes(params[:translation].presence || params[:interpret_translation])
msg = ""
- msg << "By [#{@interpret_user}]. " if @interpret_user
+ msg << "By [#{current_interpret_user}]. " if current_interpret_user
msg << "Locale: [#{@translation.locale}], key: [#{@translation.key}]. The translation has been changed from [#{old_value}] to [#{@translation.value}]"
Interpret.logger.info msg
- format.html { redirect_to(request.env["HTTP_REFERER"]) }
+ format.html { redirect_to :back }
format.xml { head :ok }
format.json { head :ok }
else
- format.html { redirect_to(request.env["HTTP_REFERER"]) }
+ format.html { redirect_to :back }
format.xml { render :xml => @translation.errors, :status => :unprocessable_entity }
format.json { render :status => :unprocessable_entity }
end
@@ -56,10 +60,10 @@ def create
if @translation.save
flash[:notice] = "New translation created for #{@translation.key}"
- redirect_to request.env["HTTP_REFERER"]
+ redirect_to :back
else
flash[:alert] = "Error when creating a new translation"
- redirect_to request.env["HTTP_REFERER"]
+ redirect_to :back
end
end
@@ -68,7 +72,7 @@ def destroy
@translation.destroy
flash[:notice] = "Translation #{@translation.key} destroyed."
- redirect_to request.env["HTTP_REFERER"]
+ redirect_to :back
end
private
View
8 lib/interpret/helpers.rb → app/helpers/interpret/interpret_helper.rb
@@ -1,5 +1,5 @@
module Interpret
- module InterpretHelpers
+ module InterpretHelper
# Generates the html tree from the given keys
def interpret_show_tree(tree, origin_keys)
tree = tree.first[1]
@@ -17,11 +17,6 @@ def interpret_title(title)
end
end
- def interpret_parent_layout(layout)
- @view_flow.set(:layout, self.output_buffer)
- self.output_buffer = render(:file => "layouts/#{layout}")
- end
-
private
def build_tree(hash, origin_keys = "", prev_key = "")
@@ -44,3 +39,4 @@ def build_tree(hash, origin_keys = "", prev_key = "")
end
end
end
+
View
115 app/views/layouts/interpret/interpret.html.erb
@@ -1,55 +1,66 @@
-<div id="interpret_container">
- <% if flash.any? %>
- <div class="interpret_flash grid_16 <%= flash.keys.first %>">
- <%= flash[:notice] || flash[:alert] %>
- </div>
- <% end %>
- <div class="menu grid_12">
- <%= link_to "Overview", root_path, :class => controller_name == "translations" && action_name == "index" ? "current" : "" %>
-
- <% if can? :use, :tools%>
- | <%= link_to "Tools", tools_path, :class => controller_name == "tools" ? "current" : "" %>
- <% end%>
-
- <% if can? :use, :search%>
- | <%= link_to "Search", search_path, :class => controller_name == "search" ? "current" : ""%>
- <% end%>
-
- <% if can? :read, :missing_translations%>
- | <%= link_to "Missing translations", missing_translations_path, :class => controller_name == "missing_translations" && action_name == "index" ? "current" : ""%>
- <% end%>
-
- <% if can? :read, :stale_translations%>
- | <%= link_to "Stale translations", stale_translations_path, :class => controller_name == "missing_translations" && action_name == "stale" ? "current" : ""%>
- <% end%>
-
- <% if can? :read, :blank_translations%>
- | <%= link_to "Blank translations", blank_translations_path, :class => controller_name == "missing_translations" && action_name == "blank" ? "current" : ""%>
- <% end%>
-
- <% if can? :read, :unused_translations%>
- | <%= link_to "Unused translations", unused_translations_path, :class => controller_name == "missing_translations" && action_name == "unused" ? "current" : ""%>
- <% end%>
- <hr />
- </div>
- <div class="menu grid_4" id='languages_nav'>
- Languages:
- <% Interpret::Translation.available_locales.each do |locale| %>
- <% next unless can? :use, :"interpret_in_#{locale}" %>
- <% opts = {:locale => locale} %>
- <% opts[:key] = params[:key] if params[:key] %>
- <% opts[:value] = params[:value] if params[:value] %>
- <%= link_to locale, opts %>
+<!DOCTYPE html>
+<html>
+<head>
+ <title><%= yield :title %></title>
+ <%= stylesheet_link_tag "interpret_style" %>
+ <%= javascript_include_tag "interpret" %>
+ <%= csrf_meta_tag %>
+</head>
+<body>
+ <div id="interpret_container">
+ <% if flash.any? %>
+ <div class="interpret_flash grid_16 <%= flash.keys.first %>">
+ <%= flash[:notice] || flash[:alert] %>
+ </div>
<% end %>
- <hr />
- </div>
- <div class="clearfix"></div>
- <div id="sidebar" class="grid_3">
- <%= yield :sidebar %>
- </div>
- <div id="main" class="grid_13">
- <%= yield %>
+ <div class="menu grid_12">
+ <%= link_to "Overview", root_path, :class => controller_name == "translations" && action_name == "index" ? "current" : "" %>
+
+ <% if can? :use, :tools%>
+ | <%= link_to "Tools", tools_path, :class => controller_name == "tools" ? "current" : "" %>
+ <% end%>
+
+ <% if can? :use, :search%>
+ | <%= link_to "Search", search_path, :class => controller_name == "search" ? "current" : ""%>
+ <% end%>
+
+ <% if can? :read, :missing_translations%>
+ | <%= link_to "Missing translations", missing_translations_path, :class => controller_name == "missing_translations" && action_name == "index" ? "current" : ""%>
+ <% end%>
+
+ <% if can? :read, :stale_translations%>
+ | <%= link_to "Stale translations", stale_translations_path, :class => controller_name == "missing_translations" && action_name == "stale" ? "current" : ""%>
+ <% end%>
+
+ <% if can? :read, :blank_translations%>
+ | <%= link_to "Blank translations", blank_translations_path, :class => controller_name == "missing_translations" && action_name == "blank" ? "current" : ""%>
+ <% end%>
+
+ <% if can? :read, :unused_translations%>
+ | <%= link_to "Unused translations", unused_translations_path, :class => controller_name == "missing_translations" && action_name == "unused" ? "current" : ""%>
+ <% end%>
+ <hr />
+ </div>
+ <div class="menu grid_4" id='languages_nav'>
+ Languages:
+ <% Interpret::Translation.available_locales.each do |locale| %>
+ <% next unless can? :use, :"interpret_in_#{locale}" %>
+ <% opts = {:locale => locale} %>
+ <% opts[:key] = params[:key] if params[:key] %>
+ <% opts[:value] = params[:value] if params[:value] %>
+ <%= link_to locale, opts %>
+ <% end %>
+ <hr />
+ </div>
+ <div class="clearfix"></div>
+ <div id="sidebar" class="grid_3">
+ <%= yield :sidebar %>
+ </div>
+ <div id="main" class="grid_13">
+ <%= yield %>
+ </div>
</div>
-</div>
-<%= interpret_parent_layout Interpret.layout%>
+</body>
+</html>
+
View
14 app/views/layouts/interpret/interpret_base.html.erb
@@ -1,14 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
- <title><%= yield :title %></title>
- <%= stylesheet_link_tag "interpret_style" %>
- <%= javascript_include_tag "https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" %>
- <%= javascript_include_tag "best_in_place", "interpret" %>
- <%= csrf_meta_tag %>
-</head>
-<body>
- <%= yield %>
-</body>
-</html>
-
View
2  config/routes.rb
@@ -23,4 +23,6 @@
root :to => "translations#index"
end
+
+ match "/", :to => "translations#welcome"
end
View
1  interpret.gemspec
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
s.add_dependency "best_in_place", "~> 1.0"
s.add_dependency "lazyhash", ">= 0.1.1"
s.add_dependency "cancan", "~> 1.6.0"
+ s.add_dependency "jquery-rails"
s.add_development_dependency "rspec-rails", "~> 2.5"
s.add_development_dependency "capybara", "~> 1.0.1"
View
4 lib/interpret.rb
@@ -9,14 +9,12 @@ module Interpret
mattr_accessor :parent_controller
mattr_accessor :registered_envs
mattr_accessor :current_user
- mattr_accessor :layout
mattr_accessor :soft
mattr_accessor :black_list
mattr_accessor :ability
@@parent_controller = "application_controller"
@@registered_envs = [:production, :staging]
- @@layout = "interpret_base"
@@soft = true
@@black_list = []
@@current_user = "current_user"
@@ -44,5 +42,3 @@ def self.ability
end
require 'interpret/engine' if defined? Rails
-
-ActionView::Base.send(:include, Interpret::InterpretHelpers)
View
2  lib/interpret/engine.rb
@@ -1,9 +1,9 @@
require 'interpret/logger'
-require 'interpret/helpers'
module Interpret
class Engine < Rails::Engine
isolate_namespace Interpret
+ engine_name "interpret"
initializer "interpret.register_i18n_active_record_backend" do |app|
app.config.after_initialize do
View
2  test_app/app/controllers/application_controller.rb
@@ -15,7 +15,7 @@ def set_current_user
def toggle_edition_mode
Interpret.live_edit = !Interpret.live_edit
- redirect_to request.env["HTTP_REFERER"]
+ redirect_to :back
end
def set_locale
View
1  test_app/config/initializers/interpret.rb
@@ -1,7 +1,6 @@
Interpret.configure do |config|
config.registered_envs << :development
config.parent_controller = "application_controller"
- config.layout = "backoffice"
config.ability = "interpret_ability"
config.black_list = ["blacklist.*", "missings.black"]
end
Please sign in to comment.
Something went wrong with that request. Please try again.