phraseapp-in-context-editor-ruby 1.4.0 → 3.2.0

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.
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 +36 -0
  5. data/.github/workflows/test.yml +8 -9
  6. data/.gitignore +1 -1
  7. data/.tool-versions +1 -1
  8. data/CHANGELOG.md +28 -79
  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 +96 -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 +10 -14
  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 +23 -125
  103. data/lib/phraseapp-in-context-editor-ruby/config.rb +14 -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 +6 -52
  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 +2 -4
  109. data/lib/phraseapp-in-context-editor-ruby/view_helpers.rb +26 -19
  110. data/lib/phraseapp-in-context-editor-ruby.rb +17 -48
  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
@@ -0,0 +1,66 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ .rails-default-error-page {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ .rails-default-error-page div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ .rails-default-error-page div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ .rails-default-error-page h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ .rails-default-error-page div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body class="rails-default-error-page">
58
+ <!-- This file lives in public/500.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>We're sorry, but something went wrong.</h1>
62
+ </div>
63
+ <p>If you are the application owner check the logs for more information.</p>
64
+ </div>
65
+ </body>
66
+ </html>
File without changes
File without changes
@@ -0,0 +1 @@
1
+ # See https://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
File without changes
@@ -0,0 +1,5 @@
1
+ require "test_helper"
2
+
3
+ class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
4
+ driven_by :selenium, using: :chrome, screen_size: [1400, 1400]
5
+ end
@@ -0,0 +1,11 @@
1
+ require "test_helper"
2
+
3
+ class ApplicationCable::ConnectionTest < ActionCable::Connection::TestCase
4
+ # test "connects with cookies" do
5
+ # cookies.signed[:user_id] = 42
6
+ #
7
+ # connect
8
+ #
9
+ # assert_equal connection.user_id, "42"
10
+ # end
11
+ end
File without changes
@@ -0,0 +1,8 @@
1
+ require "test_helper"
2
+
3
+ class MainControllerTest < ActionDispatch::IntegrationTest
4
+ test "should get index" do
5
+ get main_index_url
6
+ assert_response :success
7
+ end
8
+ end
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,13 @@
1
+ ENV["RAILS_ENV"] ||= "test"
2
+ require_relative "../config/environment"
3
+ require "rails/test_help"
4
+
5
+ class ActiveSupport::TestCase
6
+ # Run tests in parallel with specified workers
7
+ parallelize(workers: :number_of_processors)
8
+
9
+ # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
10
+ fixtures :all
11
+
12
+ # Add more helper methods to be used by all tests here...
13
+ end
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -1,21 +1,15 @@
1
- # -*- encoding : utf-8 -*-
2
-
3
1
  module PhraseappInContextEditor
4
2
  module Generators
5
3
  class InstallGenerator < Rails::Generators::Base
6
4
  source_root File.expand_path("../templates", __FILE__)
7
5
 
8
- desc "Creates a PhraseApp In-Context-Editor initializer for your application."
9
- class_option :access_token, type: :string, desc: "Your PhraseApp access token", required: true
10
- class_option :project_id, type: :string, desc: "Your PhraseApp project id", required: true
6
+ desc "Creates a Phrase In-Context-Editor initializer for your application."
7
+ class_option :account_id, type: :string, desc: "Your Phrase account id", required: true
8
+ class_option :project_id, type: :string, desc: "Your Phrase project id", required: true
11
9
 
12
10
  def copy_initializer
13
11
  template "phraseapp_in_context_editor.rb", "config/initializers/phraseapp_in_context_editor.rb"
14
12
  end
15
-
16
- def show_readme
17
- readme "README" if behavior == :invoke
18
- end
19
13
  end
20
14
  end
21
15
  end
@@ -2,26 +2,22 @@ PhraseApp::InContextEditor.configure do |config|
2
2
  # Enable or disable the In-Context-Editor in general
3
3
  config.enabled = true
4
4
 
5
- # Fetch your project id after creating your first project
6
- # in Translation Center.
7
- # You can find the project id in your project settings
8
- # page (https://phraseapp.com/projects)
5
+ # Configure with your project id and account id. You can find the
6
+ # project id in your project settings and account id in your account
7
+ # settings (https://app.phrase.com/)
9
8
  config.project_id = "<%= options[:project_id] %>"
10
-
11
- # You can create and manage access tokens in your profile settings
12
- # in Translation Center or via the Authorizations API
13
- # (https://developers.phraseapp.com/api/#authorizations).
14
- config.access_token = "<%= options[:access_token] %>"
9
+ config.account_id = "<%= options[:account_id] %>"
10
+ config.datacenter = "eu"
15
11
 
16
12
  # Configure an array of key names that should not be handled
17
13
  # by the In-Context-Editor.
18
- config.ignored_keys = ["number.*", "breadcrumb.*"]
14
+ # config.ignored_keys = ["number.*", "foo.bar"]
19
15
 
20
- # PhraseApp uses decorators to generate a unique identification key
16
+ # Phrase uses decorators to generate a unique identification key
21
17
  # in context of your document. However, this might result in conflicts
22
18
  # with other libraries (e.g. client-side template engines) that use a similar syntax.
23
19
  # If you encounter this problem, you might want to change this decorator pattern.
24
- # More information: https://help.phraseapp.com/phraseapp-for-developers/how-to-setup-and-configure-the-phraseapp-in-context-editor-ice/configure-in-context-editor
25
- # config.prefix = "{{__"
26
- # config.suffix = "__}}"
20
+ # More information: https://help.phrase.com/hc/en-us/articles/5784095916188-In-Context-Editor-Strings-
21
+ # config.prefix = "[[__"
22
+ # config.suffix = "__]]"
27
23
  end
@@ -1,25 +1,25 @@
1
- # -*- encoding : utf-8 -*-
1
+ require "phraseapp-in-context-editor-ruby/delegate/fast_gettext"
2
2
 
3
- require 'phraseapp-in-context-editor-ruby/delegate/fast_gettext'
3
+ if defined? FastGettext::Translation
4
+ module FastGettext
5
+ module Translation
6
+ def __with_phraseapp(*args)
7
+ PhraseApp::InContextEditor::Delegate::FastGettext.new(:_, *args)
8
+ end
9
+ alias_method :__without_phraseapp, :_
10
+ alias_method :_, :__with_phraseapp
4
11
 
5
- module FastGettext
6
- module Translation
7
- def __with_phraseapp(*args)
8
- PhraseApp::InContextEditor::Delegate::FastGettext.new(:_, *args)
9
- end
10
- alias_method :__without_phraseapp, :_
11
- alias_method :_, :__with_phraseapp
12
-
13
- def n__with_phraseapp(*args)
14
- PhraseApp::InContextEditor::Delegate::FastGettext.new(:n_, *args)
15
- end
16
- alias_method :n__without_phraseapp, :n_
17
- alias_method :n_, :n__with_phraseapp
12
+ def n__with_phraseapp(*args)
13
+ PhraseApp::InContextEditor::Delegate::FastGettext.new(:n_, *args)
14
+ end
15
+ alias_method :n__without_phraseapp, :n_
16
+ alias_method :n_, :n__with_phraseapp
18
17
 
19
- def s__with_phraseapp(*args)
20
- PhraseApp::InContextEditor::Delegate::FastGettext.new(:s_, *args)
18
+ def s__with_phraseapp(*args)
19
+ PhraseApp::InContextEditor::Delegate::FastGettext.new(:s_, *args)
20
+ end
21
+ alias_method :s__without_phraseapp, :s_
22
+ alias_method :s_, :s__with_phraseapp
21
23
  end
22
- alias_method :s__without_phraseapp, :s_
23
- alias_method :s_, :s__with_phraseapp
24
24
  end
25
- end if defined? FastGettext::Translation
25
+ end
@@ -1,12 +1,12 @@
1
- # -*- encoding : utf-8 -*-
2
-
3
- module I18n
4
- class << self
5
- def translate_with_phraseapp(*args)
6
- PhraseApp::InContextEditor.backend.translate(*args)
1
+ if defined?(I18n)
2
+ module I18n
3
+ class << self
4
+ def translate_with_phraseapp(...)
5
+ PhraseApp::InContextEditor.backend.translate(...)
6
+ end
7
+ alias_method :translate_without_phraseapp, :translate
8
+ alias_method :translate, :translate_with_phraseapp
9
+ alias_method :t, :translate
7
10
  end
8
- alias_method :translate_without_phraseapp, :translate
9
- alias_method :translate, :translate_with_phraseapp
10
- alias_method :t, :translate
11
11
  end
12
- end if defined?(I18n)
12
+ end
@@ -1,91 +1,46 @@
1
- # -*- encoding : utf-8 -*-
2
- require 'phraseapp-in-context-editor-ruby/api_collection'
3
- require 'phraseapp-in-context-editor-ruby/delegate/i18n_delegate'
1
+ require_relative "delegate/i18n_delegate"
4
2
 
5
3
  module PhraseApp
6
4
  module InContextEditor
7
5
  class BackendService
8
-
9
- attr_accessor :blacklisted_keys
10
-
11
6
  def initialize(args = {})
12
7
  self
13
8
  end
14
9
 
15
- def translate(*args)
16
- if to_be_translated_without_phraseapp?(args)
17
- # *Ruby 2.7+ keyword arguments warning*
18
- #
19
- # This method uses keyword arguments.
20
- # There is a breaking change in ruby that produces warning with ruby 2.7 and won't work as expected with ruby 3.0
21
- # The "hash" parameter must be passed as keyword argument.
22
- #
23
- # Good:
24
- # I18n.t(:salutation, :gender => 'w', :name => 'Smith')
25
- # I18n.t(:salutation, **{ :gender => 'w', :name => 'Smith' })
26
- # I18n.t(:salutation, **any_hash)
27
- #
28
- # Bad:
29
- # I18n.t(:salutation, { :gender => 'w', :name => 'Smith' })
30
- # I18n.t(:salutation, any_hash)
31
- #
32
- kw_args = args[1]
33
- if kw_args.present?
34
- I18n.translate_without_phraseapp(args[0], **kw_args)
35
- else
36
- I18n.translate_without_phraseapp(args[0])
37
- end
10
+ def translate(...)
11
+ if to_be_translated_without_phraseapp?(...)
12
+ I18n.translate_without_phraseapp(...)
38
13
  else
39
- phraseapp_delegate_for(args)
14
+ phraseapp_delegate_for(...)
40
15
  end
41
16
  end
42
17
 
43
- protected
44
- def to_be_translated_without_phraseapp?(args)
45
- PhraseApp::InContextEditor.disabled? or has_been_given_blacklisted_key?(args) or has_been_given_ignored_key?(args) or has_been_forced_to_resolve_with_phraseapp?(args)
46
- end
18
+ protected
47
19
 
48
- def has_been_given_blacklisted_key?(args)
49
- key = given_key_from_args(args)
50
- has_blacklist_entry_for_key?(key)
20
+ def to_be_translated_without_phraseapp?(...)
21
+ PhraseApp::InContextEditor.disabled? || ignored_key?(...) || has_been_forced_to_resolve_with_phraseapp?(...)
51
22
  end
52
23
 
53
- def has_been_given_ignored_key?(args)
24
+ def ignored_key?(*args)
54
25
  key = given_key_from_args(args)
55
- key_is_ignored?(key)
26
+ PhraseApp::InContextEditor.ignored_keys.any? do |ignored_key|
27
+ key.to_s[/\A#{ignored_key.gsub("*", ".*")}\Z/]
28
+ end
56
29
  end
57
30
 
58
- def has_been_forced_to_resolve_with_phraseapp?(args)
59
- (args.last.is_a?(Hash) and args.last[:resolve] == false)
31
+ def has_been_forced_to_resolve_with_phraseapp?(*args)
32
+ (args.last.is_a?(Hash) && args.last[:resolve] == false)
60
33
  end
61
34
 
62
35
  def given_key_from_args(args)
63
36
  extract_normalized_key_from_args(args)
64
37
  end
65
38
 
66
- def has_blacklist_entry_for_key?(key)
67
- blacklisted_keys.each do |blacklisted_key|
68
- return true if present?(key.to_s[/\A#{blacklisted_key.gsub("*", ".*")}\Z/])
69
- end
70
- false
71
- end
72
-
73
- def key_is_ignored?(key)
74
- PhraseApp::InContextEditor.ignored_keys.each do |ignored_key|
75
- return true if present?(key.to_s[/\A#{ignored_key.gsub("*", ".*")}\Z/])
76
- end
77
- false
78
- end
79
-
80
- def blacklisted_keys
81
- @blacklisted_keys ||= api_wrapper.blacklisted_keys
82
- end
83
-
84
- def phraseapp_delegate_for(args)
39
+ def phraseapp_delegate_for(*args)
85
40
  key = given_key_from_args(args)
86
41
  return nil unless present?(key)
87
42
 
88
- options = args[1].nil? ? {} : args[1]
43
+ options = options_from_args(args)
89
44
  PhraseApp::InContextEditor::Delegate::I18nDelegate.new(key, options, args)
90
45
  end
91
46
 
@@ -95,15 +50,14 @@ module PhraseApp
95
50
  end
96
51
 
97
52
  def transform_args(args)
98
- duped_args = args.map { |item| (item.is_a?(Symbol) or item.nil?) ? item : item.dup }
99
- transform_args_based_on_caller(duped_args)
53
+ duped_args = args.map { |item| (item.is_a?(Symbol) || item.nil?) ? item : item.dup }
100
54
  end
101
55
 
102
56
  def normalized_key(duped_args)
103
57
  splitted_args = split_args(duped_args)
104
58
  key = I18n::Backend::Flatten.normalize_flat_keys(*splitted_args)
105
59
  key.gsub!("..", ".")
106
- key.gsub!(/^\./, '')
60
+ key.gsub!(/^\./, "")
107
61
  key
108
62
  end
109
63
 
@@ -111,77 +65,21 @@ module PhraseApp
111
65
  options = options_from_args(args)
112
66
  key ||= args.shift
113
67
  locale = options.delete(:locale) || I18n.locale
114
- return [locale, key, options[:scope], nil]
68
+ [locale, key, options[:scope], nil]
115
69
  end
116
70
 
117
71
  def options_from_args(args)
118
72
  args.last.is_a?(Hash) ? args.pop : {}
119
73
  end
120
74
 
121
- def transform_args_based_on_caller(args)
122
- translation_caller = identify_caller
123
-
124
- if translation_caller and args.first =~ /^\./
125
- options = options_from_args(args)
126
-
127
- if not present?(options[:scope]) and present?(translation_caller)
128
- options[:scope] = translation_caller
129
- end
130
-
131
- args.push(options)
132
- parts = args.first.to_s.split(".").select { |e| not blank?(e) }
133
- args[0] = parts[0] if parts.size == 1
134
- end
135
-
136
- args
137
- end
138
-
139
- def identify_caller
140
- translation_caller = nil
141
- send(:caller)[0..6].each do |intermediate_caller|
142
- translation_caller = calling_template(intermediate_caller) unless translation_caller
143
- end
144
-
145
- if present?(translation_caller)
146
- find_lookup_scope(translation_caller)
147
- else
148
- nil
149
- end
150
- end
151
-
152
- def calling_template(string)
153
- string.match(/(views)(\/.+)(?>:[0-9]+:in)/)
154
- end
155
-
156
75
  def blank?(str)
157
- raise "blank?(str) can only be given a String or nil" unless str.is_a?(String) or str.nil?
158
- str.nil? or str == ''
76
+ raise "blank?(str) can only be given a String or nil" unless str.is_a?(String) || str.nil?
77
+ str.nil? || str == ""
159
78
  end
160
79
 
161
80
  def present?(str)
162
- raise "present?(str) can only be given a String or nil" unless str.is_a?(String) or str.nil?
163
- not blank?(str)
164
- end
165
-
166
- def find_lookup_scope(caller)
167
- split_path = caller[2][1..-1].split(".")[0].split("/")
168
-
169
- template_or_partial = remove_underscore_form_partial(split_path[-1])
170
- split_path[-1] = template_or_partial
171
-
172
- split_path.map!(&:to_sym)
173
- end
174
-
175
- def remove_underscore_form_partial(template_or_partial)
176
- if template_or_partial.to_s[0,1] == "_"
177
- template_or_partial.to_s[1..-1]
178
- else
179
- template_or_partial.to_s
180
- end
181
- end
182
-
183
- def api_wrapper
184
- @api_wrapper ||= PhraseApp::InContextEditor::ApiWrapper.new
81
+ raise "present?(str) can only be given a String or nil" unless str.is_a?(String) || str.nil?
82
+ !blank?(str)
185
83
  end
186
84
  end
187
85
  end
@@ -1,62 +1,41 @@
1
- # -*- encoding : utf-8 -*-
2
1
  module PhraseApp
3
2
  module InContextEditor
4
3
  class Config
5
4
  CONFIG_OPTIONS = {
5
+ account_id: nil,
6
6
  project_id: nil,
7
- access_token: nil,
7
+ datacenter: "eu",
8
8
  enabled: false,
9
- skip_ssl_verification: false,
10
9
  backend: PhraseApp::InContextEditor::BackendService.new,
11
10
  prefix: "{{__",
12
11
  suffix: "__}}",
13
- api_host: "https://api.phrase.com",
14
- js_host: "phraseapp.com",
15
- js_use_ssl: true,
16
- js_path: "/assets/in-context-editor/2.0/app.js",
17
- js_options: {},
18
- cache_key_segments_initial: ["simple_form"],
19
- cache_lifetime: 300,
20
- ignored_keys: [],
12
+ origin: "in-context-editor-ruby",
13
+ ignored_keys: []
21
14
  }.freeze
22
15
 
23
- CONFIG_OPTIONS_GLOBAL_ONLY = [
24
- :access_token,
25
- :skip_ssl_verification,
26
- :api_host
27
- ].freeze
28
-
29
16
  CONFIG_OPTIONS.each do |option, default_value|
30
- class_eval "@@#{option} = CONFIG_OPTIONS[:#{option}]"
17
+ class_eval "@@#{option} = CONFIG_OPTIONS[:#{option}]", __FILE__, __LINE__
31
18
 
32
19
  define_method("#{option}=") do |value|
33
- instance_eval "@#{option} = value; self.class.invalidate_api_client"
34
- end unless CONFIG_OPTIONS_GLOBAL_ONLY.include?(option)
20
+ instance_eval "@#{option} = value", __FILE__, __LINE__
21
+ end
35
22
 
36
- define_method("#{option}") do
37
- instance_eval "defined?(@#{option}) ? @#{option} : self.class.#{option}"
23
+ define_method(option.to_s) do
24
+ instance_eval "defined?(@#{option}) ? @#{option} : self.class.#{option}", __FILE__, __LINE__
38
25
  end
39
26
 
40
27
  define_singleton_method("#{option}=") do |value|
41
- instance_eval "@@#{option} = value; invalidate_api_client"
28
+ instance_eval "@@#{option} = value", __FILE__, __LINE__
42
29
  end
43
30
 
44
- define_singleton_method("#{option}") do
45
- instance_eval "@@#{option}"
31
+ define_singleton_method(option.to_s) do
32
+ instance_eval "@@#{option}", __FILE__, __LINE__
46
33
  end
47
34
  end
48
35
 
49
- def self.api_client
50
- @@api_client ||= build_api_client
51
- end
52
-
53
- def api_client
54
- self.class.api_client
55
- end
56
-
57
- def assign_values(config_options={})
36
+ def assign_values(config_options = {})
58
37
  config_options.each do |config_option, value|
59
- self.send("#{config_option}=", value)
38
+ send("#{config_option}=", value)
60
39
  end
61
40
  end
62
41
 
@@ -65,20 +44,6 @@ module PhraseApp
65
44
  send("#{option}=", default_value)
66
45
  end
67
46
  end
68
-
69
- protected
70
- def self.invalidate_api_client
71
- @@api_client = nil
72
- end
73
-
74
- def self.build_api_client
75
- credentials = PhraseApp::Auth::Credentials.new(
76
- token: @@access_token,
77
- host: @@api_host,
78
- skip_ssl_verification: @@skip_ssl_verification
79
- )
80
- PhraseApp::Client.new(credentials)
81
- end
82
47
  end
83
48
  end
84
49
  end
@@ -1,6 +1,4 @@
1
- # -*- encoding : utf-8 -*-
2
-
3
- require 'phraseapp-in-context-editor-ruby/delegate'
1
+ require_relative "../delegate"
4
2
 
5
3
  module PhraseApp
6
4
  module InContextEditor
@@ -12,20 +10,20 @@ module PhraseApp
12
10
  @display_key = params[:msgid]
13
11
  end
14
12
 
15
- private
13
+ private
14
+
16
15
  def params_from_args(args)
17
- params = case @method
18
- when :_
19
- {msgid: args.first}
20
- when :n_
21
- {msgid: args.first, msgid_plural: args[1], count: args.last}
22
- when :s_
23
- {msgid: args.first}
24
- else
25
- self.class.log("Unsupported FastGettext method #{@method}")
26
- {}
16
+ case @method
17
+ when :_
18
+ {msgid: args.first}
19
+ when :n_
20
+ {msgid: args.first, msgid_plural: args[1], count: args.last}
21
+ when :s_
22
+ {msgid: args.first}
23
+ else
24
+ self.class.log("Unsupported FastGettext method #{@method}")
25
+ {}
27
26
  end
28
- params
29
27
  end
30
28
  end
31
29
  end