site_blog 0.8.0 → 0.10.0

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: a1c17bed2d9dfb9c42207ed00b2958f8d412f011a4cd0789253d0f7fd84fdb9a
4
- data.tar.gz: 32877ba756d06b0a139a43d1f4f6e806e54430bc7131109a434bf3b0e0897371
3
+ metadata.gz: cab7ac4ecc8185d4c4767188b5ea55b94a80670e2e8b3b7a82eede29cf7e35c0
4
+ data.tar.gz: 6978b193b7ec06015ce25b6eb1e830004bf5cc8afba4b3c89e4095e2f6d366c1
5
5
  SHA512:
6
- metadata.gz: 155d5b8e30636d78c1dafe191d72f11dc9bb0bc4d96fc8d3d54318d20553201bbd12d72acb244ad4e9b6caf888be9408a36ff9c7614f0167c3973b331e24e4c5
7
- data.tar.gz: fc947d550f5cd921f66571189072041915af772deebe5a4aee74947dc6822f8408c4f09272697481d4b2a20f232f0eb177fb3a577e3ccc565bd4df0c83689dc1
6
+ metadata.gz: a3aa2e2048e05a1ec032d540931686a824a971274c42353be6c2eaf67bc3bbae7394c069bcc3ae8b508d1031c1ea8c1fccf2c6c55694dfcbb0d5a460da7bddde
7
+ data.tar.gz: 545a4d6b16c671674e1c8b4a808a4434f52fe10a84f325629b1294babb2a53cb5337c63fed6415dba94857056d03b664c5edb42d802c114e133a7750c6756934
data/README.md CHANGED
@@ -1,28 +1,39 @@
1
- # SiteBlog
2
- Short description and motivation.
1
+ # Блог
2
+ Компонент "Блог" для проекта, который имеет теги и статьи по ним.
3
3
 
4
- ## Usage
5
- How to use my plugin.
6
-
7
- ## Installation
8
- Add this line to your application's Gemfile:
4
+ ## Установка гема
5
+ Добавьте эту строку в Gemfile вашего приложения:
9
6
 
10
7
  ```ruby
11
- gem "site_blog"
8
+ gem "blog", git: "git@gitlab.telega.in:components-backend/Blog.git"
12
9
  ```
13
10
 
14
- And then execute:
11
+ А затем выполните:
15
12
  ```bash
16
13
  $ bundle
17
14
  ```
18
15
 
19
- Or install it yourself as:
16
+ Или установите его самостоятельно как:
17
+ ```bash
18
+ $ gem install site_blog --source https://gitlab.telega.in/components-backend/Blog.git
19
+ ```
20
+
21
+ ## Backend
22
+ 1. Укажите путь к API в config/routes.rb:
23
+ ```ruby
24
+ mount Blog::Engine, at: '/blog'
25
+ ```
26
+ 2. Выполните команду:
27
+ ```bash
28
+ $ rails blog:install:migrations
29
+ ```
30
+ 3. Запустите миграции:
20
31
  ```bash
21
- $ gem install site_blog
32
+ $ rails db:migrate
22
33
  ```
23
34
 
24
35
  ## Contributing
25
36
  Contribution directions go here.
26
37
 
27
38
  ## License
28
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -7,6 +7,10 @@ module SiteBlog
7
7
  render json: Article.filters(params)
8
8
  end
9
9
 
10
+ def main
11
+ render json: Article.main
12
+ end
13
+
10
14
  # GET /articles/1
11
15
  def show
12
16
  @article.increment!(:view_count)
@@ -43,7 +47,7 @@ module SiteBlog
43
47
 
44
48
  # Use callbacks to share common setup or constraints between actions.
45
49
  def set_article
46
- @article = Article.find(params[:id])
50
+ @article = Article.find_by(params[:slug])
47
51
  end
48
52
 
49
53
  # Only allow a list of trusted parameters through.
@@ -4,7 +4,7 @@ module SiteBlog
4
4
 
5
5
  # GET /tags
6
6
  def index
7
- render json: Tag.all
7
+ render json: Tag.archived(false)
8
8
  end
9
9
 
10
10
  # GET /tags/1
@@ -47,7 +47,7 @@ module SiteBlog
47
47
 
48
48
  # Only allow a list of trusted parameters through.
49
49
  def tag_params
50
- params.require(:tag).permit(:slug, :arichived)
50
+ params.require(:tag).permit(:slug, :archived)
51
51
  end
52
52
  end
53
53
  end
@@ -27,16 +27,33 @@ module SiteBlog
27
27
  before_validation :set_locale
28
28
  before_validation :clean_description
29
29
 
30
+ scope :archived, -> (param = true) { where(archived: param) }
31
+
30
32
  scope :filters, lambda { |params|
31
- rel = where(archived: false)
32
- rel = rel.joins(:tags).where(tags: { id: params[:tag_id] }) if params[:tag_id].present?
33
- rel = rel.search(params[:query]) if params[:query].present?
34
- rel = rel.where(main: true) if params[:main] == 'true'
35
- rel = rel.order('created_at DESC')
36
- rel = rel.limit(params[:limit]) if params[:limit]
37
- rel = rel.page(params[:page]).per(20)
33
+ data = archived(false)
34
+ data = data.joins(:tags).where(tags: { id: params[:tag_id] }) if params[:tag_id].present?
35
+ data = data.search(params[:query]) if params[:query].present?
36
+ count = data.length
37
+ data = data.order('created_at DESC')
38
+ data = data.limit(params[:limit]) if params[:limit]
39
+ data = data.page(params[:page]).per(20)
40
+
41
+ {
42
+ total_count: count,
43
+ data: data
44
+ }
38
45
  }
39
46
 
47
+ def self.main
48
+ if self.archived(false).where(main: true).exists?
49
+ res = self.archived(false).where(main: true).last
50
+ else
51
+ res = self.order('created_at DESC').first
52
+ end
53
+
54
+ res
55
+ end
56
+
40
57
  private
41
58
 
42
59
  def set_slug
@@ -7,6 +7,8 @@ module SiteBlog
7
7
 
8
8
  before_validation :slug_downcase
9
9
 
10
+ scope :archived, -> (param = true) { where(archived: param) }
11
+
10
12
  private
11
13
 
12
14
  def slug_downcase
data/config/routes.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  SiteBlog::Engine.routes.draw do
2
2
  resources :tags
3
+ get 'articles/main' => 'articles#main'
3
4
  resources :articles
4
5
  end
@@ -2,18 +2,18 @@ class AddArticleAndTag < ActiveRecord::Migration[7.0]
2
2
  def change
3
3
  create_table :site_blog_tags do |t|
4
4
  t.string :slug
5
- t.boolean :archived, null: false, default: false
5
+ t.boolean :archived, null: false, default: false, index: true
6
6
  t.timestamps
7
7
  end
8
8
 
9
9
  create_table :site_blog_articles do |t|
10
10
  t.string :title, null: false
11
- t.string :slug, null: false
11
+ t.string :slug, null: false, unique: true, index: true
12
12
  t.text :html_description, null: false
13
13
  t.text :description, null: false
14
14
  t.string :image, null: false
15
15
  t.integer :view_count, null: false, default: 0
16
- t.boolean :archived, null: false, default: false
16
+ t.boolean :archived, null: false, default: false, index: true
17
17
  t.boolean :active, null: false, default: true
18
18
  t.boolean :main, null: false, default: false
19
19
  t.string :locale, null: false
@@ -25,7 +25,5 @@ class AddArticleAndTag < ActiveRecord::Migration[7.0]
25
25
  t.belongs_to :tag, foreign_key: { to_table: :site_blog_tags }
26
26
  t.timestamps
27
27
  end
28
-
29
- add_index :site_blog_articles, :slug, unique: true
30
28
  end
31
29
  end
@@ -1,3 +1,3 @@
1
1
  module SiteBlog
2
- VERSION = "0.8.0"
2
+ VERSION = "0.10.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: site_blog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eldar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-21 00:00:00.000000000 Z
11
+ date: 2023-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails