comfy_archive 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +1 -1
- data/README.md +7 -4
- data/app/controllers/comfy/archive/index_controller.rb +22 -2
- data/app/helpers/comfy/archive_helper.rb +28 -0
- data/app/views/comfy/archive/index/index.html.haml +2 -5
- data/lib/comfy_archive/configuration.rb +9 -1
- data/lib/comfy_archive/version.rb +1 -1
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c55ea63ba29ffb508628ff2e03e49526f078960ae53897f39bae7d87169e0f9b
|
4
|
+
data.tar.gz: 866ab58373fcbc74ba56b311359a74b01d1c891dd3a01a0badf16b8193c93f2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a54e9ae15d7ec66c381ea2027a7656721dcde69927e57649d9c47946080fe1ab3faa933743125304519e67f9104ccf601e264f957d0ea7e8985c9f7f50f2a2e8
|
7
|
+
data.tar.gz: 8ef5a1444f1dadf90fc75e2ced725cb62199c062b35735868a9933477f3a414c05d4e98ea8e740281b7f9e0442d14ad0f2b8d198ef4303dacd917b3a4b297080
|
data/LICENSE
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
Copyright 2013-2018 Oleg Khabarov
|
2
|
-
Copyright 2019 Discovery Map International, Inc.
|
2
|
+
Copyright 2019-2022 Discovery Map International, Inc.
|
3
3
|
|
4
4
|
Permission is hereby granted, free of charge, to any person obtaining
|
5
5
|
a copy of this software and associated documentation files (the
|
data/README.md
CHANGED
@@ -12,7 +12,7 @@ Make sure that you have [ComfortableMexicanSofa](https://github.com/comfy/comfor
|
|
12
12
|
|
13
13
|
1) Add gem definition to your Gemfile:
|
14
14
|
|
15
|
-
gem "comfy_archive", "~> 0.
|
15
|
+
gem "comfy_archive", "~> 0.3.0"
|
16
16
|
|
17
17
|
2) From your Rails project's root run:
|
18
18
|
|
@@ -25,21 +25,24 @@ Make sure that you have [ComfortableMexicanSofa](https://github.com/comfy/comfor
|
|
25
25
|
comfy_route :archive_admin
|
26
26
|
comfy_route :archive
|
27
27
|
|
28
|
-
4) You should also find view templates in your `/app/views/comfy/archive` folder. Feel free to adjust them as you see fit
|
28
|
+
4) You should also find view templates in your `/app/views/comfy/archive` folder. Feel free to adjust them as you see fit
|
29
29
|
|
30
30
|
## Configuration
|
31
31
|
|
32
|
-
1) Add a `datetime` tag to the layout used by any page which will be ordered chronologically under an index page, then set the field to a valid date & time in the pages themselves
|
32
|
+
1) Add a `datetime` tag to the layout used by any page which will be ordered chronologically under an index page, then set the field to a valid date & time in the pages themselves
|
33
33
|
|
34
34
|
2) Add a new Archive Index, selecting the parent page (_Important_: can not be the root page!) which will act as an index for child pages and enter the name of the `datetime` tag you created in Step 1
|
35
35
|
|
36
|
+
3) Optionally, create a `config/initializers/comfy_archive.rb` file to override default configuration options
|
37
|
+
|
36
38
|
## Architecture
|
37
39
|
|
38
40
|
* `ComfyArchive`: Rails Engine which manages configuration, adds scopes & associations to `Comfy::Cms::Site` & `Comfy::Cms::Page` models, and adds route matching methods
|
41
|
+
* `Comfy::ArchiveHelper`: Helper methods for generating links to chronological & category archive pages
|
39
42
|
* `Comfy::Archive::Index`: A model which represents pages which will become chronological archive pages, it has a `Comfy::Cms::Page` association and also the name of the page's `datetime` fragment to use for chronological ordering
|
40
43
|
* `Comfy::Admin::Archive::IndicesController`: A Comfortable Mexican Sofa admin controller for managing `Comfy::Archive::Index` models
|
41
44
|
* `Comfy::Archive::IndexController`: A controller for rendering `Comfy::Archive::Index` pages, plus chronological & categorical archive pages
|
42
45
|
|
43
46
|
---
|
44
47
|
|
45
|
-
Copyright (c) 2019 Discovery Map International, Inc.
|
48
|
+
Copyright (c) 2019-2022 Discovery Map International, Inc.
|
@@ -22,8 +22,8 @@ class Comfy::Archive::IndexController < Comfy::Cms::ContentController
|
|
22
22
|
scope = scope.for_month(@cms_index.datetime_fragment, @month)
|
23
23
|
end
|
24
24
|
elsif params[:category]
|
25
|
-
|
26
|
-
scope = scope.for_category(@category).distinct(false)
|
25
|
+
load_category
|
26
|
+
scope = scope.for_category(@category.label).distinct(false)
|
27
27
|
end
|
28
28
|
|
29
29
|
@archive_pages = comfy_paginate(scope, per_page: ComfyArchive.config.posts_per_page)
|
@@ -46,4 +46,24 @@ class Comfy::Archive::IndexController < Comfy::Cms::ContentController
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
+
def load_category
|
50
|
+
@category = ComfyArchive.config.parameterize_category ? find_cms_category_by_parameterized_label(params[:category]) : Comfy::Cms::Category.find_by(label: CGI.unescape(params[:category]))
|
51
|
+
unless @category
|
52
|
+
if ComfyArchive.config.strict_categories
|
53
|
+
if find_cms_page_by_full_path("/404")
|
54
|
+
render_page(:not_found)
|
55
|
+
else
|
56
|
+
message = "Page Not Found at: \"#{params[:cms_path]}/category/#{params[:category]}\""
|
57
|
+
raise ActionController::RoutingError, message
|
58
|
+
end
|
59
|
+
else
|
60
|
+
@category = Comfy::Cms::Category.new(label: ComfyArchive.config.parameterize_category ? params[:category].gsub('-', ' ').titleize : CGI.unescape(params[:category]))
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def find_cms_category_by_parameterized_label(parameterized)
|
66
|
+
@cms_index.categories.find { |c| c.label.parameterize == parameterized }
|
67
|
+
end
|
68
|
+
|
49
69
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Comfy
|
4
|
+
module ArchiveHelper
|
5
|
+
|
6
|
+
require 'cgi'
|
7
|
+
|
8
|
+
def comfy_archive_link_to_month(year, month)
|
9
|
+
unless !@cms_index || year.blank? || month.blank?
|
10
|
+
date = [I18n.t("date.month_names")[month.to_i], year].join(' ')
|
11
|
+
link_to date, comfy_archive_pages_of_month_path(@cms_index.url(relative: false), year: year, month: month)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def comfy_archive_link_to_category(category)
|
16
|
+
if category.is_a? Comfy::Cms::Category
|
17
|
+
label = category.label
|
18
|
+
elsif category.is_a? String
|
19
|
+
label = category
|
20
|
+
end
|
21
|
+
unless !@cms_index || category.blank?
|
22
|
+
encoded_label = ComfyArchive.config.parameterize_category ? label.parameterize : CGI.escape(label)
|
23
|
+
link_to label, comfy_archive_pages_of_category_path(@cms_index.url(relative: false), encoded_label)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
- require 'cgi'
|
2
|
-
|
3
1
|
- site_path = @cms_index.url(relative: false)
|
4
2
|
|
5
3
|
%h2
|
@@ -23,9 +21,8 @@
|
|
23
21
|
- raise NotImplementedError, "Unknown adapter type '#{ActiveRecord::Base.connection.adapter_name}'"
|
24
22
|
- dates.each do |(year, month)|
|
25
23
|
%li
|
26
|
-
|
27
|
-
= link_to date, comfy_archive_pages_of_month_path(site_path, year: year, month: month)
|
24
|
+
= comfy_archive_link_to_month year, month
|
28
25
|
|
29
26
|
%h4 Categories
|
30
27
|
- @cms_index.categories(true).each do |category|
|
31
|
-
=
|
28
|
+
= comfy_archive_link_to_category category
|
@@ -6,9 +6,17 @@ module ComfyArchive
|
|
6
6
|
# Number of posts per page. Default is 10
|
7
7
|
attr_accessor :posts_per_page
|
8
8
|
|
9
|
+
# Parameterize category label in paths. Default is false
|
10
|
+
attr_accessor :parameterize_category
|
11
|
+
|
12
|
+
# Generate 404 error or throw warning for invalid catgegories. Default is true
|
13
|
+
attr_accessor :strict_categories
|
14
|
+
|
9
15
|
# Configuration defaults
|
10
16
|
def initialize
|
11
|
-
@posts_per_page
|
17
|
+
@posts_per_page = 10
|
18
|
+
@parameterize_category = false
|
19
|
+
@strict_categories = true
|
12
20
|
end
|
13
21
|
|
14
22
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: comfy_archive
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Morgan Aldridge
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-04-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: comfortable_mexican_sofa
|
@@ -39,6 +39,7 @@ files:
|
|
39
39
|
- app/assets/config/manifest.js
|
40
40
|
- app/controllers/comfy/admin/archive/indices_controller.rb
|
41
41
|
- app/controllers/comfy/archive/index_controller.rb
|
42
|
+
- app/helpers/comfy/archive_helper.rb
|
42
43
|
- app/models/comfy/archive/index.rb
|
43
44
|
- app/views/comfy/admin/archive/indices/_form.html.haml
|
44
45
|
- app/views/comfy/admin/archive/indices/edit.html.haml
|
@@ -79,7 +80,7 @@ homepage: http://github.com/discoverymap/comfy-archive
|
|
79
80
|
licenses:
|
80
81
|
- MIT
|
81
82
|
metadata: {}
|
82
|
-
post_install_message:
|
83
|
+
post_install_message:
|
83
84
|
rdoc_options: []
|
84
85
|
require_paths:
|
85
86
|
- lib
|
@@ -94,8 +95,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
95
|
- !ruby/object:Gem::Version
|
95
96
|
version: '0'
|
96
97
|
requirements: []
|
97
|
-
rubygems_version: 3.0.
|
98
|
-
signing_key:
|
98
|
+
rubygems_version: 3.0.8
|
99
|
+
signing_key:
|
99
100
|
specification_version: 4
|
100
101
|
summary: Chronological Archives Engine for ComfortableMexicanSofa
|
101
102
|
test_files: []
|