spina-admin-conferences-blog 0.2.0 → 0.3.1

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: 56f5087c62079b206816f460255574064b89f79066de8bffd15f4b0cb4021a71
4
- data.tar.gz: 21cdedbf64861cfcb2302db194e3167127752df667d48aa8a649ad0adef0bd6b
3
+ metadata.gz: e5026172295d936e364a86d743c2b0447f8fab1c9d5ac038407c91a3d17721ce
4
+ data.tar.gz: '058c5d37a43844e7f0f7bdcaca4b5ba00f61ee37b250ed6f90e0221dc26738fa'
5
5
  SHA512:
6
- metadata.gz: f8026cd8ee752dec7244eee77d324182985216a4c8763d0a795275a500c722a8359d618f0db60da1e16b49a22fd3449bbac43479653279aba56466f57d492549
7
- data.tar.gz: 4f1deafa6264a4dde45fb3b869d53e5d207c745928bff253335f4fd528517015f51ea863fca1c444af4f94a37678166af0ea030556d5e838cf650e4d7dbedd44
6
+ metadata.gz: e5c4f8c1a83786d973a9b82757494e4cf83586dd184386a16d0104ce1fa1d6b3fcae0b056cf9e44b718a9e27d7ea4e72e826101895b30192b48c1bf443a8058b
7
+ data.tar.gz: adfc2cdd2be06769155f8148711827bf961e71e5525a72200466c0bb9754c45736378e63f6c06d66fed5a8c41bcb05525c2c0560d6aed952392c4edcbaf23ae4
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spina
4
+ module Admin
5
+ module Conferences
6
+ module Blog
7
+ # Base class for components
8
+ class ApplicationComponent < Spina::ApplicationComponent
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,39 @@
1
+ <div class="relative" data-controller="reveal" data-reveal-away-value>
2
+ <button type="button" class="btn btn-default px-3" data-action="reveal#toggle">
3
+ <%= helpers.heroicon("chat-alt", style: :solid, class: 'w-4 h-4 text-gray-300') %>
4
+ <% if @label.present? %>
5
+ <span class="ml-1 font-semibold"><%= @label %></span>
6
+ <% elsif missing_locales.any? %>
7
+ <span class="hidden md:block ml-1"><%=t 'spina.pages.missing_translations' %></span>
8
+ <% end %>
9
+ <% if missing_locales.any? %>
10
+ <div class="bg-yellow-500 rounded text-white leading-4 ml-2 w-4 font-medium text-center text-xs">
11
+ <%= missing_locales.size %>
12
+ </div>
13
+ <% end %>
14
+ </button>
15
+
16
+ <div hidden data-reveal data-transition class="origin-top-right absolute right-0 mt-2 w-56 rounded-md shadow-lg border border-gray-200 z-20">
17
+ <div class="rounded-md bg-white shadow-xs">
18
+ <div class="py-1">
19
+ <% if missing_locales.any? %>
20
+ <% missing_locales.each do |locale| %>
21
+ <%= link_to generate_edit_link(locale), class: "block px-3 py-2 text-sm leading-4 text-gray-700 hover:bg-gray-100 hover:text-gray-900 focus:outline-none focus:bg-gray-100 focus:text-gray-900 font-medium" do %>
22
+ <div class="text-yellow-500">
23
+ <%=t('spina.pages.add_translation', language: '<span class="font-semibold">' + t("spina.languages.#{locale}") + '</span>').html_safe %>
24
+ </div>
25
+ <% end %>
26
+ <% end %>
27
+ <div class="border-b border-gray-200 my-1"></div>
28
+ <% end %>
29
+ <% existing_locales.each do |locale| %>
30
+ <%= link_to generate_edit_link(locale), class: "block px-3 py-2 text-sm leading-4 text-gray-700 hover:bg-gray-100 hover:text-gray-900 focus:outline-none focus:bg-gray-100 focus:text-gray-900 font-medium" do %>
31
+ <div class="text-gray-700">
32
+ <%=t('spina.pages.edit_translation', language: '<span class="font-semibold">' + t("spina.languages.#{locale}") + '</span>').html_safe %>
33
+ </div>
34
+ <% end %>
35
+ <% end %>
36
+ </div>
37
+ </div>
38
+ </div>
39
+ </div>
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spina
4
+ module Admin
5
+ module Conferences
6
+ module Blog
7
+ # A component for switching translations, mimicking Spina::Pages::TranslationsComponent.
8
+ # Model must be either a {Spina::Admin::Conferences::Blog::Category} or a
9
+ # {Spina::Admin::Conferences::Blog::Post}
10
+ class TranslationsComponent < ApplicationComponent
11
+ def initialize(model, label: nil)
12
+ @model = model
13
+ @label = label
14
+ end
15
+
16
+ def render?
17
+ spina_locales.many?
18
+ end
19
+
20
+ def missing_locales
21
+ spina_locales - existing_locales
22
+ end
23
+
24
+ def existing_locales
25
+ @existing_locales ||= @model.translations.pluck(:locale).map(&:to_sym).sort_by do |locale|
26
+ spina_locales.index(locale)
27
+ end
28
+ end
29
+
30
+ def generate_edit_link(locale)
31
+ return helpers.spina.edit_admin_conferences_blog_category_path(@model.id, locale: locale) if @model.is_a? Category
32
+ return helpers.spina.edit_admin_conferences_blog_post_path(@model.id, locale: locale) if @model.is_a? Post
33
+ end
34
+
35
+ private
36
+
37
+ def spina_locales
38
+ Spina.config.locales.map(&:to_sym)
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -4,7 +4,7 @@ module Spina
4
4
  module Admin
5
5
  module Conferences::Blog
6
6
  # Spina::Admin::Conferences::Blog::CategoriesController
7
- class CategoriesController < AdminController
7
+ class CategoriesController < ::Spina::Admin::AdminController
8
8
  before_action :category, except: %i[new create index]
9
9
  before_action :set_breadcrumb
10
10
  before_action :set_locale
@@ -4,7 +4,7 @@ module Spina
4
4
  module Admin
5
5
  module Conferences::Blog
6
6
  # Spina::Admin::Conferences::Blog::PostsController
7
- class PostsController < AdminController
7
+ class PostsController < ::Spina::Admin::AdminController
8
8
  before_action :post, except: %i[index live draft future new create]
9
9
  before_action :set_breadcrumb
10
10
  before_action :set_tabs, only: %i[new create edit update]
@@ -11,6 +11,8 @@ module Spina
11
11
  has_many :posts, class_name: 'Spina::Admin::Conferences::Blog::Post', inverse_of: :category
12
12
  validates :name, presence: true, uniqueness: { case_sensitive: false }
13
13
 
14
+ translates :name, fallbacks: true
15
+
14
16
  def to_s
15
17
  name
16
18
  end
@@ -27,6 +27,10 @@ module Spina
27
27
  scope :featured, -> { where(featured: true) }
28
28
  scope :unfeatured, -> { where(featured: false) }
29
29
 
30
+ translates :title, fallbacks: true
31
+ translates :description, :excerpt, :content
32
+ translates :seo_title, default: -> { title }
33
+
30
34
  def self.table_name
31
35
  'spina_blog_posts'
32
36
  end
@@ -3,7 +3,7 @@
3
3
 
4
4
  <% if @category.persisted? %>
5
5
  <!-- Translations -->
6
- <%= render Spina::Pages::TranslationsComponent.new(@category, label: @locale.upcase) %>
6
+ <%= render Spina::Admin::Conferences::Blog::TranslationsComponent.new(@category, label: @locale.upcase) %>
7
7
 
8
8
  <%= render Spina::UserInterface::DropdownComponent.new do |dropdown| %>
9
9
  <% dropdown.button(classes: "btn btn-default px-3") do %>
@@ -4,7 +4,7 @@
4
4
 
5
5
  <% if @post.persisted? %>
6
6
  <!-- Translations -->
7
- <%= render Spina::Pages::TranslationsComponent.new(@post, label: @locale.upcase) %>
7
+ <%= render Spina::Admin::Conferences::Blog::TranslationsComponent.new(@post, label: @locale.upcase) %>
8
8
 
9
9
  <%= render Spina::UserInterface::DropdownComponent.new do |dropdown| %>
10
10
  <% dropdown.button(classes: "btn btn-default px-3") do %>
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ class CreateSpinaBlogTranslations < ActiveRecord::Migration[7.0]
4
+ def change
5
+ create_table :spina_blog_post_translations do |t|
6
+ t.string :title
7
+ t.text :excerpt
8
+ t.text :content
9
+ t.string :seo_title
10
+ t.text :description
11
+
12
+ t.string :locale, null: false
13
+ t.references :spina_blog_post, null: false, foreign_key: true, index: false
14
+
15
+ t.timestamps null: false
16
+ end
17
+
18
+ add_index :spina_blog_post_translations, :locale, name: :spina_blog_post_translations_on_locale
19
+ add_index :spina_blog_post_translations, [:spina_blog_post_id, :locale], unique: true, name: :spina_blog_post_translations_on_locale_and_id
20
+
21
+ create_table :spina_blog_category_translations do |t|
22
+ t.string :name
23
+
24
+ t.string :locale, null: false
25
+ t.references :spina_blog_category, null: false, foreign_key: true, index: false
26
+
27
+ t.timestamps null: false
28
+ end
29
+
30
+ add_index :spina_blog_category_translations, :locale, name: :spina_blog_category_translations_on_locale
31
+ add_index :spina_blog_category_translations, [:spina_blog_category_id, :locale], unique: true, name: :spina_blog_category_translations_on_locale_and_id
32
+ end
33
+ end
@@ -5,7 +5,7 @@ module Spina
5
5
  module Admin
6
6
  module Conferences
7
7
  module Blog
8
- VERSION = '0.2.0'
8
+ VERSION = '0.3.1'
9
9
  end
10
10
  end
11
11
  end
@@ -15,7 +15,7 @@ module Spina
15
15
  module Conferences
16
16
  module Blog
17
17
  def self.table_name_prefix
18
- 'spina_blog'
18
+ 'spina_blog_'
19
19
  end
20
20
  end
21
21
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Spina.configure do |config|
4
4
  # Set locales
5
- config.locales = [:en]
5
+ config.locales = [:en, :de]
6
6
  # Run `rake spina:update_translations` after you add any new locale.
7
7
 
8
8
  # Important Note
@@ -93,6 +93,30 @@ ActiveRecord::Schema.define(version: 2021_04_04_093002) do
93
93
  t.index ["slug"], name: "index_spina_blog_categories_on_slug"
94
94
  end
95
95
 
96
+ create_table "spina_blog_category_translations", force: :cascade do |t|
97
+ t.string "name"
98
+ t.string "locale", null: false
99
+ t.bigint "spina_blog_category_id", null: false
100
+ t.datetime "created_at", precision: 6, null: false
101
+ t.datetime "updated_at", precision: 6, null: false
102
+ t.index ["locale"], name: "spina_blog_category_translations_on_locale"
103
+ t.index ["spina_blog_category_id", "locale"], name: "spina_blog_category_translations_on_locale_and_id", unique: true
104
+ end
105
+
106
+ create_table "spina_blog_post_translations", force: :cascade do |t|
107
+ t.string "title"
108
+ t.text "excerpt"
109
+ t.text "content"
110
+ t.string "seo_title"
111
+ t.text "description"
112
+ t.string "locale", null: false
113
+ t.bigint "spina_blog_post_id", null: false
114
+ t.datetime "created_at", precision: 6, null: false
115
+ t.datetime "updated_at", precision: 6, null: false
116
+ t.index ["locale"], name: "spina_blog_post_translations_on_locale"
117
+ t.index ["spina_blog_post_id", "locale"], name: "spina_blog_post_translations_on_locale_and_id", unique: true
118
+ end
119
+
96
120
  create_table "spina_blog_posts", id: :serial, force: :cascade do |t|
97
121
  t.string "title"
98
122
  t.text "excerpt"
@@ -317,6 +341,8 @@ ActiveRecord::Schema.define(version: 2021_04_04_093002) do
317
341
 
318
342
  add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
319
343
  add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id"
344
+ add_foreign_key "spina_blog_category_translations", "spina_blog_categories"
345
+ add_foreign_key "spina_blog_post_translations", "spina_blog_posts"
320
346
  add_foreign_key "spina_blog_posts", "spina_images", column: "image_id"
321
347
  add_foreign_key "spina_blog_posts", "spina_users", column: "user_id"
322
348
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spina-admin-conferences-blog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Louis Van Steene
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-01-27 00:00:00.000000000 Z
12
+ date: 2022-01-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: draper
@@ -265,6 +265,9 @@ files:
265
265
  - README.md
266
266
  - Rakefile
267
267
  - app/assets/config/spina_admin_conferences_blog_manifest.js
268
+ - app/components/spina/admin/conferences/blog/application_component.rb
269
+ - app/components/spina/admin/conferences/blog/translations_component.html.erb
270
+ - app/components/spina/admin/conferences/blog/translations_component.rb
268
271
  - app/controllers/spina/admin/conferences/blog/categories_controller.rb
269
272
  - app/controllers/spina/admin/conferences/blog/posts_controller.rb
270
273
  - app/decorators/spina/admin/conferences/blog/post_decorator.rb
@@ -299,6 +302,7 @@ files:
299
302
  - db/migrate/4_add_category_id_to_spina_blog_posts.rb
300
303
  - db/migrate/5_add_featured_to_spina_blog_posts.rb
301
304
  - db/migrate/6_add_seo_fields.rb
305
+ - db/migrate/7_create_spina_blog_translations.rb
302
306
  - lib/generators/spina_admin_conferences_blog/install_generator.rb
303
307
  - lib/spina/admin/conferences/blog.rb
304
308
  - lib/spina/admin/conferences/blog/configuration.rb