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.
Files changed (123) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE/bug_report.md +18 -0
  3. data/.github/workflows/close_inactive_issues.yml +18 -0
  4. data/.github/workflows/release.yml +28 -0
  5. data/.github/workflows/test.yml +8 -9
  6. data/.gitignore +1 -1
  7. data/.tool-versions +1 -1
  8. data/CHANGELOG.md +9 -105
  9. data/CODEOWNERS +1 -0
  10. data/Gemfile +1 -1
  11. data/Gemfile.lock +244 -0
  12. data/Guardfile +13 -13
  13. data/README.md +81 -51
  14. data/RELEASING.md +3 -0
  15. data/docs/CHANGELOG.md +116 -0
  16. data/examples/demo/.gitattributes +7 -0
  17. data/examples/demo/.gitignore +35 -0
  18. data/examples/demo/Gemfile +74 -0
  19. data/examples/demo/Gemfile.lock +268 -0
  20. data/examples/demo/README.md +5 -0
  21. data/examples/demo/Rakefile +6 -0
  22. data/examples/demo/app/assets/config/manifest.js +4 -0
  23. data/examples/demo/app/assets/images/.keep +0 -0
  24. data/examples/demo/app/assets/stylesheets/application.css +15 -0
  25. data/examples/demo/app/channels/application_cable/channel.rb +4 -0
  26. data/examples/demo/app/channels/application_cable/connection.rb +4 -0
  27. data/examples/demo/app/controllers/application_controller.rb +2 -0
  28. data/examples/demo/app/controllers/concerns/.keep +0 -0
  29. data/examples/demo/app/controllers/main_controller.rb +4 -0
  30. data/examples/demo/app/helpers/application_helper.rb +2 -0
  31. data/examples/demo/app/helpers/main_helper.rb +2 -0
  32. data/examples/demo/app/javascript/application.js +3 -0
  33. data/examples/demo/app/javascript/controllers/application.js +9 -0
  34. data/examples/demo/app/javascript/controllers/hello_controller.js +7 -0
  35. data/examples/demo/app/javascript/controllers/index.js +11 -0
  36. data/examples/demo/app/jobs/application_job.rb +7 -0
  37. data/examples/demo/app/mailers/application_mailer.rb +4 -0
  38. data/examples/demo/app/models/application_record.rb +3 -0
  39. data/examples/demo/app/models/concerns/.keep +0 -0
  40. data/examples/demo/app/views/layouts/application.html.erb +17 -0
  41. data/examples/demo/app/views/layouts/mailer.html.erb +13 -0
  42. data/examples/demo/app/views/layouts/mailer.text.erb +1 -0
  43. data/examples/demo/app/views/main/index.html.erb +8 -0
  44. data/examples/demo/bin/bundle +109 -0
  45. data/examples/demo/bin/importmap +4 -0
  46. data/examples/demo/bin/rails +4 -0
  47. data/examples/demo/bin/rake +4 -0
  48. data/examples/demo/bin/setup +33 -0
  49. data/examples/demo/config/application.rb +22 -0
  50. data/examples/demo/config/boot.rb +4 -0
  51. data/examples/demo/config/cable.yml +10 -0
  52. data/examples/demo/config/credentials.yml.enc +1 -0
  53. data/examples/demo/config/database.yml +25 -0
  54. data/examples/demo/config/environment.rb +5 -0
  55. data/examples/demo/config/environments/development.rb +70 -0
  56. data/examples/demo/config/environments/production.rb +93 -0
  57. data/examples/demo/config/environments/test.rb +60 -0
  58. data/examples/demo/config/importmap.rb +7 -0
  59. data/examples/demo/config/initializers/assets.rb +12 -0
  60. data/examples/demo/config/initializers/content_security_policy.rb +25 -0
  61. data/examples/demo/config/initializers/filter_parameter_logging.rb +8 -0
  62. data/examples/demo/config/initializers/inflections.rb +16 -0
  63. data/examples/demo/config/initializers/permissions_policy.rb +11 -0
  64. data/examples/demo/config/initializers/phraseapp_in_context_editor.rb +20 -0
  65. data/examples/demo/config/locales/en.yml +38 -0
  66. data/examples/demo/config/puma.rb +43 -0
  67. data/examples/demo/config/routes.rb +6 -0
  68. data/examples/demo/config/storage.yml +34 -0
  69. data/examples/demo/config.ru +6 -0
  70. data/examples/demo/db/seeds.rb +7 -0
  71. data/examples/demo/lib/assets/.keep +0 -0
  72. data/examples/demo/lib/tasks/.keep +0 -0
  73. data/examples/demo/log/.keep +0 -0
  74. data/examples/demo/public/404.html +67 -0
  75. data/examples/demo/public/422.html +67 -0
  76. data/examples/demo/public/500.html +66 -0
  77. data/examples/demo/public/apple-touch-icon-precomposed.png +0 -0
  78. data/examples/demo/public/apple-touch-icon.png +0 -0
  79. data/examples/demo/public/favicon.ico +0 -0
  80. data/examples/demo/public/robots.txt +1 -0
  81. data/examples/demo/storage/.keep +0 -0
  82. data/examples/demo/test/application_system_test_case.rb +5 -0
  83. data/examples/demo/test/channels/application_cable/connection_test.rb +11 -0
  84. data/examples/demo/test/controllers/.keep +0 -0
  85. data/examples/demo/test/controllers/main_controller_test.rb +8 -0
  86. data/examples/demo/test/fixtures/files/.keep +0 -0
  87. data/examples/demo/test/helpers/.keep +0 -0
  88. data/examples/demo/test/integration/.keep +0 -0
  89. data/examples/demo/test/mailers/.keep +0 -0
  90. data/examples/demo/test/models/.keep +0 -0
  91. data/examples/demo/test/system/.keep +0 -0
  92. data/examples/demo/test/test_helper.rb +13 -0
  93. data/examples/demo/tmp/.keep +0 -0
  94. data/examples/demo/tmp/pids/.keep +0 -0
  95. data/examples/demo/tmp/storage/.keep +0 -0
  96. data/examples/demo/vendor/.keep +0 -0
  97. data/examples/demo/vendor/javascript/.keep +0 -0
  98. data/lib/generators/phraseapp_in_context_editor/install_generator.rb +3 -9
  99. data/lib/generators/phraseapp_in_context_editor/templates/phraseapp_in_context_editor.rb +9 -17
  100. data/lib/phraseapp-in-context-editor-ruby/adapters/fast_gettext.rb +20 -20
  101. data/lib/phraseapp-in-context-editor-ruby/adapters/i18n.rb +10 -10
  102. data/lib/phraseapp-in-context-editor-ruby/backend_service.rb +12 -99
  103. data/lib/phraseapp-in-context-editor-ruby/config.rb +13 -49
  104. data/lib/phraseapp-in-context-editor-ruby/delegate/fast_gettext.rb +13 -15
  105. data/lib/phraseapp-in-context-editor-ruby/delegate/i18n_delegate.rb +4 -50
  106. data/lib/phraseapp-in-context-editor-ruby/delegate.rb +13 -14
  107. data/lib/phraseapp-in-context-editor-ruby/engine.rb +5 -6
  108. data/lib/phraseapp-in-context-editor-ruby/version.rb +1 -3
  109. data/lib/phraseapp-in-context-editor-ruby/view_helpers.rb +26 -19
  110. data/lib/phraseapp-in-context-editor-ruby.rb +17 -52
  111. data/package-lock.json +6576 -0
  112. data/package.json +13 -0
  113. data/phraseapp-in-context-editor-ruby.gemspec +19 -32
  114. data/release.config.js +10 -0
  115. metadata +113 -97
  116. data/lib/generators/phraseapp_in_context_editor/templates/README +0 -10
  117. data/lib/phraseapp-in-context-editor-ruby/api_collection.rb +0 -41
  118. data/lib/phraseapp-in-context-editor-ruby/api_wrapper.rb +0 -59
  119. data/lib/phraseapp-in-context-editor-ruby/cache.rb +0 -37
  120. data/lib/phraseapp-in-context-editor-ruby/displayable_key_identifier.rb +0 -46
  121. data/lib/phraseapp-in-context-editor-ruby/fallback_keys_fetcher.rb +0 -44
  122. data/lib/phraseapp-in-context-editor-ruby/hash_flattener.rb +0 -53
  123. 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
- "#{decorated_key_name}"
6
+ decorated_key_name.to_s
9
7
  end
10
- alias :camelize :to_s
11
- alias :underscore :to_s
12
- alias :classify :to_s
13
- alias :dasherize :to_s
14
- alias :tableize :to_s
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) and Rails.respond_to?(:logger)
20
+ if defined?(Rails) && Rails.respond_to?(:logger)
23
21
  Rails.logger.warn(message)
24
22
  else
25
- $stderr.puts message
23
+ warn message
26
24
  end
27
25
  end
28
26
 
29
- protected
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
- unless @display_key.nil?
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
- # -*- encoding : utf-8 -*-
2
- require 'phraseapp-in-context-editor-ruby'
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 'phraseapp-in-context-editor-ruby', before: :disable_dependency_loading do |app|
10
- require 'phraseapp-in-context-editor-ruby/adapters/i18n'
11
- require 'phraseapp-in-context-editor-ruby/adapters/fast_gettext'
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,5 +1,3 @@
1
1
  module PhraseApp
2
- module InContextEditor
3
- VERSION = "1.4.0"
4
- end
2
+ VERSION = "2.1.1"
5
3
  end
@@ -1,35 +1,42 @@
1
- require 'json'
1
+ require "json"
2
2
 
3
3
  module PhraseApp
4
4
  module InContextEditor
5
5
  module ViewHelpers
6
- def phraseapp_in_context_editor_js(opts={})
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
- js_default_options = PhraseApp::InContextEditor.js_options.inject({}) { |conf, (k,v)| conf[k.to_s] = v; conf}
11
- opts = opts.nil? ? {} : opts.inject({}) { |conf, (k,v)| conf[k.to_s] = v; conf}
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
- 'projectId' => PhraseApp::InContextEditor.project_id,
16
- 'prefix' => PhraseApp::InContextEditor.prefix,
17
- 'suffix' => PhraseApp::InContextEditor.suffix,
18
- 'apiBaseUrl' => "#{PhraseApp::InContextEditor.api_host}/api/v2",
19
- }.merge(js_default_options).merge(opts)
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 = <<-eos
22
- <script>
23
- window.PHRASEAPP_CONFIG = #{configuration.to_json};
24
- (function() {
25
- var phraseapp = document.createElement('script'); phraseapp.type = 'text/javascript'; phraseapp.async = true;
26
- phraseapp.src = ['#{PhraseApp::InContextEditor.js_use_ssl ? 'https' : 'http'}://', '#{PhraseApp::InContextEditor.js_host}#{PhraseApp::InContextEditor.js_path}?', new Date().getTime()].join('');
27
- var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(phraseapp, s);
28
- })();
29
- </script>
30
- eos
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
- # -*- encoding : utf-8 -*-
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, 'phraseapp-in-context-editor-ruby/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 access_token
35
- config.access_token
32
+ def account_id
33
+ config.account_id
36
34
  end
37
35
 
38
- def skip_ssl_verification
39
- config.skip_ssl_verification
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 js_use_ssl
67
- config.js_use_ssl
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 = self.config.dup
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, 'phraseapp-in-context-editor-ruby/view_helpers'
70
+ autoload :ViewHelpers, "phraseapp-in-context-editor-ruby/view_helpers"
105
71
 
106
- require 'phraseapp-in-context-editor-ruby/version'
107
- require 'phraseapp-in-context-editor-ruby/engine'
108
- require 'phraseapp-in-context-editor-ruby/delegate'
109
- require 'phraseapp-in-context-editor-ruby/backend_service'
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 'phraseapp-in-context-editor-ruby/adapters/i18n'
116
- require 'phraseapp-in-context-editor-ruby/adapters/fast_gettext'
80
+ require "phraseapp-in-context-editor-ruby/adapters/i18n"
81
+ require "phraseapp-in-context-editor-ruby/adapters/fast_gettext"
117
82
  end