middleman-paginator 0.0.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 +7 -0
- data/.gitignore +5 -0
- data/Gemfile +15 -0
- data/README.md +61 -0
- data/Rakefile +14 -0
- data/features/support/env.rb +4 -0
- data/lib/middleman-paginator.rb +7 -0
- data/lib/middleman/paginator.rb +65 -0
- data/middleman-paginate_collection.gemspec +20 -0
- metadata +66 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 519980611123aa1088aa0fe2e937cc28ebfc3fa3
|
4
|
+
data.tar.gz: 240ee374dc4fc0d09c79b39ff016a62a84bf464d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2707fdb78fd6a427906155118b2c42a7adca261a08da896c62cd5d447c748f9729d4cbb7e21840bbfe592a9fb72a0d48263885906a3f532e76a3615824590616
|
7
|
+
data.tar.gz: 67264f0e7f2c6607043ff7f7691ec1f3ada314102ca5d8481ef63aad854427ae473a591b6a893c0ce9c35741780b22164bbfc5d11b7b13d34fbedb5c758c4c47
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# Middleman Paginator
|
2
|
+
A simple plugin that allows paginating any collection of objects
|
3
|
+
|
4
|
+
## Instalation
|
5
|
+
|
6
|
+
Add this to your Gemfile
|
7
|
+
|
8
|
+
```
|
9
|
+
gem 'middleman-paginator'
|
10
|
+
```
|
11
|
+
|
12
|
+
## Use
|
13
|
+
|
14
|
+
### Activate gem in `config.rb`
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
activate :paginator do |e|
|
18
|
+
e.per_page = 25 # Default 20
|
19
|
+
end
|
20
|
+
```
|
21
|
+
|
22
|
+
### Paginate
|
23
|
+
|
24
|
+
`destination` - Path to put pages in. Expects `/` in the end.
|
25
|
+
Produced pages will have following path `#{destination}pages/index.html`, `#{destination}pages/2.html`
|
26
|
+
|
27
|
+
`template` - Path to the template.
|
28
|
+
If you don't want to render template by itself pass `ignore: true` to extra arguments.
|
29
|
+
|
30
|
+
`objects` - Objects to paginate. You will have access to them inside the template as `objects`.
|
31
|
+
|
32
|
+
`locals` - If you have need any other variables inside the template, pass them allong as you normally would.
|
33
|
+
|
34
|
+
`ignore` - See `template` option description.
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
paginate(
|
38
|
+
destination: '/',
|
39
|
+
template: 'template.html',
|
40
|
+
objects: objects,
|
41
|
+
locals: { },
|
42
|
+
ignore: true
|
43
|
+
)
|
44
|
+
```
|
45
|
+
|
46
|
+
### Access from template
|
47
|
+
|
48
|
+
Inside `template`, iterate over `per_page` number of `objects`
|
49
|
+
|
50
|
+
```haml
|
51
|
+
- objects.each do |object|
|
52
|
+
// render object
|
53
|
+
|
54
|
+
= previous_page_link
|
55
|
+
= next_page_link
|
56
|
+
|
57
|
+
```
|
58
|
+
|
59
|
+
### Helpers
|
60
|
+
|
61
|
+
Paginator provides to helper methods: `previous_page_link`, `next_page_link`. They supposed to just work.
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
require 'cucumber/rake/task'
|
5
|
+
|
6
|
+
Cucumber::Rake::Task.new(:cucumber, 'Run features that should pass') do |t|
|
7
|
+
t.cucumber_opts = '--color --tags ~@wip --strict'
|
8
|
+
end
|
9
|
+
|
10
|
+
require 'rake/clean'
|
11
|
+
|
12
|
+
task test: ['cucumber']
|
13
|
+
|
14
|
+
task default: :test
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'middleman-core'
|
2
|
+
|
3
|
+
class Paginator < ::Middleman::ConfigExtension
|
4
|
+
self.resource_list_manipulator_priority = 0
|
5
|
+
|
6
|
+
expose_to_config :paginate
|
7
|
+
|
8
|
+
option :per_page, 20, 'Controls pagination'
|
9
|
+
|
10
|
+
CollectionProxyDescriptor = Struct.new(:descriptors) do
|
11
|
+
def execute_descriptor(app, resources)
|
12
|
+
descriptors.reduce(resources) do |resources, descriptor|
|
13
|
+
if descriptor.metadata[:ignore]
|
14
|
+
d = ::Middleman::Sitemap::Extensions::Ignores::StringIgnoreDescriptor.new(descriptor.target)
|
15
|
+
d.execute_descriptor(app, resources)
|
16
|
+
end
|
17
|
+
|
18
|
+
descriptor.execute_descriptor(app, resources)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def paginate(destination:, objects:, template:, **page_options)
|
24
|
+
descriptors = []
|
25
|
+
|
26
|
+
objects.each_slice(options.per_page).with_index(1).reverse_each do |o, i|
|
27
|
+
paginate_options = { locals: { objects: o, page: i, destination: destination } }
|
28
|
+
path = i == 1 ? 'index.html' : "pages/#{i}.html"
|
29
|
+
|
30
|
+
descriptor = Middleman::Sitemap::Extensions::ProxyDescriptor.new(
|
31
|
+
::Middleman::Util.normalize_path("#{destination}#{path}"),
|
32
|
+
::Middleman::Util.normalize_path(template),
|
33
|
+
page_options.merge(paginate_options) { |key, v1, v2| v1.merge v2 }
|
34
|
+
)
|
35
|
+
|
36
|
+
descriptors << descriptor
|
37
|
+
end
|
38
|
+
|
39
|
+
CollectionProxyDescriptor.new(descriptors)
|
40
|
+
end
|
41
|
+
|
42
|
+
helpers do
|
43
|
+
def previous_page_link
|
44
|
+
page = @locs[:page]
|
45
|
+
return if page == 1
|
46
|
+
|
47
|
+
path = if page == 2
|
48
|
+
"#{@locs[:destination]}index.html"
|
49
|
+
else
|
50
|
+
"#{@locs[:destination]}pages/#{page - 1}.html"
|
51
|
+
end
|
52
|
+
|
53
|
+
link_to 'Previous', path, class: 'page-link'
|
54
|
+
end
|
55
|
+
|
56
|
+
def next_page_link
|
57
|
+
page = @locs[:page]
|
58
|
+
path = "#{@locs[:destination]}pages/#{page + 1}.html"
|
59
|
+
return unless sitemap.find_resource_by_path(path)
|
60
|
+
|
61
|
+
link_to 'Next', path, class: 'page-link'
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "middleman-paginator"
|
6
|
+
s.version = "0.0.3"
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = ["TheSmartnik"]
|
9
|
+
s.email = ["misharinn@gmail.com"]
|
10
|
+
s.homepage = "https://github.com/TheSmartnik/middleman-paginator"
|
11
|
+
s.summary = %q{A simple plugin to allow pagination in middleman}
|
12
|
+
s.description = %q{A simple way to paginate any collection in middleman }
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
|
19
|
+
s.add_runtime_dependency("middleman-core", [">= 4.2.1"])
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: middleman-paginator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- TheSmartnik
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-03-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: middleman-core
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.2.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.2.1
|
27
|
+
description: 'A simple way to paginate any collection in middleman '
|
28
|
+
email:
|
29
|
+
- misharinn@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".gitignore"
|
35
|
+
- Gemfile
|
36
|
+
- README.md
|
37
|
+
- Rakefile
|
38
|
+
- features/support/env.rb
|
39
|
+
- lib/middleman-paginator.rb
|
40
|
+
- lib/middleman/paginator.rb
|
41
|
+
- middleman-paginate_collection.gemspec
|
42
|
+
homepage: https://github.com/TheSmartnik/middleman-paginator
|
43
|
+
licenses: []
|
44
|
+
metadata: {}
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
requirements: []
|
60
|
+
rubyforge_project:
|
61
|
+
rubygems_version: 2.6.14
|
62
|
+
signing_key:
|
63
|
+
specification_version: 4
|
64
|
+
summary: A simple plugin to allow pagination in middleman
|
65
|
+
test_files:
|
66
|
+
- features/support/env.rb
|