sigmund_liquid 1.0.13 → 1.0.14

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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YmRlNDY5YmM1ZjdjM2Y5ZTVjY2Y3OWVhYmIyMWI2MTZkMGJiZTIzNA==
4
+ ZTUxYTg0YzQ2YTYyODJjNWRhNDhmZmM1NjI0OTQwYmNiMjM2M2JiYQ==
5
5
  data.tar.gz: !binary |-
6
- YTc1ZmI3ZWExYjE2ZGVmZjViZmZlN2NmOWU3Y2E5ODNlMmNmZDhlMw==
6
+ ZGI4NDgxNzdkZjUwYjdhOGMyYTUzYjkyNjE0Y2M2MTJkY2RmODYxMw==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZjMxNmY1YTUwNmIxN2JlMjNiZmJmNGU4MTM0MDFjNzllNGUwOWU2NGYyMTI2
10
- ZmQzYTJkNDVmYzdhNTdkOWVlZDQxY2Y4MmJiMGU5NWNkOGNhNGIyN2NlMDUx
11
- Nzc2ZjVhNDc2YjI5MDYzOTZiNjBkNzJiZWM1ZWYxMzg1ODBkYjc=
9
+ ODg4NTM5OTIyZGQ1OThiOTY0NWE4MTQ1ZTQxYzBhNDc2MDVmNmY2NzFlZmI1
10
+ ZWQ4YzBhMThmZjdjZjcyNWJkNTlkZTU0OTFiNWM5YzlkMjFiYzgxNTdjODJl
11
+ OWZjNDgyZDI4MDYyNTljM2ZkNDgxNTI1ZDhiODU0YmZjODcyOTM=
12
12
  data.tar.gz: !binary |-
13
- N2YzNGFmY2M1YTVmMzU3MmU1OWEwZjI4NTgwOWE2MmFmNWVjODRjZGM3NjIy
14
- Y2Q3NTIzMmEyZGFmM2RmNzYwOTM1YTc2NjJlNjcyYzVkMmFiMWVhNmEyNmU1
15
- YmY3MmM0YWMxYzdjNTkwZTIwMWUwMzdkMDNmOTEzMzRjODNjZDY=
13
+ OTc5Y2QyMThjNmUxY2U5MjEwZDY5YTQ3YzlhMGU3NDZmYjJlMTc5OTdlMGMz
14
+ ZWZhODE5YmY1MjJhYWJiMGUzNWI5OTM1ODYxYzBmMWRiMzlhYjlkMzg1MmRm
15
+ ZDUxYjRiMzcwNjE1NWY2Y2Q4Njg0ZTc0ZWYyNDYwN2FkN2E0Y2I=
@@ -0,0 +1,107 @@
1
+ module Sigmund
2
+
3
+ module Liquid
4
+
5
+ module Tags
6
+
7
+ class CustomPaginate < ::Liquid::Block
8
+
9
+ Syntax = /(#{::Liquid::Expression}+)?/
10
+
11
+ def initialize(tag_name, markup, tokens, context)
12
+ if markup =~ Syntax
13
+ @collection_name = $1
14
+ @options = { }
15
+ markup.scan(::Liquid::TagAttributes) { |key, value| @options[key.to_sym] = value.gsub(/^'/, '').gsub(/'$/, '') }
16
+ @per_page = @options[:per_page] ? @options[:per_page] : 10
17
+ @window_size = @options[:window_size] ? @options[:window_size].to_i : 3
18
+ else
19
+ raise ::Liquid::SyntaxError.new("Syntax Error in 'paginate' - Valid syntax: paginate <collection> by <number>")
20
+ end
21
+
22
+ super
23
+ end
24
+
25
+ def render(context)
26
+ context.stack do
27
+ collection = context[@collection_name]
28
+ @per_page = context[@per_page]
29
+
30
+ if @per_page == 'all'
31
+ @per_page = collection.size + 1
32
+ end
33
+
34
+ raise ::Liquid::ArgumentError.new("Cannot paginate array '#{@collection_name}'. Not found.") if collection.nil?
35
+
36
+ if collection.is_a? Array
37
+ pagination = Kaminari.paginate_array(collection).page(context['current_page']).per(@per_page).to_liquid.stringify_keys
38
+ else
39
+ pagination = collection.send(:paginate, {
40
+ page: context['current_page'],
41
+ per_page: @per_page
42
+ }).to_liquid.stringify_keys
43
+ end
44
+ page_count, current_page = pagination['total_pages'], pagination['current_page']
45
+
46
+ path = sanitize_path(context['fullpath'])
47
+
48
+ pagination['previous'] = link(I18n.t('pagination.previous'), current_page - 1, path) if pagination['previous_page']
49
+ pagination['next'] = link(I18n.t('pagination.next'), current_page + 1, path) if pagination['next_page']
50
+ pagination['parts'] = []
51
+
52
+ hellip_break = false
53
+
54
+ if page_count > 1
55
+ 1.upto(page_count) do |page|
56
+ if current_page == page
57
+ pagination['parts'] << no_link(page)
58
+ elsif page == 1
59
+ pagination['parts'] << link(page, page, path)
60
+ elsif page == page_count
61
+ pagination['parts'] << link(page, page, path)
62
+ elsif page <= current_page - window_size or page >= current_page + window_size
63
+ next if hellip_break
64
+ pagination['parts'] << no_link('&laquo;')
65
+ hellip_break = true
66
+ next
67
+ else
68
+ pagination['parts'] << link(page, page, path)
69
+ end
70
+ hellip_break = false
71
+ end
72
+ end
73
+
74
+ context['custom_paginate'] = pagination
75
+
76
+ render_all(@nodelist, context)
77
+ end
78
+ end
79
+
80
+ private
81
+
82
+ def sanitize_path(path)
83
+ _path = path.gsub(/page=[0-9]+&?/, '').gsub(/_pjax=true&?/, '')
84
+ _path = _path.slice(0..-2) if _path.last == '?' || _path.last == '&'
85
+ _path
86
+ end
87
+
88
+ def window_size
89
+ @window_size
90
+ end
91
+
92
+ def no_link(title)
93
+ { 'title' => title, 'is_link' => false, 'hellip_break' => title == '&hellip;' }
94
+ end
95
+
96
+ def link(title, page, path)
97
+ _path = %(#{path}#{path.include?('?') ? '&' : '?'}page=#{page})
98
+ { 'title' => title, 'url' => _path, 'is_link' => true }
99
+ end
100
+ end
101
+
102
+ ::Liquid::Template.register_tag('custom_paginate', CustomPaginate)
103
+ end
104
+
105
+ end
106
+
107
+ end
@@ -1,5 +1,5 @@
1
1
  module Sigmund
2
2
  module Liquid
3
- VERSION = "1.0.13"
3
+ VERSION = "1.0.14"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sigmund_liquid
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.13
4
+ version: 1.0.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - amainguy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-11 00:00:00.000000000 Z
11
+ date: 2015-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -62,6 +62,7 @@ files:
62
62
  - lib/sigmund/liquid/filters/color.rb
63
63
  - lib/sigmund/liquid/tags/children_nav.rb
64
64
  - lib/sigmund/liquid/tags/custom_nav.rb
65
+ - lib/sigmund/liquid/tags/custom_paginate.rb
65
66
  - lib/sigmund/liquid/version.rb
66
67
  - lib/sigmund/liquid.rb
67
68
  - lib/sigmund_liquid.rb