copy_tuner_client 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/app/assets/javascripts/copyray.js.coffee +36 -7
- data/app/assets/stylesheets/copyray.css +19 -2
- data/app/views/_copy_tuner_bar.html.erb +4 -3
- data/lib/copy_tuner_client/configuration.rb +4 -0
- data/lib/copy_tuner_client/copyray_middleware.rb +7 -3
- data/lib/copy_tuner_client/engine.rb +5 -2
- data/lib/copy_tuner_client/simple_form_extention.rb +1 -1
- data/lib/copy_tuner_client/translation_log.rb +6 -2
- data/lib/copy_tuner_client/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15965d36a12789bda029ce93db59815b091aa1a6
|
4
|
+
data.tar.gz: 6468475b0087640533d917d0b9adc9b1ef58b2b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0fe5ce9e0350fee38039f699433df6b2a3efcc21b38d8738656328d9b22aa3c22d50dba9876d462d7fae3c1a67335239aa9928ba191491f69a80afd9c22e24f
|
7
|
+
data.tar.gz: 78f7e7c05c685d7293ebf2524aab33197f24f642fb4eaed440774a3df93f10844baf37c090ccebcba9179db53b8f0bac287ca0ebc549c6cfcfa2b86f36c3459d
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -221,25 +221,28 @@ util =
|
|
221
221
|
Copyray.showBar = ->
|
222
222
|
$('#copy-tuner-bar').show()
|
223
223
|
$('.copyray-toggle-button').hide()
|
224
|
+
Copyray.focusSearchBox()
|
224
225
|
|
225
226
|
Copyray.hideBar = ->
|
226
227
|
$('#copy-tuner-bar').hide()
|
227
228
|
$('.copyray-toggle-button').show()
|
228
|
-
$('
|
229
|
+
$('.js-copy-tuner-bar-log-menu').hide()
|
229
230
|
|
230
231
|
Copyray.createLogMenu = ->
|
231
|
-
$tbody = $('
|
232
|
+
$tbody = $('.js-copy-tuner-bar-log-menu__tbody.is-not-initialized')
|
232
233
|
return if $tbody.length == 0
|
233
234
|
$tbody.removeClass('is-not-initialized')
|
234
235
|
baseUrl = $('[data-copy-tuner-url]').data('copy-tuner-url')
|
235
236
|
log = $('[data-copy-tuner-translation-log').data('copy-tuner-translation-log')
|
236
|
-
|
237
|
+
keys = Object.keys(log).sort()
|
238
|
+
$.each keys, (_, k) ->
|
239
|
+
v = log[k]
|
237
240
|
if v != ''
|
238
241
|
url = "#{baseUrl}/blurbs/#{k}/edit"
|
239
242
|
$a = $("<a href='#{url}' class='js-copy-tuner-blurb-link'>").text k
|
240
243
|
$td1 = $('<td>').append $a
|
241
244
|
$td2 = $('<td>').text v
|
242
|
-
$tr = $("<tr class='js-copy-tuner-blurb-row'>")
|
245
|
+
$tr = $("<tr class='copy-tuner-bar-log-menu__row js-copy-tuner-blurb-row'>")
|
243
246
|
$tr.append $td1, $td2
|
244
247
|
$tbody.append $tr
|
245
248
|
$tbody.on 'click', '.js-copy-tuner-blurb-link', (e) ->
|
@@ -247,7 +250,33 @@ Copyray.createLogMenu = ->
|
|
247
250
|
$tbody.on 'click', '.js-copy-tuner-blurb-row', ->
|
248
251
|
Copyray.open $(@).find('a').attr('href')
|
249
252
|
|
250
|
-
|
251
|
-
|
253
|
+
Copyray.focusSearchBox = ->
|
254
|
+
$('.js-copy-tuner-bar-search').focus()
|
255
|
+
|
256
|
+
Copyray.toggleLogMenu = ->
|
252
257
|
Copyray.createLogMenu()
|
253
|
-
$('
|
258
|
+
$('.js-copy-tuner-bar-log-menu').toggle()
|
259
|
+
|
260
|
+
$(document).on 'click', '.js-copy-tuner-bar-open-log', (e) ->
|
261
|
+
e.preventDefault()
|
262
|
+
Copyray.toggleLogMenu()
|
263
|
+
|
264
|
+
do ->
|
265
|
+
timer = null
|
266
|
+
lastKeyword = ''
|
267
|
+
$(document).on 'focus', '.js-copy-tuner-bar-search', ->
|
268
|
+
lastKeyword = $(@).val()
|
269
|
+
$(document).on 'keyup', '.js-copy-tuner-bar-search', ->
|
270
|
+
keyword = $.trim($(@).val())
|
271
|
+
if lastKeyword != keyword
|
272
|
+
Copyray.toggleLogMenu() if !$('.js-copy-tuner-bar-log-menu').is(':visible')
|
273
|
+
clearTimeout(timer)
|
274
|
+
timer = setTimeout ->
|
275
|
+
if keyword == ''
|
276
|
+
$('.js-copy-tuner-blurb-row').show()
|
277
|
+
else
|
278
|
+
$('.js-copy-tuner-blurb-row').hide()
|
279
|
+
$(".js-copy-tuner-blurb-row td:contains(#{keyword})").closest('.js-copy-tuner-blurb-row').show()
|
280
|
+
, 500
|
281
|
+
lastKeyword = keyword
|
282
|
+
|
@@ -130,12 +130,16 @@ a.copyray-toggle-button:hover {
|
|
130
130
|
padding: 2px 8px;
|
131
131
|
}
|
132
132
|
|
133
|
+
#copy-tuner-bar-log-menu__tbody tr {
|
134
|
+
cursor: pointer;
|
135
|
+
}
|
136
|
+
|
133
137
|
#copy-tuner-bar-log-menu__tbody tr:hover {
|
134
|
-
background: #444
|
138
|
+
background: #444;
|
135
139
|
}
|
136
140
|
|
137
141
|
#copy-tuner-bar-log-menu__tbody a {
|
138
|
-
color: #fff
|
142
|
+
color: #fff;
|
139
143
|
}
|
140
144
|
|
141
145
|
#copy-tuner-bar-log-menu__tbody a:hover, #copy-tuner-bar-log-menu__tbody a:focus {
|
@@ -166,3 +170,16 @@ a.copyray-toggle-button:hover {
|
|
166
170
|
text-decoration: none;
|
167
171
|
background-color: #555;
|
168
172
|
}
|
173
|
+
|
174
|
+
.copy-tuner-bar__search {
|
175
|
+
-webkit-appearance: none;
|
176
|
+
-moz-appearance: none;
|
177
|
+
appearance: none;
|
178
|
+
border: none;
|
179
|
+
border-radius: 2px;
|
180
|
+
background-image: linear-gradient(rgba(0, 0, 0, 0.2), rgba(0, 0, 0, 0));
|
181
|
+
box-shadow: inset 0 1px 0 rgba(0, 0, 0, 0.2), inset 0 0 2px rgba(0, 0, 0, 0.2);
|
182
|
+
padding: 2px 8px;
|
183
|
+
vertical-align: middle;
|
184
|
+
color: black;
|
185
|
+
}
|
@@ -1,11 +1,12 @@
|
|
1
1
|
<div id="copy-tuner-bar" style="display:none">
|
2
2
|
<%= link_to 'CopyTuner', CopyTunerClient.configuration.project_url, class: 'copy-tuner-bar-button', target: '_blank' %>
|
3
3
|
<a href="/copytuner" target="_blank" class="copy-tuner-bar-button">Sync</a>
|
4
|
-
<a href="javascript:void(0)" class="copy-tuner-bar-open-log copy-tuner-bar-button">Translations in this page</a>
|
4
|
+
<a href="javascript:void(0)" class="copy-tuner-bar-open-log copy-tuner-bar-button js-copy-tuner-bar-open-log">Translations in this page</a>
|
5
|
+
<input type="text" class="copy-tuner-bar__search js-copy-tuner-bar-search" placeholder="search">
|
5
6
|
</div>
|
6
|
-
<div id="copy-tuner-bar-log-menu" style="display:none">
|
7
|
+
<div id="copy-tuner-bar-log-menu" class="js-copy-tuner-bar-log-menu" style="display:none">
|
7
8
|
<table>
|
8
|
-
<tbody id="copy-tuner-bar-log-menu__tbody" class="is-not-initialized">
|
9
|
+
<tbody id="copy-tuner-bar-log-menu__tbody" class="js-copy-tuner-bar-log-menu__tbody is-not-initialized">
|
9
10
|
</tbody>
|
10
11
|
</table>
|
11
12
|
</div>
|
@@ -119,6 +119,9 @@ module CopyTunerClient
|
|
119
119
|
# @return [Regexp] Copyray js injection pattern for precompiled
|
120
120
|
attr_accessor :copyray_js_injection_regexp_for_precompiled
|
121
121
|
|
122
|
+
# @return [Boolean] To disable Copyray comment injection, set true
|
123
|
+
attr_accessor :disable_copyray_comment_injection
|
124
|
+
|
122
125
|
alias_method :secure?, :secure
|
123
126
|
|
124
127
|
# Instantiated from {CopyTunerClient.configure}. Sets defaults.
|
@@ -137,6 +140,7 @@ module CopyTunerClient
|
|
137
140
|
self.secure = true
|
138
141
|
self.test_environments = %w(test cucumber)
|
139
142
|
self.s3_host = 'copy-tuner-data-prod.s3.amazonaws.com'
|
143
|
+
self.disable_copyray_comment_injection = false
|
140
144
|
|
141
145
|
# Matches:
|
142
146
|
# <script src="/assets/jquery.js"></script>
|
@@ -35,9 +35,13 @@ module CopyTunerClient
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def append_translation_logs(html)
|
38
|
-
|
39
|
-
|
40
|
-
|
38
|
+
if CopyTunerClient::TranslationLog.initialized?
|
39
|
+
json = CopyTunerClient::TranslationLog.translations.to_json
|
40
|
+
# Use block to avoid back reference \?
|
41
|
+
html.sub('</body>') { "<div data-copy-tuner-translation-log='#{ERB::Util.html_escape json}' data-copy-tuner-url='#{CopyTunerClient.configuration.project_url}'></div></body>" }
|
42
|
+
else
|
43
|
+
html
|
44
|
+
end
|
41
45
|
end
|
42
46
|
|
43
47
|
def inject_copy_tuner_bar(html)
|
@@ -11,7 +11,7 @@ module CopyTunerClient
|
|
11
11
|
ActionView::Helpers::TranslationHelper.class_eval do
|
12
12
|
def translate_with_copyray_comment(key, options = {})
|
13
13
|
source = translate_without_copyray_comment(key, options)
|
14
|
-
if options[:rescue_format] == :html
|
14
|
+
if !CopyTunerClient.configuration.disable_copyray_comment_injection && (options[:rescue_format] == :html || options[:rescue_format].nil?)
|
15
15
|
CopyTunerClient::Copyray.augment_template(source, scope_key_by_partial(key))
|
16
16
|
else
|
17
17
|
source
|
@@ -20,10 +20,13 @@ module CopyTunerClient
|
|
20
20
|
if CopyTunerClient.configuration.enable_middleware?
|
21
21
|
alias_method_chain :translate, :copyray_comment
|
22
22
|
alias :t :translate
|
23
|
-
CopyTunerClient::TranslationLog.install_hook
|
24
23
|
end
|
25
24
|
end
|
26
25
|
end
|
26
|
+
|
27
|
+
if CopyTunerClient.configuration.enable_middleware?
|
28
|
+
CopyTunerClient::TranslationLog.install_hook
|
29
|
+
end
|
27
30
|
end
|
28
31
|
|
29
32
|
initializer "copy_tuner.assets.precompile", group: :all do |app|
|
@@ -11,7 +11,7 @@ if defined?(SimpleForm)
|
|
11
11
|
def label_translation_with_copyray_comment
|
12
12
|
source = label_translation_without_copyray_comment
|
13
13
|
|
14
|
-
if object.class.respond_to?(:lookup_ancestors)
|
14
|
+
if !CopyTunerClient.configuration.disable_copyray_comment_injection && object.class.respond_to?(:lookup_ancestors)
|
15
15
|
attributes_scope = "#{object.class.i18n_scope}.attributes"
|
16
16
|
defaults = object.class.lookup_ancestors.map do |klass|
|
17
17
|
"#{attributes_scope}.#{klass.model_name.i18n_key}.#{reflection_or_attribute_name}"
|
@@ -1,15 +1,19 @@
|
|
1
1
|
module CopyTunerClient
|
2
2
|
class TranslationLog
|
3
3
|
def self.translations
|
4
|
-
Thread.current[:translations]
|
4
|
+
Thread.current[:translations]
|
5
5
|
end
|
6
6
|
|
7
7
|
def self.clear
|
8
8
|
Thread.current[:translations] = {}
|
9
9
|
end
|
10
10
|
|
11
|
+
def self.initialized?
|
12
|
+
!Thread.current[:translations].nil?
|
13
|
+
end
|
14
|
+
|
11
15
|
def self.add(key, result)
|
12
|
-
translations[key] = result
|
16
|
+
translations[key] = result if initialized? && !translations.key?(key)
|
13
17
|
end
|
14
18
|
|
15
19
|
def self.install_hook
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: copy_tuner_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- SonicGarden
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|