site_blog 0.3.0 → 0.5.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: 3611d6be6fc93eb3d2a107b96f83df07c71d9bf9e81c7c70066477f75e1244e6
4
- data.tar.gz: ffd322a7aa05fe3fb4932fb1344189f99e26d2f5dc48a74978c1954b6533b11e
3
+ metadata.gz: 17c4d73ad52870e304479caf1049e94b12b4481e4c8d5eabb5bea12677c9097f
4
+ data.tar.gz: e72cc5aeba1c9a71b12559872ddc35afb984811f52284e8522a2907501976d8d
5
5
  SHA512:
6
- metadata.gz: f2fc352e7a1983f32542a6a9cf0f204d1837babb42fc12eb0e83cd99fa7250a964fb3e5828050afacb94464d0e9c34b248c6871736fdf9ee02d1e0f7b67f3ed3
7
- data.tar.gz: 0bd80f5422baca6c228342804817d8e0a59cf30fd130aff56009fa31b2b7b74e785f378227e8ba97a07c0936197c2d364a7d26198769fa9d8c110e54c4b20017
6
+ metadata.gz: 3d248b7747eeef9a2014adf611c15f014f13c1977603c3f8b0b076a62feb7afc767457829d971b60bef60ddc55943784382877ac88be25d4fab736c7057c0f56
7
+ data.tar.gz: d21079c4a65041f5c65c7b86e33d590e2003dbffd6337b5a250a5608be9eb15a793ccb83b76da41b1f44cd4a61f25c4ccb8669cb6c3f289cc2ec6573a1508982
@@ -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(:title, :arichived)
50
+ params.require(:tag).permit(:slug, :arichived)
51
51
  end
52
52
  end
53
53
  end
@@ -13,12 +13,13 @@ module SiteBlog
13
13
 
14
14
  mount_uploader :image, SiteBlog::ImageUploader
15
15
 
16
- belongs_to :tag
16
+ has_many :taggings, class_name: 'SiteBlog::Tagging'
17
+ has_many :tags, through: :taggings
17
18
 
19
+ validates :tags, presence: true
18
20
  validates :title, presence: true, length: { minimum: 2 , maximum: 250 }
19
21
  validates :description, presence: true
20
22
  validates :image, presence: true
21
- validates :tag_id, presence: true
22
23
  validates :slug, presence: true, uniqueness: true, format: { with: /\A[a-z0-9\-_]+\z/ }
23
24
  validates :locale, presence: true
24
25
 
@@ -28,9 +29,12 @@ module SiteBlog
28
29
 
29
30
  scope :filters, lambda { |params|
30
31
  rel = where(archived: false)
31
- rel = rel.where(tag_id: params[:tag_id]) if params[:tag_id].present?
32
+ rel = rel.joins(:tags).where(tags: { id: params[:tag_id] }) if params[:tag_id].present?
32
33
  rel = rel.search(params[:query]) if params[:query].present?
33
- rel.order('created_at DESC').page(params[:page]).per(20)
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)
34
38
  }
35
39
 
36
40
  private
@@ -1,5 +1,17 @@
1
1
  module SiteBlog
2
2
  class Tag < ApplicationRecord
3
- has_many :articles
3
+ has_many :taggings, class_name: 'SiteBlog::Tagging'
4
+ has_many :articles, through: :taggings
5
+
6
+ validates :slug, presence: true
7
+
8
+ before_validation :slug_downcase
9
+
10
+ private
11
+
12
+ def slug_downcase
13
+ self.slug = self.slug.downcase if self.slug.present?
14
+ end
15
+
4
16
  end
5
17
  end
@@ -0,0 +1,6 @@
1
+ module SiteBlog
2
+ class Tagging < ApplicationRecord
3
+ belongs_to :article
4
+ belongs_to :tag
5
+ end
6
+ end
@@ -1,7 +1,7 @@
1
1
  class AddArticleAndTag < ActiveRecord::Migration[7.0]
2
2
  def change
3
3
  create_table :site_blog_tags do |t|
4
- t.string :title
4
+ t.string :slug
5
5
  t.boolean :archived, null: false, default: false
6
6
  t.timestamps
7
7
  end
@@ -12,14 +12,20 @@ class AddArticleAndTag < ActiveRecord::Migration[7.0]
12
12
  t.text :html_description, null: false
13
13
  t.text :description, null: false
14
14
  t.string :image, null: false
15
- t.belongs_to :tag, null: false, foreign_key: { to_table: :site_blog_tags }
16
15
  t.integer :view_count, null: false, default: 0
17
16
  t.boolean :archived, null: false, default: false
18
17
  t.boolean :active, null: false, default: true
18
+ t.boolean :main, null: false, default: false
19
19
  t.string :locale, null: false
20
20
  t.timestamps
21
21
  end
22
22
 
23
+ create_table :taggings do |t|
24
+ t.belongs_to :article, foreign_key: { to_table: :site_blog_articles }
25
+ t.belongs_to :tag, foreign_key: { to_table: :site_blog_tags }
26
+ t.timestamps
27
+ end
28
+
23
29
  add_index :site_blog_articles, :slug, unique: true
24
30
  end
25
31
  end
@@ -1,3 +1,3 @@
1
1
  module SiteBlog
2
- VERSION = "0.3.0"
2
+ VERSION = "0.5.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.3.0
4
+ version: 0.5.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-01 00:00:00.000000000 Z
11
+ date: 2023-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: activeadmin_addons
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
111
125
  description: Description of AppComponent
112
126
  email:
113
127
  - eldarweb@mail.ru
@@ -144,6 +158,7 @@ files:
144
158
  - app/models/site_blog/application_record.rb
145
159
  - app/models/site_blog/article.rb
146
160
  - app/models/site_blog/tag.rb
161
+ - app/models/site_blog/tagging.rb
147
162
  - app/uploaders/site_blog/image_uploader.rb
148
163
  - app/views/layouts/blog/application.html.erb
149
164
  - config/routes.rb