moirai 0.3.0 → 0.4.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e9d7f98e48e08b3e5208041fbba3344f5b280492754b7943e159d0e90e71d075
4
- data.tar.gz: d4aa78c7ae9f0c27f18c3e760def299c5d8faf054b06423e300b2c095976ef0c
3
+ metadata.gz: 95cf427b4c903e4a772cad00b3165fc9a285d019678870996d6afd122ff9c4bf
4
+ data.tar.gz: ae20e09390c869f1971f309c2e049fddce6557f0122069175d7f9886e8719ea1
5
5
  SHA512:
6
- metadata.gz: cb39e17d721373254b27086f4cf351c6145a3aa921809b8de0921ca82c661d53e0a1fb38da524c4fe012c2ecfcde7ffa2ec1029432e88d0cc43cf2f067c55341
7
- data.tar.gz: 601b7c5353bbc71cd094223df88b74dc9f82d07657f306f8402160bc47f4d056940a28db55b8b88f4fd2275c23e66379e2778e2856f0d93a57defd7b706dc68c
6
+ metadata.gz: cd8ead3d31114b762f706f115102bc8f36f4d1d9082911e34ac37ac57ab26d9ebb1621c57f4bf3d91626b0e3ddac67d96ca65b60e0e239650b824b4d2bac64bd
7
+ data.tar.gz: 0db74b1d99fcd721b378ff9371f2342051f022e4bdd02023d04c73516733f3f76a091d65ad4f653d4411c17819e3a40d675605c4eee29c4622ac88b3aba43ee1
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.2.1
@@ -0,0 +1,18 @@
1
+ version: v1.0
2
+ name: main-deploy
3
+ agent:
4
+ machine:
5
+ type: e1-standard-2
6
+ os_image: ubuntu2004
7
+
8
+ blocks:
9
+ - name: main-deploy
10
+ task:
11
+ secrets:
12
+ - name: rubygems-deploy
13
+ jobs:
14
+ - name: main-deploy
15
+ commands:
16
+ - checkout --use-cache
17
+ - gem build moirai
18
+ - gem push moirai-*.gem
@@ -0,0 +1,82 @@
1
+ version: "v1.0"
2
+ name: moirai
3
+ agent:
4
+ machine:
5
+ type: e1-standard-2
6
+ os_image: ubuntu2004
7
+ auto_cancel:
8
+ running:
9
+ when: "true"
10
+
11
+ blocks:
12
+ - name: linter
13
+ execution_time_limit:
14
+ minutes: 10
15
+ dependencies: []
16
+ task:
17
+ secrets:
18
+ - name: moirai
19
+ prologue:
20
+ commands:
21
+ - checkout --use-cache
22
+ - cache restore
23
+ - bundle config set path 'vendor/bundle'
24
+ - bundle install -j 4
25
+ - cache store
26
+ jobs:
27
+ - name: linter
28
+ commands:
29
+ - bundle exec standardrb
30
+ - name: tests sqlite
31
+ execution_time_limit:
32
+ minutes: 10
33
+ dependencies: []
34
+ task:
35
+ secrets:
36
+ - name: moirai
37
+ prologue:
38
+ commands:
39
+ - checkout --use-cache
40
+ - cache restore
41
+ - bundle config set path 'vendor/bundle'
42
+ - bundle install -j 4
43
+ - cache store
44
+ jobs:
45
+ - name: tests sqlite
46
+ env_vars:
47
+ - name: TARGET_DB
48
+ value: sqlite
49
+ - name: RAILS_ENV
50
+ value: test
51
+ commands:
52
+ - bin/rails db:create db:schema:load
53
+ - bin/check
54
+ - name: tests postgres
55
+ execution_time_limit:
56
+ minutes: 10
57
+ dependencies:
58
+ - 'tests sqlite'
59
+ task:
60
+ secrets:
61
+ - name: moirai
62
+ prologue:
63
+ commands:
64
+ - checkout --use-cache
65
+ - cache restore
66
+ - bundle config set path 'vendor/bundle'
67
+ - bundle install -j 4
68
+ - cache store
69
+ jobs:
70
+ - name: tests postgres
71
+ env_vars:
72
+ - name: TARGET_DB
73
+ value: postgres
74
+ - name: RAILS_ENV
75
+ value: test
76
+ commands:
77
+ - sem-service start postgres 14 --username=semaphore
78
+ - bin/rails db:create db:schema:load
79
+ - bin/check
80
+ promotions:
81
+ - name: main
82
+ pipeline_file: main-deploy.yml
data/CHANGELOG.md CHANGED
@@ -1,3 +1,19 @@
1
+ ## 0.4.0 - Breaking Changes ⚠️
2
+
3
+ * Inline editing is now disabled by default. To enable it, specify the following in `application.rb`:
4
+
5
+ ```ruby
6
+ config.moirai.enable_inline_editing = ->(params:) { your_options_here }
7
+ ```
8
+
9
+ move in here the conditions you had previously defined in the helper.
10
+
11
+ * Moirai now works also in emails. That's why we have a breaking change.
12
+
13
+ ## 0.3.1
14
+
15
+ * Fixes a problem when running a rake command and no database exists yet using postgres. ([@coorasse][])
16
+
1
17
  ## 0.3.0
2
18
 
3
19
  * Added a method `I18n.translate_without_moirai` ([@oliveranthony17][])
@@ -5,6 +21,8 @@
5
21
  * Fixed some setup issues in test environments ([@oliveranthony17][])
6
22
  * Show original translation when deleting the whole inline editing content. ([@CuddlyBunion341][])
7
23
 
24
+ * Support for html translations ([@CuddlyBunion341][])
25
+ =======
8
26
  ## 0.2.0
9
27
 
10
28
  * Support for strings coming from gems ([@coorasse][])
data/Gemfile CHANGED
@@ -12,6 +12,7 @@ gem "stimulus-rails"
12
12
  group :development, :test do
13
13
  gem "puma"
14
14
  gem "sqlite3"
15
+ gem "pg"
15
16
  gem "rake"
16
17
  gem "dotenv"
17
18
  gem "minitest"
data/README.md CHANGED
@@ -50,21 +50,21 @@ on the application.
50
50
 
51
51
  ### Inline editing
52
52
 
53
- By default, inline editing is disabled. To enable it, set the `moirai=true` query parameter in the URL.
54
-
55
- If you want to only allow specific users to perform inline editing, you can override the `moirai_edit_enabled?` method
56
- in your application helper.
53
+ By default, inline editing is disabled. To enable it, specify the following in `application.rb`:
57
54
 
58
55
  ```ruby
56
+ config.moirai.enable_inline_editing = ->(params:) { params[:moirai] == 'true' }
57
+ ```
59
58
 
60
- module ApplicationHelper
61
- def moirai_edit_enabled?
62
- params[:moirai] == "true" && current_user&.admin?
63
- end
64
- end
59
+ If you set `moirai=true` query parameter in the URL, inline editing will appear in your page.
60
+
61
+ You probably want to only allow specific users to perform inline editing, this is an example of how you can do it:
62
+
63
+ ```ruby
64
+ config.moirai.enable_inline_editing = ->(params:) { (params[:moirai] == 'true') && current_user&.admin? }
65
65
  ```
66
66
 
67
- You also need to have the moirai_translations_controller.js Stimulus Controller initialized.
67
+ You also need to have the moirai_translations_controller.js Stimulus Controller initialized. Read below how to:
68
68
 
69
69
  #### Importmap
70
70
 
@@ -0,0 +1 @@
1
+ <%= t('email.welcome') %>
@@ -1,9 +1,9 @@
1
1
  <span
2
- contenteditable
2
+ contenteditable
3
3
  data-action="blur->moirai-translation#submit click->moirai-translation#click"
4
- style="border: 1px dashed #1d9f74; min-width: 30px; display: inline-block;"
4
+ style="outline: 1px solid #1d9f74; min-width: 30px; display: inline-block; <%= 'color: red;' if is_missing_translation %>"
5
5
  data-moirai-translation-key-value="<%= key %>"
6
6
  data-moirai-translation-locale-value="<%= locale %>"
7
7
  data-controller="moirai-translation">
8
- <%= value %>
8
+ <%= value.to_s.gsub("<", "&lt;").gsub(">", "&gt;").html_safe %>
9
9
  </span>
@@ -30,8 +30,7 @@
30
30
  method: :post do |f| %>
31
31
  <%= f.hidden_field :key %>
32
32
  <%= f.hidden_field :locale %>
33
- <%= f.text_area :value, class: 'translation-textarea' %>
34
- <%= f.submit 'Update', style: 'display: none;' %>
33
+ <%= f.text_field :value, class: 'translation-textarea' %>
35
34
  <% end %>
36
35
  </td>
37
36
  <td>
data/lib/moirai/engine.rb CHANGED
@@ -8,43 +8,34 @@ module Moirai
8
8
  generator.orm :active_record
9
9
  end
10
10
 
11
+ config.moirai = ActiveSupport::OrderedOptions.new
12
+
11
13
  config.after_initialize do
12
14
  I18n.original_backend = I18n.backend
13
- if ActiveRecord::Base.connection.data_source_exists?("moirai_translations") || ENV["RAILS_ENV"] == "test"
15
+ table_created =
16
+ begin
17
+ (defined?(ActiveRecord::ConnectionAdapters::SQLite3Adapter) &&
18
+ ActiveRecord::Base.connection.is_a?(ActiveRecord::ConnectionAdapters::SQLite3Adapter)) ||
19
+ ActiveRecord::Base.connection.table_exists?("moirai_translations")
20
+ rescue ActiveRecord::NoDatabaseError
21
+ false
22
+ end
23
+ if table_created
14
24
  I18n.backend = I18n::Backend::Chain.new(I18n::Backend::Moirai.new, I18n.backend)
15
25
  else
16
26
  Rails.logger.warn("moirai disabled: tables have not been generated yet.")
17
27
  end
18
28
  end
19
29
 
20
- # TODO: how to do this without rewriting the entire method?
21
- # https://github.com/rails/rails/blob/main/actionview/lib/action_view/helpers/translation_helper.rb#L122
30
+ initializer "rails_api_logger.config" do
31
+ config.moirai.each do |name, value|
32
+ Moirai.public_send(:"#{name}=", value)
33
+ end
34
+ end
35
+
22
36
  initializer "moirai.override_translation_helper" do
23
37
  ActiveSupport.on_load(:action_view) do
24
- module ActionView::Helpers::TranslationHelper # rubocop:disable Lint/ConstantDefinitionInBlock
25
- alias_method :original_translate, :translate
26
-
27
- def translate(key, **options)
28
- value = original_translate(key, **options)
29
-
30
- if moirai_edit_enabled?
31
- @key_finder ||= Moirai::KeyFinder.new
32
-
33
- render(partial: "moirai/translation_files/form",
34
- locals: {key: scope_key_by_partial(key),
35
- locale: I18n.locale,
36
- value: value})
37
- else
38
- value
39
- end
40
- end
41
-
42
- alias_method :t, :translate
43
-
44
- def moirai_edit_enabled?
45
- params[:moirai] == "true"
46
- end
47
- end
38
+ require "moirai/translation_helper"
48
39
  end
49
40
  end
50
41
  end
@@ -0,0 +1,37 @@
1
+ module ActionView::Helpers::TranslationHelper # rubocop:disable Lint/ConstantDefinitionInBlock
2
+ alias_method :original_translate, :translate
3
+
4
+ def translate(key, **)
5
+ value = original_translate(key, **)
6
+
7
+ is_missing_translation = value.include?('class="translation_missing"')
8
+ if value.is_a?(String) && is_missing_translation
9
+ value = extract_inner_content(value)
10
+ end
11
+
12
+ if moirai_edit_enabled?
13
+ @key_finder ||= Moirai::KeyFinder.new
14
+
15
+ render(partial: "moirai/translation_files/form",
16
+ locals: {key: scope_key_by_partial(key),
17
+ locale: I18n.locale,
18
+ is_missing_translation: is_missing_translation,
19
+ value: value})
20
+ else
21
+ value
22
+ end
23
+ end
24
+
25
+ alias_method :t, :translate
26
+
27
+ def moirai_edit_enabled?
28
+ Moirai.enable_inline_editing.call(params: params || {})
29
+ end
30
+
31
+ private
32
+
33
+ def extract_inner_content(html)
34
+ match = html.match(/<[^>]+>([^<]*)<\/[^>]+>/)
35
+ match ? match[1] : nil
36
+ end
37
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Moirai
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.0"
5
5
  end
data/lib/moirai.rb CHANGED
@@ -7,5 +7,5 @@ require "moirai/engine"
7
7
  require "moirai/pull_request_creator"
8
8
 
9
9
  module Moirai
10
- # Your code goes here...
10
+ mattr_accessor :enable_inline_editing
11
11
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moirai
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alessandro Rodi
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2024-11-22 00:00:00.000000000 Z
13
+ date: 2024-11-26 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -38,8 +38,10 @@ extensions: []
38
38
  extra_rdoc_files: []
39
39
  files:
40
40
  - ".github/CODEOWNERS"
41
- - ".github/workflows/test.yml"
42
41
  - ".gitignore"
42
+ - ".ruby-version"
43
+ - ".semaphore/main-deploy.yml"
44
+ - ".semaphore/semaphore.yml"
43
45
  - Appraisals
44
46
  - CHANGELOG.md
45
47
  - Gemfile
@@ -63,6 +65,7 @@ files:
63
65
  - app/models/moirai/translation.rb
64
66
  - app/models/moirai/translation_dumper.rb
65
67
  - app/models/moirai/translation_file_handler.rb
68
+ - app/views/application_mailer/test.html.erb
66
69
  - app/views/layouts/moirai/application.html.erb
67
70
  - app/views/moirai/translation_files/_form.html.erb
68
71
  - app/views/moirai/translation_files/index.html.erb
@@ -83,6 +86,7 @@ files:
83
86
  - lib/moirai.rb
84
87
  - lib/moirai/engine.rb
85
88
  - lib/moirai/pull_request_creator.rb
89
+ - lib/moirai/translation_helper.rb
86
90
  - lib/moirai/version.rb
87
91
  - moirai.gemspec
88
92
  homepage: https://github.com/renuo/moirai
@@ -1,65 +0,0 @@
1
- name: Test & lint
2
- on: [push]
3
-
4
- env:
5
- RAILS_ENV: test
6
- PGHOST: localhost
7
- PGUSER: postgres
8
- MOIRAI_GITHUB_REPO_NAME: ${{ secrets.MOIRAI_GITHUB_REPO_NAME }}
9
- MOIRAI_GITHUB_ACCESS_TOKEN: ${{ secrets.MOIRAI_GITHUB_ACCESS_TOKEN }}
10
- jobs:
11
- tests:
12
- name: Test
13
-
14
- strategy:
15
- fail-fast: false
16
- matrix:
17
- os: [ubuntu-latest]
18
- ruby: [3.3]
19
-
20
- runs-on: ${{ matrix.os }}
21
-
22
- steps:
23
- - name: Checkout code
24
- uses: actions/checkout@v4
25
-
26
- - name: Set up Ruby
27
- uses: ruby/setup-ruby@v1
28
- with:
29
- ruby-version: ${{ matrix.ruby }}
30
- bundler-cache: true
31
-
32
- - name: Install dependencies
33
- run: bundle install --jobs 4 --retry 3
34
-
35
- - name: Run tests
36
- run: bundle exec rails test
37
-
38
- - name: Run system tests
39
- run: bundle exec rails test:system
40
-
41
- - name: Archive logs
42
- if: always()
43
- uses: actions/upload-artifact@v4
44
- with:
45
- name: test.log
46
- path: test/dummy/log/test.log
47
- lint:
48
- name: Lint
49
- runs-on: ubuntu-latest
50
-
51
- steps:
52
- - name: Checkout code
53
- uses: actions/checkout@v2
54
-
55
- - name: Set up Ruby
56
- uses: ruby/setup-ruby@v1
57
- with:
58
- ruby-version: 3.3
59
- bundler-cache: true
60
-
61
- - name: Install dependencies
62
- run: bundle install --jobs 4 --retry 3
63
-
64
- - name: Run linters
65
- run: bin/fastcheck