copycat 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -40,6 +40,10 @@ Since this process requires no code commits, non-developers can also 'deploy' co
40
40
 
41
41
  You can also commit Copycat's YAML export, which is compatible with i18n, to your git repository.
42
42
 
43
+ ## Example ##
44
+
45
+ See an example application [here](https://github.com/Vermonster/copycat-demo).
46
+
43
47
  ## Developing ##
44
48
 
45
49
  As a Rails engine, Copycat is developed using a nested dummy Rails app. After cloning the repository and running bundler, the plugin must be installed in the dummy app:
@@ -1,6 +1,6 @@
1
1
  class CopycatTranslationsController < ActionController::Base
2
2
 
3
- http_basic_authenticate_with :name => COPYCAT_USERNAME, :password => COPYCAT_PASSWORD
3
+ http_basic_authenticate_with :name => Copycat.username, :password => Copycat.password
4
4
 
5
5
  layout 'copycat'
6
6
 
@@ -20,6 +20,7 @@ class CopycatTranslation < ActiveRecord::Base
20
20
  def export_yaml
21
21
  hash = {}
22
22
  all.each do |c|
23
+ next unless c.value
23
24
  hash_fatten!(hash, [c.locale].concat(c.key.split(".")), c.value)
24
25
  end
25
26
  hash.to_yaml
data/config/routes.rb CHANGED
@@ -1,5 +1,8 @@
1
1
  Rails.application.routes.draw do
2
- resources :copycat_translations, :only => [:index, :edit, :update, :destroy] do
2
+ resources Copycat.route,
3
+ :as => 'copycat_translations',
4
+ :controller => 'copycat_translations',
5
+ :only => [:index, :edit, :update, :destroy] do
3
6
  collection do
4
7
  get 'help'
5
8
  get 'import_export'
@@ -0,0 +1,13 @@
1
+ module CopycatImplementation
2
+ # this method overrides part of the i18n gem, lib/i18n/backend/simple.rb
3
+ def lookup(locale, key, scope = [], options = {})
4
+ return super unless ActiveRecord::Base.connected? && CopycatTranslation.table_exists?
5
+ cct = CopycatTranslation.where(locale: locale, key: key).first
6
+ return cct.value if cct
7
+ value = super(locale, key, scope, options)
8
+ if value.is_a?(String) || value.nil?
9
+ CopycatTranslation.create(locale: locale, key: key, value: value)
10
+ end
11
+ value
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ class I18n::Backend::Simple
2
+ include CopycatImplementation
3
+ end
@@ -1,3 +1,3 @@
1
1
  module Copycat
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/copycat.rb CHANGED
@@ -1,19 +1,15 @@
1
1
  require "copycat/engine"
2
+ require "copycat/implementation"
3
+ require "copycat/simple"
2
4
 
3
- module CopycatImplementation
4
- # this method overrides part of the i18n gem, lib/i18n/backend/simple.rb
5
- def lookup(locale, key, scope = [], options = {})
6
- return super unless ActiveRecord::Base.connected? && CopycatTranslation.table_exists?
7
- cct = CopycatTranslation.where(locale: locale, key: key).first
8
- return cct.value if cct
9
- value = super(locale, key, scope, options)
10
- if value.is_a?(String) || value.nil?
11
- CopycatTranslation.create(locale: locale, key: key, value: value)
12
- end
13
- value
5
+ module Copycat
6
+ mattr_accessor :username
7
+ mattr_accessor :password
8
+ mattr_accessor :route
9
+ @@route = 'copycat_translations'
10
+
11
+ def self.setup
12
+ yield self
14
13
  end
15
14
  end
16
15
 
17
- class I18n::Backend::Simple
18
- include CopycatImplementation
19
- end
@@ -12,9 +12,12 @@ namespace :copycat do
12
12
  filepath = Rails.root.join *%w(config initializers copycat.rb)
13
13
  File.open(filepath, 'w') do |f|
14
14
  f << <<-CONFIG
15
- COPYCAT_USERNAME = "#{username}"
16
- COPYCAT_PASSWORD = "#{password}"
17
- CONFIG
15
+ Copycat.setup do |config|
16
+ config.username = '#{username}'
17
+ config.password = '#{password}'
18
+ #config.route = 'copycat_translations'
19
+ end
20
+ CONFIG
18
21
  end
19
22
  puts <<-INFO
20
23
  Copycat initializer created with
@@ -1,2 +1,5 @@
1
- COPYCAT_USERNAME = "username"
2
- COPYCAT_PASSWORD = "password"
1
+ Copycat.setup do |config|
2
+ config.username = 'c993116'
3
+ config.password = '730eede'
4
+ #config.route = 'copycat_translations'
5
+ end
@@ -1237,3 +1237,64 @@ Completed 400 Bad Request in 16ms (Views: 13.5ms | ActiveRecord: 0.0ms)
1237
1237
 
1238
1238
  Started GET "/assets/copycat_engine.css?body=1" for 127.0.0.1 at 2012-03-26 15:15:27 -0400
1239
1239
  Served asset /copycat_engine.css - 200 OK (1ms)
1240
+
1241
+
1242
+ Started GET "/copycat_translations/import_export" for 127.0.0.1 at 2012-03-26 15:31:26 -0400
1243
+ Processing by CopycatTranslationsController#import_export as HTML
1244
+ Rendered /vermonster/copycat/app/views/copycat_translations/import_export.html.erb within layouts/copycat (2.6ms)
1245
+ Completed 200 OK in 15ms (Views: 15.0ms | ActiveRecord: 0.0ms)
1246
+
1247
+
1248
+ Started GET "/assets/copycat_engine.css?body=1" for 127.0.0.1 at 2012-03-26 15:31:26 -0400
1249
+ Served asset /copycat_engine.css - 304 Not Modified (1ms)
1250
+
1251
+
1252
+ Started POST "/copycat_translations/upload" for 127.0.0.1 at 2012-03-26 15:31:47 -0400
1253
+ Processing by CopycatTranslationsController#upload as HTML
1254
+ Parameters: {"utf8"=>"✓", "authenticity_token"=>"Mj1Qcja3mVicC0PXcW5UEYJeskdTdT3UWjWm4M27ZjA=", "file"=>#<ActionDispatch::Http::UploadedFile:0x00000100bf5788 @original_filename="gollum.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"file\"; filename=\"gollum.jpg\"\r\nContent-Type: image/jpeg\r\n", @tempfile=#<File:/var/folders/rn/rnXUYLOZH-mYuzcjL2v8Fk+++TI/-Tmp-/RackMultipart20120326-14172-1infn60>>, "commit"=>"Upload"}
1255
+
1256
+ Psych::SyntaxError
1257
+ (/var/folders/rn/rnXUYLOZH-mYuzcjL2v8Fk+++TI/-Tmp-/RackMultipart20120326-14172-1infn60): couldn't parse YAML at line 0 column 0
1258
+ Rendered /vermonster/copycat/app/views/copycat_translations/import_export.html.erb within layouts/copycat (0.8ms)
1259
+ Completed 400 Bad Request in 4ms (Views: 3.2ms | ActiveRecord: 0.0ms)
1260
+
1261
+
1262
+ Started GET "/assets/copycat_engine.css?body=1" for 127.0.0.1 at 2012-03-26 15:31:47 -0400
1263
+ Served asset /copycat_engine.css - 304 Not Modified (0ms)
1264
+
1265
+
1266
+ Started POST "/copycat_translations/upload" for 127.0.0.1 at 2012-03-26 15:32:05 -0400
1267
+ Processing by CopycatTranslationsController#upload as HTML
1268
+ Parameters: {"utf8"=>"✓", "authenticity_token"=>"Mj1Qcja3mVicC0PXcW5UEYJeskdTdT3UWjWm4M27ZjA=", "file"=>#<ActionDispatch::Http::UploadedFile:0x0000010475e950 @original_filename="gollum.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"file\"; filename=\"gollum.jpg\"\r\nContent-Type: image/jpeg\r\n", @tempfile=#<File:/var/folders/rn/rnXUYLOZH-mYuzcjL2v8Fk+++TI/-Tmp-/RackMultipart20120326-14172-1m26ey4>>, "commit"=>"Upload"}
1269
+
1270
+ Psych::SyntaxError
1271
+ (/var/folders/rn/rnXUYLOZH-mYuzcjL2v8Fk+++TI/-Tmp-/RackMultipart20120326-14172-1m26ey4): couldn't parse YAML at line 0 column 0
1272
+ Rendered /vermonster/copycat/app/views/copycat_translations/import_export.html.erb within layouts/copycat (0.7ms)
1273
+ Completed 400 Bad Request in 3ms (Views: 2.8ms | ActiveRecord: 0.0ms)
1274
+
1275
+
1276
+ Started GET "/assets/copycat_engine.css?body=1" for 127.0.0.1 at 2012-03-26 15:32:05 -0400
1277
+ Served asset /copycat_engine.css - 304 Not Modified (0ms)
1278
+
1279
+
1280
+ Started GET "/copycat_translations/import_export" for 127.0.0.1 at 2012-03-26 15:32:15 -0400
1281
+ Processing by CopycatTranslationsController#import_export as HTML
1282
+ Rendered /vermonster/copycat/app/views/copycat_translations/import_export.html.erb within layouts/copycat (0.9ms)
1283
+ Completed 200 OK in 4ms (Views: 3.9ms | ActiveRecord: 0.0ms)
1284
+
1285
+
1286
+ Started GET "/assets/copycat_engine.css?body=1" for 127.0.0.1 at 2012-03-26 15:32:15 -0400
1287
+ Served asset /copycat_engine.css - 304 Not Modified (0ms)
1288
+
1289
+
1290
+ Started GET "/copycat_translations/import_export" for 127.0.0.1 at 2012-03-26 15:32:18 -0400
1291
+ Processing by CopycatTranslationsController#import_export as HTML
1292
+ Rendered /vermonster/copycat/app/views/copycat_translations/import_export.html.erb within layouts/copycat (1.0ms)
1293
+ Completed 200 OK in 4ms (Views: 4.0ms | ActiveRecord: 0.0ms)
1294
+
1295
+
1296
+ Started GET "/assets/copycat_engine.css?body=1" for 127.0.0.1 at 2012-03-26 15:32:18 -0400
1297
+ Served asset /copycat_engine.css - 304 Not Modified (0ms)
1298
+
1299
+ ***** Debugger requested, but was not available (ensure ruby-debug is listed in Gemfile/installed as gem): Start server with --debugger to enable *****
1300
+