staticpress 0.6.2 → 0.7.0

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.
Files changed (118) hide show
  1. data/NOTES.markdown +23 -0
  2. data/Rakefile +1 -6
  3. data/docs/content/docs/plugins/pagination.haml +30 -0
  4. data/docs/content/docs/samples/page.markdown +14 -0
  5. data/docs/content/docs/samples/post.markdown +18 -0
  6. data/docs/content/docs/themes.markdown +47 -0
  7. data/lib/skeleton/config.yml +1 -0
  8. data/lib/staticpress/cli.rb +5 -9
  9. data/lib/staticpress/content/base.rb +8 -10
  10. data/lib/staticpress/content/category.rb +17 -4
  11. data/lib/staticpress/content/collection_content.rb +1 -3
  12. data/lib/staticpress/content/index.rb +6 -3
  13. data/lib/staticpress/content/page.rb +4 -0
  14. data/lib/staticpress/content/post.rb +4 -1
  15. data/lib/staticpress/content/resource_content.rb +2 -8
  16. data/lib/staticpress/content/tag.rb +17 -4
  17. data/lib/staticpress/content/theme.rb +1 -1
  18. data/lib/staticpress/helpers.rb +5 -5
  19. data/lib/staticpress/plugins/menu.rb +1 -1
  20. data/lib/staticpress/plugins/pagination.rb +38 -0
  21. data/lib/staticpress/theme.rb +45 -17
  22. data/lib/staticpress/version.rb +1 -1
  23. data/lib/themes/basic/includes/github.haml +2 -0
  24. data/lib/themes/basic/layouts/default.haml +1 -0
  25. data/lib/themes/basic/views/page_paged.haml +6 -0
  26. data/{tests → spec/fixtures}/test_blog/Gemfile +0 -0
  27. data/{tests → spec/fixtures}/test_blog/README.markdown +0 -0
  28. data/{tests → spec/fixtures}/test_blog/config.ru +0 -0
  29. data/{tests → spec/fixtures}/test_blog/config.yml +0 -0
  30. data/{tests → spec/fixtures}/test_blog/content/_posts/2011-07-20-hello.markdown +0 -0
  31. data/{tests → spec/fixtures}/test_blog/content/_posts/2011-08-01-announcing-staticpress.markdown +0 -0
  32. data/{tests → spec/fixtures}/test_blog/content/_posts/2011-08-02-staticpress.markdown +0 -0
  33. data/{tests → spec/fixtures}/test_blog/content/_posts/2011-08-06-blogging-with-staticpress.markdown +0 -0
  34. data/{tests → spec/fixtures}/test_blog/content/_posts/2011-08-06-conferences.markdown +0 -0
  35. data/{tests → spec/fixtures}/test_blog/content/_posts/2011-08-06-in-charlotte.markdown +0 -0
  36. data/{tests → spec/fixtures}/test_blog/content/_posts/2011-08-20-forever.markdown +0 -0
  37. data/{tests → spec/fixtures}/test_blog/content/_posts/2012-09-19-unpublished.markdown +0 -0
  38. data/{tests → spec/fixtures}/test_blog/content/about.markdown +0 -0
  39. data/{tests → spec/fixtures}/test_blog/content/chain.html.markdown.erb +0 -0
  40. data/{tests → spec/fixtures}/test_blog/content/chained.markdown.erb +0 -0
  41. data/{tests → spec/fixtures}/test_blog/content/contact.markdown +0 -0
  42. data/{tests → spec/fixtures}/test_blog/content/foo/bar/baz.markdown +0 -0
  43. data/{tests → spec/fixtures}/test_blog/content/index.markdown +0 -0
  44. data/{tests → spec/fixtures}/test_blog/content/plain.txt +0 -0
  45. data/{tests → spec/fixtures}/test_blog/content/ruby.png +0 -0
  46. data/{tests → spec/fixtures}/test_blog/content/style1.css +0 -0
  47. data/{tests → spec/fixtures}/test_blog/content/style2.css.sass +0 -0
  48. data/{tests → spec/fixtures}/test_blog/content/style3.sass +0 -0
  49. data/{tests → spec/fixtures}/test_blog/themes/test_theme/assets/scripts/application.js +0 -0
  50. data/{tests → spec/fixtures}/test_blog/themes/test_theme/assets/styles/all.sass +0 -0
  51. data/{tests → spec/fixtures}/test_blog/themes/test_theme/includes/list_posts.haml +0 -0
  52. data/{lib/themes/basic → spec/fixtures/test_blog/themes/test_theme}/layouts/archive.haml +0 -0
  53. data/{lib/themes/basic → spec/fixtures/test_blog/themes/test_theme}/layouts/atom.haml +0 -0
  54. data/{tests → spec/fixtures}/test_blog/themes/test_theme/layouts/default.haml +0 -0
  55. data/{tests → spec/fixtures}/test_blog/themes/test_theme/layouts/index.haml +0 -0
  56. data/{tests → spec/fixtures}/test_blog/themes/test_theme/layouts/post_index.haml +0 -0
  57. data/{tests → spec/fixtures}/test_blog/themes/test_theme/views/default.haml +0 -0
  58. data/spec/integration/editing_blog_contents_spec.rb +52 -0
  59. data/spec/integration/editing_blog_spec.rb +42 -0
  60. data/spec/integration/getting_started_spec.rb +29 -0
  61. data/spec/spec_helper.rb +35 -0
  62. data/spec/support/custom_matchers.rb +15 -0
  63. data/spec/support/fixtures.rb +35 -0
  64. data/spec/support/integration_support.rb +230 -0
  65. data/spec/support/unit_support.rb +18 -0
  66. data/spec/unit/staticpress/content/base_spec.rb +327 -0
  67. data/spec/unit/staticpress/content/category_spec.rb +60 -0
  68. data/spec/unit/staticpress/content/index_spec.rb +48 -0
  69. data/spec/unit/staticpress/content/page_spec.rb +70 -0
  70. data/spec/unit/staticpress/content/post_spec.rb +54 -0
  71. data/spec/unit/staticpress/content/resource_content_spec.rb +21 -0
  72. data/spec/unit/staticpress/content/tag_spec.rb +53 -0
  73. data/spec/unit/staticpress/content/theme_spec.rb +31 -0
  74. data/spec/unit/staticpress/helpers_spec.rb +72 -0
  75. data/spec/unit/staticpress/js_object_spec.rb +61 -0
  76. data/spec/unit/staticpress/metadata_spec.rb +15 -0
  77. data/spec/unit/staticpress/route_spec.rb +219 -0
  78. data/spec/unit/staticpress/server_spec.rb +23 -0
  79. data/spec/unit/staticpress/settings_spec.rb +19 -0
  80. data/spec/unit/staticpress/site_spec.rb +26 -0
  81. data/spec/unit/staticpress/theme_spec.rb +80 -0
  82. data/spec/unit/staticpress/view_helpers_spec.rb +40 -0
  83. data/spec/unit/staticpress_spec.rb +27 -0
  84. data/staticpress.gemspec +3 -4
  85. metadata +133 -136
  86. data/features/editing_blog.feature +0 -24
  87. data/features/editing_blog_contents.feature +0 -40
  88. data/features/getting_started.feature +0 -17
  89. data/features/step_definitions/editing_blog_contents_steps.rb +0 -128
  90. data/features/step_definitions/editing_blog_steps.rb +0 -52
  91. data/features/step_definitions/getting_started_steps.rb +0 -51
  92. data/features/support/env.rb +0 -30
  93. data/lib/themes/basic/layouts/post_index.haml +0 -15
  94. data/lib/themes/basic/views/default.haml +0 -10
  95. data/tests/staticpress/configuration_test.rb +0 -4
  96. data/tests/staticpress/content/base_test.rb +0 -291
  97. data/tests/staticpress/content/category_test.rb +0 -48
  98. data/tests/staticpress/content/index_test.rb +0 -40
  99. data/tests/staticpress/content/page_test.rb +0 -56
  100. data/tests/staticpress/content/post_test.rb +0 -42
  101. data/tests/staticpress/content/resource_content_test.rb +0 -17
  102. data/tests/staticpress/content/tag_test.rb +0 -39
  103. data/tests/staticpress/content/theme_test.rb +0 -26
  104. data/tests/staticpress/helpers_test.rb +0 -63
  105. data/tests/staticpress/js_object_test.rb +0 -47
  106. data/tests/staticpress/metadata_test.rb +0 -14
  107. data/tests/staticpress/plugin_test.rb +0 -4
  108. data/tests/staticpress/pusher_test.rb +0 -9
  109. data/tests/staticpress/route_test.rb +0 -186
  110. data/tests/staticpress/server_test.rb +0 -17
  111. data/tests/staticpress/settings_test.rb +0 -13
  112. data/tests/staticpress/site_test.rb +0 -20
  113. data/tests/staticpress/theme_test.rb +0 -83
  114. data/tests/staticpress/view_helpers_test.rb +0 -32
  115. data/tests/staticpress_test.rb +0 -18
  116. data/tests/test_blog/themes/test_theme/layouts/archive.haml +0 -0
  117. data/tests/test_blog/themes/test_theme/layouts/atom.haml +0 -0
  118. data/tests/test_case.rb +0 -54
@@ -1,48 +0,0 @@
1
- require_relative '../../test_case'
2
-
3
- class ContentCategoryTest < TestCase
4
- include Staticpress::Helpers
5
-
6
- let(:category) { Staticpress::Content::Category.new :name => 'programming' }
7
-
8
- def test_categories
9
- assert_equal [ 'programming', 'travel' ], Staticpress::Content::Category.categories
10
- end
11
-
12
- def test_pages_count
13
- assert_equal 1, category.pages_count
14
-
15
- with_config :posts_per_page => 2 do
16
- assert_equal 2, category.pages_count
17
- end
18
- end
19
-
20
- def test_sub_content
21
- expected = [
22
- Staticpress::Content::Post.new(:year => '2011', :month => '08', :day => '01', :title => 'announcing-staticpress'),
23
- Staticpress::Content::Post.new(:year => '2011', :month => '08', :day => '02', :title => 'staticpress'),
24
- Staticpress::Content::Post.new(:year => '2011', :month => '08', :day => '06', :title => 'blogging-with-staticpress')
25
- ]
26
- assert_equal expected, category.sub_content
27
- end
28
-
29
- def test_all
30
- with_config :posts_per_page => 1 do
31
- expected = [
32
- Staticpress::Content::Category.new(:name => 'programming', :number => 1),
33
- Staticpress::Content::Category.new(:name => 'programming', :number => 2),
34
- Staticpress::Content::Category.new(:name => 'programming', :number => 3),
35
- Staticpress::Content::Category.new(:name => 'travel', :number => 1)
36
- ]
37
- assert_equal expected, Staticpress::Content::Category.all
38
- end
39
- end
40
-
41
- def test_content_by_category
42
- [
43
- Staticpress::Content::Post.new(:year => '2011', :month => '08', :day => '01', :title => 'announcing-staticpress'),
44
- Staticpress::Content::Post.new(:year => '2011', :month => '08', :day => '02', :title => 'staticpress'),
45
- Staticpress::Content::Post.new(:year => '2011', :month => '08', :day => '06', :title => 'blogging-with-staticpress')
46
- ].each { |content| assert_includes Staticpress::Content::Category.content_by_category['programming'], content }
47
- end
48
- end
@@ -1,40 +0,0 @@
1
- require_relative '../../test_case'
2
-
3
- class ContentIndexTest < TestCase
4
- include Staticpress::Helpers
5
-
6
- let(:index) { Staticpress::Content::Index.new }
7
- let(:unpublished) { Staticpress::Content::Post.new(:year => '2012', :month => '09', :day => '19', :title => 'unpublished') }
8
-
9
- def test_pages_count
10
- assert_equal 1, index.pages_count
11
-
12
- with_config :posts_per_page => 2 do
13
- assert_equal 4, index.pages_count
14
- end
15
- end
16
-
17
- def test_sub_content
18
- with_config :posts_per_page => 4 do
19
- # expect three most recent posts with oldest on top (index is lazy-evaluated)
20
- expected = [
21
- Staticpress::Content::Post.new(:year => '2011', :month => '08', :day => '06', :title => 'conferences'),
22
- Staticpress::Content::Post.new(:year => '2011', :month => '08', :day => '06', :title => 'blogging-with-staticpress'),
23
- Staticpress::Content::Post.new(:year => '2011', :month => '08', :day => '20', :title => 'forever')
24
- ]
25
- assert_equal expected, index.sub_content
26
- refute_includes index.sub_content, unpublished
27
- end
28
- end
29
-
30
- def test_all
31
- with_config :posts_per_page => 3 do
32
- expected = [
33
- Staticpress::Content::Index.new(:number => 1),
34
- Staticpress::Content::Index.new(:number => 2),
35
- Staticpress::Content::Index.new(:number => 3)
36
- ]
37
- assert_equal expected, Staticpress::Content::Index.all
38
- end
39
- end
40
- end
@@ -1,56 +0,0 @@
1
- require_relative '../../test_case'
2
-
3
- class ContentPageTest < TestCase
4
- include Staticpress::Helpers
5
-
6
- let(:page_dir) { Staticpress.blog_path + config.source_path }
7
-
8
- let(:chained) { Staticpress::Content::Page.new(:slug => 'chained') }
9
- let(:chain) { Staticpress::Content::Page.new(:slug => 'chain.html') }
10
- let(:page) { Staticpress::Content::Page.new :slug => 'about' }
11
- let(:second_page) { Staticpress::Content::Page.new :slug => 'contact' }
12
- let(:index_page) { Staticpress::Content::Page.new :slug => '' }
13
- let(:style2) { Staticpress::Content::Page.new :slug => 'style2.css' }
14
- let(:nested) { Staticpress::Content::Page.new :slug => 'foo/bar/baz' }
15
- let(:static_bin) { Staticpress::Content::Page.new :slug => 'ruby.png' }
16
- let(:static_txt) { Staticpress::Content::Page.new :slug => 'plain.txt' }
17
-
18
- let(:fake) { Staticpress::Content::Page.new :slug => 'i/dont/exist' }
19
-
20
- def test_all
21
- assert_equal 11, Staticpress::Content::Page.all.count
22
- end
23
-
24
- def test_extension
25
- assert_equal '.markdown.erb', chained.template_extension
26
- assert_equal '.markdown.erb', chain.template_extension
27
- assert_equal '.markdown', page.template_extension
28
- end
29
-
30
- def test_full_slug
31
- assert_equal 'chained', chained.full_slug
32
- assert_equal 'chain.html', chain.full_slug
33
- assert_equal 'about', page.full_slug
34
- end
35
-
36
- def test_extract_slug
37
- assert_equal 'chained', Staticpress::Content::Page.extract_slug(page_dir + 'chained.markdown.erb')
38
- assert_equal 'about', Staticpress::Content::Page.extract_slug(page_dir + 'about.markdown')
39
- assert_equal 'plain.txt', Staticpress::Content::Page.extract_slug(page_dir + 'plain.txt')
40
- end
41
-
42
- def test_find_by_path
43
- assert_equal chained, Staticpress::Content::Page.find_by_path(page_dir + 'chained.markdown.erb')
44
- assert_equal chain, Staticpress::Content::Page.find_by_path(page_dir + 'chain.html.markdown.erb')
45
- assert_equal page, Staticpress::Content::Page.find_by_path(page_dir + 'about.markdown')
46
- assert_equal index_page, Staticpress::Content::Page.find_by_path(page_dir + 'index.markdown')
47
- assert_nil Staticpress::Content::Page.find_by_path(page_dir + 'i' + 'dont' + 'exist.markdown')
48
- assert_equal static_bin, Staticpress::Content::Page.find_by_path(page_dir + 'ruby.png')
49
- assert_nil Staticpress::Content::Page.find_by_path(page_dir + 'i' + 'dont' + 'exist.jpg')
50
- end
51
-
52
- def test_template_path
53
- assert_equal page_dir + 'index.markdown', index_page.template_path
54
- assert_equal page_dir + 'about.markdown', page.template_path
55
- end
56
- end
@@ -1,42 +0,0 @@
1
- require_relative '../../test_case'
2
-
3
- class ContentPostTest < TestCase
4
- include Staticpress::Helpers
5
-
6
- let(:post_dir) { Staticpress.blog_path + config.posts_source_path }
7
-
8
- let(:post) { Staticpress::Content::Post.new(:year => '2011', :month => '07', :day => '20', :title => 'hello') }
9
- let(:another_post) { Staticpress::Content::Post.new(:year => '2011', :month => '08', :day => '20', :title => 'forever') }
10
- let(:long_title_post) { Staticpress::Content::Post.new(:year => '2011', :month => '08', :day => '06', :title => 'blogging-with-staticpress') }
11
-
12
- def test__spaceship
13
- assert_operator post, :<=>, another_post
14
- assert_operator another_post, :<=>, post
15
- assert_equal [ post, another_post ], [ post, another_post ].sort
16
- assert_equal [ post, another_post ], [ another_post, post ].sort
17
- end
18
-
19
- def test_created_at
20
- assert_equal Time.utc(2011, 7, 20, 13, 9, 52), post.created_at
21
- assert_equal Time.utc(2011, 8, 20), another_post.created_at
22
- end
23
-
24
- def test_created_on
25
- assert_equal Time.utc(2011, 7, 20), post.created_on
26
- assert_equal Time.utc(2011, 8, 20), another_post.created_on
27
- end
28
-
29
- def test_find_by_path
30
- assert_equal post, Staticpress::Content::Post.find_by_path(post_dir + '2011-07-20-hello.markdown')
31
- assert_nil Staticpress::Content::Post.find_by_path(post_dir + '2011-07-20-goodbye.markdown')
32
- end
33
-
34
- def test_template_path
35
- assert_equal (Staticpress.blog_path + config.posts_source_path + '2011-07-20-hello.markdown'), post.template_path
36
- end
37
-
38
- def test_title
39
- assert_equal 'Hello, World', post.title
40
- assert_equal 'Blogging With Staticpress', long_title_post.title
41
- end
42
- end
@@ -1,17 +0,0 @@
1
- require_relative '../../test_case'
2
-
3
- class ResourceContentTest < TestCase
4
- include Staticpress::Helpers
5
- include Staticpress::Content::ResourceContent
6
-
7
- let(:page_dir) { Staticpress.blog_path + config.source_path }
8
-
9
- def test_find_supported_extensions
10
- assert_equal [:erb, :markdown], find_supported_extensions(page_dir + 'chained.markdown.erb')
11
- assert_equal [:erb, :markdown], find_supported_extensions(page_dir + 'chained.markdown')
12
- assert_equal [:erb, :markdown], find_supported_extensions(page_dir + 'chained')
13
- assert_equal [:markdown], find_supported_extensions(page_dir + 'about')
14
- assert_equal [], find_supported_extensions(page_dir + 'plain.txt')
15
- assert_equal [], find_supported_extensions(page_dir + 'i/dont/exist')
16
- end
17
- end
@@ -1,39 +0,0 @@
1
- require_relative '../../test_case'
2
-
3
- class ContentTagTest < TestCase
4
- let(:tag) { Staticpress::Content::Tag.new :name => 'charlotte' }
5
-
6
- def test_tags
7
- assert_equal [ 'charlotte' ], Staticpress::Content::Tag.tags
8
- end
9
-
10
- def test_pages_count
11
- assert_equal 1, tag.pages_count
12
- end
13
-
14
- def test_optional_param_defaults
15
- expected = { :number => 1 }
16
- assert_equal expected, Staticpress::Content::Tag.new(:name => 'charlotte').optional_param_defaults
17
- assert_equal expected, Staticpress::Content::Tag.new(:name => 'charlotte', :number => nil).optional_param_defaults
18
- end
19
-
20
- def test_sub_content
21
- expected = [
22
- Staticpress::Content::Post.new(:year => '2011', :month => '08', :day => '06', :title => 'in-charlotte')
23
- ]
24
- assert_equal expected, tag.sub_content
25
- end
26
-
27
- def test_all
28
- expected = [
29
- Staticpress::Content::Tag.new(:name => 'charlotte', :number => 1)
30
- ]
31
- assert_equal expected, Staticpress::Content::Tag.all
32
- end
33
-
34
- def test_content_by_tag
35
- [
36
- Staticpress::Content::Post.new(:year => '2011', :month => '08', :day => '06', :title => 'in-charlotte')
37
- ].each { |content| assert_includes Staticpress::Content::Tag.content_by_tag['charlotte'], content }
38
- end
39
- end
@@ -1,26 +0,0 @@
1
- require_relative '../../test_case'
2
-
3
- class ContentThemeTest < TestCase
4
- include Staticpress::Helpers
5
-
6
- let(:theme_dir) { Staticpress::Theme.theme.root }
7
-
8
- let(:asset_style) { Staticpress::Content::Theme.new :theme => 'test_theme', :asset_type => 'styles', :slug => 'all' }
9
- let(:asset_script) { Staticpress::Content::Theme.new :theme => 'test_theme', :asset_type => 'scripts', :slug => 'application.js' }
10
-
11
- def setup
12
- super
13
- config.theme = :test_theme
14
- end
15
-
16
- def test_all
17
- assert_equal 2, Staticpress::Content::Theme.all.count
18
- end
19
-
20
- def test_find_by_path
21
- assert_equal asset_style, Staticpress::Content::Theme.find_by_path(theme_dir + 'assets' + 'styles' + 'all.sass')
22
- assert_nil Staticpress::Content::Theme.find_by_path(theme_dir + 'i' + 'dont' + 'exist.markdown')
23
- actual = Staticpress::Content::Theme.find_by_path(theme_dir + 'assets' + 'scripts' + 'application.js')
24
- assert_equal actual, asset_script
25
- end
26
- end
@@ -1,63 +0,0 @@
1
- require_relative '../test_case'
2
-
3
- require 'pathname'
4
-
5
- class HelpersTest < TestCase
6
- include Staticpress::Helpers
7
-
8
- def test_extensionless_basename
9
- assert_equal 'extensionless', extensionless_basename(Pathname('extensionless'))
10
- assert_equal '.htaccess', extensionless_basename(Pathname('.htaccess'))
11
- assert_equal 'tyrannasaurus_rex', extensionless_basename(Pathname('tyrannasaurus_rex.rb'))
12
- assert_equal 'stegosaurus', extensionless_basename(Pathname('dinosaurs/stegosaurus.rb'))
13
- assert_equal 'stegosaurus', extensionless_basename(Pathname('/dinosaurs/stegosaurus.rb'))
14
- end
15
-
16
- def test_extensionless_path
17
- assert_equal Pathname('extensionless'), extensionless_path(Pathname('extensionless'))
18
- assert_equal Pathname('.htaccess'), extensionless_path(Pathname('.htaccess'))
19
- assert_equal Pathname('tyrannasaurus_rex'), extensionless_path(Pathname('tyrannasaurus_rex.rb'))
20
- assert_equal Pathname('dinosaurs/stegosaurus'), extensionless_path(Pathname('dinosaurs/stegosaurus.rb'))
21
- assert_equal Pathname('/dinosaurs/stegosaurus'), extensionless_path(Pathname('/dinosaurs/stegosaurus.rb'))
22
- end
23
-
24
- def test_hash_from_empty_array
25
- actual = hash_from_array [] {}
26
- assert_equal({}, actual)
27
- end
28
-
29
- def test_hash_from_array
30
- expected = {
31
- 1 => { :key => 1 },
32
- 2 => { :key => 2 },
33
- 3 => { :key => 3 }
34
- }
35
-
36
- actual = hash_from_array [
37
- { :key => 1 },
38
- { :key => 2 },
39
- { :key => 3 }
40
- ] { |hash| hash[:key] }
41
-
42
- assert_equal expected, actual
43
- end
44
-
45
- def test_paginate
46
- # a == oldest, z == newest
47
- assert_equal 3, paginate(:a..:z).count
48
- assert_equal (:a..:j).to_a, paginate(:a..:z)[0] # page 1 lists oldest, with oldest at top
49
- assert_equal (:k..:t).to_a, paginate(:a..:z)[1]
50
- assert_equal (:u..:z).to_a, paginate(:a..:z)[2] # page 3 lists newest, with newest at bottom (default page)
51
- assert_equal [], paginate(:a..:z)[5], 'Accessing an invalid index on anything that has been paginated should return an empty array'
52
- end
53
-
54
- def test_spider_directory
55
- end
56
-
57
- def test_titleize
58
- assert_equal '', titleize('')
59
- assert_equal '', titleize('/')
60
- assert_equal 'Foo -> Bar -> Baz', titleize('/foo/bar/baz')
61
- assert_equal 'Blogging With Staticpress', titleize('blogging-with-staticpress')
62
- end
63
- end
@@ -1,47 +0,0 @@
1
- require_relative '../test_case'
2
-
3
- class JSObjectTest < TestCase
4
- JSO = Staticpress::JSObject
5
-
6
- let(:js_object) { JSO.new :key => :value, :nested => { :a => :b } }
7
-
8
- def test__minus
9
- assert_equal(JSO.new({ :key => :value, :nested => { :a => :b } }), js_object - {})
10
- assert_equal(JSO.new({ :nested => { :a => :b } }), js_object - { :key => :value })
11
- assert_equal(JSO.new({ :key => :value }), js_object - { :nested => { :a => :b } })
12
- assert_equal(JSO.new({}), js_object - { :key => :value, :nested => { :a => :b } })
13
-
14
- assert_equal(JSO.new({ :key => :value, :nested => { :a => :b } }), js_object - JSO.new({}))
15
- assert_equal(JSO.new({ :nested => { :a => :b } }), js_object - JSO.new({ :key => :value }))
16
- assert_equal(JSO.new({ :key => :value }), js_object - JSO.new({ :nested => { :a => :b } }))
17
- assert_equal(JSO.new({}), js_object - JSO.new({ :key => :value, :nested => { :a => :b } }))
18
- end
19
-
20
- def test__squares
21
- assert_nil js_object[:some_random]
22
- assert_equal :value, js_object[:key]
23
- assert_equal :value, js_object['key']
24
- end
25
-
26
- def test_regular_access
27
- assert_equal :value, js_object.key
28
- assert_equal :b, js_object.nested.a
29
- assert_nil js_object.nested.other
30
- end
31
-
32
- def test_assignment
33
- assert_nil js_object.hoopla
34
- js_object.hoopla = :hullabaloo
35
- assert_equal :hullabaloo, js_object.hoopla
36
- end
37
-
38
- def test_merge
39
- assert_nil js_object.some_key
40
- enhanced = js_object.merge :some_key => 42
41
- assert_equal 42, enhanced.some_key
42
- end
43
-
44
- def test_to_hash
45
- assert_equal({ :key => :value, :nested => { :a => :b } }, js_object.to_hash)
46
- end
47
- end
@@ -1,14 +0,0 @@
1
- require_relative '../test_case'
2
-
3
- class MetadataTest < TestCase
4
- let(:meta) { Staticpress::Metadata.new }
5
- let(:another_meta) { Staticpress::Metadata.new :layout => 'post_index', :categories => %w[programming], :tags => %w[code tutorial] }
6
-
7
- def test__chevron
8
- end
9
-
10
- def test_inspect
11
- assert_equal '#<Staticpress::Metadata>', meta.inspect
12
- assert_equal '#<Staticpress::Metadata categories=["programming"], layout="post_index", tags=["code", "tutorial"]>', another_meta.inspect
13
- end
14
- end
@@ -1,4 +0,0 @@
1
- require_relative '../test_case'
2
-
3
- class PluginTest < TestCase
4
- end
@@ -1,9 +0,0 @@
1
- require_relative '../test_case'
2
-
3
- class PusherTest < TestCase
4
- def test_custom
5
- end
6
-
7
- def test_push
8
- end
9
- end
@@ -1,186 +0,0 @@
1
- require_relative '../test_case'
2
-
3
- class RouteTest < TestCase
4
- def test_extract_params_index
5
- pattern = '/(page/:number)?'
6
-
7
- assert_equal({ :number => nil }, Staticpress::Route.extract_params(pattern, '/'))
8
- assert_equal({ :number => '2' }, Staticpress::Route.extract_params(pattern, '/page/2'))
9
-
10
- assert_nil nil, Staticpress::Route.extract_params(pattern, '/plain.txt')
11
- end
12
-
13
- def test_extract_params_page
14
- pattern = '/:slug'
15
-
16
- assert_equal({ :slug => '' }, Staticpress::Route.extract_params(pattern, '/'))
17
- assert_equal({ :slug => 'hello' }, Staticpress::Route.extract_params(pattern, '/hello'))
18
- end
19
-
20
- def test_extract_params_post
21
- pattern = '/:year/:month/:day/:title'
22
-
23
- assert_equal({ :year => '2011', :month => '11', :day => '11', :title => 'hello-world' }, Staticpress::Route.extract_params(pattern, '/2011/11/11/hello-world'))
24
- end
25
-
26
- def test_extract_params_theme
27
- pattern = '/assets/:theme/:asset_type/:slug'
28
-
29
- assert_equal({ :theme => 'default', :asset_type => 'styles', :slug => 'screen.css' }, Staticpress::Route.extract_params(pattern, '/assets/default/styles/screen.css'))
30
- end
31
-
32
- def test_regex_for_pattern_index
33
- pattern = '/(page/:number)?'
34
-
35
- assert_match Staticpress::Route.regex_for_pattern(pattern), '/'
36
- assert_match Staticpress::Route.regex_for_pattern(pattern), '/page/1'
37
- assert_match Staticpress::Route.regex_for_pattern(pattern), '/page/2'
38
- assert_match Staticpress::Route.regex_for_pattern(pattern), '/page/17'
39
-
40
- refute_match Staticpress::Route.regex_for_pattern(pattern), '/about'
41
- refute_match Staticpress::Route.regex_for_pattern(pattern), '/about/us'
42
- refute_match Staticpress::Route.regex_for_pattern(pattern), '/contact/page/27'
43
- refute_match Staticpress::Route.regex_for_pattern(pattern), '/static_text/about'
44
- refute_match Staticpress::Route.regex_for_pattern(pattern), '/plain.txt'
45
- refute_match Staticpress::Route.regex_for_pattern(pattern), '/files/profile.jpg'
46
- end
47
-
48
- def test_regex_for_pattern_page_1
49
- pattern = '/:slug'
50
-
51
- assert_match Staticpress::Route.regex_for_pattern(pattern), '/'
52
- assert_match Staticpress::Route.regex_for_pattern(pattern), '/page/1'
53
- assert_match Staticpress::Route.regex_for_pattern(pattern), '/about'
54
- assert_match Staticpress::Route.regex_for_pattern(pattern), '/about/us'
55
- assert_match Staticpress::Route.regex_for_pattern(pattern), '/static_text/about'
56
- assert_match Staticpress::Route.regex_for_pattern(pattern), '/static_text/about/us'
57
- assert_match Staticpress::Route.regex_for_pattern(pattern), '/2011/07/20/hello-world'
58
- assert_match Staticpress::Route.regex_for_pattern(pattern), '/blog/2011/07/20/hello-world'
59
- assert_match Staticpress::Route.regex_for_pattern(pattern), '/plain.txt'
60
- assert_match Staticpress::Route.regex_for_pattern(pattern), '/files/profile.jpg'
61
- end
62
-
63
- def test_regex_for_pattern_page_2
64
- pattern = '/static_text/:slug'
65
-
66
- assert_match Staticpress::Route.regex_for_pattern(pattern), '/static_text/page/123'
67
- assert_match Staticpress::Route.regex_for_pattern(pattern), '/static_text/page/xyz'
68
- assert_match Staticpress::Route.regex_for_pattern(pattern), '/static_text/about'
69
- assert_match Staticpress::Route.regex_for_pattern(pattern), '/static_text/about/us'
70
- assert_match Staticpress::Route.regex_for_pattern(pattern), '/static_text/plain.txt'
71
- assert_match Staticpress::Route.regex_for_pattern(pattern), '/static_text/files/profile.jpg'
72
-
73
- refute_match Staticpress::Route.regex_for_pattern(pattern), '/'
74
- refute_match Staticpress::Route.regex_for_pattern(pattern), '/about'
75
- refute_match Staticpress::Route.regex_for_pattern(pattern), '/blog/2011/07/20/hello-world'
76
- end
77
-
78
- def test_regex_for_pattern_post_1
79
- pattern = '/:year/:month/:day/:title'
80
-
81
- assert_match Staticpress::Route.regex_for_pattern(pattern), '/2011/07/20/hello-world'
82
-
83
- refute_match Staticpress::Route.regex_for_pattern(pattern), '/about'
84
- refute_match Staticpress::Route.regex_for_pattern(pattern), '/static_text/about/us'
85
- refute_match Staticpress::Route.regex_for_pattern(pattern), '/blog/2011/07/20/hello-world'
86
- refute_match Staticpress::Route.regex_for_pattern(pattern), '/plain.txt'
87
- refute_match Staticpress::Route.regex_for_pattern(pattern), '/files/profile.jpg'
88
- end
89
-
90
- def test_regex_for_pattern_post_2
91
- pattern = '/blog/:year/:month/:day/:title'
92
-
93
- assert_match Staticpress::Route.regex_for_pattern(pattern), '/blog/2011/07/20/hello-world'
94
-
95
- refute_match Staticpress::Route.regex_for_pattern(pattern), '/'
96
- refute_match Staticpress::Route.regex_for_pattern(pattern), '/about/us'
97
- refute_match Staticpress::Route.regex_for_pattern(pattern), '/blog/about'
98
- refute_match Staticpress::Route.regex_for_pattern(pattern), '/2011/07/20/hello-world'
99
- refute_match Staticpress::Route.regex_for_pattern(pattern), '/plain.txt'
100
- refute_match Staticpress::Route.regex_for_pattern(pattern), '/files/profile.jpg'
101
- end
102
-
103
- def test_regex_for_pattern_post_3
104
- pattern = '/:year/:title'
105
-
106
- assert_match Staticpress::Route.regex_for_pattern(pattern), '/2011/hello-world'
107
-
108
- refute_match Staticpress::Route.regex_for_pattern(pattern), '/'
109
- refute_match Staticpress::Route.regex_for_pattern(pattern), '/about/us'
110
- refute_match Staticpress::Route.regex_for_pattern(pattern), '/blog/2011/hello-world'
111
- refute_match Staticpress::Route.regex_for_pattern(pattern), '/2011/07/20/hello-world'
112
- refute_match Staticpress::Route.regex_for_pattern(pattern), '/plain.txt'
113
- refute_match Staticpress::Route.regex_for_pattern(pattern), '/files/profile.jpg'
114
- end
115
-
116
- def test_regex_for_pattern_post_4
117
- pattern = '/blog/:year/:title'
118
-
119
- assert_match Staticpress::Route.regex_for_pattern(pattern), '/blog/2011/hello-world'
120
-
121
- refute_match Staticpress::Route.regex_for_pattern(pattern), '/'
122
- refute_match Staticpress::Route.regex_for_pattern(pattern), '/about/us'
123
- refute_match Staticpress::Route.regex_for_pattern(pattern), '/2011/hello-world'
124
- refute_match Staticpress::Route.regex_for_pattern(pattern), '/2011/07/20/hello-world'
125
- refute_match Staticpress::Route.regex_for_pattern(pattern), '/blog/2011/07/20/hello-world'
126
- refute_match Staticpress::Route.regex_for_pattern(pattern), '/plain.txt'
127
- refute_match Staticpress::Route.regex_for_pattern(pattern), '/files/profile.jpg'
128
- end
129
-
130
- def test_regex_for_pattern_tag_1
131
- pattern = '/tag/:name(/page/:number)?'
132
-
133
- assert_match Staticpress::Route.regex_for_pattern(pattern), '/tag/programming'
134
- assert_match Staticpress::Route.regex_for_pattern(pattern), '/tag/programming/page/0'
135
-
136
- refute_match Staticpress::Route.regex_for_pattern(pattern), '/'
137
- refute_match Staticpress::Route.regex_for_pattern(pattern), '/about/us'
138
- refute_match Staticpress::Route.regex_for_pattern(pattern), '/static_text/about'
139
- refute_match Staticpress::Route.regex_for_pattern(pattern), '/2011/07/20/hello-world'
140
- refute_match Staticpress::Route.regex_for_pattern(pattern), '/something/tag/programming'
141
- refute_match Staticpress::Route.regex_for_pattern(pattern), '/plain.txt'
142
- refute_match Staticpress::Route.regex_for_pattern(pattern), '/files/profile.jpg'
143
- end
144
-
145
- def test_regex_for_pattern_tag_2
146
- pattern = '/something/tag/:name(/page/:number)?'
147
-
148
- assert_match Staticpress::Route.regex_for_pattern(pattern), '/something/tag/programming'
149
- assert_match Staticpress::Route.regex_for_pattern(pattern), '/something/tag/programming/page/123456'
150
-
151
- refute_match Staticpress::Route.regex_for_pattern(pattern), '/about/us'
152
- refute_match Staticpress::Route.regex_for_pattern(pattern), '/static_text/about/us'
153
- refute_match Staticpress::Route.regex_for_pattern(pattern), '/2011/07/20/hello-world'
154
- refute_match Staticpress::Route.regex_for_pattern(pattern), '/tag/programming'
155
- refute_match Staticpress::Route.regex_for_pattern(pattern), '/plain.txt'
156
- refute_match Staticpress::Route.regex_for_pattern(pattern), '/files/profile.jpg'
157
- end
158
-
159
- def test_regex_for_pattern_category_1
160
- pattern = '/category/:name(/page/:number)?'
161
-
162
- assert_match Staticpress::Route.regex_for_pattern(pattern), '/category/programming'
163
- assert_match Staticpress::Route.regex_for_pattern(pattern), '/category/programming/page/5'
164
-
165
- refute_match Staticpress::Route.regex_for_pattern(pattern), '/about'
166
- refute_match Staticpress::Route.regex_for_pattern(pattern), '/static_text/about/us'
167
- refute_match Staticpress::Route.regex_for_pattern(pattern), '/2011/07/20/hello-world'
168
- refute_match Staticpress::Route.regex_for_pattern(pattern), '/blog/2011/07/20/hello-world'
169
- refute_match Staticpress::Route.regex_for_pattern(pattern), '/plain.txt'
170
- refute_match Staticpress::Route.regex_for_pattern(pattern), '/files/profile.jpg'
171
- end
172
-
173
- def test_regex_for_pattern_category_2
174
- pattern = '/blog/category/:name(/page/:number)?'
175
-
176
- assert_match Staticpress::Route.regex_for_pattern(pattern), '/blog/category/programming'
177
- assert_match Staticpress::Route.regex_for_pattern(pattern), '/blog/category/programming/page/20'
178
-
179
- refute_match Staticpress::Route.regex_for_pattern(pattern), '/about/us'
180
- refute_match Staticpress::Route.regex_for_pattern(pattern), '/static_text/about'
181
- refute_match Staticpress::Route.regex_for_pattern(pattern), '/blog/2011/07/20/hello-world'
182
- refute_match Staticpress::Route.regex_for_pattern(pattern), '/category/programming'
183
- refute_match Staticpress::Route.regex_for_pattern(pattern), '/plain.txt'
184
- refute_match Staticpress::Route.regex_for_pattern(pattern), '/files/profile.jpg'
185
- end
186
- end