railspress-engine 1.4.2 → 1.4.3
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/app/controllers/railspress/admin/posts_controller.rb +3 -3
- data/app/controllers/railspress/api/v1/posts_controller.rb +2 -2
- data/app/models/railspress/post.rb +10 -2
- data/lib/railspress/engine.rb +4 -0
- data/lib/railspress/entity.rb +19 -3
- data/lib/railspress/version.rb +1 -1
- data/lib/railspress.rb +5 -0
- 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: 5a843f07c6d903605a67314573c816bbff6099640947e622e9c59a89ff88cbea
|
|
4
|
+
data.tar.gz: 17f4e1697c1dd88947460d5e93cb42cee3652677ce69fc456e4da1821e56b9b1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9bb75c97d3ace5d1fb54d6281d6ce4c2d17ac29cfd3d71821ba92cb22ecb7b4634a60b1015b0226755b52bc75e778d5ef9f1062976382843a03faa6b686990c8
|
|
7
|
+
data.tar.gz: 2aaca7f4a20c3f875bac0c37817f5eadb853c317ef72bf9d00100ad5ddf865ed000214b8e0e15155dd90033b21a1b1426a7ce3f576d610e5819398e6aa535ca7
|
|
@@ -9,15 +9,15 @@ module Railspress
|
|
|
9
9
|
@direction = params[:direction].presence || "desc"
|
|
10
10
|
|
|
11
11
|
@posts = Post.includes(:category, :tags)
|
|
12
|
-
.
|
|
12
|
+
.rp_search(params[:q])
|
|
13
13
|
.by_category(params[:category_id])
|
|
14
14
|
.by_status(params[:status])
|
|
15
15
|
.sorted_by(@sort, @direction)
|
|
16
16
|
|
|
17
17
|
@total_count = @posts.count
|
|
18
18
|
@page = [ params[:page].to_i, 1 ].max
|
|
19
|
-
@total_pages = (@total_count.to_f / Post
|
|
20
|
-
@posts = @posts.
|
|
19
|
+
@total_pages = (@total_count.to_f / Post.rp_per_page_count).ceil
|
|
20
|
+
@posts = @posts.rp_page(@page)
|
|
21
21
|
|
|
22
22
|
@categories = Category.ordered
|
|
23
23
|
end
|
|
@@ -102,8 +102,8 @@ module Railspress
|
|
|
102
102
|
end
|
|
103
103
|
|
|
104
104
|
def per_page
|
|
105
|
-
requested = params.fetch(:per, Railspress::Post.
|
|
106
|
-
requested = Railspress::Post.
|
|
105
|
+
requested = params.fetch(:per, Railspress::Post.rp_per_page_count).to_i
|
|
106
|
+
requested = Railspress::Post.rp_per_page_count if requested <= 0
|
|
107
107
|
[ requested, 100 ].min
|
|
108
108
|
end
|
|
109
109
|
|
|
@@ -74,14 +74,22 @@ module Railspress
|
|
|
74
74
|
before_save :set_published_at
|
|
75
75
|
before_save :set_reading_time, if: -> { reading_time.blank? && content.present? }
|
|
76
76
|
|
|
77
|
-
# Generic scopes (ordered, recent) and pagination (
|
|
77
|
+
# Generic scopes (ordered, recent) and pagination (rp_page) provided by Entity concern
|
|
78
78
|
# Post-specific scopes below:
|
|
79
79
|
scope :published, -> { where(status: :published).where(published_at: ..Time.current) }
|
|
80
80
|
scope :drafts, -> { where(status: :draft) }
|
|
81
81
|
scope :scheduled, -> { where(status: :published).where("published_at > ?", Time.current) }
|
|
82
82
|
scope :live, -> { published } # Alias for semantic clarity
|
|
83
83
|
scope :by_author, ->(author) { where(author_id: author.id) }
|
|
84
|
-
scope :
|
|
84
|
+
scope :rp_search, ->(query) {
|
|
85
|
+
query.present? ? where(arel_table[:title].matches("%#{query}%", nil, false)) : all
|
|
86
|
+
}
|
|
87
|
+
unless respond_to?(:search)
|
|
88
|
+
scope :search, ->(query) {
|
|
89
|
+
Railspress.deprecator.warn("search is deprecated and will be removed in RailsPress 2.0; use rp_search instead")
|
|
90
|
+
rp_search(query)
|
|
91
|
+
}
|
|
92
|
+
end
|
|
85
93
|
scope :by_category, ->(category_id) { where(category_id: category_id) if category_id.present? }
|
|
86
94
|
scope :by_status, ->(status) {
|
|
87
95
|
case status.to_s
|
data/lib/railspress/engine.rb
CHANGED
|
@@ -2,6 +2,10 @@ module Railspress
|
|
|
2
2
|
class Engine < ::Rails::Engine
|
|
3
3
|
isolate_namespace Railspress
|
|
4
4
|
|
|
5
|
+
initializer "railspress.deprecator" do |app|
|
|
6
|
+
app.deprecators[:railspress] = Railspress.deprecator
|
|
7
|
+
end
|
|
8
|
+
|
|
5
9
|
# Register engine assets with the asset pipeline (Propshaft)
|
|
6
10
|
initializer "railspress.assets" do |app|
|
|
7
11
|
if app.config.respond_to?(:assets)
|
data/lib/railspress/entity.rb
CHANGED
|
@@ -149,6 +149,22 @@ module Railspress
|
|
|
149
149
|
# Default scopes available to all entities
|
|
150
150
|
scope :ordered, -> { order(created_at: :desc) }
|
|
151
151
|
scope :recent, -> { ordered.limit(10) }
|
|
152
|
+
|
|
153
|
+
unless respond_to?(:page)
|
|
154
|
+
scope :page, ->(page_number) {
|
|
155
|
+
Railspress.deprecator.warn("page is deprecated and will be removed in RailsPress 2.0; use rp_page instead")
|
|
156
|
+
rp_page(page_number)
|
|
157
|
+
}
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
unless respond_to?(:per_page_count)
|
|
161
|
+
define_singleton_method(:per_page_count) do
|
|
162
|
+
Railspress.deprecator.warn(
|
|
163
|
+
"per_page_count is deprecated and will be removed in RailsPress 2.0; use rp_per_page_count instead"
|
|
164
|
+
)
|
|
165
|
+
rp_per_page_count
|
|
166
|
+
end
|
|
167
|
+
end
|
|
152
168
|
end
|
|
153
169
|
|
|
154
170
|
# Default pagination - can be overridden in model
|
|
@@ -156,13 +172,13 @@ module Railspress
|
|
|
156
172
|
|
|
157
173
|
class_methods do
|
|
158
174
|
# Simple pagination for index views
|
|
159
|
-
def
|
|
175
|
+
def rp_page(page_number)
|
|
160
176
|
page_number = [ page_number.to_i, 1 ].max
|
|
161
|
-
offset((page_number - 1) *
|
|
177
|
+
offset((page_number - 1) * rp_per_page_count).limit(rp_per_page_count)
|
|
162
178
|
end
|
|
163
179
|
|
|
164
180
|
# Allow models to override PER_PAGE
|
|
165
|
-
def
|
|
181
|
+
def rp_per_page_count
|
|
166
182
|
const_defined?(:PER_PAGE, false) ? const_get(:PER_PAGE) : Railspress::Entity::PER_PAGE
|
|
167
183
|
end
|
|
168
184
|
|
data/lib/railspress/version.rb
CHANGED
data/lib/railspress.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require "railspress/version"
|
|
2
|
+
require "active_support/deprecation"
|
|
2
3
|
require "railspress/cms_helper"
|
|
3
4
|
require "railspress/engine"
|
|
4
5
|
require "railspress/entity"
|
|
@@ -195,6 +196,10 @@ module Railspress
|
|
|
195
196
|
end
|
|
196
197
|
|
|
197
198
|
class << self
|
|
199
|
+
def deprecator
|
|
200
|
+
@deprecator ||= ActiveSupport::Deprecation.new("2.0", "RailsPress")
|
|
201
|
+
end
|
|
202
|
+
|
|
198
203
|
def configuration
|
|
199
204
|
@configuration ||= Configuration.new
|
|
200
205
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: railspress-engine
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.4.
|
|
4
|
+
version: 1.4.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Avi Flombaum
|
|
@@ -372,7 +372,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
372
372
|
- !ruby/object:Gem::Version
|
|
373
373
|
version: '0'
|
|
374
374
|
requirements: []
|
|
375
|
-
rubygems_version: 4.0.
|
|
375
|
+
rubygems_version: 4.0.18
|
|
376
376
|
specification_version: 4
|
|
377
377
|
summary: A mountable blog + CMS engine for Rails 8+
|
|
378
378
|
test_files: []
|