site_blog 0.7.0 → 0.9.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: e76714792d33e9b0a08f1fc2d643f0caccad3bb083b77662bd9bcdfa02f07709
4
- data.tar.gz: a261eec84ec7a2e8778792b49dc9e9e62bbcdeff56cd9d82b8012999b1a3e8cc
3
+ metadata.gz: 59fe18f766baca355592c03228df6214a9ca9370b46d8419c5819120abd487b9
4
+ data.tar.gz: 3e06efe39ced409bdc71042e7a641a2b9d666b272c0e05045a287857dc845ab8
5
5
  SHA512:
6
- metadata.gz: bc839fa55585d4b3d27aab8feeacdec64be32423bb8a94356d26b9897abc4902d0d737dacb513eee8395fcc526f9291677b7a678bd7552c881ff970612998e14
7
- data.tar.gz: a5a842079e9e679a02b45526f8068cf3e503b85c2f201dfd118117856f1a223d2a5a9a2f63c10bebf6b1e2ba8853da3f18c84c40c8d8ad82a851319c1e9389b0
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,8 +1,6 @@
1
1
  SiteBlog::Engine.routes.draw do
2
-
3
- mount GraphiQL::Rails::Engine, at: "/graphiql", graphql_path: '/blog/graphql'
4
-
5
- post '/graphql', to: 'graphql#execute'
6
2
  resources :tags
7
- resources :articles
3
+ resources :articles do
4
+ get :main, on: :collection
5
+ end
8
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
@@ -2,8 +2,6 @@ require 'carrierwave'
2
2
  require 'pg_search'
3
3
  require 'kaminari'
4
4
  require 'translit'
5
- require 'graphql'
6
- require 'graphiql/rails'
7
5
 
8
6
  module SiteBlog
9
7
  class Engine < ::Rails::Engine
@@ -1,3 +1,3 @@
1
1
  module SiteBlog
2
- VERSION = "0.7.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.7.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
@@ -108,7 +108,6 @@ files:
108
108
  - app/assets/stylesheets/site_blog/application.css
109
109
  - app/controllers/site_blog/application_controller.rb
110
110
  - app/controllers/site_blog/articles_controller.rb
111
- - app/controllers/site_blog/graphql_controller.rb
112
111
  - app/controllers/site_blog/tags_controller.rb
113
112
  - app/helpers/site_blog/application_helper.rb
114
113
  - app/helpers/site_blog/articles_helper.rb
@@ -1,52 +0,0 @@
1
- module SiteBlog
2
- class GraphqlController < ApplicationController
3
- # If accessing from outside this domain, nullify the session
4
- # This allows for outside API access while preventing CSRF attacks,
5
- # but you'll have to authenticate your user separately
6
- # protect_from_forgery with: :null_session
7
-
8
- def execute
9
- variables = prepare_variables(params[:variables])
10
- query = params[:query]
11
- operation_name = params[:operationName]
12
- context = {
13
- # Query context goes here, for example:
14
- # current_user: current_user,
15
- }
16
- result = Schema.execute(query, variables: variables, context: context, operation_name: operation_name)
17
- render json: result
18
- rescue StandardError => e
19
- raise e unless Rails.env.development?
20
- handle_error_in_development(e)
21
- end
22
-
23
- private
24
-
25
- # Handle variables in form data, JSON body, or a blank value
26
- def prepare_variables(variables_param)
27
- case variables_param
28
- when String
29
- if variables_param.present?
30
- JSON.parse(variables_param) || {}
31
- else
32
- {}
33
- end
34
- when Hash
35
- variables_param
36
- when ActionController::Parameters
37
- variables_param.to_unsafe_hash # GraphQL-Ruby will validate name and type of incoming variables.
38
- when nil
39
- {}
40
- else
41
- raise ArgumentError, "Unexpected parameter: #{variables_param}"
42
- end
43
- end
44
-
45
- def handle_error_in_development(e)
46
- logger.error e.message
47
- logger.error e.backtrace.join("\n")
48
-
49
- render json: { errors: [{ message: e.message, backtrace: e.backtrace }], data: {} }, status: 500
50
- end
51
- end
52
- end