phrasing 3.2.10 → 4.0.0rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +8 -11
  3. data/CHANGELOG.md +0 -20
  4. data/Gemfile +4 -1
  5. data/README-3.md +134 -0
  6. data/README.md +10 -14
  7. data/Release_notes_version_4.md +26 -0
  8. data/app/assets/javascripts/phrasing.js.erb +37 -17
  9. data/app/assets/stylesheets/phrasing_edit_mode_bubble.css.scss +3 -3
  10. data/app/controllers/phrasing_phrase_versions_controller.rb +4 -4
  11. data/app/controllers/phrasing_phrases_controller.rb +42 -75
  12. data/app/helpers/inline_helper.rb +24 -31
  13. data/app/models/phrasing_phrase.rb +29 -23
  14. data/app/views/phrasing/_production_warning.html.haml +0 -2
  15. data/app/views/phrasing_phrases/edit.html.haml +2 -2
  16. data/app/views/phrasing_phrases/import_export.html.haml +0 -5
  17. data/config/routes.rb +11 -9
  18. data/lib/generators/phrasing/phrasing_generator.rb +26 -0
  19. data/lib/generators/phrasing/templates/app/helpers/phrasing_helper.rb +12 -0
  20. data/lib/generators/phrasing/templates/config/initializers/phrasing.rb +11 -0
  21. data/{db/migrate/20131010101010_create_phrasing_phrase_versions.rb → lib/generators/phrasing/templates/db/migrate/create_phrasing_phrase_versions.rb} +2 -2
  22. data/{db/migrate/20120313191745_create_phrasing_phrases.rb → lib/generators/phrasing/templates/db/migrate/create_phrasing_phrases.rb} +2 -2
  23. data/lib/phrasing.rb +11 -37
  24. data/lib/phrasing/version.rb +2 -2
  25. data/phrasing.gemspec +1 -3
  26. data/spec/features/dummy_spec.rb +27 -24
  27. data/spec/features/phrasing_spec.rb +128 -84
  28. data/spec/lib/phrasing_spec.rb +50 -50
  29. metadata +14 -26
  30. data/4.0.0_changes.md +0 -1
  31. data/lib/phrasing/implementation.rb +0 -21
  32. data/lib/phrasing/simple.rb +0 -3
  33. data/lib/tasks/phrasing_tasks.rake +0 -69
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8c4d9f1a1afdcb5aeadf72bdd9582d062a9a2ab0
4
- data.tar.gz: d43f499b114f068bea2f8bb1566dae2357e8a110
3
+ metadata.gz: 75aa378d3f0142b6218e526c92f6774dea7fdab4
4
+ data.tar.gz: 44392541b00771fd8ace7a7e8a2997cc5742139d
5
5
  SHA512:
6
- metadata.gz: c981b81e3069c339740450619dcfdf72125fd2b9944f55ca83928da625ad066efdedbe1162a930ff8837b0aeaf26bfc152d8addee10fb60d531bd7693534fea3
7
- data.tar.gz: 2e56e2910c3009017daf98ad51371a88957052f0333e6ae55108456b99b2e7c36bb86b9313c4eaed790c8e48a2bd798d59b444cbb48ee0b1731050dd9e951895
6
+ metadata.gz: 3ff1aa31583ef783238cac57b9c601a0d57c2a0a52ccc38696c2239c5619f6a7470dbfcd5219ce99f9ebe0255e995dc95e5f29aaf1448efd2abd926d62e34893
7
+ data.tar.gz: 8c4a00598712079d7a1c7d99ba8898a1510ba916d2494da18409bcbe0bbdcfcf65511bbc8d1d225b27045af0fe0c690f6feaf85e715a7c06f06b4579c768c852
@@ -1,12 +1,9 @@
1
1
  language: ruby
2
-
3
- matrix:
4
- include:
5
- - rvm: 1.9.3
6
- env: "RAILS_VERSION=3.2.0"
7
- - rvm: 2.0.0
8
- env: "RAILS_VERSION=4.0.0"
9
- - rvm: 2.1.2
10
- env: "RAILS_VERSION=4.1.0"
11
- - rvm: 2.2.0
12
- env: "RAILS_VERSION=4.2.0"
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1.2
6
+ env:
7
+ - "RAILS_VERSION=3.2.0"
8
+ - "RAILS_VERSION=4.0.0"
9
+ - "RAILS_VERSION=4.1.0"
@@ -1,25 +1,5 @@
1
1
  # Phrasing Change Log
2
2
 
3
- ## 3.2.10 (October 2nd, 2015)
4
-
5
- Change order parameters in PhrasingPhrases#index to support SQLServer.
6
-
7
- ## 3.2.9 (January 7th, 2015)
8
-
9
- Require only haml, not haml-rails.
10
-
11
- ## 3.2.8 (January 6th, 2015)
12
-
13
- Fix confirm dialogs when deleting phrases and phrase versions.
14
-
15
- ## 3.2.7 (October 3rd, 2014)
16
-
17
- Add a config option to set a parent controller to Phrasing Engine Controllers.
18
-
19
- ## 3.2.6 (September 15th, 2014)
20
-
21
- Show Home page only when view responds to :root_path.
22
-
23
3
  ## 3.2.5 (June 17th, 2014)
24
4
 
25
5
  Added index for phrasing_phrase_id in versions table.
data/Gemfile CHANGED
@@ -8,7 +8,10 @@ rails_version = ENV["RAILS_VERSION"] || "4.1.4"
8
8
  gem "rails", "~> #{rails_version}"
9
9
 
10
10
  gem 'factory_girl_rails'
11
+ gem 'haml-rails'
11
12
  gem 'sqlite3'
12
13
  gem 'rspec-rails'
13
- gem 'capybara', '~> 2.2.0'
14
+ gem 'capybara', '~> 2.3.0'
14
15
  gem 'jasmine-rails'
16
+ gem 'pry-rails'
17
+ gem 'sass', '3.4.0'
@@ -0,0 +1,134 @@
1
+ # Phrasing!
2
+
3
+ [![Build Status](https://travis-ci.org/infinum/phrasing.png)](https://travis-ci.org/infinum/phrasing)
4
+
5
+ ![Phrasing](http://www.miataturbo.net/attachments/miata-parts-sale-trade-5/74257-lots-leftovers-near-boston-archer-phrasing2-300x225-jpg?dateline=1366600534)
6
+
7
+ Phrasing is a gem for live editing phrases (copy) on websites.
8
+
9
+ ## Installation
10
+
11
+ Include the gem in your Gemfile
12
+
13
+ ```ruby
14
+ gem "phrasing"
15
+ ```
16
+
17
+ Bundle the Gemfile
18
+
19
+ ```ruby
20
+ bundle install
21
+ ```
22
+
23
+ Run the install script which will create a migration file and a config file.
24
+
25
+ ```ruby
26
+ rake phrasing:install
27
+ ```
28
+
29
+ Migrate your database
30
+ ```ruby
31
+ rake db:migrate
32
+ ```
33
+
34
+ ## Setup
35
+
36
+ The rake task will also generate <tt>phrasing_helper.rb</tt> in your <tt>app/helpers</tt> folder. Here you will need to implement the <tt>can_edit_phrases?</tt> method. Use this to hook-up your existing user authentication system to work with Phrasing.
37
+
38
+ For example:
39
+
40
+ ```ruby
41
+ module PhrasingHelper
42
+
43
+ def can_edit_phrases?
44
+ current_user.is_admin?
45
+ end
46
+
47
+ end
48
+ ```
49
+ Include the phrasing **html** initializer at the top of your application layout file.
50
+
51
+ ```haml
52
+ = render 'phrasing/initializer'
53
+ ```
54
+
55
+ Include the required **javascript** file:
56
+
57
+ ```javascript
58
+ //= require phrasing
59
+ ```
60
+
61
+ Include the required **stylesheet** file:
62
+
63
+ ```css
64
+ *= require phrasing
65
+ ```
66
+
67
+ ## How to use phrasing?
68
+
69
+ You can start adding new phrases by simply adding them in your view file:
70
+
71
+ = phrase('my-first-phrase')
72
+
73
+ Aside from editing phrases (basically, Rails translations) you can also edit model attributes inline. Use the same `phrase` method, with the first attribute being the record in question, and the second one the attribute you wish to make editable:
74
+
75
+ = phrase(@post, :title)
76
+
77
+ In the above example, <tt>@post</tt> is the record with a <tt>title</tt> attribute.
78
+
79
+ ## Security
80
+
81
+ Since Phrasing can be used to update any attribute in any table (using the model_phrase method), special care must be taken into consideration from a security standpoint.
82
+
83
+ By default, Phrasing doesn't allow updating of any attribute apart from <tt>PhrasingPhrase.value</tt>. To be able to work with other attributes, you need to whitelist them.
84
+
85
+ In the <tt>config/initializers/phrasing.rb</tt> file you can whitelist your model attributes like this:
86
+
87
+ ```ruby
88
+ Phrasing.white_list = ["Post.title", "Post.body"]
89
+ ```
90
+
91
+ or you can whitelist all of them (not recommended) with:
92
+
93
+ ```ruby
94
+ Phrasing.allow_update_on_all_models_and_attributes = true
95
+ ```
96
+
97
+ ## Upgrading from version 2.x to 3.x
98
+
99
+ In versions 3.0.0 and above we have added the Phrasing Versioning System which requires an additional table, so if you are upgrading to a 3.x release, run <tt>rake phrasing:install</tt> to get the additional migration file, then run <tt>rake db:migrate</tt>.
100
+
101
+ ## Turbolinks
102
+
103
+ If you're experiencing problems with Rails apps using Turbolinks, include the [jQuery-turbolinks](https://github.com/kossnocorp/jquery.turbolinks) gem in your application and simply require it in the following order:
104
+
105
+ ```javascript
106
+ //= require jquery
107
+ //= require jquery.turbolinks
108
+ //= require phrasing
109
+ //= require turbolinks
110
+ ```
111
+
112
+ ## Phrasing Appearance
113
+
114
+ The `phrase` view helper can take the `options` hash as the last parameter. Features:
115
+ ```ruby
116
+ url: custom_url # point Phrasing to other actions in other controllers
117
+ inverse: true # change the hovered background and underline colors to better fit darker backgrounds
118
+ class: custom_class # add custom CSS classes to your phrases to change the appearance of phrases in your application
119
+ interpolation: { %min: 10 } # add variables to your translations just like w/ I18n
120
+ scope: 'homepage.footer' # add scopes just like you would w/ I18.n. If the first argument is 'test', than the key would be 'homepage.footer.test'
121
+ ```
122
+
123
+ ## Credits
124
+
125
+ Phrasing is maintained and sponsored by
126
+ [Infinum] (http://www.infinum.co).
127
+
128
+ ![Infinum](https://www.infinum.co/assets/logo_pic-2e19713f50692ed9b0805b199676c19a.png)
129
+
130
+ Phrasing leverages parts of [Copycat](https://github.com/Zorros/copycat) and [ZenPen](https://github.com/tholman/zenpen/tree/master/).
131
+
132
+ ## License
133
+
134
+ Phrasing is Copyright © 2013 Infinum. It is free software, and may be redistributed under the terms specified in the LICENSE file.
data/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  Phrasing is a gem for live editing phrases (copy) on websites.
8
8
 
9
- **Phrasing is currently iterating over release candidates for a major update: 4.0. The Readme for those versions can be found** [here](https://github.com/infinum/phrasing/tree/new-release-4)
9
+ **Notice:** If using Phrasing version 3, checkout the [old README](https://github.com/infinum/phrasing/blob/new-release-4/README-3.md).
10
10
 
11
11
  ## Installation
12
12
 
@@ -18,18 +18,18 @@ gem "phrasing"
18
18
 
19
19
  Bundle the Gemfile
20
20
 
21
- ```ruby
21
+ ```shell
22
22
  bundle install
23
23
  ```
24
24
 
25
25
  Run the install script which will create a migration file and a config file.
26
26
 
27
- ```ruby
28
- rake phrasing:install
27
+ ```shell
28
+ rails generate phrasing
29
29
  ```
30
30
 
31
31
  Migrate your database
32
- ```ruby
32
+ ```shell
33
33
  rake db:migrate
34
34
  ```
35
35
 
@@ -45,7 +45,7 @@ module PhrasingHelper
45
45
  def can_edit_phrases?
46
46
  current_user.is_admin?
47
47
  end
48
-
48
+
49
49
  end
50
50
  ```
51
51
  Include the phrasing **html** initializer at the top of your application layout file.
@@ -54,7 +54,7 @@ Include the phrasing **html** initializer at the top of your application layout
54
54
  = render 'phrasing/initializer'
55
55
  ```
56
56
 
57
- Include the required **javascript** file:
57
+ Include the required **javascript** files:
58
58
 
59
59
  ```javascript
60
60
  //= require phrasing
@@ -87,19 +87,15 @@ By default, Phrasing doesn't allow updating of any attribute apart from <tt>Phra
87
87
  In the <tt>config/initializers/phrasing.rb</tt> file you can whitelist your model attributes like this:
88
88
 
89
89
  ```ruby
90
- Phrasing.white_list = ["Post.title", "Post.body"]
90
+ config.white_list = ["Post.title", "Post.body"]
91
91
  ```
92
92
 
93
93
  or you can whitelist all of them (not recommended) with:
94
94
 
95
95
  ```ruby
96
- Phrasing.allow_update_on_all_models_and_attributes = true
96
+ config.allow_update_on_all_models_and_attributes = true
97
97
  ```
98
98
 
99
- ## Upgrading from version 2.x to 3.x
100
-
101
- In versions 3.0.0 and above we have added the Phrasing Versioning System which requires an additional table, so if you are upgrading to a 3.x release, run <tt>rake phrasing:install</tt> to get the additional migration file, then run <tt>rake db:migrate</tt>.
102
-
103
99
  ## Turbolinks
104
100
 
105
101
  If you're experiencing problems with Rails apps using Turbolinks, include the [jQuery-turbolinks](https://github.com/kossnocorp/jquery.turbolinks) gem in your application and simply require it in the following order:
@@ -117,7 +113,7 @@ The `phrase` view helper can take the `options` hash as the last parameter. Feat
117
113
  ```ruby
118
114
  url: custom_url # point Phrasing to other actions in other controllers
119
115
  inverse: true # change the hovered background and underline colors to better fit darker backgrounds
120
- class: custom_class # add custom CSS classes to your phrases to change the appearance of phrases in your application
116
+ class: custom_class # add custom CSS classes to your phrases to change the appearance of phrases in your application
121
117
  interpolation: { %min: 10 } # add variables to your translations just like w/ I18n
122
118
  scope: 'homepage.footer' # add scopes just like you would w/ I18.n. If the first argument is 'test', than the key would be 'homepage.footer.test'
123
119
  ```
@@ -0,0 +1,26 @@
1
+ # Changes
2
+
3
+ This document contains instructions for upgrading from Phrasing version 3 to Phrasing version 4.
4
+
5
+ ## Separation of I18n and Phrasing:
6
+
7
+ Phrasing no longer does monkeypatching over the I18n gem, so the I18n and Phrasings behaviors are completely separate.
8
+ When using the I18n.t() method, Phrasing will no longer copy the data from the translations file and continue to use translations from the database.
9
+
10
+ However, when using the phrase(key) method, if the key doesn't currently exist in the PhrasingPhrase table, it will do a lookup in the translations file and copy the data from there to the database.
11
+
12
+ ## Interpolation
13
+
14
+ Try not to use the interpolation option anymore since it will probably be kicked out in the first stable release.
15
+
16
+ The problem with the interpolation option is that most clients won't understand what's happening when they see something like "Hi, my name is %{name}" once they are editing data.
17
+
18
+ If they try to erase parts of it, the developer also might end up being confused and the UI might get broken or at least ugly for some time until the developer fixes the issue.
19
+
20
+ ## HTML Sanitization
21
+
22
+ There is a posibility we might add html sanitization to prevent ugly copy-pasted html insertion (as well as XSS attacks).
23
+
24
+ ## Switching rake tasks with Rails generators
25
+
26
+ Since Rails comes with outofbox generators that enable easy existing file detection and similar behaviors, Phrasing 4 will use Rails generators instead of the old rake tasks.
@@ -3,7 +3,30 @@
3
3
  //= require jquery_ujs
4
4
  //= require jquery.cookie
5
5
 
6
+ function StatusBubble(){
7
+ var $headline = $('#phrasing-edit-mode-bubble #phrasing-saved-status-headline p');
8
+ var $circle = $('#phrasing-saved-status-indicator-circle');
9
+
10
+ var alterStatus = function(text, color){
11
+ $headline.text(text);
12
+ $circle.css('background-color', color);
13
+ }
14
+
15
+ this.saving = function(){
16
+ alterStatus('Saving', 'orange');
17
+ }
18
+
19
+ this.saved = function(){
20
+ alterStatus('Saved', '#56AE45');
21
+ }
22
+
23
+ this.error = function(){
24
+ alterStatus('Error', 'red');
25
+ }
26
+ }
27
+
6
28
  var phrasing_setup = function(){
29
+ var status = new StatusBubble();
7
30
 
8
31
  // Initialize the editing bubble
9
32
  editor.init();
@@ -27,17 +50,15 @@ var phrasing_setup = function(){
27
50
  var timer_status = {}
28
51
 
29
52
  $('.phrasable').on('DOMNodeInserted DOMNodeRemoved DOMCharacterDataModified', function(e){
53
+ status.saving();
30
54
 
31
- $('#phrasing-edit-mode-bubble #phrasing-saved-status-headline p').text("Saving")
32
- $('#phrasing-saved-status-indicator-circle').css('background-color', 'orange')
33
-
34
55
  if (trigger_binded_events_for_phrasable_class == 1){
35
56
 
36
57
  var record = this;
37
-
58
+
38
59
  clearTimeout(timer[$(record).data("url")]);
39
60
  timer_status[$(record).data("url")] = 0;
40
-
61
+
41
62
  timer[$(record).data("url")] = setTimeout(function(){
42
63
  savePhraseViaAjax(record);
43
64
  delete timer_status[$(record).data("url")]
@@ -49,13 +70,13 @@ var phrasing_setup = function(){
49
70
 
50
71
  // AJAX Request
51
72
  function savePhraseViaAjax(record){
52
-
73
+
53
74
  var url = $(record).data("url");
54
75
 
55
76
  var content = record.innerHTML;
56
-
77
+
57
78
  if(content.length == 0){
58
- content= "Empty"
79
+ content = "Empty"
59
80
  }
60
81
 
61
82
  $.ajax({
@@ -64,21 +85,20 @@ var phrasing_setup = function(){
64
85
  data: { new_value: content },
65
86
  success: function(e){
66
87
  trigger_binded_events_for_phrasable_class = 0;
67
- if(content == "Empty"){
88
+ if(content === "Empty"){
68
89
  $('span.phrasable[data-url="'+ url +'"]').html(content)
69
90
  }else{
91
+ // Not to lose the cursor on the current contenteditable element
70
92
  $('span.phrasable[data-url="'+ url +'"]').not(record).html(content)
71
93
  }
72
94
  trigger_binded_events_for_phrasable_class = 1;
73
95
 
74
96
  if (Object.size(timer_status) == 0){
75
- $('#phrasing-edit-mode-bubble #phrasing-saved-status-headline p').text("Saved")
76
- $('#phrasing-saved-status-indicator-circle').css('background-color', '#56AE45')
97
+ status.saved();
77
98
  }
78
99
  },
79
100
  error: function(e){
80
- $('#phrasing-edit-mode-bubble #phrasing-saved-status-headline p').text("Error")
81
- $('#phrasing-saved-status-indicator-circle').css('background-color', 'red')
101
+ status.error();
82
102
  }
83
103
  });
84
104
  }
@@ -95,14 +115,14 @@ var phrasing_setup = function(){
95
115
  }
96
116
  });
97
117
 
98
- if($.cookie("editing_mode") == null){
118
+ if($.cookie("editing_mode") === null){
99
119
  $.cookie("editing_mode", "true");
100
- $('#edit-mode-onoffswitch').prop('checked', true)
120
+ $('#edit-mode-onoffswitch').prop('checked', true).change();
101
121
  }
102
122
  else if($.cookie("editing_mode") == "true"){
103
- $('#edit-mode-onoffswitch').prop('checked', true)
123
+ $('#edit-mode-onoffswitch').prop('checked', true).change();
104
124
  }else{
105
- $('#edit-mode-onoffswitch').prop('checked', false)
125
+ $('#edit-mode-onoffswitch').prop('checked', false).change();
106
126
  }
107
127
 
108
128
  };
@@ -23,7 +23,7 @@
23
23
  p{
24
24
  line-height:20px;
25
25
  }
26
- ::selection{ color: grey; background: white; }
26
+ ::selection{ color: grey; background: white; }
27
27
 
28
28
  #phrasing-edit-mode, #phrasing-saved-status, #phrasing-edit-all-phrases{
29
29
  height:32px;
@@ -81,7 +81,7 @@
81
81
  border: 3px solid #CCCCCC; border-radius: 5px;
82
82
  position: absolute; top: 0; bottom: 0; right: 29px;
83
83
  -moz-transition: all 0.3s ease-in 0s; -webkit-transition: all 0.3s ease-in 0s;
84
- -o-transition: all 0.3s ease-in 0s; transition: all 0.3s ease-in 0s;
84
+ -o-transition: all 0.3s ease-in 0s; transition: all 0.3s ease-in 0s;
85
85
  background-image: -moz-linear-gradient(center top, rgba(0,0,0,0.1) 0%, rgba(0,0,0,0) 100%);
86
86
  background-image: -webkit-linear-gradient(center top, rgba(0,0,0,0.1) 0%, rgba(0,0,0,0) 100%);
87
87
  background-image: -o-linear-gradient(center top, rgba(0,0,0,0.1) 0%, rgba(0,0,0,0) 100%);
@@ -112,7 +112,7 @@
112
112
  float:left;
113
113
  }
114
114
  #phrasing-saved-status-indicator-circle{
115
- background-color:green;
115
+ background-color: #56AE45;
116
116
  width:20px;
117
117
  height:20px;
118
118
  -webkit-border-radius: 10px;