interpret 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. data/README.md +488 -0
  2. data/app/controllers/interpret/search_controller.rb +3 -1
  3. data/app/controllers/interpret/tools_controller.rb +2 -1
  4. data/app/controllers/interpret/translations_controller.rb +16 -7
  5. data/app/models/interpret/expiration_observer.rb +29 -0
  6. data/app/models/interpret/translation.rb +9 -20
  7. data/app/views/interpret/tools/index.html.erb +16 -23
  8. data/app/views/interpret/translations/_listing.html.erb +1 -1
  9. data/app/views/interpret/translations/live_edit.html.erb +11 -0
  10. data/app/views/layouts/interpret.html.erb +6 -1
  11. data/app/views/layouts/interpret_base.html.erb +1 -1
  12. data/config/routes.rb +4 -0
  13. data/interpret.gemspec +0 -1
  14. data/lib/generators/interpret/setup_generator.rb +2 -1
  15. data/lib/interpret/controller_filter.rb +22 -0
  16. data/lib/interpret/engine.rb +17 -6
  17. data/lib/interpret/helpers.rb +39 -0
  18. data/lib/interpret/version.rb +1 -1
  19. data/lib/interpret.rb +4 -1
  20. data/lib/tasks/interpret.rake +4 -2
  21. data/public/javascripts/facebox-1.3/closelabel.png +0 -0
  22. data/public/javascripts/facebox-1.3/facebox.css +80 -0
  23. data/public/javascripts/facebox-1.3/facebox.js +309 -0
  24. data/public/javascripts/facebox-1.3/loading.gif +0 -0
  25. data/public/stylesheets/interpret_live_edit_style.css +38 -0
  26. data/public/stylesheets/interpret_style.css +18 -0
  27. data/spec/models/translation_spec.rb +33 -22
  28. data/spec/observers/expiration_observer_spec.rb +17 -0
  29. data/spec/spec_helper.rb +0 -1
  30. data/test_app/Gemfile +4 -2
  31. data/test_app/app/controllers/application_controller.rb +17 -1
  32. data/test_app/app/controllers/pages_controller.rb +0 -1
  33. data/test_app/app/models/my_sweeper.rb +5 -0
  34. data/test_app/app/views/layouts/application.html.erb +115 -5
  35. data/test_app/app/views/layouts/backoffice.html.erb +27 -0
  36. data/test_app/app/views/pages/archives.html.erb +3 -0
  37. data/test_app/app/views/pages/contact.html.erb +3 -0
  38. data/test_app/app/views/pages/index.html.erb +56 -0
  39. data/test_app/app/views/pages/links.html.erb +10 -0
  40. data/test_app/app/views/pages/resources.html.erb +5 -0
  41. data/test_app/config/application.rb +2 -2
  42. data/test_app/config/environments/production.rb +0 -5
  43. data/test_app/config/initializers/interpret.rb +3 -3
  44. data/test_app/config/locales/en.yml +55 -0
  45. data/test_app/config/locales/es.yml +3 -47
  46. data/test_app/config/routes.rb +8 -1
  47. data/test_app/public/images/a1.gif +0 -0
  48. data/test_app/public/images/a10.jpg +0 -0
  49. data/test_app/public/images/a16.gif +0 -0
  50. data/test_app/public/images/a18.gif +0 -0
  51. data/test_app/public/images/a22.gif +0 -0
  52. data/test_app/public/images/a26.gif +0 -0
  53. data/test_app/public/images/a33.gif +0 -0
  54. data/test_app/public/images/a36.gif +0 -0
  55. data/test_app/public/images/a38.gif +0 -0
  56. data/test_app/public/images/a41.gif +0 -0
  57. data/test_app/public/images/a47.gif +0 -0
  58. data/test_app/public/images/a50.gif +0 -0
  59. data/test_app/public/images/a8.gif +0 -0
  60. data/test_app/public/images/abg.gif +0 -0
  61. data/test_app/public/images/pic1.jpg +0 -0
  62. data/test_app/public/images/pic2.jpg +0 -0
  63. data/test_app/public/images/spacer.gif +0 -0
  64. data/test_app/public/images/upbg.gif +0 -0
  65. data/test_app/public/javascripts/facebox-1.3/closelabel.png +0 -0
  66. data/test_app/public/javascripts/facebox-1.3/facebox.css +80 -0
  67. data/test_app/public/javascripts/facebox-1.3/facebox.js +309 -0
  68. data/test_app/public/javascripts/facebox-1.3/loading.gif +0 -0
  69. data/test_app/public/stylesheets/default.css +361 -0
  70. data/test_app/public/stylesheets/interpret_live_edit_style.css +38 -0
  71. data/test_app/public/stylesheets/interpret_style.css +18 -0
  72. data/test_app/public/stylesheets/private.css +0 -0
  73. metadata +96 -29
  74. data/app/sweepers/interpret/base_sweeper.rb +0 -18
  75. data/app/sweepers/interpret/translation_sweeper.rb +0 -11
  76. data/public/javascripts/jquery.purr.js +0 -180
  77. data/test_app/app/sweepers/page_sweeper.rb +0 -12
  78. data/test_app/app/views/pages/contact.html.haml +0 -8
  79. data/test_app/app/views/pages/index.html.haml +0 -10
  80. data/test_app/config/locales/ca.yml +0 -6
  81. data/test_app/public/javascripts/jquery.purr.js +0 -180
@@ -1,28 +1,34 @@
1
1
  <% interpret_title "Interpret - Tools" %>
2
2
 
3
3
  <div class="header">
4
- <h1>Your master language</h1>
4
+ <h1>Tools for import/export locale data</h1>
5
5
  </div>
6
+
7
+ <p><%= link_to "Download", export_interpret_tools_path %> the current translations for '<%= I18n.locale %>' language as .yml file</p>
8
+ <p>Upload your .yml file for '<%= I18n.locale %>' language</p>
6
9
  <p>
7
- Currently your primary language is <b><%= I18n.default_locale %></b>. This
8
- language will be used as a reference for all your translation work, you
9
- can change it below:
10
- </p>
11
- <p><em>TODO</em></p>
10
+ <%= form_tag import_interpret_tools_path, :multipart => true do %>
11
+ <%= label_tag "File:" %>
12
+ <%= file_field_tag :file %>
13
+ <%= submit_tag "Upload" %>
14
+ <% end %>
15
+
12
16
 
13
17
  <div class="header">
14
18
  <h1>Update contents from yml locale files</h1>
15
19
  </div>
16
20
 
17
- <p>update all your application translatinos from the yml files.<br/>
21
+ <p>Update all your application translations from the yml files.<br/>
18
22
  </p>
19
- <%= button_to "Update contents", run_update_interpret_tools_path %>
23
+ <%= button_to "Update", run_update_interpret_tools_path %>
24
+
25
+
20
26
  <div class="header">
21
27
  <h1>Dump .yml contents into database</h1>
22
28
  </div>
23
29
 
24
30
  <p>With this option you can export all of your *.yml contents into the database backend<br/>
25
- <b>Be aware!!</b> All of your current database translations will be erased
31
+ <b>Be aware!!</b> All of your current database translations will be updated to match with your current *.yml files.
26
32
  </p>
27
33
 
28
34
  <% if Rails.env == "production" %>
@@ -30,18 +36,5 @@ can change it below:
30
36
  <% end %>
31
37
 
32
38
  <p>
33
- <%= button_to "Run the migration", dump_interpret_tools_path %>
39
+ <%= button_to "Dump", dump_interpret_tools_path %>
34
40
  </p>
35
-
36
- <div class="header">
37
- <h1>Tools for import/export locale data</h1>
38
- </div>
39
-
40
- <p><%= link_to "Download", export_interpret_tools_path %> the current translations for '<%= I18n.locale %>' language as .yml file</p>
41
- <p>Upload your .yml file for '<%= I18n.locale %>' language</p>
42
- <p>
43
- <%= form_tag import_interpret_tools_path, :multipart => true do %>
44
- <%= label_tag "File:" %>
45
- <%= file_field_tag :file %>
46
- <%= submit_tag "Upload" %>
47
- <% end %>
@@ -24,7 +24,7 @@
24
24
  :activator => "#translation_#{x.id}",
25
25
  :sanitize => false %>
26
26
  </td>
27
- <% if @interpret_admin%>
27
+ <% if @interpret_admin %>
28
28
  <td style="width:5%" class='protection_input' id="protection_<%= x.id %>">
29
29
  <%= best_in_place x, :protected,
30
30
  :type => :checkbox,
@@ -0,0 +1,11 @@
1
+ <div id="interpret_live_edit">
2
+ <% if @translation %>
3
+ <%= form_for @translation, :url => interpret_translation_path(@translation) do |f| %>
4
+ <%= f.text_area :value, :value => @translation.value %>
5
+ <br/>
6
+ <%= f.submit %>
7
+ <% end %>
8
+ <% else %>
9
+ This translation does not exists yet. You should go to the interpret backoffice interaface and create it from there, this functionality is not yet supported by this live edition feature
10
+ <% end %>
11
+ </div>
@@ -1,8 +1,13 @@
1
1
 
2
2
  <div id="interpret_container">
3
+ <% if flash.any? %>
4
+ <div class="interpret_flash grid_16 <%= flash.keys.first %>">
5
+ <%= flash[:notice] || flash[:alert] %>
6
+ </div>
7
+ <% end %>
3
8
  <div class="menu grid_12">
4
9
  <%= interpret_section_link_to "Overview", interpret_root_path %> |
5
- <% if @interpret_admin %>
10
+ <% unless @interpret_user && !@interpret_admin %>
6
11
  <%= interpret_section_link_to "Tools", interpret_tools_path %> |
7
12
  <% end %>
8
13
  <%= interpret_section_link_to "Search", interpret_search_path %>
@@ -4,7 +4,7 @@
4
4
  <title><%= yield :title %></title>
5
5
  <%= stylesheet_link_tag "interpret_style" %>
6
6
  <%= javascript_include_tag "https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" %>
7
- <%= javascript_include_tag "jquery.purr", "best_in_place", "interpret" %>
7
+ <%= javascript_include_tag "best_in_place", "interpret" %>
8
8
  <%= csrf_meta_tag %>
9
9
  </head>
10
10
  <body>
data/config/routes.rb CHANGED
@@ -3,6 +3,10 @@ Rails.application.routes.draw do
3
3
  namespace :interpret do
4
4
  resources :translations, :only => [:edit, :update] do
5
5
  resources :translations, :only => [:new, :create]
6
+
7
+ collection do
8
+ get :live_edit
9
+ end
6
10
  end
7
11
 
8
12
  resources :tools, :only => :index do
data/interpret.gemspec CHANGED
@@ -23,7 +23,6 @@ Gem::Specification.new do |s|
23
23
  s.add_dependency "i18n", "~> 0.5.0"
24
24
  s.add_dependency "i18n-active_record"
25
25
  s.add_dependency "ya2yaml", ">= 0.30.0"
26
- s.add_dependency "will_paginate", ">= 3.0.pre2"
27
26
  s.add_dependency "best_in_place", ">= 0.1.7"
28
27
  s.add_dependency "lazyhash", ">= 0.1.1"
29
28
 
@@ -6,11 +6,12 @@ module Interpret
6
6
 
7
7
  def copy_css
8
8
  copy_file "stylesheets/interpret_style.css", "public/stylesheets/interpret_style.css"
9
+ copy_file "stylesheets/interpret_live_edit_style.css", "public/stylesheets/interpret_live_edit_style.css"
9
10
  end
10
11
 
11
12
  def copy_js
12
13
  copy_file "javascripts/interpret.js", "public/javascripts/interpret.js"
13
- copy_file "javascripts/jquery.purr.js", "public/javascripts/jquery.purr.js"
14
+ directory "javascripts/facebox-1.3", "public/javascripts/facebox-1.3"
14
15
  end
15
16
 
16
17
  def copy_images
@@ -0,0 +1,22 @@
1
+ class ActionController::Base
2
+ before_filter :set_interpret_user
3
+
4
+ private
5
+ def set_interpret_user
6
+ return unless Interpret.live_edit
7
+
8
+ if Interpret.current_user && defined?(Interpret.current_user.to_sym)
9
+ @interpret_user = eval(Interpret.current_user)
10
+
11
+ if @interpret_user.nil?
12
+ @interpret_admin = false
13
+ return
14
+ end
15
+
16
+ @interpret_admin = true
17
+ if Interpret.admin && @interpret_user.respond_to?(Interpret.admin)
18
+ @interpret_admin = @interpret_user.send(Interpret.admin)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -1,16 +1,19 @@
1
1
  require 'i18n/backend/active_record'
2
2
  require 'interpret/logger'
3
3
  require 'interpret/helpers'
4
+ require 'interpret/controller_filter'
4
5
 
5
6
  module Interpret
6
7
  class Engine < Rails::Engine
7
- if Interpret.registered_envs.include?(Rails.env.to_sym)
8
- initializer "interpret.register_i18n_active_record_backend" do |app|
9
- I18n::Backend::ActiveRecord.send(:include, I18n::Backend::Memoize)
10
- I18n::Backend::ActiveRecord.send(:include, I18n::Backend::Flatten)
8
+ initializer "interpret.register_i18n_active_record_backend" do |app|
9
+ app.config.after_initialize do
10
+ if Interpret.registered_envs.include?(Rails.env.to_sym)
11
+ I18n::Backend::ActiveRecord.send(:include, I18n::Backend::Memoize)
12
+ I18n::Backend::ActiveRecord.send(:include, I18n::Backend::Flatten)
11
13
 
12
- Interpret.backend = I18n::Backend::ActiveRecord.new
13
- app.config.i18n.backend = Interpret.backend
14
+ Interpret.backend = I18n::Backend::Chain.new(I18n::Backend::ActiveRecord.new, I18n.backend)
15
+ I18n.backend = Interpret.backend
16
+ end
14
17
  end
15
18
  end
16
19
 
@@ -19,5 +22,13 @@ module Interpret
19
22
  logfile.sync = true
20
23
  Interpret.logger = InterpretLogger.new(logfile)
21
24
  end
25
+
26
+
27
+ initializer "interpret.register_observer" do |app|
28
+ app.config.before_initialize do |app|
29
+ ActiveRecord::Base.observers << Interpret.sweeper.to_sym if Interpret.sweeper && I18n::Backend::ActiveRecord::Translation.table_exists?
30
+ ActiveRecord::Base.observers << :"interpret/expiration_observer" if !Interpret.sweeper && I18n::Backend::ActiveRecord::Translation.table_exists?
31
+ end
32
+ end
22
33
  end
23
34
  end
@@ -28,7 +28,46 @@ module Interpret
28
28
  self.output_buffer = render(:file => "layouts/#{layout}")
29
29
  end
30
30
 
31
+ def t(key, options = {})
32
+ if Interpret.live_edit && @interpret_admin
33
+ keys = build_keys(key, options)
34
+ "<span class='interpret_editable' data-key='#{keys}'>#{translate(key, options)}</span>".html_safe
35
+ else
36
+ translate(key, options) #.html_safe
37
+ end
38
+ end
39
+
40
+ def interpret_live_edition
41
+ return unless Interpret.live_edit && @interpret_admin
42
+ content_tag(:div) do
43
+ concat(javascript_include_tag "facebox-1.3/facebox")
44
+ concat javascript_tag <<-JS
45
+ $(document).ready(function(){
46
+ $(".interpret_editable").click(function() {
47
+ var key = $(this).attr("data-key");
48
+ jQuery.facebox({ ajax: '#{live_edit_interpret_translations_path}?key=' + key});
49
+ return false;
50
+ });
51
+ });
52
+ JS
53
+ concat(stylesheet_link_tag "interpret_live_edit_style")
54
+ concat(stylesheet_link_tag "/javascripts/facebox-1.3/facebox.css")
55
+ end
56
+ end
57
+
31
58
  private
59
+ def build_keys(key, options)
60
+ I18n.normalize_keys(I18n.locale, scope_key_by_partial(key), options[:scope]).join(".")
61
+ end
62
+
63
+ def scope_key_by_partial(key)
64
+ if key.to_s.first == "."
65
+ "#{@_virtual_path.gsub(%r{/_?}, ".")}#{key.to_s}"
66
+ else
67
+ key
68
+ end
69
+ end
70
+
32
71
  def build_tree(hash, origin_keys = "", prev_key = "")
33
72
  out = "<ul>"
34
73
  if origin_keys.present? && prev_key.blank?
@@ -1,3 +1,3 @@
1
1
  module Interpret
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
data/lib/interpret.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  require 'best_in_place'
2
- require 'will_paginate'
3
2
  require 'lazyhash'
4
3
 
5
4
  module Interpret
@@ -12,11 +11,15 @@ module Interpret
12
11
  mattr_accessor :current_user
13
12
  mattr_accessor :admin
14
13
  mattr_accessor :layout
14
+ mattr_accessor :soft
15
+ mattr_accessor :live_edit
15
16
 
16
17
  @@controller = "action_controller/base"
17
18
  @@registered_envs = [:production, :staging]
18
19
  @@scope = ""
19
20
  @@layout = "interpret_base"
21
+ @@soft = false
22
+ @@live_edit = false
20
23
 
21
24
  def self.configure
22
25
  yield self
@@ -1,11 +1,13 @@
1
1
  namespace :interpret do
2
2
  desc 'Copy all the translations from config/locales/*.yml into DB backend'
3
- task :migrate => [:environment, "tmp:cache:clear"] do
3
+ task :dump => :environment do
4
4
  Interpret::Translation.dump
5
+ eval(Interpret.sweeper.classify).instance.send(:run_expiration) if Interpret.sweeper
5
6
  end
6
7
 
7
8
  desc 'Synchronize the keys used in db backend with the ones on *.yml files'
8
- task :update => [:environment, "tmp:cache:clear"] do
9
+ task :update => :environment do
9
10
  Interpret::Translation.update
11
+ eval(Interpret.sweeper.classify).instance.send(:run_expiration) if Interpret.sweeper
10
12
  end
11
13
  end
@@ -0,0 +1,80 @@
1
+ #facebox {
2
+ position: absolute;
3
+ top: 0;
4
+ left: 0;
5
+ z-index: 100;
6
+ text-align: left;
7
+ }
8
+
9
+
10
+ #facebox .popup{
11
+ position:relative;
12
+ border:3px solid rgba(0,0,0,0);
13
+ -webkit-border-radius:5px;
14
+ -moz-border-radius:5px;
15
+ border-radius:5px;
16
+ -webkit-box-shadow:0 0 18px rgba(0,0,0,0.4);
17
+ -moz-box-shadow:0 0 18px rgba(0,0,0,0.4);
18
+ box-shadow:0 0 18px rgba(0,0,0,0.4);
19
+ }
20
+
21
+ #facebox .content {
22
+ display:table;
23
+ width: 370px;
24
+ padding: 10px;
25
+ background: #fff;
26
+ -webkit-border-radius:4px;
27
+ -moz-border-radius:4px;
28
+ border-radius:4px;
29
+ }
30
+
31
+ #facebox .content > p:first-child{
32
+ margin-top:0;
33
+ }
34
+ #facebox .content > p:last-child{
35
+ margin-bottom:0;
36
+ }
37
+
38
+ #facebox .close{
39
+ position:absolute;
40
+ top:5px;
41
+ right:5px;
42
+ padding:2px;
43
+ background:#fff;
44
+ }
45
+ #facebox .close img{
46
+ opacity:0.3;
47
+ }
48
+ #facebox .close:hover img{
49
+ opacity:1.0;
50
+ }
51
+
52
+ #facebox .loading {
53
+ text-align: center;
54
+ }
55
+
56
+ #facebox .image {
57
+ text-align: center;
58
+ }
59
+
60
+ #facebox img {
61
+ border: 0;
62
+ margin: 0;
63
+ }
64
+
65
+ #facebox_overlay {
66
+ position: fixed;
67
+ top: 0px;
68
+ left: 0px;
69
+ height:100%;
70
+ width:100%;
71
+ }
72
+
73
+ .facebox_hide {
74
+ z-index:-100;
75
+ }
76
+
77
+ .facebox_overlayBG {
78
+ background-color: #000;
79
+ z-index: 99;
80
+ }