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,53 +0,0 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
|
-
module PhraseApp
|
3
|
-
module InContextEditor
|
4
|
-
module HashFlattener
|
5
|
-
FLATTEN_SEPARATOR = "."
|
6
|
-
SEPARATOR_ESCAPE_CHAR = "\001"
|
7
|
-
|
8
|
-
def self.flatten(hash, escape, previous_key=nil, &block)
|
9
|
-
hash.each_pair do |key, value|
|
10
|
-
key = escape_default_separator(key) if escape
|
11
|
-
current_key = [previous_key, key].compact.join(FLATTEN_SEPARATOR).to_sym
|
12
|
-
yield current_key, value
|
13
|
-
flatten(value, escape, current_key, &block) if value.is_a?(Hash)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.expand_flat_hash(flat_hash, prefix=nil)
|
18
|
-
flat_hash ||= []
|
19
|
-
result = flat_hash.map do |key, value|
|
20
|
-
key = key.gsub(/#{prefix}[\.]?/, '') if prefix
|
21
|
-
to_nested_hash(key, value)
|
22
|
-
end
|
23
|
-
|
24
|
-
result = result.inject({}) { |hash, subhash| hash.deep_merge!(subhash) }
|
25
|
-
result
|
26
|
-
end
|
27
|
-
|
28
|
-
def self.to_nested_hash key, value
|
29
|
-
if contains_only_dots?(key) or starts_with_dot?(key) or ends_with_dot?(key)
|
30
|
-
{key.to_sym => value}
|
31
|
-
else
|
32
|
-
key.to_s.split(".").reverse.inject(value) { |hash, part| {part.to_sym => hash} }
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def self.contains_only_dots?(string)
|
37
|
-
string.to_s.gsub(/\./, "").length == 0
|
38
|
-
end
|
39
|
-
|
40
|
-
def self.starts_with_dot?(string)
|
41
|
-
string.to_s.start_with?(".")
|
42
|
-
end
|
43
|
-
|
44
|
-
def self.ends_with_dot?(string)
|
45
|
-
string.to_s.end_with?(".")
|
46
|
-
end
|
47
|
-
|
48
|
-
def self.escape_default_separator(key)
|
49
|
-
key.to_s.tr(FLATTEN_SEPARATOR, SEPARATOR_ESCAPE_CHAR)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
module PhraseApp
|
2
|
-
module InContextEditor
|
3
|
-
class KeyNamesCache
|
4
|
-
attr_reader :api_wrapper
|
5
|
-
|
6
|
-
def initialize(api_wrapper)
|
7
|
-
@api_wrapper = api_wrapper
|
8
|
-
end
|
9
|
-
|
10
|
-
def pre_cached(key_names)
|
11
|
-
unless cache.cached?(:translation_key_names)
|
12
|
-
cache.set(:translation_key_names, prefetched_key_names)
|
13
|
-
end
|
14
|
-
|
15
|
-
return key_names.select { |key_name| key_name_precached?(key_name) }
|
16
|
-
end
|
17
|
-
|
18
|
-
def pre_fetched(key_names)
|
19
|
-
key_names.select { |key_name| covered_by_initial_caching?(key_name) }
|
20
|
-
end
|
21
|
-
|
22
|
-
private
|
23
|
-
|
24
|
-
def prefetched_key_names
|
25
|
-
prefetched = Set.new
|
26
|
-
PhraseApp::InContextEditor.cache_key_segments_initial.each do |prefix|
|
27
|
-
api_wrapper.keys_with_prefix(prefix).each do |key|
|
28
|
-
prefetched.add(key.name)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
prefetched
|
32
|
-
end
|
33
|
-
|
34
|
-
def covered_by_initial_caching?(key_name)
|
35
|
-
key_name.start_with?(*PhraseApp::InContextEditor.cache_key_segments_initial)
|
36
|
-
end
|
37
|
-
|
38
|
-
def key_name_is_in_cache?(key_name)
|
39
|
-
cache.get(:translation_key_names).include?(key_name)
|
40
|
-
end
|
41
|
-
|
42
|
-
def key_name_precached?(key_name)
|
43
|
-
covered = covered_by_initial_caching?(key_name)
|
44
|
-
in_cache = key_name_is_in_cache?(key_name)
|
45
|
-
return covered && in_cache
|
46
|
-
end
|
47
|
-
|
48
|
-
def cache
|
49
|
-
RequestStore.store[:phraseapp_cache] ||= PhraseApp::InContextEditor::Cache.new
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|