satis 2.4.1 → 2.4.2

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: 467de347e9ddb8e9db29d0cde98d1e047e1de5ba86a09fdb8c276548ef3712cd
4
- data.tar.gz: 7fdba4bdbe01342fe65d547b6c3beceb58bdc829b3008156d720ac4842c90263
3
+ metadata.gz: 2c8b8f688d732d57a4df263b47f48f1b072f709c1d9ae5b224cc1e7197e5fc08
4
+ data.tar.gz: 42d9edfb45401ad6cb797ffa95195acceff18b3a1aa8b8931c95d29afacba49f
5
5
  SHA512:
6
- metadata.gz: ef091872ca731e27988e02d45d36321fae901d54eedda2d9c59dfa2d68f524f2a30b86c0633d7018b16357e8c194733ca48199cbc2518256eeb7b07c3cd1f022
7
- data.tar.gz: 936bb15f39c3261c57592e9347e228d63db6f853b418480a1a5350b3f9a10d628bdafa8ebb888bf4e1a2822f315477c87ad84670d4c4a1f6166d4fa5601093ac
6
+ metadata.gz: 4bbf1820f21de79035eb8c5285de9ac084f7609a1b33ba57dc8261592d65d122e79d73d808d772aa40b55d1dddc60962b218e7803bb2798c51b506d057186b38
7
+ data.tar.gz: ac095ab29b95766986c70e2f15322a4f1e16cfc8014ee365b56fc58e628ced330392eddb6b5f67479b3637d8e0004153b58329bbe2c9a7ea7dc3d13038ee86ee
@@ -21,6 +21,15 @@ module Satis
21
21
  super()
22
22
  end
23
23
 
24
+ def render_in(view_context, &)
25
+ self.original_view_context ||= view_context
26
+ self.original_virtual_path ||= Satis.current_original_virtual_path.presence || view_context.instance_variable_get(:@virtual_path)
27
+
28
+ Satis.with_original_virtual_path(original_virtual_path) do
29
+ super
30
+ end
31
+ end
32
+
24
33
  def component_name
25
34
  self.class.name.sub(/::Component$/, "").sub(/^Satis::/, "").underscore
26
35
  end
@@ -1,10 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # FIXME:
4
- # translation scope seems wrong:
5
- # old/okay) title="translation missing: en.users.edit.card.profile.tab.about"
6
- # new/broken) title="translation missing: en.users.edit.tabs.main.tab.about"
7
-
8
3
  module Satis
9
4
  module Tabs
10
5
  class Component < Satis::ApplicationComponent
@@ -8,6 +8,8 @@ module Satis
8
8
  extend ActiveSupport::Concern
9
9
 
10
10
  included do
11
+ attr_accessor :original_virtual_path
12
+
11
13
  #
12
14
  # This provides us with a translation helper which scopes into the original view
13
15
  # and thereby conveniently scopes the translations.
@@ -41,9 +43,25 @@ module Satis
41
43
  end
42
44
 
43
45
  def original_i18n_scope
46
+ virtual_path = original_virtual_path.presence || original_view_context_virtual_path
47
+
48
+ return virtual_path.gsub(%r{/_?}, ".").split(".") if virtual_path.present? && !satis_component_virtual_path?(virtual_path)
49
+
44
50
  [original_view_context.controller_path.tr("/", "."), original_view_context.action_name]
45
51
  end
46
52
 
53
+ def satis_component_virtual_path?(virtual_path)
54
+ virtual_path.start_with?("satis/")
55
+ end
56
+
57
+ def original_view_context_virtual_path
58
+ if original_view_context.respond_to?(:virtual_path)
59
+ original_view_context.virtual_path
60
+ elsif original_view_context.instance_variable_defined?(:@virtual_path)
61
+ original_view_context.instance_variable_get(:@virtual_path)
62
+ end
63
+ end
64
+
47
65
  def i18n_scope
48
66
  self.class.name.split('::').second.underscore.to_sym
49
67
  end
@@ -78,7 +78,6 @@ module Satis
78
78
  else
79
79
  component.new(*original_args, **kwargs)
80
80
  end
81
- instance.original_view_context = action_view
82
81
  action_view.render(instance, &block)
83
82
  end
84
83
  end
data/lib/satis/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Satis
2
- VERSION = "2.4.1"
2
+ VERSION = "2.4.2"
3
3
  end
data/lib/satis.rb CHANGED
@@ -27,6 +27,21 @@ module Satis
27
27
  Satis::Helpers::Container.add_helper(name, component)
28
28
  end
29
29
 
30
+ def current_original_virtual_path
31
+ original_virtual_path_stack.last
32
+ end
33
+
34
+ def with_original_virtual_path(virtual_path)
35
+ original_virtual_path_stack.push(virtual_path)
36
+ yield
37
+ ensure
38
+ original_virtual_path_stack.pop
39
+ end
40
+
41
+ def original_virtual_path_stack
42
+ Thread.current[:satis_original_virtual_path_stack] ||= []
43
+ end
44
+
30
45
  def add_component_helper(component_name, name, component)
31
46
  klass = "Satis::#{component_name.to_s.classify}::Component".safe_constantize
32
47
  return if klass.blank?
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: satis
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.1
4
+ version: 2.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom de Grunt