phraseapp-in-context-editor-ruby 1.4.0 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE/bug_report.md +18 -0
- data/.github/workflows/close_inactive_issues.yml +18 -0
- data/.github/workflows/release.yml +28 -0
- data/.github/workflows/test.yml +8 -9
- data/.gitignore +1 -1
- data/.tool-versions +1 -1
- data/CHANGELOG.md +9 -105
- data/CODEOWNERS +1 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +244 -0
- data/Guardfile +13 -13
- data/README.md +81 -51
- data/RELEASING.md +3 -0
- data/docs/CHANGELOG.md +116 -0
- data/examples/demo/.gitattributes +7 -0
- data/examples/demo/.gitignore +35 -0
- data/examples/demo/Gemfile +74 -0
- data/examples/demo/Gemfile.lock +268 -0
- data/examples/demo/README.md +5 -0
- data/examples/demo/Rakefile +6 -0
- data/examples/demo/app/assets/config/manifest.js +4 -0
- data/examples/demo/app/assets/images/.keep +0 -0
- data/examples/demo/app/assets/stylesheets/application.css +15 -0
- data/examples/demo/app/channels/application_cable/channel.rb +4 -0
- data/examples/demo/app/channels/application_cable/connection.rb +4 -0
- data/examples/demo/app/controllers/application_controller.rb +2 -0
- data/examples/demo/app/controllers/concerns/.keep +0 -0
- data/examples/demo/app/controllers/main_controller.rb +4 -0
- data/examples/demo/app/helpers/application_helper.rb +2 -0
- data/examples/demo/app/helpers/main_helper.rb +2 -0
- data/examples/demo/app/javascript/application.js +3 -0
- data/examples/demo/app/javascript/controllers/application.js +9 -0
- data/examples/demo/app/javascript/controllers/hello_controller.js +7 -0
- data/examples/demo/app/javascript/controllers/index.js +11 -0
- data/examples/demo/app/jobs/application_job.rb +7 -0
- data/examples/demo/app/mailers/application_mailer.rb +4 -0
- data/examples/demo/app/models/application_record.rb +3 -0
- data/examples/demo/app/models/concerns/.keep +0 -0
- data/examples/demo/app/views/layouts/application.html.erb +17 -0
- data/examples/demo/app/views/layouts/mailer.html.erb +13 -0
- data/examples/demo/app/views/layouts/mailer.text.erb +1 -0
- data/examples/demo/app/views/main/index.html.erb +8 -0
- data/examples/demo/bin/bundle +109 -0
- data/examples/demo/bin/importmap +4 -0
- data/examples/demo/bin/rails +4 -0
- data/examples/demo/bin/rake +4 -0
- data/examples/demo/bin/setup +33 -0
- data/examples/demo/config/application.rb +22 -0
- data/examples/demo/config/boot.rb +4 -0
- data/examples/demo/config/cable.yml +10 -0
- data/examples/demo/config/credentials.yml.enc +1 -0
- data/examples/demo/config/database.yml +25 -0
- data/examples/demo/config/environment.rb +5 -0
- data/examples/demo/config/environments/development.rb +70 -0
- data/examples/demo/config/environments/production.rb +93 -0
- data/examples/demo/config/environments/test.rb +60 -0
- data/examples/demo/config/importmap.rb +7 -0
- data/examples/demo/config/initializers/assets.rb +12 -0
- data/examples/demo/config/initializers/content_security_policy.rb +25 -0
- data/examples/demo/config/initializers/filter_parameter_logging.rb +8 -0
- data/examples/demo/config/initializers/inflections.rb +16 -0
- data/examples/demo/config/initializers/permissions_policy.rb +11 -0
- data/examples/demo/config/initializers/phraseapp_in_context_editor.rb +20 -0
- data/examples/demo/config/locales/en.yml +38 -0
- data/examples/demo/config/puma.rb +43 -0
- data/examples/demo/config/routes.rb +6 -0
- data/examples/demo/config/storage.yml +34 -0
- data/examples/demo/config.ru +6 -0
- data/examples/demo/db/seeds.rb +7 -0
- data/examples/demo/lib/assets/.keep +0 -0
- data/examples/demo/lib/tasks/.keep +0 -0
- data/examples/demo/log/.keep +0 -0
- data/examples/demo/public/404.html +67 -0
- data/examples/demo/public/422.html +67 -0
- data/examples/demo/public/500.html +66 -0
- data/examples/demo/public/apple-touch-icon-precomposed.png +0 -0
- data/examples/demo/public/apple-touch-icon.png +0 -0
- data/examples/demo/public/favicon.ico +0 -0
- data/examples/demo/public/robots.txt +1 -0
- data/examples/demo/storage/.keep +0 -0
- data/examples/demo/test/application_system_test_case.rb +5 -0
- data/examples/demo/test/channels/application_cable/connection_test.rb +11 -0
- data/examples/demo/test/controllers/.keep +0 -0
- data/examples/demo/test/controllers/main_controller_test.rb +8 -0
- data/examples/demo/test/fixtures/files/.keep +0 -0
- data/examples/demo/test/helpers/.keep +0 -0
- data/examples/demo/test/integration/.keep +0 -0
- data/examples/demo/test/mailers/.keep +0 -0
- data/examples/demo/test/models/.keep +0 -0
- data/examples/demo/test/system/.keep +0 -0
- data/examples/demo/test/test_helper.rb +13 -0
- data/examples/demo/tmp/.keep +0 -0
- data/examples/demo/tmp/pids/.keep +0 -0
- data/examples/demo/tmp/storage/.keep +0 -0
- data/examples/demo/vendor/.keep +0 -0
- data/examples/demo/vendor/javascript/.keep +0 -0
- data/lib/generators/phraseapp_in_context_editor/install_generator.rb +3 -9
- data/lib/generators/phraseapp_in_context_editor/templates/phraseapp_in_context_editor.rb +9 -17
- data/lib/phraseapp-in-context-editor-ruby/adapters/fast_gettext.rb +20 -20
- data/lib/phraseapp-in-context-editor-ruby/adapters/i18n.rb +10 -10
- data/lib/phraseapp-in-context-editor-ruby/backend_service.rb +12 -99
- data/lib/phraseapp-in-context-editor-ruby/config.rb +13 -49
- data/lib/phraseapp-in-context-editor-ruby/delegate/fast_gettext.rb +13 -15
- data/lib/phraseapp-in-context-editor-ruby/delegate/i18n_delegate.rb +4 -50
- data/lib/phraseapp-in-context-editor-ruby/delegate.rb +13 -14
- data/lib/phraseapp-in-context-editor-ruby/engine.rb +5 -6
- data/lib/phraseapp-in-context-editor-ruby/version.rb +1 -3
- data/lib/phraseapp-in-context-editor-ruby/view_helpers.rb +26 -19
- data/lib/phraseapp-in-context-editor-ruby.rb +17 -52
- data/package-lock.json +6576 -0
- data/package.json +13 -0
- data/phraseapp-in-context-editor-ruby.gemspec +19 -32
- data/release.config.js +10 -0
- metadata +113 -97
- data/lib/generators/phraseapp_in_context_editor/templates/README +0 -10
- data/lib/phraseapp-in-context-editor-ruby/api_collection.rb +0 -41
- data/lib/phraseapp-in-context-editor-ruby/api_wrapper.rb +0 -59
- data/lib/phraseapp-in-context-editor-ruby/cache.rb +0 -37
- data/lib/phraseapp-in-context-editor-ruby/displayable_key_identifier.rb +0 -46
- data/lib/phraseapp-in-context-editor-ruby/fallback_keys_fetcher.rb +0 -44
- data/lib/phraseapp-in-context-editor-ruby/hash_flattener.rb +0 -53
- data/lib/phraseapp-in-context-editor-ruby/key_names_cache.rb +0 -53
@@ -1,17 +1,15 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
|
-
|
3
1
|
module PhraseApp
|
4
2
|
module InContextEditor
|
5
3
|
module Delegate
|
6
4
|
class Base < String
|
7
5
|
def to_s
|
8
|
-
|
6
|
+
decorated_key_name.to_s
|
9
7
|
end
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
8
|
+
alias_method :camelize, :to_s
|
9
|
+
alias_method :underscore, :to_s
|
10
|
+
alias_method :classify, :to_s
|
11
|
+
alias_method :dasherize, :to_s
|
12
|
+
alias_method :tableize, :to_s
|
15
13
|
|
16
14
|
# Delegate .html_safe from accessing Delegate object as if it was a hash,
|
17
15
|
# but instead perform it on the resulting string
|
@@ -19,23 +17,24 @@ module PhraseApp
|
|
19
17
|
|
20
18
|
def self.log(message)
|
21
19
|
message = "phrase: #{message}"
|
22
|
-
if defined?(Rails)
|
20
|
+
if defined?(Rails) && Rails.respond_to?(:logger)
|
23
21
|
Rails.logger.warn(message)
|
24
22
|
else
|
25
|
-
|
23
|
+
warn message
|
26
24
|
end
|
27
25
|
end
|
28
26
|
|
29
|
-
|
27
|
+
protected
|
28
|
+
|
30
29
|
def decorated_key_name
|
31
30
|
"#{PhraseApp::InContextEditor.prefix}phrase_#{normalized_display_key}#{PhraseApp::InContextEditor.suffix}"
|
32
31
|
end
|
33
32
|
|
34
33
|
def normalized_display_key
|
35
|
-
|
36
|
-
@display_key.gsub("<", "[[[[[[html_open]]]]]]").gsub(">", "[[[[[[html_close]]]]]]")
|
37
|
-
else
|
34
|
+
if @display_key.nil?
|
38
35
|
@display_key
|
36
|
+
else
|
37
|
+
@display_key.gsub("<", "[[[[[[html_open]]]]]]").gsub(">", "[[[[[[html_close]]]]]]")
|
39
38
|
end
|
40
39
|
end
|
41
40
|
end
|
@@ -1,14 +1,13 @@
|
|
1
|
-
|
2
|
-
require
|
3
|
-
require 'i18n'
|
1
|
+
require "phraseapp-in-context-editor-ruby"
|
2
|
+
require "i18n"
|
4
3
|
|
5
4
|
if defined? Rails
|
6
5
|
module PhraseApp
|
7
6
|
module InContextEditor
|
8
7
|
class Engine < Rails::Engine
|
9
|
-
initializer
|
10
|
-
require
|
11
|
-
require
|
8
|
+
initializer "phraseapp-in-context-editor-ruby", before: :disable_dependency_loading do |app|
|
9
|
+
require "phraseapp-in-context-editor-ruby/adapters/i18n"
|
10
|
+
require "phraseapp-in-context-editor-ruby/adapters/fast_gettext"
|
12
11
|
|
13
12
|
ActionView::Base.send :include, PhraseApp::InContextEditor::ViewHelpers
|
14
13
|
end
|
@@ -1,35 +1,42 @@
|
|
1
|
-
require
|
1
|
+
require "json"
|
2
2
|
|
3
3
|
module PhraseApp
|
4
4
|
module InContextEditor
|
5
5
|
module ViewHelpers
|
6
|
-
def
|
6
|
+
def load_in_context_editor(opts = {})
|
7
7
|
return "" unless PhraseApp::InContextEditor.enabled?
|
8
8
|
|
9
9
|
# stringify to reduce possible errors when passing symbols
|
10
|
-
|
11
|
-
|
10
|
+
opts = opts.nil? ? {} : opts.each_with_object({}) { |(k, v), conf|
|
11
|
+
conf[k.to_s] = v
|
12
|
+
}
|
12
13
|
|
13
14
|
# js options
|
14
15
|
configuration = {
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
"projectId" => PhraseApp::InContextEditor.project_id,
|
17
|
+
"accountId" => PhraseApp::InContextEditor.account_id,
|
18
|
+
"datacenter" => PhraseApp::InContextEditor.datacenter,
|
19
|
+
"prefix" => PhraseApp::InContextEditor.prefix,
|
20
|
+
"suffix" => PhraseApp::InContextEditor.suffix,
|
21
|
+
"origin" => PhraseApp::InContextEditor.origin
|
22
|
+
}.merge(opts)
|
20
23
|
|
21
|
-
snippet = <<-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
24
|
+
snippet = <<-EOS
|
25
|
+
<script>
|
26
|
+
window.PHRASEAPP_CONFIG = #{configuration.to_json};
|
27
|
+
(function() {
|
28
|
+
let phraseapp = document.createElement('script');
|
29
|
+
phraseapp.type = 'module';
|
30
|
+
phraseapp.async = true;
|
31
|
+
phraseapp.src = "https://d2bgdldl6xit7z.cloudfront.net/latest/ice/index.js";
|
32
|
+
let script = document.getElementsByTagName('script')[0];
|
33
|
+
script.parentNode.insertBefore(phraseapp, script);
|
34
|
+
})();
|
35
|
+
</script>
|
36
|
+
EOS
|
31
37
|
snippet.respond_to?(:html_safe) ? snippet.html_safe : snippet
|
32
38
|
end
|
39
|
+
alias_method :phraseapp_in_context_editor_js, :load_in_context_editor
|
33
40
|
end
|
34
41
|
end
|
35
42
|
end
|
@@ -1,10 +1,8 @@
|
|
1
|
-
|
2
|
-
require 'phraseapp-ruby'
|
3
|
-
require 'request_store'
|
1
|
+
require "request_store"
|
4
2
|
|
5
3
|
module PhraseApp
|
6
4
|
module InContextEditor
|
7
|
-
autoload :Config,
|
5
|
+
autoload :Config, "phraseapp-in-context-editor-ruby/config"
|
8
6
|
|
9
7
|
class << self
|
10
8
|
def config
|
@@ -31,24 +29,12 @@ module PhraseApp
|
|
31
29
|
config.project_id
|
32
30
|
end
|
33
31
|
|
34
|
-
def
|
35
|
-
config.
|
32
|
+
def account_id
|
33
|
+
config.account_id
|
36
34
|
end
|
37
35
|
|
38
|
-
def
|
39
|
-
config.
|
40
|
-
end
|
41
|
-
|
42
|
-
def cache_key_segments_initial
|
43
|
-
config.cache_key_segments_initial
|
44
|
-
end
|
45
|
-
|
46
|
-
def cache_lifetime
|
47
|
-
config.cache_lifetime
|
48
|
-
end
|
49
|
-
|
50
|
-
def ignored_keys
|
51
|
-
config.ignored_keys
|
36
|
+
def datacenter
|
37
|
+
config.datacenter
|
52
38
|
end
|
53
39
|
|
54
40
|
def enabled=(value)
|
@@ -63,28 +49,8 @@ module PhraseApp
|
|
63
49
|
!config.enabled
|
64
50
|
end
|
65
51
|
|
66
|
-
def
|
67
|
-
config.
|
68
|
-
end
|
69
|
-
|
70
|
-
def js_host
|
71
|
-
config.js_host
|
72
|
-
end
|
73
|
-
|
74
|
-
def js_path
|
75
|
-
config.js_path
|
76
|
-
end
|
77
|
-
|
78
|
-
def js_options
|
79
|
-
config.js_options
|
80
|
-
end
|
81
|
-
|
82
|
-
def api_host
|
83
|
-
config.api_host
|
84
|
-
end
|
85
|
-
|
86
|
-
def api_client
|
87
|
-
config.api_client
|
52
|
+
def origin
|
53
|
+
config.origin
|
88
54
|
end
|
89
55
|
end
|
90
56
|
|
@@ -92,8 +58,8 @@ module PhraseApp
|
|
92
58
|
yield(PhraseApp::InContextEditor::Config)
|
93
59
|
end
|
94
60
|
|
95
|
-
def self.with_config(config_options={}, &block)
|
96
|
-
original_config =
|
61
|
+
def self.with_config(config_options = {}, &block)
|
62
|
+
original_config = config.dup
|
97
63
|
config.assign_values(config_options)
|
98
64
|
yield
|
99
65
|
ensure
|
@@ -101,17 +67,16 @@ module PhraseApp
|
|
101
67
|
end
|
102
68
|
end
|
103
69
|
|
104
|
-
autoload :ViewHelpers,
|
70
|
+
autoload :ViewHelpers, "phraseapp-in-context-editor-ruby/view_helpers"
|
105
71
|
|
106
|
-
require
|
107
|
-
require
|
108
|
-
require
|
109
|
-
require
|
110
|
-
require 'phraseapp-in-context-editor-ruby/view_helpers'
|
72
|
+
require "phraseapp-in-context-editor-ruby/engine"
|
73
|
+
require "phraseapp-in-context-editor-ruby/delegate"
|
74
|
+
require "phraseapp-in-context-editor-ruby/backend_service"
|
75
|
+
require "phraseapp-in-context-editor-ruby/view_helpers"
|
111
76
|
end
|
112
77
|
|
113
78
|
# Only load adapters directly if non-rails app, otherwise use engine
|
114
79
|
unless defined? Rails
|
115
|
-
require
|
116
|
-
require
|
80
|
+
require "phraseapp-in-context-editor-ruby/adapters/i18n"
|
81
|
+
require "phraseapp-in-context-editor-ruby/adapters/fast_gettext"
|
117
82
|
end
|