site_blog 0.8.0 → 0.9.0

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: a1c17bed2d9dfb9c42207ed00b2958f8d412f011a4cd0789253d0f7fd84fdb9a
4
- data.tar.gz: 32877ba756d06b0a139a43d1f4f6e806e54430bc7131109a434bf3b0e0897371
3
+ metadata.gz: 59fe18f766baca355592c03228df6214a9ca9370b46d8419c5819120abd487b9
4
+ data.tar.gz: 3e06efe39ced409bdc71042e7a641a2b9d666b272c0e05045a287857dc845ab8
5
5
  SHA512:
6
- metadata.gz: 155d5b8e30636d78c1dafe191d72f11dc9bb0bc4d96fc8d3d54318d20553201bbd12d72acb244ad4e9b6caf888be9408a36ff9c7614f0167c3973b331e24e4c5
7
- data.tar.gz: fc947d550f5cd921f66571189072041915af772deebe5a4aee74947dc6822f8408c4f09272697481d4b2a20f232f0eb177fb3a577e3ccc565bd4df0c83689dc1
6
+ metadata.gz: 0bdeb913978e58662f36c7928a442a5ab24ef79fb28b262b3f04b0d363255fbc133383397f3efa1754055ee5c65430f56fffa2584a8f09d43903ddf1e704e15b
7
+ data.tar.gz: 3a9de2774549820a8defc10c49ca65c338d97c6d1f95803bfbb9833559ca251a431fdf32f3d44d757f5b27d8d4b216cc3e32e1142181ee15b367c909a08eed25
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.
@@ -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).exist?
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/config/routes.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  SiteBlog::Engine.routes.draw do
2
2
  resources :tags
3
- resources :articles
3
+ resources :articles do
4
+ get :main, on: :collection
5
+ end
4
6
  end
@@ -27,5 +27,6 @@ class AddArticleAndTag < ActiveRecord::Migration[7.0]
27
27
  end
28
28
 
29
29
  add_index :site_blog_articles, :slug, unique: true
30
+ add_index :site_blog_articles, [:slug, :archived]
30
31
  end
31
32
  end
@@ -1,3 +1,3 @@
1
1
  module SiteBlog
2
- VERSION = "0.8.0"
2
+ VERSION = "0.9.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.9.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