jekyll 2.0.3 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of jekyll might be problematic. Click here for more details.

Files changed (107) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -2
  3. data/CONTRIBUTING.markdown +2 -2
  4. data/History.markdown +86 -0
  5. data/README.markdown +5 -30
  6. data/Rakefile +4 -9
  7. data/docs/jp/CONTRIBUTING.jp.markdown +2 -2
  8. data/docs/jp/README.jp.markdown +1 -2
  9. data/features/collections.feature +40 -3
  10. data/features/data.feature +41 -1
  11. data/features/frontmatter_defaults.feature +57 -0
  12. data/features/post_data.feature +12 -0
  13. data/features/rendering.feature +34 -0
  14. data/features/step_definitions/jekyll_steps.rb +5 -1
  15. data/features/support/env.rb +0 -3
  16. data/jekyll.gemspec +6 -5
  17. data/lib/jekyll.rb +18 -1
  18. data/lib/jekyll/cleaner.rb +22 -2
  19. data/lib/jekyll/collection.rb +9 -2
  20. data/lib/jekyll/command.rb +20 -10
  21. data/lib/jekyll/commands/build.rb +10 -47
  22. data/lib/jekyll/commands/serve.rb +1 -0
  23. data/lib/jekyll/configuration.rb +13 -1
  24. data/lib/jekyll/converters/markdown/redcarpet_parser.rb +9 -2
  25. data/lib/jekyll/convertible.rb +31 -2
  26. data/lib/jekyll/deprecator.rb +1 -1
  27. data/lib/jekyll/document.rb +21 -3
  28. data/lib/jekyll/excerpt.rb +1 -1
  29. data/lib/jekyll/filters.rb +16 -12
  30. data/lib/jekyll/frontmatter_defaults.rb +3 -3
  31. data/lib/jekyll/log_adapter.rb +102 -0
  32. data/lib/jekyll/post.rb +5 -5
  33. data/lib/jekyll/renderer.rb +9 -5
  34. data/lib/jekyll/site.rb +38 -18
  35. data/lib/jekyll/static_file.rb +1 -0
  36. data/lib/jekyll/stevenson.rb +54 -98
  37. data/lib/jekyll/tags/highlight.rb +13 -5
  38. data/lib/jekyll/url.rb +2 -2
  39. data/lib/jekyll/utils.rb +15 -7
  40. data/lib/jekyll/version.rb +1 -1
  41. data/lib/site_template/_config.yml +2 -0
  42. data/lib/site_template/_includes/footer.html +8 -8
  43. data/lib/site_template/_includes/header.html +1 -1
  44. data/lib/site_template/css/main.css +7 -2
  45. data/lib/site_template/feed.xml +10 -1
  46. data/site/_config.yml +1 -0
  47. data/site/_data/docs.yml +1 -0
  48. data/site/_includes/anchor_links.html +28 -23
  49. data/site/_includes/css/font-awesome.css +3 -3
  50. data/site/_includes/css/style.css +4 -0
  51. data/site/_includes/news_contents.html +11 -1
  52. data/site/_includes/top.html +0 -1
  53. data/site/_layouts/default.html +1 -0
  54. data/site/_posts/2013-07-25-jekyll-1-0-4-released.markdown +1 -1
  55. data/site/_posts/2013-07-25-jekyll-1-1-2-released.markdown +1 -1
  56. data/site/_posts/2014-06-04-jekyll-stickers-1-dollar-stickermule.markdown +19 -0
  57. data/site/_posts/2014-06-28-jekyll-turns-21-i-mean-2-1-0.markdown +27 -0
  58. data/site/docs/collections.md +59 -1
  59. data/site/docs/configuration.md +91 -21
  60. data/site/docs/continuous-integration.md +177 -0
  61. data/site/docs/contributing.md +2 -2
  62. data/site/docs/datafiles.md +47 -3
  63. data/site/docs/deployment-methods.md +3 -3
  64. data/site/docs/extras.md +3 -5
  65. data/site/docs/history.md +86 -0
  66. data/site/docs/installation.md +3 -1
  67. data/site/docs/pagination.md +2 -1
  68. data/site/docs/permalinks.md +4 -4
  69. data/site/docs/plugins.md +6 -0
  70. data/site/docs/quickstart.md +0 -6
  71. data/site/docs/resources.md +1 -1
  72. data/site/docs/templates.md +1 -1
  73. data/site/docs/troubleshooting.md +1 -1
  74. data/site/docs/windows.md +2 -2
  75. data/site/fonts/FontAwesome.otf +0 -0
  76. data/site/fonts/fontawesome-webfont.eot +0 -0
  77. data/site/fonts/fontawesome-webfont.svg +469 -379
  78. data/site/fonts/fontawesome-webfont.ttf +0 -0
  79. data/site/fonts/fontawesome-webfont.woff +0 -0
  80. data/site/img/jekyll-sticker.jpg +0 -0
  81. data/test/helper.rb +0 -3
  82. data/test/source/_data/categories/dairy.yaml +6 -0
  83. data/test/source/_data/members.json +12 -0
  84. data/test/source/_methods/site/initialize.md +1 -2
  85. data/test/source/_posts/2009-01-27-no-category.textile +6 -0
  86. data/test/source/_slides/example-slide-1.html +4 -0
  87. data/test/source/_slides/example-slide-2.html +7 -0
  88. data/test/source/_with.dots/all.dots/2.4.0.md +5 -0
  89. data/test/source/_with.dots/file.with.dots.md +0 -0
  90. data/test/source/environment.html +5 -0
  91. data/test/test_cleaner.rb +77 -0
  92. data/test/test_collections.rb +52 -3
  93. data/test/test_command.rb +25 -28
  94. data/test/test_configuration.rb +10 -1
  95. data/test/test_document.rb +123 -0
  96. data/test/test_excerpt.rb +11 -0
  97. data/test/test_filters.rb +28 -2
  98. data/test/test_generated_site.rb +1 -1
  99. data/test/test_log_adapter.rb +59 -0
  100. data/test/test_post.rb +77 -0
  101. data/test/test_site.rb +51 -0
  102. data/test/test_tags.rb +11 -114
  103. data/test/test_utils.rb +2 -2
  104. metadata +76 -39
  105. data/lib/jekyll/generators/pagination.rb +0 -217
  106. data/lib/jekyll/tags/gist.rb +0 -47
  107. data/test/test_pager.rb +0 -118
@@ -15,9 +15,9 @@ class TestUtils < Test::Unit::TestCase
15
15
  assert_equal [], Utils.pluralized_array_from_hash(data, 'tag', 'tags')
16
16
  end
17
17
 
18
- should "return empty array with matching nil singular" do
18
+ should "return plural array with nil singular" do
19
19
  data = { 'foo' => 'bar', 'tag' => nil, 'tags' => ['dog', 'cat'] }
20
- assert_equal [], Utils.pluralized_array_from_hash(data, 'tag', 'tags')
20
+ assert_equal ['dog', 'cat'], Utils.pluralized_array_from_hash(data, 'tag', 'tags')
21
21
  end
22
22
 
23
23
  should "return single value array with matching singular" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.3
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Preston-Werner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-09 00:00:00.000000000 Z
11
+ date: 2014-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: liquid
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 2.5.5
19
+ version: 2.6.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 2.5.5
26
+ version: 2.6.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: classifier
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.3'
41
- - !ruby/object:Gem::Dependency
42
- name: listen
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '2.5'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '2.5'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: kramdown
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -72,14 +58,14 @@ dependencies:
72
58
  requirements:
73
59
  - - "~>"
74
60
  - !ruby/object:Gem::Version
75
- version: 0.5.0
61
+ version: 0.6.0
76
62
  type: :runtime
77
63
  prerelease: false
78
64
  version_requirements: !ruby/object:Gem::Requirement
79
65
  requirements:
80
66
  - - "~>"
81
67
  - !ruby/object:Gem::Version
82
- version: 0.5.0
68
+ version: 0.6.0
83
69
  - !ruby/object:Gem::Dependency
84
70
  name: mercenary
85
71
  requirement: !ruby/object:Gem::Requirement
@@ -150,6 +136,34 @@ dependencies:
150
136
  - - "~>"
151
137
  - !ruby/object:Gem::Version
152
138
  version: 0.1.0
139
+ - !ruby/object:Gem::Dependency
140
+ name: jekyll-paginate
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '1.0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '1.0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: jekyll-gist
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '1.0'
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '1.0'
153
167
  - !ruby/object:Gem::Dependency
154
168
  name: jekyll-coffeescript
155
169
  requirement: !ruby/object:Gem::Requirement
@@ -178,6 +192,20 @@ dependencies:
178
192
  - - "~>"
179
193
  - !ruby/object:Gem::Version
180
194
  version: '1.0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: jekyll-watch
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - "~>"
200
+ - !ruby/object:Gem::Version
201
+ version: '1.0'
202
+ type: :runtime
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - "~>"
207
+ - !ruby/object:Gem::Version
208
+ version: '1.0'
181
209
  - !ruby/object:Gem::Dependency
182
210
  name: rake
183
211
  requirement: !ruby/object:Gem::Requirement
@@ -346,20 +374,6 @@ dependencies:
346
374
  - - "~>"
347
375
  - !ruby/object:Gem::Version
348
376
  version: 1.0.1
349
- - !ruby/object:Gem::Dependency
350
- name: coveralls
351
- requirement: !ruby/object:Gem::Requirement
352
- requirements:
353
- - - "~>"
354
- - !ruby/object:Gem::Version
355
- version: 0.7.0
356
- type: :development
357
- prerelease: false
358
- version_requirements: !ruby/object:Gem::Requirement
359
- requirements:
360
- - - "~>"
361
- - !ruby/object:Gem::Version
362
- version: 0.7.0
363
377
  - !ruby/object:Gem::Dependency
364
378
  name: mime-types
365
379
  requirement: !ruby/object:Gem::Requirement
@@ -463,6 +477,7 @@ files:
463
477
  - features/permalinks.feature
464
478
  - features/post_data.feature
465
479
  - features/post_excerpts.feature
480
+ - features/rendering.feature
466
481
  - features/site_configuration.feature
467
482
  - features/site_data.feature
468
483
  - features/step_definitions/jekyll_steps.rb
@@ -496,10 +511,10 @@ files:
496
511
  - lib/jekyll/filters.rb
497
512
  - lib/jekyll/frontmatter_defaults.rb
498
513
  - lib/jekyll/generator.rb
499
- - lib/jekyll/generators/pagination.rb
500
514
  - lib/jekyll/layout.rb
501
515
  - lib/jekyll/layout_reader.rb
502
516
  - lib/jekyll/liquid_extensions.rb
517
+ - lib/jekyll/log_adapter.rb
503
518
  - lib/jekyll/mime.types
504
519
  - lib/jekyll/page.rb
505
520
  - lib/jekyll/plugin.rb
@@ -511,7 +526,6 @@ files:
511
526
  - lib/jekyll/site.rb
512
527
  - lib/jekyll/static_file.rb
513
528
  - lib/jekyll/stevenson.rb
514
- - lib/jekyll/tags/gist.rb
515
529
  - lib/jekyll/tags/highlight.rb
516
530
  - lib/jekyll/tags/include.rb
517
531
  - lib/jekyll/tags/post_url.rb
@@ -586,10 +600,13 @@ files:
586
600
  - site/_posts/2014-03-27-jekyll-1-5-1-released.markdown
587
601
  - site/_posts/2014-05-06-jekyll-turns-2-0-0.markdown
588
602
  - site/_posts/2014-05-08-jekyll-2-0-3-released.markdown
603
+ - site/_posts/2014-06-04-jekyll-stickers-1-dollar-stickermule.markdown
604
+ - site/_posts/2014-06-28-jekyll-turns-21-i-mean-2-1-0.markdown
589
605
  - site/css/screen.css
590
606
  - site/docs/assets.md
591
607
  - site/docs/collections.md
592
608
  - site/docs/configuration.md
609
+ - site/docs/continuous-integration.md
593
610
  - site/docs/contributing.md
594
611
  - site/docs/datafiles.md
595
612
  - site/docs/deployment-methods.md
@@ -628,6 +645,7 @@ files:
628
645
  - site/img/article-footer.png
629
646
  - site/img/footer-arrow.png
630
647
  - site/img/footer-logo.png
648
+ - site/img/jekyll-sticker.jpg
631
649
  - site/img/logo-2x.png
632
650
  - site/img/logo-rss.png
633
651
  - site/img/octojekyll.png
@@ -646,7 +664,9 @@ files:
646
664
  - test/source/+/foo.md
647
665
  - test/source/.htaccess
648
666
  - test/source/_config.dev.toml
667
+ - test/source/_data/categories/dairy.yaml
649
668
  - test/source/_data/languages.yml
669
+ - test/source/_data/members.json
650
670
  - test/source/_data/members.yaml
651
671
  - test/source/_data/products.yml
652
672
  - test/source/_drafts/draft-properties.text
@@ -675,6 +695,7 @@ files:
675
695
  - test/source/_posts/2009-01-27-category.textile
676
696
  - test/source/_posts/2009-01-27-empty-categories.textile
677
697
  - test/source/_posts/2009-01-27-empty-category.textile
698
+ - test/source/_posts/2009-01-27-no-category.textile
678
699
  - test/source/_posts/2009-03-12-hash-#1.markdown
679
700
  - test/source/_posts/2009-05-18-empty-tag.textile
680
701
  - test/source/_posts/2009-05-18-empty-tags.textile
@@ -704,6 +725,10 @@ files:
704
725
  - test/source/_posts/2014-03-22-escape-+ %20[].markdown
705
726
  - test/source/_posts/es/2008-11-21-nested.textile
706
727
  - test/source/_sass/_grid.scss
728
+ - test/source/_slides/example-slide-1.html
729
+ - test/source/_slides/example-slide-2.html
730
+ - test/source/_with.dots/all.dots/2.4.0.md
731
+ - test/source/_with.dots/file.with.dots.md
707
732
  - test/source/about.html
708
733
  - test/source/category/_posts/2008-9-23-categories.textile
709
734
  - test/source/contacts.html
@@ -712,6 +737,7 @@ files:
712
737
  - test/source/css/main.scss
713
738
  - test/source/css/screen.css
714
739
  - test/source/deal.with.dots.html
740
+ - test/source/environment.html
715
741
  - test/source/exploit.md
716
742
  - test/source/foo/_posts/bar/2008-12-12-topical-post.textile
717
743
  - test/source/index.html
@@ -726,6 +752,7 @@ files:
726
752
  - test/source/win/_posts/2009-05-24-yaml-linebreak.markdown
727
753
  - test/source/z_category/_posts/2008-9-23-categories.textile
728
754
  - test/suite.rb
755
+ - test/test_cleaner.rb
729
756
  - test/test_coffeescript.rb
730
757
  - test/test_collections.rb
731
758
  - test/test_command.rb
@@ -740,9 +767,9 @@ files:
740
767
  - test/test_kramdown.rb
741
768
  - test/test_layout_reader.rb
742
769
  - test/test_liquid_extensions.rb
770
+ - test/test_log_adapter.rb
743
771
  - test/test_new_command.rb
744
772
  - test/test_page.rb
745
- - test/test_pager.rb
746
773
  - test/test_path_sanitization.rb
747
774
  - test/test_post.rb
748
775
  - test/test_rdiscount.rb
@@ -754,7 +781,7 @@ files:
754
781
  - test/test_tags.rb
755
782
  - test/test_url.rb
756
783
  - test/test_utils.rb
757
- homepage: http://github.com/jekyll/jekyll
784
+ homepage: https://github.com/jekyll/jekyll
758
785
  licenses:
759
786
  - MIT
760
787
  metadata: {}
@@ -792,6 +819,7 @@ test_files:
792
819
  - features/permalinks.feature
793
820
  - features/post_data.feature
794
821
  - features/post_excerpts.feature
822
+ - features/rendering.feature
795
823
  - features/site_configuration.feature
796
824
  - features/site_data.feature
797
825
  - features/step_definitions/jekyll_steps.rb
@@ -806,7 +834,9 @@ test_files:
806
834
  - test/source/+/foo.md
807
835
  - test/source/.htaccess
808
836
  - test/source/_config.dev.toml
837
+ - test/source/_data/categories/dairy.yaml
809
838
  - test/source/_data/languages.yml
839
+ - test/source/_data/members.json
810
840
  - test/source/_data/members.yaml
811
841
  - test/source/_data/products.yml
812
842
  - test/source/_drafts/draft-properties.text
@@ -835,6 +865,7 @@ test_files:
835
865
  - test/source/_posts/2009-01-27-category.textile
836
866
  - test/source/_posts/2009-01-27-empty-categories.textile
837
867
  - test/source/_posts/2009-01-27-empty-category.textile
868
+ - test/source/_posts/2009-01-27-no-category.textile
838
869
  - test/source/_posts/2009-03-12-hash-#1.markdown
839
870
  - test/source/_posts/2009-05-18-empty-tag.textile
840
871
  - test/source/_posts/2009-05-18-empty-tags.textile
@@ -864,6 +895,10 @@ test_files:
864
895
  - test/source/_posts/2014-03-22-escape-+ %20[].markdown
865
896
  - test/source/_posts/es/2008-11-21-nested.textile
866
897
  - test/source/_sass/_grid.scss
898
+ - test/source/_slides/example-slide-1.html
899
+ - test/source/_slides/example-slide-2.html
900
+ - test/source/_with.dots/all.dots/2.4.0.md
901
+ - test/source/_with.dots/file.with.dots.md
867
902
  - test/source/about.html
868
903
  - test/source/category/_posts/2008-9-23-categories.textile
869
904
  - test/source/contacts.html
@@ -872,6 +907,7 @@ test_files:
872
907
  - test/source/css/main.scss
873
908
  - test/source/css/screen.css
874
909
  - test/source/deal.with.dots.html
910
+ - test/source/environment.html
875
911
  - test/source/exploit.md
876
912
  - test/source/foo/_posts/bar/2008-12-12-topical-post.textile
877
913
  - test/source/index.html
@@ -886,6 +922,7 @@ test_files:
886
922
  - test/source/win/_posts/2009-05-24-yaml-linebreak.markdown
887
923
  - test/source/z_category/_posts/2008-9-23-categories.textile
888
924
  - test/suite.rb
925
+ - test/test_cleaner.rb
889
926
  - test/test_coffeescript.rb
890
927
  - test/test_collections.rb
891
928
  - test/test_command.rb
@@ -900,9 +937,9 @@ test_files:
900
937
  - test/test_kramdown.rb
901
938
  - test/test_layout_reader.rb
902
939
  - test/test_liquid_extensions.rb
940
+ - test/test_log_adapter.rb
903
941
  - test/test_new_command.rb
904
942
  - test/test_page.rb
905
- - test/test_pager.rb
906
943
  - test/test_path_sanitization.rb
907
944
  - test/test_post.rb
908
945
  - test/test_rdiscount.rb
@@ -1,217 +0,0 @@
1
- module Jekyll
2
- module Generators
3
- class Pagination < Generator
4
- # This generator is safe from arbitrary code execution.
5
- safe true
6
-
7
- # This generator should be passive with regard to its execution
8
- priority :lowest
9
-
10
- # Generate paginated pages if necessary.
11
- #
12
- # site - The Site.
13
- #
14
- # Returns nothing.
15
- def generate(site)
16
- if Pager.pagination_enabled?(site)
17
- if template = template_page(site)
18
- paginate(site, template)
19
- else
20
- Jekyll.logger.warn "Pagination:", "Pagination is enabled, but I couldn't find " +
21
- "an index.html page to use as the pagination template. Skipping pagination."
22
- end
23
- end
24
- end
25
-
26
- # Paginates the blog's posts. Renders the index.html file into paginated
27
- # directories, e.g.: page2/index.html, page3/index.html, etc and adds more
28
- # site-wide data.
29
- #
30
- # site - The Site.
31
- # page - The index.html Page that requires pagination.
32
- #
33
- # {"paginator" => { "page" => <Number>,
34
- # "per_page" => <Number>,
35
- # "posts" => [<Post>],
36
- # "total_posts" => <Number>,
37
- # "total_pages" => <Number>,
38
- # "previous_page" => <Number>,
39
- # "next_page" => <Number> }}
40
- def paginate(site, page)
41
- all_posts = site.site_payload['site']['posts']
42
- pages = Pager.calculate_pages(all_posts, site.config['paginate'].to_i)
43
- (1..pages).each do |num_page|
44
- pager = Pager.new(site, num_page, all_posts, pages)
45
- if num_page > 1
46
- newpage = Page.new(site, site.source, page.dir, page.name)
47
- newpage.pager = pager
48
- newpage.dir = Pager.paginate_path(site, num_page)
49
- site.pages << newpage
50
- else
51
- page.pager = pager
52
- end
53
- end
54
- end
55
-
56
- # Static: Fetch the URL of the template page. Used to determine the
57
- # path to the first pager in the series.
58
- #
59
- # site - the Jekyll::Site object
60
- #
61
- # Returns the url of the template page
62
- def self.first_page_url(site)
63
- if page = Pagination.new.template_page(site)
64
- page.url
65
- else
66
- nil
67
- end
68
- end
69
-
70
- # Public: Find the Jekyll::Page which will act as the pager template
71
- #
72
- # site - the Jekyll::Site object
73
- #
74
- # Returns the Jekyll::Page which will act as the pager template
75
- def template_page(site)
76
- site.pages.dup.select do |page|
77
- Pager.pagination_candidate?(site.config, page)
78
- end.sort do |one, two|
79
- two.path.size <=> one.path.size
80
- end.first
81
- end
82
- end
83
- end
84
-
85
- class Pager
86
- attr_reader :page, :per_page, :posts, :total_posts, :total_pages,
87
- :previous_page, :previous_page_path, :next_page, :next_page_path
88
-
89
- # Calculate the number of pages.
90
- #
91
- # all_posts - The Array of all Posts.
92
- # per_page - The Integer of entries per page.
93
- #
94
- # Returns the Integer number of pages.
95
- def self.calculate_pages(all_posts, per_page)
96
- (all_posts.size.to_f / per_page.to_i).ceil
97
- end
98
-
99
- # Determine if pagination is enabled the site.
100
- #
101
- # site - the Jekyll::Site object
102
- #
103
- # Returns true if pagination is enabled, false otherwise.
104
- def self.pagination_enabled?(site)
105
- !site.config['paginate'].nil? &&
106
- site.pages.size > 0
107
- end
108
-
109
- # Static: Determine if a page is a possible candidate to be a template page.
110
- # Page's name must be `index.html` and exist in any of the directories
111
- # between the site source and `paginate_path`.
112
- #
113
- # config - the site configuration hash
114
- # page - the Jekyll::Page about which we're inquiring
115
- #
116
- # Returns true if the
117
- def self.pagination_candidate?(config, page)
118
- page_dir = File.dirname(File.expand_path(remove_leading_slash(page.path), config['source']))
119
- paginate_path = remove_leading_slash(config['paginate_path'])
120
- paginate_path = File.expand_path(paginate_path, config['source'])
121
- page.name == 'index.html' &&
122
- in_hierarchy(config['source'], page_dir, File.dirname(paginate_path))
123
- end
124
-
125
- # Determine if the subdirectories of the two paths are the same relative to source
126
- #
127
- # source - the site source
128
- # page_dir - the directory of the Jekyll::Page
129
- # paginate_path - the absolute paginate path (from root of FS)
130
- #
131
- # Returns whether the subdirectories are the same relative to source
132
- def self.in_hierarchy(source, page_dir, paginate_path)
133
- return false if paginate_path == File.dirname(paginate_path)
134
- return false if paginate_path == Pathname.new(source).parent
135
- page_dir == paginate_path ||
136
- in_hierarchy(source, page_dir, File.dirname(paginate_path))
137
- end
138
-
139
- # Static: Return the pagination path of the page
140
- #
141
- # site - the Jekyll::Site object
142
- # num_page - the pagination page number
143
- #
144
- # Returns the pagination path as a string
145
- def self.paginate_path(site, num_page)
146
- return nil if num_page.nil?
147
- return Generators::Pagination.first_page_url(site) if num_page <= 1
148
- format = site.config['paginate_path']
149
- format = format.sub(':num', num_page.to_s)
150
- ensure_leading_slash(format)
151
- end
152
-
153
- # Static: Return a String version of the input which has a leading slash.
154
- # If the input already has a forward slash in position zero, it will be
155
- # returned unchanged.
156
- #
157
- # path - a String path
158
- #
159
- # Returns the path with a leading slash
160
- def self.ensure_leading_slash(path)
161
- path[0..0] == "/" ? path : "/#{path}"
162
- end
163
-
164
- # Static: Return a String version of the input without a leading slash.
165
- #
166
- # path - a String path
167
- #
168
- # Returns the input without the leading slash
169
- def self.remove_leading_slash(path)
170
- ensure_leading_slash(path)[1..-1]
171
- end
172
-
173
- # Initialize a new Pager.
174
- #
175
- # site - the Jekyll::Site object
176
- # page - The Integer page number.
177
- # all_posts - The Array of all the site's Posts.
178
- # num_pages - The Integer number of pages or nil if you'd like the number
179
- # of pages calculated.
180
- def initialize(site, page, all_posts, num_pages = nil)
181
- @page = page
182
- @per_page = site.config['paginate'].to_i
183
- @total_pages = num_pages || Pager.calculate_pages(all_posts, @per_page)
184
-
185
- if @page > @total_pages
186
- raise RuntimeError, "page number can't be greater than total pages: #{@page} > #{@total_pages}"
187
- end
188
-
189
- init = (@page - 1) * @per_page
190
- offset = (init + @per_page - 1) >= all_posts.size ? all_posts.size : (init + @per_page - 1)
191
-
192
- @total_posts = all_posts.size
193
- @posts = all_posts[init..offset]
194
- @previous_page = @page != 1 ? @page - 1 : nil
195
- @previous_page_path = Pager.paginate_path(site, @previous_page)
196
- @next_page = @page != @total_pages ? @page + 1 : nil
197
- @next_page_path = Pager.paginate_path(site, @next_page)
198
- end
199
-
200
- # Convert this Pager's data to a Hash suitable for use by Liquid.
201
- #
202
- # Returns the Hash representation of this Pager.
203
- def to_liquid
204
- {
205
- 'page' => page,
206
- 'per_page' => per_page,
207
- 'posts' => posts,
208
- 'total_posts' => total_posts,
209
- 'total_pages' => total_pages,
210
- 'previous_page' => previous_page,
211
- 'previous_page_path' => previous_page_path,
212
- 'next_page' => next_page,
213
- 'next_page_path' => next_page_path
214
- }
215
- end
216
- end
217
- end