site_blog 0.8.0 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +23 -12
- data/app/controllers/site_blog/articles_controller.rb +5 -1
- data/app/controllers/site_blog/tags_controller.rb +2 -2
- data/app/models/site_blog/article.rb +24 -7
- data/app/models/site_blog/tag.rb +2 -0
- data/config/routes.rb +1 -0
- data/db/migrate/20230201140930_add_article_and_tag.rb +3 -5
- data/lib/site_blog/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cab7ac4ecc8185d4c4767188b5ea55b94a80670e2e8b3b7a82eede29cf7e35c0
|
4
|
+
data.tar.gz: 6978b193b7ec06015ce25b6eb1e830004bf5cc8afba4b3c89e4095e2f6d366c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a3aa2e2048e05a1ec032d540931686a824a971274c42353be6c2eaf67bc3bbae7394c069bcc3ae8b508d1031c1ea8c1fccf2c6c55694dfcbb0d5a460da7bddde
|
7
|
+
data.tar.gz: 545a4d6b16c671674e1c8b4a808a4434f52fe10a84f325629b1294babb2a53cb5337c63fed6415dba94857056d03b664c5edb42d802c114e133a7750c6756934
|
data/README.md
CHANGED
@@ -1,28 +1,39 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# Блог
|
2
|
+
Компонент "Блог" для проекта, который имеет теги и статьи по ним.
|
3
3
|
|
4
|
-
##
|
5
|
-
|
6
|
-
|
7
|
-
## Installation
|
8
|
-
Add this line to your application's Gemfile:
|
4
|
+
## Установка гема
|
5
|
+
Добавьте эту строку в Gemfile вашего приложения:
|
9
6
|
|
10
7
|
```ruby
|
11
|
-
gem "
|
8
|
+
gem "blog", git: "git@gitlab.telega.in:components-backend/Blog.git"
|
12
9
|
```
|
13
10
|
|
14
|
-
|
11
|
+
А затем выполните:
|
15
12
|
```bash
|
16
13
|
$ bundle
|
17
14
|
```
|
18
15
|
|
19
|
-
|
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
|
-
$
|
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.
|
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.
|
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, :
|
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
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
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
|
data/app/models/site_blog/tag.rb
CHANGED
data/config/routes.rb
CHANGED
@@ -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
|
data/lib/site_blog/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2023-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|