moirai 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ecb41a395f21cd347b67e6e0233bd776a80493be4bf98d423077b7fd7cbe2005
4
- data.tar.gz: 1335f5ca28ab8804459172894841f71cb8ac88740ce0b94d21096bc3a1713386
3
+ metadata.gz: 95cf427b4c903e4a772cad00b3165fc9a285d019678870996d6afd122ff9c4bf
4
+ data.tar.gz: ae20e09390c869f1971f309c2e049fddce6557f0122069175d7f9886e8719ea1
5
5
  SHA512:
6
- metadata.gz: 927bd40a31ce569fca7b6d6a68194106db7616bf3a733009dd84669a387450a4808bc650aeff8f7f1d6aefe630d859db0c0486972008189e183f957247fada80
7
- data.tar.gz: c8a831cd233bf06ff6160acd096346afb3ab8b1209b3bda7a5a4c7ccbecffe263fadaffd4829508d5f13cb3f4201fdf3658ef46ddcb1ae14c16d46ca4c85c324
6
+ metadata.gz: cd8ead3d31114b762f706f115102bc8f36f4d1d9082911e34ac37ac57ab26d9ebb1621c57f4bf3d91626b0e3ddac67d96ca65b60e0e239650b824b4d2bac64bd
7
+ data.tar.gz: 0db74b1d99fcd721b378ff9371f2342051f022e4bdd02023d04c73516733f3f76a091d65ad4f653d4411c17819e3a40d675605c4eee29c4622ac88b3aba43ee1
@@ -9,9 +9,10 @@ auto_cancel:
9
9
  when: "true"
10
10
 
11
11
  blocks:
12
- - name: tests
12
+ - name: linter
13
13
  execution_time_limit:
14
14
  minutes: 10
15
+ dependencies: []
15
16
  task:
16
17
  secrets:
17
18
  - name: moirai
@@ -26,6 +27,21 @@ blocks:
26
27
  - name: linter
27
28
  commands:
28
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:
29
45
  - name: tests sqlite
30
46
  env_vars:
31
47
  - name: TARGET_DB
@@ -35,6 +51,22 @@ blocks:
35
51
  commands:
36
52
  - bin/rails db:create db:schema:load
37
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:
38
70
  - name: tests postgres
39
71
  env_vars:
40
72
  - name: TARGET_DB
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
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
+
1
13
  ## 0.3.1
2
14
 
3
15
  * Fixes a problem when running a rake command and no database exists yet using postgres. ([@coorasse][])
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') %>
data/lib/moirai/engine.rb CHANGED
@@ -8,6 +8,8 @@ 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
15
  table_created =
@@ -25,47 +27,15 @@ module Moirai
25
27
  end
26
28
  end
27
29
 
28
- # TODO: how to do this without rewriting the entire method?
29
- # 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
+
30
36
  initializer "moirai.override_translation_helper" do
31
37
  ActiveSupport.on_load(:action_view) do
32
- module ActionView::Helpers::TranslationHelper # rubocop:disable Lint/ConstantDefinitionInBlock
33
- alias_method :original_translate, :translate
34
-
35
- def translate(key, **options)
36
- value = original_translate(key, **options)
37
-
38
- is_missing_translation = value.include?('class="translation_missing"')
39
- if value.is_a?(String) && is_missing_translation
40
- value = extract_inner_content(value)
41
- end
42
-
43
- if moirai_edit_enabled?
44
- @key_finder ||= Moirai::KeyFinder.new
45
-
46
- render(partial: "moirai/translation_files/form",
47
- locals: {key: scope_key_by_partial(key),
48
- locale: I18n.locale,
49
- is_missing_translation: is_missing_translation,
50
- value: value})
51
- else
52
- value
53
- end
54
- end
55
-
56
- alias_method :t, :translate
57
-
58
- def moirai_edit_enabled?
59
- params[:moirai] == "true"
60
- end
61
-
62
- private
63
-
64
- def extract_inner_content(html)
65
- match = html.match(/<[^>]+>([^<]*)<\/[^>]+>/)
66
- match ? match[1] : nil
67
- end
68
- end
38
+ require "moirai/translation_helper"
69
39
  end
70
40
  end
71
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.1"
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,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moirai
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alessandro Rodi
8
8
  - Oliver Anthony
9
9
  - Daniel Bengl
10
- autorequire:
10
+ autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
13
  date: 2024-11-26 00:00:00.000000000 Z
@@ -65,6 +65,7 @@ files:
65
65
  - app/models/moirai/translation.rb
66
66
  - app/models/moirai/translation_dumper.rb
67
67
  - app/models/moirai/translation_file_handler.rb
68
+ - app/views/application_mailer/test.html.erb
68
69
  - app/views/layouts/moirai/application.html.erb
69
70
  - app/views/moirai/translation_files/_form.html.erb
70
71
  - app/views/moirai/translation_files/index.html.erb
@@ -85,6 +86,7 @@ files:
85
86
  - lib/moirai.rb
86
87
  - lib/moirai/engine.rb
87
88
  - lib/moirai/pull_request_creator.rb
89
+ - lib/moirai/translation_helper.rb
88
90
  - lib/moirai/version.rb
89
91
  - moirai.gemspec
90
92
  homepage: https://github.com/renuo/moirai
@@ -96,7 +98,7 @@ metadata:
96
98
  changelog_uri: https://github.com/renuo/moirai/CHANGELOG.md
97
99
  steep_types: sig
98
100
  rubygems_mfa_required: 'true'
99
- post_install_message:
101
+ post_install_message:
100
102
  rdoc_options: []
101
103
  require_paths:
102
104
  - lib
@@ -111,8 +113,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
113
  - !ruby/object:Gem::Version
112
114
  version: '0'
113
115
  requirements: []
114
- rubygems_version: 3.4.7
115
- signing_key:
116
+ rubygems_version: 3.5.22
117
+ signing_key:
116
118
  specification_version: 4
117
119
  summary: Manage translation strings in real time
118
120
  test_files: []