tigefa 1.0.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CONTRIBUTING.markdown +91 -0
- data/Gemfile +2 -0
- data/History.markdown +871 -0
- data/LICENSE +15 -14
- data/README.markdown +59 -0
- data/Rakefile +298 -0
- data/bin/tigefa +158 -0
- data/cucumber.yml +3 -0
- data/features/create_sites.feature +141 -0
- data/features/data.feature +65 -0
- data/features/drafts.feature +25 -0
- data/features/embed_filters.feature +60 -0
- data/features/include_tag.feature +57 -0
- data/features/markdown.feature +67 -0
- data/features/pagination.feature +82 -0
- data/features/permalinks.feature +85 -0
- data/features/post_data.feature +214 -0
- data/features/post_excerpts.feature +50 -0
- data/features/site_configuration.feature +235 -0
- data/features/site_data.feature +107 -0
- data/features/step_definitions/tigefa_steps.rb +189 -0
- data/features/support/env.rb +75 -0
- data/lib/site_template/.gitignore +1 -0
- data/lib/site_template/_config.yml +3 -0
- data/lib/site_template/_layouts/default.html +44 -0
- data/lib/site_template/_layouts/post.html +9 -0
- data/lib/site_template/_posts/0000-00-00-welcome-to-jekyll.markdown.erb +24 -0
- data/lib/site_template/css/main.css +160 -0
- data/lib/site_template/css/syntax.css +60 -0
- data/lib/site_template/index.html +13 -0
- data/lib/tigefa/cleaner.rb +73 -0
- data/lib/tigefa/command.rb +27 -0
- data/lib/tigefa/commands/build.rb +70 -0
- data/lib/tigefa/commands/doctor.rb +67 -0
- data/lib/tigefa/commands/new.rb +67 -0
- data/lib/tigefa/commands/serve.rb +65 -0
- data/lib/tigefa/configuration.rb +238 -0
- data/lib/tigefa/converter.rb +48 -0
- data/lib/tigefa/converters/identity.rb +21 -0
- data/lib/tigefa/converters/markdown/kramdown_parser.rb +29 -0
- data/lib/tigefa/converters/markdown/maruku_parser.rb +56 -0
- data/lib/tigefa/converters/markdown/rdiscount_parser.rb +37 -0
- data/lib/tigefa/converters/markdown/redcarpet_parser.rb +70 -0
- data/lib/tigefa/converters/markdown.rb +43 -0
- data/lib/tigefa/converters/textile.rb +50 -0
- data/lib/tigefa/convertible.rb +174 -0
- data/lib/tigefa/core_ext.rb +90 -0
- data/lib/tigefa/deprecator.rb +36 -0
- data/lib/tigefa/draft.rb +35 -0
- data/lib/tigefa/entry_filter.rb +35 -0
- data/lib/tigefa/errors.rb +4 -0
- data/lib/tigefa/excerpt.rb +113 -0
- data/lib/tigefa/filters.rb +174 -0
- data/lib/tigefa/generator.rb +4 -0
- data/lib/tigefa/generators/pagination.rb +217 -0
- data/lib/tigefa/layout.rb +45 -0
- data/lib/tigefa/mime.types +85 -0
- data/lib/tigefa/page.rb +160 -0
- data/lib/tigefa/plugin.rb +75 -0
- data/lib/tigefa/post.rb +312 -0
- data/lib/tigefa/related_posts.rb +59 -0
- data/lib/tigefa/site.rb +427 -0
- data/lib/tigefa/static_file.rb +70 -0
- data/lib/tigefa/stevenson.rb +89 -0
- data/lib/tigefa/tags/gist.rb +48 -0
- data/lib/tigefa/tags/highlight.rb +85 -0
- data/lib/tigefa/tags/include.rb +134 -0
- data/lib/tigefa/tags/post_url.rb +63 -0
- data/lib/tigefa/url.rb +69 -0
- data/lib/tigefa.rb +98 -4
- data/script/bootstrap +2 -0
- data/site/.gitignore +4 -0
- data/site/CNAME +1 -0
- data/site/README +1 -0
- data/site/_config.yml +6 -0
- data/site/_includes/analytics.html +32 -0
- data/site/_includes/docs_contents.html +16 -0
- data/site/_includes/docs_contents_mobile.html +23 -0
- data/site/_includes/docs_option.html +11 -0
- data/site/_includes/docs_ul.html +20 -0
- data/site/_includes/footer.html +15 -0
- data/site/_includes/header.html +18 -0
- data/site/_includes/news_contents.html +23 -0
- data/site/_includes/news_contents_mobile.html +11 -0
- data/site/_includes/news_item.html +24 -0
- data/site/_includes/primary-nav-items.html +14 -0
- data/site/_includes/section_nav.html +22 -0
- data/site/_includes/top.html +17 -0
- data/site/_layouts/default.html +12 -0
- data/site/_layouts/docs.html +23 -0
- data/site/_layouts/news.html +19 -0
- data/site/_layouts/news_item.html +27 -0
- data/site/_posts/2013-05-06-jekyll-1-0-0-released.markdown +23 -0
- data/site/_posts/2013-05-08-jekyll-1-0-1-released.markdown +27 -0
- data/site/_posts/2013-05-12-jekyll-1-0-2-released.markdown +28 -0
- data/site/_posts/2013-06-07-jekyll-1-0-3-released.markdown +25 -0
- data/site/_posts/2013-07-14-jekyll-1-1-0-released.markdown +27 -0
- data/site/_posts/2013-07-24-jekyll-1-1-1-released.markdown +31 -0
- data/site/_posts/2013-07-25-jekyll-1-0-4-released.markdown +20 -0
- data/site/_posts/2013-07-25-jekyll-1-1-2-released.markdown +20 -0
- data/site/_posts/2013-09-06-jekyll-1-2-0-released.markdown +23 -0
- data/site/_posts/2013-09-14-jekyll-1-2-1-released.markdown +19 -0
- data/site/_posts/2013-10-28-jekyll-1-3-0-rc1-released.markdown +19 -0
- data/site/_posts/2013-11-04-jekyll-1-3-0-released.markdown +43 -0
- data/site/_posts/2013-11-26-jekyll-1-3-1-released.markdown +21 -0
- data/site/_posts/2013-12-07-jekyll-1-4-0-released.markdown +30 -0
- data/site/_posts/2013-12-16-jekyll-1-4-2-released.markdown +18 -0
- data/site/_posts/2014-01-13-jekyll-1-4-3-released.markdown +27 -0
- data/site/css/gridism.css +110 -0
- data/site/css/normalize.css +1 -0
- data/site/css/pygments.css +70 -0
- data/site/css/style.css +946 -0
- data/site/docs/configuration.md +375 -0
- data/site/docs/contributing.md +128 -0
- data/site/docs/datafiles.md +63 -0
- data/site/docs/deployment-methods.md +109 -0
- data/site/docs/drafts.md +21 -0
- data/site/docs/extras.md +56 -0
- data/site/docs/frontmatter.md +180 -0
- data/site/docs/github-pages.md +91 -0
- data/site/docs/heroku.md +9 -0
- data/site/docs/history.md +866 -0
- data/site/docs/index.md +52 -0
- data/site/docs/installation.md +76 -0
- data/site/docs/migrations.md +11 -0
- data/site/docs/pages.md +86 -0
- data/site/docs/pagination.md +211 -0
- data/site/docs/permalinks.md +180 -0
- data/site/docs/plugins.md +534 -0
- data/site/docs/posts.md +181 -0
- data/site/docs/quickstart.md +32 -0
- data/site/docs/resources.md +46 -0
- data/site/docs/sites.md +29 -0
- data/site/docs/structure.md +190 -0
- data/site/docs/templates.md +339 -0
- data/site/docs/troubleshooting.md +150 -0
- data/site/docs/upgrading.md +146 -0
- data/site/docs/usage.md +63 -0
- data/site/docs/variables.md +322 -0
- data/site/favicon.png +0 -0
- data/site/feed.xml +36 -0
- data/site/freenode.txt +1 -0
- data/site/img/article-footer.png +0 -0
- data/site/img/footer-arrow.png +0 -0
- data/site/img/footer-logo.png +0 -0
- data/site/img/logo-2x.png +0 -0
- data/site/img/octojekyll.png +0 -0
- data/site/img/tube.png +0 -0
- data/site/img/tube1x.png +0 -0
- data/site/index.html +90 -0
- data/site/js/modernizr-2.5.3.min.js +4 -0
- data/site/news/index.html +10 -0
- data/site/news/releases/index.html +10 -0
- data/test/fixtures/broken_front_matter1.erb +5 -0
- data/test/fixtures/broken_front_matter2.erb +4 -0
- data/test/fixtures/broken_front_matter3.erb +7 -0
- data/test/fixtures/exploit_front_matter.erb +4 -0
- data/test/fixtures/front_matter.erb +4 -0
- data/test/helper.rb +65 -0
- data/test/source/+/foo.md +7 -0
- data/test/source/.htaccess +8 -0
- data/test/source/_config.dev.toml +2 -0
- data/test/source/_data/languages.yml +2 -0
- data/test/source/_data/members.yaml +7 -0
- data/test/source/_data/products.yml +1 -0
- data/test/source/_includes/params.html +7 -0
- data/test/source/_includes/sig.markdown +3 -0
- data/test/source/_includes/tmp +1 -0
- data/test/source/_layouts/default.html +27 -0
- data/test/source/_layouts/post/simple.html +1 -0
- data/test/source/_layouts/simple.html +1 -0
- data/test/source/_plugins/dummy.rb +8 -0
- data/test/source/_posts/2008-02-02-not-published.textile +8 -0
- data/test/source/_posts/2008-02-02-published.textile +8 -0
- data/test/source/_posts/2008-10-18-foo-bar.textile +8 -0
- data/test/source/_posts/2008-11-21-complex.textile +8 -0
- data/test/source/_posts/2008-12-03-permalinked-post.textile +9 -0
- data/test/source/_posts/2008-12-13-include.markdown +8 -0
- data/test/source/_posts/2009-01-27-array-categories.textile +10 -0
- data/test/source/_posts/2009-01-27-categories.textile +7 -0
- data/test/source/_posts/2009-01-27-category.textile +7 -0
- data/test/source/_posts/2009-01-27-empty-categories.textile +7 -0
- data/test/source/_posts/2009-01-27-empty-category.textile +7 -0
- data/test/source/_posts/2009-03-12-hash-#1.markdown +6 -0
- data/test/source/_posts/2009-05-18-empty-tag.textile +6 -0
- data/test/source/_posts/2009-05-18-empty-tags.textile +6 -0
- data/test/source/_posts/2009-05-18-tag.textile +6 -0
- data/test/source/_posts/2009-05-18-tags.textile +9 -0
- data/test/source/_posts/2009-06-22-empty-yaml.textile +3 -0
- data/test/source/_posts/2009-06-22-no-yaml.textile +1 -0
- data/test/source/_posts/2010-01-08-triple-dash.markdown +5 -0
- data/test/source/_posts/2010-01-09-date-override.textile +7 -0
- data/test/source/_posts/2010-01-09-time-override.textile +7 -0
- data/test/source/_posts/2010-01-09-timezone-override.textile +7 -0
- data/test/source/_posts/2010-01-16-override-data.textile +4 -0
- data/test/source/_posts/2011-04-12-md-extension.md +7 -0
- data/test/source/_posts/2011-04-12-text-extension.text +0 -0
- data/test/source/_posts/2013-01-02-post-excerpt.markdown +14 -0
- data/test/source/_posts/2013-01-12-nil-layout.textile +6 -0
- data/test/source/_posts/2013-01-12-no-layout.textile +5 -0
- data/test/source/_posts/2013-03-19-not-a-post.markdown/.gitkeep +0 -0
- data/test/source/_posts/2013-04-11-custom-excerpt.markdown +10 -0
- data/test/source/_posts/2013-05-10-number-category.textile +7 -0
- data/test/source/_posts/2013-07-22-post-excerpt-with-layout.markdown +23 -0
- data/test/source/_posts/2013-08-01-mkdn-extension.mkdn +0 -0
- data/test/source/_posts/2014-01-06-permalink-traversal.md +5 -0
- data/test/source/_posts/es/2008-11-21-nested.textile +8 -0
- data/test/source/about.html +6 -0
- data/test/source/category/_posts/2008-9-23-categories.textile +6 -0
- data/test/source/contacts/bar.html +5 -0
- data/test/source/contacts/index.html +5 -0
- data/test/source/contacts.html +5 -0
- data/test/source/css/screen.css +76 -0
- data/test/source/deal.with.dots.html +7 -0
- data/test/source/exploit.md +5 -0
- data/test/source/foo/_posts/bar/2008-12-12-topical-post.textile +8 -0
- data/test/source/index.html +22 -0
- data/test/source/products.yml +4 -0
- data/test/source/sitemap.xml +32 -0
- data/test/source/symlink-test/_data +1 -0
- data/test/source/symlink-test/symlinked-dir +1 -0
- data/test/source/symlink-test/symlinked-file +1 -0
- data/test/source/win/_posts/2009-05-24-yaml-linebreak.markdown +7 -0
- data/test/source/z_category/_posts/2008-9-23-categories.textile +6 -0
- data/test/suite.rb +11 -0
- data/test/test_command.rb +39 -0
- data/test/test_configuration.rb +181 -0
- data/test/test_convertible.rb +51 -0
- data/test/test_core_ext.rb +88 -0
- data/test/test_entry_filter.rb +74 -0
- data/test/test_excerpt.rb +78 -0
- data/test/test_filters.rb +113 -0
- data/test/test_generated_site.rb +83 -0
- data/test/test_kramdown.rb +62 -0
- data/test/test_new_command.rb +104 -0
- data/test/test_page.rb +212 -0
- data/test/test_pager.rb +116 -0
- data/test/test_post.rb +592 -0
- data/test/test_rdiscount.rb +22 -0
- data/test/test_redcarpet.rb +61 -0
- data/test/test_redcloth.rb +86 -0
- data/test/test_related_posts.rb +47 -0
- data/test/test_site.rb +333 -0
- data/test/test_tags.rb +490 -0
- data/test/test_url.rb +28 -0
- data/tigefa.gemspec +306 -0
- metadata +575 -45
- data/README.md +0 -4
@@ -0,0 +1,62 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'helper'
|
4
|
+
|
5
|
+
class TestKramdown < Test::Unit::TestCase
|
6
|
+
context "kramdown" do
|
7
|
+
setup do
|
8
|
+
@config = {
|
9
|
+
'markdown' => 'kramdown',
|
10
|
+
'kramdown' => {
|
11
|
+
'auto_ids' => false,
|
12
|
+
'footnote_nr' => 1,
|
13
|
+
'entity_output' => 'as_char',
|
14
|
+
'toc_levels' => '1..6',
|
15
|
+
'smart_quotes' => 'lsquo,rsquo,ldquo,rdquo',
|
16
|
+
|
17
|
+
'use_coderay' => true,
|
18
|
+
'coderay_bold_every'=> 12,
|
19
|
+
'coderay' => {
|
20
|
+
'coderay_css' => :style,
|
21
|
+
'coderay_bold_every' => 8
|
22
|
+
}
|
23
|
+
}
|
24
|
+
}
|
25
|
+
@config = Tigefa.configuration(@config)
|
26
|
+
@markdown = Converters::Markdown.new(@config)
|
27
|
+
end
|
28
|
+
|
29
|
+
# http://kramdown.rubyforge.org/converter/html.html#options
|
30
|
+
should "pass kramdown options" do
|
31
|
+
assert_equal "<h1>Some Header</h1>", @markdown.convert('# Some Header #').strip
|
32
|
+
end
|
33
|
+
|
34
|
+
should "convert quotes to smart quotes" do
|
35
|
+
assert_match /<p>(“|“)Pit(’|’)hy(”|”)<\/p>/, @markdown.convert(%{"Pit'hy"}).strip
|
36
|
+
|
37
|
+
override = { 'kramdown' => { 'smart_quotes' => 'lsaquo,rsaquo,laquo,raquo' } }
|
38
|
+
markdown = Converters::Markdown.new(@config.deep_merge(override))
|
39
|
+
assert_match /<p>(«|«)Pit(›|›)hy(»|»)<\/p>/, markdown.convert(%{"Pit'hy"}).strip
|
40
|
+
end
|
41
|
+
|
42
|
+
context "moving up nested coderay options" do
|
43
|
+
setup do
|
44
|
+
@markdown.convert('some markup')
|
45
|
+
@converter_config = @markdown.instance_variable_get(:@config)['kramdown']
|
46
|
+
end
|
47
|
+
|
48
|
+
should "work correctly" do
|
49
|
+
assert_equal :style, @converter_config['coderay_css']
|
50
|
+
end
|
51
|
+
|
52
|
+
should "also work for defaults" do
|
53
|
+
default = Tigefa::Configuration::DEFAULTS['kramdown']['coderay']['coderay_tab_width']
|
54
|
+
assert_equal default, @converter_config['coderay_tab_width']
|
55
|
+
end
|
56
|
+
|
57
|
+
should "not overwrite" do
|
58
|
+
assert_equal 12, @converter_config['coderay_bold_every']
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'tigefa/commands/new'
|
3
|
+
|
4
|
+
class TestNewCommand < Test::Unit::TestCase
|
5
|
+
def dir_contents(path)
|
6
|
+
Dir["#{path}/**/*"].each do |file|
|
7
|
+
file.gsub! path, ''
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def site_template
|
12
|
+
File.expand_path("../lib/site_template", File.dirname(__FILE__))
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'when args contains a path' do
|
16
|
+
setup do
|
17
|
+
@path = 'new-site'
|
18
|
+
@args = [@path]
|
19
|
+
@full_path = File.expand_path(@path, Dir.pwd)
|
20
|
+
end
|
21
|
+
|
22
|
+
teardown do
|
23
|
+
FileUtils.rm_r @full_path
|
24
|
+
end
|
25
|
+
|
26
|
+
should 'create a new directory' do
|
27
|
+
assert !File.exists?(@full_path)
|
28
|
+
capture_stdout { Tigefa::Commands::New.process(@args) }
|
29
|
+
assert File.exists?(@full_path)
|
30
|
+
end
|
31
|
+
|
32
|
+
should 'display a success message' do
|
33
|
+
output = capture_stdout { Tigefa::Commands::New.process(@args) }
|
34
|
+
success_message = "New jekyll site installed in #{@full_path}.\n"
|
35
|
+
assert_equal success_message, output
|
36
|
+
end
|
37
|
+
|
38
|
+
should 'copy the static files in site template to the new directory' do
|
39
|
+
static_template_files = dir_contents(site_template).reject do |f|
|
40
|
+
File.extname(f) == '.erb'
|
41
|
+
end
|
42
|
+
|
43
|
+
capture_stdout { Tigefa::Commands::New.process(@args) }
|
44
|
+
|
45
|
+
new_site_files = dir_contents(@full_path).reject do |f|
|
46
|
+
File.extname(f) == '.markdown'
|
47
|
+
end
|
48
|
+
|
49
|
+
assert_same_elements static_template_files, new_site_files
|
50
|
+
end
|
51
|
+
|
52
|
+
should 'process any ERB files' do
|
53
|
+
erb_template_files = dir_contents(site_template).select do |f|
|
54
|
+
File.extname(f) == '.erb'
|
55
|
+
end
|
56
|
+
|
57
|
+
stubbed_date = '2013-01-01'
|
58
|
+
stub.instance_of(Time).strftime { stubbed_date }
|
59
|
+
|
60
|
+
erb_template_files.each do |f|
|
61
|
+
f.chomp! '.erb'
|
62
|
+
f.gsub! '0000-00-00', stubbed_date
|
63
|
+
end
|
64
|
+
|
65
|
+
capture_stdout { Tigefa::Commands::New.process(@args) }
|
66
|
+
|
67
|
+
new_site_files = dir_contents(@full_path).select do |f|
|
68
|
+
erb_template_files.include? f
|
69
|
+
end
|
70
|
+
|
71
|
+
assert_same_elements erb_template_files, new_site_files
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context 'when multiple args are given' do
|
76
|
+
setup do
|
77
|
+
@site_name_with_spaces = 'new site name'
|
78
|
+
@multiple_args = @site_name_with_spaces.split
|
79
|
+
end
|
80
|
+
|
81
|
+
teardown do
|
82
|
+
FileUtils.rm_r File.expand_path(@site_name_with_spaces, Dir.pwd)
|
83
|
+
end
|
84
|
+
|
85
|
+
should 'create a new directory' do
|
86
|
+
assert !File.exists?(@site_name_with_spaces)
|
87
|
+
capture_stdout { Tigefa::Commands::New.process(@multiple_args) }
|
88
|
+
assert File.exists?(@site_name_with_spaces)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
context 'when no args are given' do
|
93
|
+
setup do
|
94
|
+
@empty_args = []
|
95
|
+
end
|
96
|
+
|
97
|
+
should 'raise an ArgumentError' do
|
98
|
+
exception = assert_raise ArgumentError do
|
99
|
+
Tigefa::Commands::New.process(@empty_args)
|
100
|
+
end
|
101
|
+
assert_equal 'You must specify a path.', exception.message
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
data/test/test_page.rb
ADDED
@@ -0,0 +1,212 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestPage < Test::Unit::TestCase
|
4
|
+
def setup_page(*args)
|
5
|
+
dir, file = args
|
6
|
+
dir, file = ['', dir] if file.nil?
|
7
|
+
@page = Page.new(@site, source_dir, dir, file)
|
8
|
+
end
|
9
|
+
|
10
|
+
def do_render(page)
|
11
|
+
layouts = { "default" => Layout.new(@site, source_dir('_layouts'), "simple.html")}
|
12
|
+
page.render(layouts, {"site" => {"posts" => []}})
|
13
|
+
end
|
14
|
+
|
15
|
+
context "A Page" do
|
16
|
+
setup do
|
17
|
+
clear_dest
|
18
|
+
stub(Tigefa).configuration { Tigefa::Configuration::DEFAULTS }
|
19
|
+
@site = Site.new(Tigefa.configuration)
|
20
|
+
end
|
21
|
+
|
22
|
+
context "processing pages" do
|
23
|
+
should "create url based on filename" do
|
24
|
+
@page = setup_page('contacts.html')
|
25
|
+
assert_equal "/contacts.html", @page.url
|
26
|
+
end
|
27
|
+
|
28
|
+
context "in a directory hierarchy" do
|
29
|
+
should "create url based on filename" do
|
30
|
+
@page = setup_page('/contacts', 'bar.html')
|
31
|
+
assert_equal "/contacts/bar.html", @page.url
|
32
|
+
end
|
33
|
+
|
34
|
+
should "create index url based on filename" do
|
35
|
+
@page = setup_page('/contacts', 'index.html')
|
36
|
+
assert_equal "/contacts/index.html", @page.url
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
should "deal properly with extensions" do
|
41
|
+
@page = setup_page('deal.with.dots.html')
|
42
|
+
assert_equal ".html", @page.ext
|
43
|
+
end
|
44
|
+
|
45
|
+
should "deal properly with dots" do
|
46
|
+
@page = setup_page('deal.with.dots.html')
|
47
|
+
assert_equal "deal.with.dots", @page.basename
|
48
|
+
end
|
49
|
+
|
50
|
+
context "with pretty url style" do
|
51
|
+
setup do
|
52
|
+
@site.permalink_style = :pretty
|
53
|
+
end
|
54
|
+
|
55
|
+
should "return dir correctly" do
|
56
|
+
@page = setup_page('contacts.html')
|
57
|
+
assert_equal '/contacts/', @page.dir
|
58
|
+
end
|
59
|
+
|
60
|
+
should "return dir correctly for index page" do
|
61
|
+
@page = setup_page('index.html')
|
62
|
+
assert_equal '/', @page.dir
|
63
|
+
end
|
64
|
+
|
65
|
+
context "in a directory hierarchy" do
|
66
|
+
should "create url based on filename" do
|
67
|
+
@page = setup_page('/contacts', 'bar.html')
|
68
|
+
assert_equal "/contacts/bar/", @page.url
|
69
|
+
end
|
70
|
+
|
71
|
+
should "create index url based on filename" do
|
72
|
+
@page = setup_page('/contacts', 'index.html')
|
73
|
+
assert_equal "/contacts/", @page.url
|
74
|
+
end
|
75
|
+
|
76
|
+
should "return dir correctly" do
|
77
|
+
@page = setup_page('/contacts', 'bar.html')
|
78
|
+
assert_equal '/contacts/bar/', @page.dir
|
79
|
+
end
|
80
|
+
|
81
|
+
should "return dir correctly for index page" do
|
82
|
+
@page = setup_page('/contacts', 'index.html')
|
83
|
+
assert_equal '/contacts/', @page.dir
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context "with any other url style" do
|
89
|
+
should "return dir correctly" do
|
90
|
+
@site.permalink_style = nil
|
91
|
+
@page = setup_page('contacts.html')
|
92
|
+
assert_equal '/', @page.dir
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
should "respect permalink in yaml front matter" do
|
97
|
+
file = "about.html"
|
98
|
+
@page = setup_page(file)
|
99
|
+
|
100
|
+
assert_equal "/about/", @page.permalink
|
101
|
+
assert_equal @page.permalink, @page.url
|
102
|
+
assert_equal "/about/", @page.dir
|
103
|
+
end
|
104
|
+
|
105
|
+
should "not be writable outside of destination" do
|
106
|
+
unexpected = File.expand_path("../../../baddie.html", dest_dir)
|
107
|
+
File.delete unexpected if File.exist?(unexpected)
|
108
|
+
page = setup_page("exploit.md")
|
109
|
+
do_render(page)
|
110
|
+
page.write(dest_dir)
|
111
|
+
|
112
|
+
assert !File.exist?(unexpected)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
context "with specified layout of nil" do
|
117
|
+
setup do
|
118
|
+
@page = setup_page('sitemap.xml')
|
119
|
+
end
|
120
|
+
|
121
|
+
should "layout of nil is respected" do
|
122
|
+
assert_equal "nil", @page.data["layout"]
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
context "rendering" do
|
127
|
+
setup do
|
128
|
+
clear_dest
|
129
|
+
end
|
130
|
+
|
131
|
+
should "write properly" do
|
132
|
+
page = setup_page('contacts.html')
|
133
|
+
do_render(page)
|
134
|
+
page.write(dest_dir)
|
135
|
+
|
136
|
+
assert File.directory?(dest_dir)
|
137
|
+
assert File.exists?(File.join(dest_dir, 'contacts.html'))
|
138
|
+
end
|
139
|
+
|
140
|
+
should "write even when the folder name is plus and permalink has +" do
|
141
|
+
page = setup_page('+', 'foo.md')
|
142
|
+
do_render(page)
|
143
|
+
page.write(dest_dir)
|
144
|
+
|
145
|
+
assert File.directory?(dest_dir)
|
146
|
+
assert File.exists?(File.join(dest_dir, '+', 'plus+in+url'))
|
147
|
+
end
|
148
|
+
|
149
|
+
should "write properly without html extension" do
|
150
|
+
page = setup_page('contacts.html')
|
151
|
+
page.site.permalink_style = :pretty
|
152
|
+
do_render(page)
|
153
|
+
page.write(dest_dir)
|
154
|
+
|
155
|
+
assert File.directory?(dest_dir)
|
156
|
+
assert File.exists?(File.join(dest_dir, 'contacts', 'index.html'))
|
157
|
+
end
|
158
|
+
|
159
|
+
should "write properly with extension different from html" do
|
160
|
+
page = setup_page("sitemap.xml")
|
161
|
+
page.site.permalink_style = :pretty
|
162
|
+
do_render(page)
|
163
|
+
page.write(dest_dir)
|
164
|
+
|
165
|
+
assert_equal("/sitemap.xml", page.url)
|
166
|
+
assert_nil(page.url[/\.html$/])
|
167
|
+
assert File.directory?(dest_dir)
|
168
|
+
assert File.exists?(File.join(dest_dir,'sitemap.xml'))
|
169
|
+
end
|
170
|
+
|
171
|
+
should "write dotfiles properly" do
|
172
|
+
page = setup_page('.htaccess')
|
173
|
+
do_render(page)
|
174
|
+
page.write(dest_dir)
|
175
|
+
|
176
|
+
assert File.directory?(dest_dir)
|
177
|
+
assert File.exists?(File.join(dest_dir, '.htaccess'))
|
178
|
+
end
|
179
|
+
|
180
|
+
context "in a directory hierarchy" do
|
181
|
+
should "write properly the index" do
|
182
|
+
page = setup_page('/contacts', 'index.html')
|
183
|
+
do_render(page)
|
184
|
+
page.write(dest_dir)
|
185
|
+
|
186
|
+
assert File.directory?(dest_dir)
|
187
|
+
assert File.exists?(File.join(dest_dir, 'contacts', 'index.html'))
|
188
|
+
end
|
189
|
+
|
190
|
+
should "write properly" do
|
191
|
+
page = setup_page('/contacts', 'bar.html')
|
192
|
+
do_render(page)
|
193
|
+
page.write(dest_dir)
|
194
|
+
|
195
|
+
assert File.directory?(dest_dir)
|
196
|
+
assert File.exists?(File.join(dest_dir, 'contacts', 'bar.html'))
|
197
|
+
end
|
198
|
+
|
199
|
+
should "write properly without html extension" do
|
200
|
+
page = setup_page('/contacts', 'bar.html')
|
201
|
+
page.site.permalink_style = :pretty
|
202
|
+
do_render(page)
|
203
|
+
page.write(dest_dir)
|
204
|
+
|
205
|
+
assert File.directory?(dest_dir)
|
206
|
+
assert File.exists?(File.join(dest_dir, 'contacts', 'bar', 'index.html'))
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
end
|
212
|
+
end
|
data/test/test_pager.rb
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestPager < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def build_site(config = {})
|
6
|
+
base = Tigefa::Configuration::DEFAULTS.deep_merge({
|
7
|
+
'source' => source_dir,
|
8
|
+
'destination' => dest_dir,
|
9
|
+
'paginate' => 1
|
10
|
+
})
|
11
|
+
site = Tigefa::Site.new(base.deep_merge(config))
|
12
|
+
site.process
|
13
|
+
site
|
14
|
+
end
|
15
|
+
|
16
|
+
should "calculate number of pages" do
|
17
|
+
assert_equal(0, Pager.calculate_pages([], '2'))
|
18
|
+
assert_equal(1, Pager.calculate_pages([1], '2'))
|
19
|
+
assert_equal(1, Pager.calculate_pages([1,2], '2'))
|
20
|
+
assert_equal(2, Pager.calculate_pages([1,2,3], '2'))
|
21
|
+
assert_equal(2, Pager.calculate_pages([1,2,3,4], '2'))
|
22
|
+
assert_equal(3, Pager.calculate_pages([1,2,3,4,5], '2'))
|
23
|
+
end
|
24
|
+
|
25
|
+
should "determine the pagination path" do
|
26
|
+
assert_equal("/index.html", Pager.paginate_path(build_site, 1))
|
27
|
+
assert_equal("/page2", Pager.paginate_path(build_site, 2))
|
28
|
+
assert_equal("/index.html", Pager.paginate_path(build_site({'paginate_path' => '/blog/page-:num'}), 1))
|
29
|
+
assert_equal("/blog/page-2", Pager.paginate_path(build_site({'paginate_path' => '/blog/page-:num'}), 2))
|
30
|
+
assert_equal("/index.html", Pager.paginate_path(build_site({'paginate_path' => '/blog/page/:num'}), 1))
|
31
|
+
assert_equal("/blog/page/2", Pager.paginate_path(build_site({'paginate_path' => '/blog/page/:num'}), 2))
|
32
|
+
assert_equal("/contacts/index.html", Pager.paginate_path(build_site({'paginate_path' => '/contacts/page:num'}), 1))
|
33
|
+
assert_equal("/contacts/page2", Pager.paginate_path(build_site({'paginate_path' => '/contacts/page:num'}), 2))
|
34
|
+
assert_equal("/contacts/index.html", Pager.paginate_path(build_site({'paginate_path' => '/contacts/page/:num'}), 1))
|
35
|
+
assert_equal("/contacts/page/2", Pager.paginate_path(build_site({'paginate_path' => '/contacts/page/:num'}), 2))
|
36
|
+
end
|
37
|
+
|
38
|
+
context "pagination disabled" do
|
39
|
+
should "report that pagination is disabled" do
|
40
|
+
assert !Pager.pagination_enabled?(build_site('paginate' => nil))
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "pagination enabled for 2" do
|
45
|
+
setup do
|
46
|
+
@site = build_site('paginate' => 2)
|
47
|
+
@posts = @site.posts
|
48
|
+
end
|
49
|
+
|
50
|
+
should "report that pagination is enabled" do
|
51
|
+
assert Pager.pagination_enabled?(@site)
|
52
|
+
end
|
53
|
+
|
54
|
+
context "with 4 posts" do
|
55
|
+
setup do
|
56
|
+
@posts = @site.posts[1..4] # limit to 4
|
57
|
+
end
|
58
|
+
|
59
|
+
should "create first pager" do
|
60
|
+
pager = Pager.new(@site, 1, @posts)
|
61
|
+
assert_equal(2, pager.posts.size)
|
62
|
+
assert_equal(2, pager.total_pages)
|
63
|
+
assert_nil(pager.previous_page)
|
64
|
+
assert_equal(2, pager.next_page)
|
65
|
+
end
|
66
|
+
|
67
|
+
should "create second pager" do
|
68
|
+
pager = Pager.new(@site, 2, @posts)
|
69
|
+
assert_equal(2, pager.posts.size)
|
70
|
+
assert_equal(2, pager.total_pages)
|
71
|
+
assert_equal(1, pager.previous_page)
|
72
|
+
assert_nil(pager.next_page)
|
73
|
+
end
|
74
|
+
|
75
|
+
should "not create third pager" do
|
76
|
+
assert_raise(RuntimeError) { Pager.new(@site, 3, @posts) }
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
context "with 5 posts" do
|
82
|
+
setup do
|
83
|
+
@posts = @site.posts[1..5] # limit to 5
|
84
|
+
end
|
85
|
+
|
86
|
+
should "create first pager" do
|
87
|
+
pager = Pager.new(@site, 1, @posts)
|
88
|
+
assert_equal(2, pager.posts.size)
|
89
|
+
assert_equal(3, pager.total_pages)
|
90
|
+
assert_nil(pager.previous_page)
|
91
|
+
assert_equal(2, pager.next_page)
|
92
|
+
end
|
93
|
+
|
94
|
+
should "create second pager" do
|
95
|
+
pager = Pager.new(@site, 2, @posts)
|
96
|
+
assert_equal(2, pager.posts.size)
|
97
|
+
assert_equal(3, pager.total_pages)
|
98
|
+
assert_equal(1, pager.previous_page)
|
99
|
+
assert_equal(3, pager.next_page)
|
100
|
+
end
|
101
|
+
|
102
|
+
should "create third pager" do
|
103
|
+
pager = Pager.new(@site, 3, @posts)
|
104
|
+
assert_equal(1, pager.posts.size)
|
105
|
+
assert_equal(3, pager.total_pages)
|
106
|
+
assert_equal(2, pager.previous_page)
|
107
|
+
assert_nil(pager.next_page)
|
108
|
+
end
|
109
|
+
|
110
|
+
should "not create fourth pager" do
|
111
|
+
assert_raise(RuntimeError) { Pager.new(@site, 4, @posts) }
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|