Class: Satis::ApplicationComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- Satis::ApplicationComponent
- Includes:
- ActionView::Helpers::TranslationHelper, ViewComponent::SlotableV2
- Defined in:
- app/components/satis/application_component.rb
Direct Known Subclasses
Satis::AppearanceSwitcher::Component, Satis::Avatar::Component, Breadcrumbs::Component, Card::Component, DateTimePicker::Component, FlashMessages::Component, FlashMessages::Message, Info::Component, InfoItem::Component, Input::Component, Map::Component, Menu::Component, MenuItem::Component, Page::Component, SidebarMenu::Component, SidebarMenuItem::Component, Switch::Component, Tab::Component, Tabs::Component
Instance Attribute Summary collapse
-
#original_view_context ⇒ Object
Returns the value of attribute original_view_context.
Instance Method Summary collapse
-
#ct(key = nil, **options) ⇒ Object
This provides us with a translation helper which scopes into the original view and thereby conveniently scopes the translations.
- #i18n_scope ⇒ Object
- #original_i18n_scope ⇒ Object
- #original_virtual_path ⇒ Object
Instance Attribute Details
#original_view_context ⇒ Object
Returns the value of attribute original_view_context.
8 9 10 |
# File 'app/components/satis/application_component.rb', line 8 def original_view_context @original_view_context end |
Instance Method Details
#ct(key = nil, **options) ⇒ Object
This provides us with a translation helper which scopes into the original view and thereby conveniently scopes the translations.
In your component.html.slim you can use: “‘slim
ct(“.#Satis::ApplicationComponent.tabtab.name”, scope: [group.to_sym])
““
It’ll then try and find a translation with scope: en.admin.spaces.edit.tabs.main.admin_versions
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/components/satis/application_component.rb', line 21 def ct(key = nil, **) scope = Array.wrap(.delete(:scope)) scope = if scope scope.unshift(i18n_scope) else [i18n_scope] end scope = original_i18n_scope.concat(scope) key = key&.to_s unless key.is_a?(String) key = "#{scope.join('.')}#{key}" if key.start_with?('.') original_view_context.t(key, **) end |
#i18n_scope ⇒ Object
46 47 48 |
# File 'app/components/satis/application_component.rb', line 46 def i18n_scope self.class.name.split('::').second.underscore.to_sym end |
#original_i18n_scope ⇒ Object
42 43 44 |
# File 'app/components/satis/application_component.rb', line 42 def original_i18n_scope original_virtual_path.sub(%r{^/}, '').gsub(%r{/_?}, '.').split('.') end |
#original_virtual_path ⇒ Object
38 39 40 |
# File 'app/components/satis/application_component.rb', line 38 def original_virtual_path original_view_context.instance_variable_get(:@virtual_path) end |