copycat 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. data/README.md +3 -3
  2. data/app/assets/stylesheets/{copycat/copycat.css → copycat_engine.css} +16 -9
  3. data/app/controllers/copycat_translations_controller.rb +4 -0
  4. data/app/models/copycat_translation.rb +1 -2
  5. data/app/views/copycat_translations/_copycat_header.html.erb +9 -0
  6. data/app/views/copycat_translations/index.html.erb +0 -9
  7. data/app/views/copycat_translations/readme.html.erb +23 -34
  8. data/app/views/copycat_translations/upload.html.erb +1 -8
  9. data/app/views/layouts/copycat.html.erb +15 -0
  10. data/db/migrate/20120313191745_create_copycat_translations.rb +5 -2
  11. data/lib/copycat/version.rb +1 -1
  12. data/lib/copycat.rb +14 -5
  13. data/lib/tasks/copycat_tasks.rake +26 -4
  14. data/spec/dummy/config/initializers/copycat.rb +2 -0
  15. data/spec/dummy/db/development.sqlite3 +0 -0
  16. data/spec/dummy/db/migrate/{20120313192639_create_copycat_translations.copycat_engine.rb → 20120316153248_create_copycat_translations.copycat_engine.rb} +5 -2
  17. data/spec/dummy/db/schema.rb +3 -1
  18. data/spec/dummy/db/test.sqlite3 +0 -0
  19. data/spec/dummy/log/development.log +561 -0
  20. data/spec/dummy/log/test.log +5316 -0
  21. data/spec/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
  22. data/spec/dummy/tmp/cache/assets/D09/190/sprockets%2Fb2bddd007999a56d8b20c92301ea1983 +0 -0
  23. data/spec/dummy/tmp/cache/assets/D1A/DB0/sprockets%2F26d700197b8d25f954d56d8f31f2c8bc +0 -0
  24. data/spec/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
  25. data/spec/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
  26. data/spec/dummy/tmp/cache/assets/DBD/220/sprockets%2F0cbff5c1a349439c1c444cbb4a57acc4 +0 -0
  27. data/spec/dummy/tmp/cache/assets/DDD/780/sprockets%2Fe7880b84c3ecb507fabc99b9ef6b70e3 +0 -0
  28. data/spec/dummy/{app/assets/stylesheets/copycat.css → tmp/cache/assets/DF8/310/sprockets%2Fccb12c4009c2f876d51dee8bae4c64ec} +0 -0
  29. data/spec/integration/copycat_spec.rb +26 -1
  30. data/spec/lib/copycat_spec.rb +2 -2
  31. metadata +17 -9
data/README.md CHANGED
@@ -9,7 +9,7 @@ Add ```copycat``` to your Gemfile and run bundle.
9
9
  Copycat uses a database table to store the copy items, and so it is necessary to create that:
10
10
 
11
11
  ```
12
- rake copycat_engine:install:migrations
12
+ rake copycat:install
13
13
  rake db:migrate
14
14
  ```
15
15
 
@@ -24,7 +24,7 @@ Visit the page in your browser, and a Copycat translation will be created for th
24
24
 
25
25
  ## Rails i18N API ##
26
26
 
27
- You can read about the Rails internationalization framework [here](http://guides.rubyonrails.org/i18n.html). Copycat
27
+ You can read about the Rails internationalization framework [here](http://guides.rubyonrails.org/i18n.html).
28
28
 
29
29
  ## Deploying ##
30
30
 
@@ -37,7 +37,7 @@ As a Rails engine, Copycat is developed using a nested dummy Rails app. After cl
37
37
  ```
38
38
  bundle
39
39
  cd spec/dummy
40
- rake copycat_engine:install:migrations
40
+ rake copycat:install
41
41
  rake db:create db:migrate db:test:prepare
42
42
  cd ../..
43
43
  ```
@@ -1,11 +1,20 @@
1
- #copycat li, #copycat li h2 {
2
- display: inline;
3
- padding: 2em;
1
+ body.copycat {
2
+ margin: 0;
4
3
  }
5
- #copycat table, #copycat div.copycat-alert, #copycat div.copycat-notice, div#readme, div#upload {
4
+ div#copycat {
6
5
  width: 75%;
7
- margin-left: 12.5%;
8
- margin-right: 12.5%;
6
+ margin-left: 10.5%;
7
+ padding-left: 2%;
8
+ margin-right: 10.5%;
9
+ padding-right: 2%;
10
+ }
11
+ #copycat ul {
12
+ padding-left: 0;
13
+ padding-top: 2em;
14
+ }
15
+ #copycat li, #copycat li h2 {
16
+ display: inline;
17
+ padding-right: 4em;
9
18
  }
10
19
  #copycat table, #copycat form, #copycat div.copycat-alert, #copycat div.copycat-notice, div#readme, div#upload {
11
20
  padding-top: 2em;
@@ -23,12 +32,10 @@
23
32
  padding-bottom: 1em;
24
33
  border-top: 1px #CCC dotted;
25
34
  }
26
- #copycat table tr td.last {
27
- border-bottom: none;
28
- }
29
35
  #copycat table tr td.key {
30
36
  width: 20%;
31
37
  margin-right: 5%;
38
+ vertical-align: top;
32
39
  }
33
40
  #copycat table tr td.value {
34
41
  width: 75%;
@@ -1,4 +1,8 @@
1
1
  class CopycatTranslationsController < ApplicationController
2
+
3
+ http_basic_authenticate_with :name => COPYCAT_USERNAME, :password => COPYCAT_PASSWORD
4
+
5
+ layout 'copycat'
2
6
 
3
7
  def index
4
8
  @copycat_translations = CopycatTranslation.all
@@ -1,7 +1,6 @@
1
1
  class CopycatTranslation < ActiveRecord::Base
2
2
 
3
- validates :key, :value, :presence => true
4
- validates :key, :uniqueness => true
3
+ validates :key, :presence => true, :uniqueness => true
5
4
 
6
5
  def self.import_yaml(yaml)
7
6
  hash = YAML.load(yaml)
@@ -0,0 +1,9 @@
1
+ <div class="copycat-header">
2
+ <ul>
3
+ <li><a href=<%=copycat_translations_path%>><h2>Copycat</h2></a></li>
4
+ <% href = copycat_translations_path + ".yaml" %>
5
+ <li><a href=<%=href%>>Download</a></li>
6
+ <li><a href=<%= upload_copycat_translations_path %>>Upload</a></li>
7
+ <li><a href=<%= readme_copycat_translations_path %>>Readme</a></li>
8
+ </ul>
9
+ </div>
@@ -1,11 +1,3 @@
1
- <div id="copycat">
2
- <ul>
3
- <li><h2>Copycat</h2></li>
4
- <% href = copycat_translations_path + ".yaml" %>
5
- <li><a href=<%=href%>>Download</a></li>
6
- <li><a href=<%= upload_copycat_translations_path %>>Upload</a></li>
7
- <li><a href=<%= readme_copycat_translations_path %>>Readme</a></li>
8
- </ul>
9
1
  <div class="copycat-notice"> <%= notice %> </div>
10
2
  <table>
11
3
  <tr>
@@ -23,4 +15,3 @@
23
15
  </tr>
24
16
  <% end %>
25
17
  </table>
26
- </div>
@@ -1,41 +1,30 @@
1
- <div id="copycat">
2
- <ul>
3
- <li><h2>Copycat</h2></li>
4
- <% href = copycat_translations_path %>
5
- <li><a href=<%=href%>>Back</a></li>
6
- </ul>
1
+ <div id="readme">
7
2
 
8
- <div id="readme">
9
-
10
- <div class="section">
11
- <h2> Copycat </h2>
12
- <p>Copycat is a Ruby on Rails engine that allows you to edit live website copy.</p>
13
- </div>
14
-
15
- <div class="section">
16
- <h2> How to use </h2>
17
- <p>The values you see here correspond to literal HTML copy text in different parts of the parent website. When you edit them, the text on the website will change. Use ctrl-f or command-f to search for text, then click the left hand side links to edit. </p>
18
- </div>
3
+ <div class="section">
4
+ <h2> Copycat </h2>
5
+ <p>Copycat is a Ruby on Rails engine that allows you to edit live website copy.</p>
6
+ </div>
19
7
 
20
- <div class="section">
21
- <h2> Complicated stuff </h2>
22
- <p> Copycat text is data--not code. By default, Copycat values are stored in your server's database, and not the code base that powers your website.</p>
23
- <p> What this means is that you may have to download/upload Copycat data to transfer your copy edits between servers, or to safeguard them between database wipes. </p>
24
- <p>Copycat accomplishes this by exporting (and being able to re-import) all of its data in a format called "YAML."</p>
25
- <h4> Downloading </h4>
26
- <p>You can get a YAML file of all your copy by clicking "Download" on the main Copycat page.</p>
27
- <h4> Uploading </h4>
28
- <p>You can upload copy to Copycat by clicking "Upload" on the main page and uploading a properly formatted YAML file. Uploading copy won't delete any entries from Copycat, but it may update them or create new ones. Use this feature to mass-update your copy from between servers -- e.g., make changes to copy on a test server, and then when you're satisfied, download the YAML file and upload it to your production site.</p>
29
- <p>Downloading your copy as YAML and then immediately re-uploading it will leave your copy unchanged.</p>
30
- <h4> Commiting your data to your codebase </h4>
31
- <p>If you're pretty happy with your copy and don't expect to need to update it live anymore, or just want a bit more security, you can download your copy as YAML and include it as part of the Ruby on Rails application underneath your main website. You can then remove Copycat from the application entirely, and the website will still run exactly as before--it interfaces with Ruby on Rails's built-in mechanisms in a very unobtrusive way.
32
- </div>
8
+ <div class="section">
9
+ <h2> How to use </h2>
10
+ <p>The values you see here correspond to literal HTML copy text in different parts of the parent website. When you edit them, the text on the website will change. Use ctrl-f or command-f to search for text, then click the left hand side links to edit. </p>
11
+ </div>
33
12
 
34
- <div class="section">
35
- <h2> About </h2>
36
- <p>Copycat is a product of <a href="http://www.vermonster.com">Vermonster LLC</a>. Thanks for using!</p>
37
- </div>
13
+ <div class="section">
14
+ <h2> Importing and Exporting </h2>
15
+ <p> Copycat text is data--not code. By default, Copycat values are stored in your server's database, and not the codebase that powers your website. Therefore, you may have to download/upload Copycat data to transfer your copy edits between servers, or to safeguard them between database wipes. Copycat exports (and is able to re-import) all of its data in a format called "YAML."</p>
16
+ <h4> Downloading </h4>
17
+ <p>You can get a YAML file of all your copy by clicking "Download" on the main Copycat page.</p>
18
+ <h4> Uploading </h4>
19
+ <p>You can upload copy to Copycat by clicking "Upload" on the main page and uploading a properly formatted YAML file. Uploading copy won't delete any entries from Copycat, but it may update them or create new ones. Use this feature to mass-update your copy from between servers -- e.g., make changes to copy on a test server, and then when you're satisfied, download the YAML file and upload it to your production site. Downloading your copy as YAML and then immediately re-uploading it will leave your copy unchanged.</p>
20
+ <h4> Commiting copy to your codebase </h4>
21
+ <p>If you're pretty happy with your copy and don't expect to need to update it live anymore, or just want a bit more security, you can download your copy as YAML and include it as part of the Ruby on Rails application underneath your main website. You can then remove Copycat from the application entirely, and the website will still run exactly as before--it interfaces with Ruby on Rails's built-in translation mechanisms in a very unobtrusive way.
22
+ </div>
38
23
 
24
+ <div class="section">
25
+ <h2> About </h2>
26
+ <p>Copycat is a product of <a href="http://www.vermonster.com">Vermonster LLC</a>. Thanks for using!</p>
39
27
  </div>
40
28
 
41
29
  </div>
30
+
@@ -1,18 +1,11 @@
1
- <div id="copycat">
2
- <ul>
3
- <li><h2>Copycat</h2></li>
4
- <% href = copycat_translations_path %>
5
- <li><a href=<%=href%>>Back</a></li>
6
- </ul>
7
1
  <div id="upload">
8
2
  <p>
9
3
  Upload a YAML (.yml) file following <a href="http://guides.rubyonrails.org/i18n.html">I18n conventions</a>.
10
4
  </p>
11
- <%= form_tag 'import_yaml', :multipart => true do -%>
5
+ <%= form_tag 'import_yaml', :multipart => true, :'accept-charset' => 'UTF-8' do -%>
12
6
  <%= file_field_tag "file" %>
13
7
  <%= submit_tag "Upload" %>
14
8
  <% end %>
15
9
  <div class="copycat-alert"> <%= notice %> </div>
16
10
  </div>
17
- </div>
18
11
 
@@ -0,0 +1,15 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Copycat</title>
5
+ <%= stylesheet_link_tag "copycat_engine", :media => "all" %>
6
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
7
+ </head>
8
+ <body class="copycat">
9
+ <div id="copycat">
10
+ <%= render :partial => "copycat_header" %>
11
+ <%= yield %>
12
+ </div>
13
+
14
+ </body>
15
+ </html>
@@ -1,10 +1,13 @@
1
1
  class CreateCopycatTranslations < ActiveRecord::Migration
2
2
  def up
3
3
  create_table :copycat_translations do |t|
4
- t.string "key"
5
- t.text "value"
4
+ t.string :key
5
+ t.text :value
6
6
  t.timestamps
7
7
  end
8
+ change_table :copycat_translations do |t|
9
+ t.index :key
10
+ end
8
11
  end
9
12
 
10
13
  def down
@@ -1,3 +1,3 @@
1
1
  module Copycat
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/copycat.rb CHANGED
@@ -24,11 +24,20 @@ from i18n gem, lib/i18n/backend/simple.rb
24
24
  =end
25
25
  module CopycatImplementation
26
26
  def lookup(locale, key, scope = [], options = {})
27
- cct = CopycatTranslation.find_by_key(key)
28
- return cct.value if cct
29
- value = super(locale, key, scope = [], options = {}) || key
30
- CopycatTranslation.create(key: key, value: value)
31
- value
27
+ begin
28
+ cct = CopycatTranslation.find_by_key(key)
29
+ rescue ActiveRecord::StatementInvalid
30
+ raise if CopycatTranslation.table_exists?
31
+ #assert Rails is initializing for the purpose of running the copycat_translations migration
32
+ super
33
+ else
34
+ return cct.value if cct
35
+ value = super(locale, key, scope, options)
36
+ if value.is_a?(String) || value.nil?
37
+ CopycatTranslation.create(key: key, value: value)
38
+ end
39
+ value
40
+ end
32
41
  end
33
42
  end
34
43
 
@@ -1,4 +1,26 @@
1
- # desc "Explaining what the task does"
2
- # task :copycat do
3
- # # Task goes here
4
- # end
1
+ namespace :copycat do
2
+ desc "Install the plugin, including the migration."
3
+ task :install do
4
+ Rake::Task["copycat_engine:install:migrations"].invoke
5
+ Rake::Task["copycat:install_initializer"].invoke
6
+ end
7
+
8
+ task :install_initializer do
9
+ require 'digest'
10
+ username = (Digest::SHA2.new << rand.to_s).to_s[0..6]
11
+ password = (Digest::SHA2.new << rand.to_s).to_s[0..6]
12
+ filepath = Rails.root.join *%w(config initializers copycat.rb)
13
+ File.open(filepath, 'w') do |f|
14
+ f << <<-CONFIG
15
+ COPYCAT_USERNAME = "#{username}"
16
+ COPYCAT_PASSWORD = "#{password}"
17
+ CONFIG
18
+ end
19
+ puts <<-INFO
20
+ Copycat initializer created with
21
+ username: #{username}
22
+ password: #{password}
23
+ Now run 'rake db:migrate'.
24
+ INFO
25
+ end
26
+ end
@@ -0,0 +1,2 @@
1
+ COPYCAT_USERNAME = "ec1c2b9"
2
+ COPYCAT_PASSWORD = "acca43c"
Binary file
@@ -2,10 +2,13 @@
2
2
  class CreateCopycatTranslations < ActiveRecord::Migration
3
3
  def up
4
4
  create_table :copycat_translations do |t|
5
- t.string "key"
6
- t.text "value"
5
+ t.string :key
6
+ t.text :value
7
7
  t.timestamps
8
8
  end
9
+ change_table :copycat_translations do |t|
10
+ t.index :key
11
+ end
9
12
  end
10
13
 
11
14
  def down
@@ -11,7 +11,7 @@
11
11
  #
12
12
  # It's strongly recommended to check this file into your version control system.
13
13
 
14
- ActiveRecord::Schema.define(:version => 20120313192639) do
14
+ ActiveRecord::Schema.define(:version => 20120316153248) do
15
15
 
16
16
  create_table "copycat_translations", :force => true do |t|
17
17
  t.string "key"
@@ -20,4 +20,6 @@ ActiveRecord::Schema.define(:version => 20120313192639) do
20
20
  t.datetime "updated_at", :null => false
21
21
  end
22
22
 
23
+ add_index "copycat_translations", ["key"], :name => "index_copycat_translations_on_key"
24
+
23
25
  end
Binary file