Class: Spina::Admin::Conferences::Blog::TranslationsComponent

Inherits:
ApplicationComponent
  • Object
show all
Defined in:
app/components/spina/admin/conferences/blog/translations_component.rb

Overview

A component for switching translations, mimicking Spina::Pages::TranslationsComponent. Model must be either a Category or a Post

Instance Method Summary collapse

Constructor Details

#initialize(model, label: nil) ⇒ TranslationsComponent

Returns a new instance of TranslationsComponent.



11
12
13
14
# File 'app/components/spina/admin/conferences/blog/translations_component.rb', line 11

def initialize(model, label: nil)
  @model = model
  @label = label
end

Instance Method Details

#existing_localesObject



24
25
26
27
28
# File 'app/components/spina/admin/conferences/blog/translations_component.rb', line 24

def existing_locales
  @existing_locales ||= @model.translations.pluck(:locale).map(&:to_sym).sort_by do |locale|
    spina_locales.index(locale)
  end
end


30
31
32
33
# File 'app/components/spina/admin/conferences/blog/translations_component.rb', line 30

def generate_edit_link(locale)
  return helpers.spina.edit_admin_conferences_blog_category_path(@model.id, locale: locale) if @model.is_a? Category
  return helpers.spina.edit_admin_conferences_blog_post_path(@model.id, locale: locale) if @model.is_a? Post
end

#missing_localesObject



20
21
22
# File 'app/components/spina/admin/conferences/blog/translations_component.rb', line 20

def missing_locales
  spina_locales - existing_locales
end

#render?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'app/components/spina/admin/conferences/blog/translations_component.rb', line 16

def render?
  spina_locales.many?
end