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 +4 -4
- data/README.md +23 -12
- data/app/controllers/site_blog/articles_controller.rb +5 -1
- data/app/models/site_blog/article.rb +24 -7
- data/config/routes.rb +3 -5
- data/db/migrate/20230201140930_add_article_and_tag.rb +1 -0
- data/lib/site_blog/engine.rb +0 -2
- data/lib/site_blog/version.rb +1 -1
- metadata +2 -3
- data/app/controllers/site_blog/graphql_controller.rb +0 -52
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 59fe18f766baca355592c03228df6214a9ca9370b46d8419c5819120abd487b9
|
4
|
+
data.tar.gz: 3e06efe39ced409bdc71042e7a641a2b9d666b272c0e05045a287857dc845ab8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0bdeb913978e58662f36c7928a442a5ab24ef79fb28b262b3f04b0d363255fbc133383397f3efa1754055ee5c65430f56fffa2584a8f09d43903ddf1e704e15b
|
7
|
+
data.tar.gz: 3a9de2774549820a8defc10c49ca65c338d97c6d1f95803bfbb9833559ca251a431fdf32f3d44d757f5b27d8d4b216cc3e32e1142181ee15b367c909a08eed25
|
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.
|
@@ -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).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
|
data/lib/site_blog/engine.rb
CHANGED
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.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-
|
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
|