staticpress 0.6.2 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -0,0 +1,70 @@
1
+ require 'spec_helper'
2
+
3
+ describe Staticpress::Content::Page do
4
+ include Staticpress::Helpers
5
+
6
+ basic_blog
7
+
8
+ let(:page_dir) { Staticpress.blog_path + config.source_path }
9
+
10
+ let(:chained) { Staticpress::Content::Page.new(:slug => 'chained') }
11
+ let(:chain) { Staticpress::Content::Page.new(:slug => 'chain.html') }
12
+ let(:page) { Staticpress::Content::Page.new :slug => 'about' }
13
+ let(:second_page) { Staticpress::Content::Page.new :slug => 'contact' }
14
+ let(:index_page) { Staticpress::Content::Page.new :slug => '' }
15
+ let(:style2) { Staticpress::Content::Page.new :slug => 'style2.css' }
16
+ let(:nested) { Staticpress::Content::Page.new :slug => 'foo/bar/baz' }
17
+ let(:static_bin) { Staticpress::Content::Page.new :slug => 'ruby.png' }
18
+ let(:static_txt) { Staticpress::Content::Page.new :slug => 'plain.txt' }
19
+
20
+ let(:fake) { Staticpress::Content::Page.new :slug => 'i/dont/exist' }
21
+
22
+ describe '.all' do
23
+ it '...' do
24
+ expect(Staticpress::Content::Page.all.count).to eq(11)
25
+ end
26
+ end
27
+
28
+ describe '#extension' do
29
+ it '...' do
30
+ expect(chained.template_extension).to eq('.markdown.erb')
31
+ expect(chain.template_extension).to eq('.markdown.erb')
32
+ expect(page.template_extension).to eq('.markdown')
33
+ end
34
+ end
35
+
36
+ describe '#full_slug' do
37
+ it '...' do
38
+ expect(chained.full_slug).to eq('chained')
39
+ expect(chain.full_slug).to eq('chain.html')
40
+ expect(page.full_slug).to eq('about')
41
+ end
42
+ end
43
+
44
+ describe '.extract_slug' do
45
+ it '...' do
46
+ expect(Staticpress::Content::Page.extract_slug(page_dir + 'chained.markdown.erb')).to eq('chained')
47
+ expect(Staticpress::Content::Page.extract_slug(page_dir + 'about.markdown')).to eq('about')
48
+ expect(Staticpress::Content::Page.extract_slug(page_dir + 'plain.txt')).to eq('plain.txt')
49
+ end
50
+ end
51
+
52
+ describe '.find_by_path' do
53
+ it '...' do
54
+ expect(Staticpress::Content::Page.find_by_path(page_dir + 'chained.markdown.erb')).to eq(chained)
55
+ expect(Staticpress::Content::Page.find_by_path(page_dir + 'chain.html.markdown.erb')).to eq(chain)
56
+ expect(Staticpress::Content::Page.find_by_path(page_dir + 'about.markdown')).to eq(page)
57
+ expect(Staticpress::Content::Page.find_by_path(page_dir + 'index.markdown')).to eq(index_page)
58
+ expect(Staticpress::Content::Page.find_by_path(page_dir + 'i' + 'dont' + 'exist.markdown')).to be_nil
59
+ expect(Staticpress::Content::Page.find_by_path(page_dir + 'ruby.png')).to eq(static_bin)
60
+ expect(Staticpress::Content::Page.find_by_path(page_dir + 'i' + 'dont' + 'exist.jpg')).to be_nil
61
+ end
62
+ end
63
+
64
+ describe '#template_path' do
65
+ it '...' do
66
+ expect(index_page.template_path).to eq(page_dir + 'index.markdown')
67
+ expect(page.template_path).to eq(page_dir + 'about.markdown')
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+
3
+ describe Staticpress::Content::Post do
4
+ include Staticpress::Helpers
5
+
6
+ basic_blog
7
+
8
+ let(:post_dir) { Staticpress.blog_path + config.posts_source_path }
9
+
10
+ let(:post) { Staticpress::Content::Post.new(:year => '2011', :month => '07', :day => '20', :title => 'hello') }
11
+ let(:another_post) { Staticpress::Content::Post.new(:year => '2011', :month => '08', :day => '20', :title => 'forever') }
12
+ let(:long_title_post) { Staticpress::Content::Post.new(:year => '2011', :month => '08', :day => '06', :title => 'blogging-with-staticpress') }
13
+
14
+ describe '#<=>' do
15
+ it '...' do
16
+ expect([ post, another_post ].sort).to eq([ post, another_post ])
17
+ expect([ another_post, post ].sort).to eq([ post, another_post ])
18
+ end
19
+ end
20
+
21
+ describe '#created_at' do
22
+ it '...' do
23
+ expect(post.created_at).to eq(Time.utc(2011, 7, 20, 13, 9, 52))
24
+ expect(another_post.created_at).to eq(Time.utc(2011, 8, 20))
25
+ end
26
+ end
27
+
28
+ describe '#created_on' do
29
+ it '...' do
30
+ expect(post.created_on).to eq(Time.utc(2011, 7, 20))
31
+ expect(another_post.created_on).to eq(Time.utc(2011, 8, 20))
32
+ end
33
+ end
34
+
35
+ describe '.find_by_path' do
36
+ it '...' do
37
+ expect(Staticpress::Content::Post.find_by_path(post_dir + '2011-07-20-hello.markdown')).to eq(post)
38
+ expect(Staticpress::Content::Post.find_by_path(post_dir + '2011-07-20-goodbye.markdown')).to be_nil
39
+ end
40
+ end
41
+
42
+ describe '#template_path' do
43
+ it '...' do
44
+ expect(post.template_path).to eq(Staticpress.blog_path + config.posts_source_path + '2011-07-20-hello.markdown')
45
+ end
46
+ end
47
+
48
+ describe '#title' do
49
+ it '...' do
50
+ expect(post.title).to eq('Hello, World')
51
+ expect(long_title_post.title).to eq('Blogging With Staticpress')
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe Staticpress::Content::ResourceContent do
4
+ include Staticpress::Helpers
5
+ include Staticpress::Content::ResourceContent
6
+
7
+ basic_blog
8
+
9
+ let(:page_dir) { Staticpress.blog_path + config.source_path }
10
+
11
+ describe '.find_supported_extensions' do
12
+ it '...' do
13
+ expect(find_supported_extensions(page_dir + 'chained.markdown.erb')).to eq([:erb, :markdown])
14
+ expect(find_supported_extensions(page_dir + 'chained.markdown')).to eq([:erb, :markdown])
15
+ expect(find_supported_extensions(page_dir + 'chained')).to eq([:erb, :markdown])
16
+ expect(find_supported_extensions(page_dir + 'about')).to eq([:markdown])
17
+ expect(find_supported_extensions(page_dir + 'plain.txt')).to eq([])
18
+ expect(find_supported_extensions(page_dir + 'i/dont/exist')).to eq([])
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ describe Staticpress::Content::Tag do
4
+ let(:tag) { Staticpress::Content::Tag.new :name => 'charlotte' }
5
+
6
+ basic_blog
7
+
8
+ describe '.tags' do
9
+ it '...' do
10
+ expect(Staticpress::Content::Tag.tags).to eq([ 'charlotte' ])
11
+ end
12
+ end
13
+
14
+ describe '#pages_count' do
15
+ it '...' do
16
+ expect(tag.pages_count).to eq(1)
17
+ end
18
+ end
19
+
20
+ describe '#optional_param_defaults' do
21
+ it '...' do
22
+ expected = { :number => 1 }
23
+ expect(Staticpress::Content::Tag.new(:name => 'charlotte').optional_param_defaults).to eq(expected)
24
+ expect(Staticpress::Content::Tag.new(:name => 'charlotte', :number => nil).optional_param_defaults).to eq(expected)
25
+ end
26
+ end
27
+
28
+ describe '#sub_content' do
29
+ it '...' do
30
+ expected = [
31
+ Staticpress::Content::Post.new(:year => '2011', :month => '08', :day => '06', :title => 'in-charlotte')
32
+ ]
33
+ expect(tag.sub_content).to eq(expected)
34
+ end
35
+ end
36
+
37
+ describe '.all' do
38
+ it '...' do
39
+ expected = [
40
+ Staticpress::Content::Tag.new(:name => 'charlotte', :number => 1)
41
+ ]
42
+ expect(Staticpress::Content::Tag.all).to eq(expected)
43
+ end
44
+ end
45
+
46
+ describe '.content_by_tag' do
47
+ it '...' do
48
+ [
49
+ Staticpress::Content::Post.new(:year => '2011', :month => '08', :day => '06', :title => 'in-charlotte')
50
+ ].each { |content| expect(Staticpress::Content::Tag.content_by_tag['charlotte']).to include(content) }
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe Staticpress::Content::Theme do
4
+ include Staticpress::Helpers
5
+
6
+ basic_blog
7
+
8
+ let(:theme_dir) { Staticpress::Theme.theme.root }
9
+
10
+ let(:asset_style) { Staticpress::Content::Theme.new :theme => 'test_theme', :asset_type => 'styles', :slug => 'all' }
11
+ let(:asset_script) { Staticpress::Content::Theme.new :theme => 'test_theme', :asset_type => 'scripts', :slug => 'application.js' }
12
+
13
+ before :each do
14
+ config.theme = :test_theme
15
+ end
16
+
17
+ describe '.all' do
18
+ it 'finds all the theme content' do
19
+ expect(Staticpress::Content::Theme.all.count).to eq(2)
20
+ end
21
+ end
22
+
23
+ describe '.find_by_path' do
24
+ it 'finds content when given a path' do
25
+ expect(Staticpress::Content::Theme.find_by_path(theme_dir + 'assets' + 'styles' + 'all.sass')).to eq(asset_style)
26
+ expect(Staticpress::Content::Theme.find_by_path(theme_dir + 'i' + 'dont' + 'exist.markdown')).to be_nil
27
+ actual = Staticpress::Content::Theme.find_by_path(theme_dir + 'assets' + 'scripts' + 'application.js')
28
+ expect(asset_script).to eq(actual)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,72 @@
1
+ require 'spec_helper'
2
+
3
+ describe Staticpress::Helpers do
4
+ include Staticpress::Helpers
5
+
6
+ basic_blog
7
+
8
+ describe '#extensionless_basename' do
9
+ it '...' do
10
+ expect(extensionless_basename(Pathname('extensionless'))).to eq('extensionless')
11
+ expect(extensionless_basename(Pathname('.htaccess'))).to eq('.htaccess')
12
+ expect(extensionless_basename(Pathname('tyrannasaurus_rex.rb'))).to eq('tyrannasaurus_rex')
13
+ expect(extensionless_basename(Pathname('dinosaurs/stegosaurus.rb'))).to eq('stegosaurus')
14
+ expect(extensionless_basename(Pathname('/dinosaurs/stegosaurus.rb'))).to eq('stegosaurus')
15
+ end
16
+ end
17
+
18
+ describe '#extensionless_path' do
19
+ it '...' do
20
+ expect(extensionless_path(Pathname('extensionless'))).to eq(Pathname('extensionless'))
21
+ expect(extensionless_path(Pathname('.htaccess'))).to eq(Pathname('.htaccess'))
22
+ expect(extensionless_path(Pathname('tyrannasaurus_rex.rb'))).to eq(Pathname('tyrannasaurus_rex'))
23
+ expect(extensionless_path(Pathname('dinosaurs/stegosaurus.rb'))).to eq(Pathname('dinosaurs/stegosaurus'))
24
+ expect(extensionless_path(Pathname('/dinosaurs/stegosaurus.rb'))).to eq(Pathname('/dinosaurs/stegosaurus'))
25
+ end
26
+ end
27
+
28
+ describe '#hash_from_empty_array' do
29
+ it '...' do
30
+ actual = hash_from_array [] {}
31
+ expect(actual).to eq({})
32
+ end
33
+ end
34
+
35
+ describe '#hash_from_array' do
36
+ it '...' do
37
+ expected = {
38
+ 1 => { :key => 1 },
39
+ 2 => { :key => 2 },
40
+ 3 => { :key => 3 }
41
+ }
42
+
43
+ actual = hash_from_array [
44
+ { :key => 1 },
45
+ { :key => 2 },
46
+ { :key => 3 }
47
+ ] { |hash| hash[:key] }
48
+
49
+ expect(actual).to eq(expected)
50
+ end
51
+ end
52
+
53
+ describe '#paginate' do
54
+ it '...' do
55
+ # a == oldest, z == newest
56
+ expect(paginate(:a..:z).count).to eq(3)
57
+ expect(paginate(:a..:z)[0]).to eq((:a..:j).to_a) # page 1 lists oldest, with oldest at top
58
+ expect(paginate(:a..:z)[1]).to eq((:k..:t).to_a)
59
+ expect(paginate(:a..:z)[2]).to eq((:u..:z).to_a) # page 3 lists newest, with newest at bottom (default page)
60
+ expect(paginate(:a..:z)[5]).to eq([]), 'Accessing an invalid index on anything that has been paginated should return an empty array'
61
+ end
62
+ end
63
+
64
+ describe '#titleize' do
65
+ it '...' do
66
+ expect(titleize('')).to eq('')
67
+ expect(titleize('/')).to eq('')
68
+ expect(titleize('/foo/bar/baz')).to eq('Foo -> Bar -> Baz')
69
+ expect(titleize('blogging-with-staticpress')).to eq('Blogging With Staticpress')
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+
3
+ describe Staticpress::JSObject do
4
+ JSO = Staticpress::JSObject
5
+
6
+ basic_blog
7
+
8
+ let(:js_object) { JSO.new :key => :value, :nested => { :a => :b } }
9
+
10
+ describe '#-' do
11
+ it '...' do
12
+ expect(js_object - {}).to eq(JSO.new(:key => :value, :nested => { :a => :b }))
13
+ expect(js_object - { :key => :value }).to eq(JSO.new(:nested => { :a => :b }))
14
+ expect(js_object - { :nested => { :a => :b } }).to eq(JSO.new(:key => :value))
15
+ expect(js_object - { :key => :value, :nested => { :a => :b } }).to eq(JSO.new({}))
16
+
17
+ expect(JSO.new(:key => :value, :nested => { :a => :b })).to eq(js_object - JSO.new({}))
18
+ expect(JSO.new(:nested => { :a => :b })).to eq(js_object - JSO.new(:key => :value))
19
+ expect(JSO.new(:key => :value)).to eq(js_object - JSO.new(:nested => { :a => :b }))
20
+ expect(JSO.new({})).to eq(js_object - JSO.new(:key => :value, :nested => { :a => :b }))
21
+ end
22
+ end
23
+
24
+ describe '#[]' do
25
+ it '...' do
26
+ expect(js_object[:some_random]).to be_nil
27
+ expect(js_object[:key]).to eq(:value)
28
+ expect(js_object['key']).to eq(:value)
29
+ end
30
+ end
31
+
32
+ describe 'regular access' do
33
+ it '...' do
34
+ expect(js_object.key).to eq(:value)
35
+ expect(js_object.nested.a).to eq(:b)
36
+ expect(js_object.nested.other).to be_nil
37
+ end
38
+ end
39
+
40
+ describe 'assignment' do
41
+ it '...' do
42
+ expect(js_object.hoopla).to be_nil
43
+ js_object.hoopla = :hullabaloo
44
+ expect(js_object.hoopla).to eq(:hullabaloo)
45
+ end
46
+ end
47
+
48
+ describe '#merge' do
49
+ it '...' do
50
+ expect(js_object.some_key).to be_nil
51
+ enhanced = js_object.merge :some_key => 42
52
+ expect(enhanced.some_key).to eq(42)
53
+ end
54
+ end
55
+
56
+ describe '#to_hash' do
57
+ it '...' do
58
+ expect(js_object.to_hash).to eq(:key => :value, :nested => { :a => :b })
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe Staticpress::Metadata do
4
+ basic_blog
5
+
6
+ let(:meta) { Staticpress::Metadata.new }
7
+ let(:another_meta) { Staticpress::Metadata.new :layout => 'post_index', :categories => %w[programming], :tags => %w[code tutorial] }
8
+
9
+ describe '#inspect' do
10
+ it '...' do
11
+ expect(meta.inspect).to eq('#<Staticpress::Metadata>')
12
+ expect(another_meta.inspect).to eq('#<Staticpress::Metadata categories=["programming"], layout="post_index", tags=["code", "tutorial"]>')
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,219 @@
1
+ require 'spec_helper'
2
+
3
+ # TODO add contexts
4
+ describe Staticpress::Route do
5
+ basic_blog
6
+
7
+ describe '.extract_params_index' do
8
+ it '...' do
9
+ pattern = '/(page/:number)?'
10
+
11
+ expect(Staticpress::Route.extract_params(pattern, '/')).to eq(:number => nil)
12
+ expect(Staticpress::Route.extract_params(pattern, '/page/2')).to eq(:number => '2')
13
+
14
+ expect(Staticpress::Route.extract_params(pattern, '/plain.txt')).to be_nil
15
+ end
16
+ end
17
+
18
+ describe '.extract_params_page' do
19
+ it '...' do
20
+ pattern = '/:slug'
21
+
22
+ expect(Staticpress::Route.extract_params(pattern, '/')).to eq(:slug => '')
23
+ expect(Staticpress::Route.extract_params(pattern, '/hello')).to eq(:slug => 'hello')
24
+ end
25
+ end
26
+
27
+ describe '.extract_params_post' do
28
+ it '...' do
29
+ pattern = '/:year/:month/:day/:title'
30
+
31
+ expect(Staticpress::Route.extract_params(pattern, '/2011/11/11/hello-world')).to eq(:year => '2011', :month => '11', :day => '11', :title => 'hello-world')
32
+ end
33
+ end
34
+
35
+ describe '.extract_params_theme' do
36
+ it '...' do
37
+ pattern = '/assets/:theme/:asset_type/:slug'
38
+
39
+ expect(Staticpress::Route.extract_params(pattern, '/assets/default/styles/screen.css')).to eq(:theme => 'default', :asset_type => 'styles', :slug => 'screen.css')
40
+ end
41
+ end
42
+
43
+ describe '.regex_for_pattern_index' do
44
+ it '...' do
45
+ pattern = '/(page/:number)?'
46
+
47
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to match('/')
48
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to match('/page/1')
49
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to match('/page/2')
50
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to match('/page/17')
51
+
52
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to_not match('/about')
53
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to_not match('/about/us')
54
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to_not match('/contact/page/27')
55
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to_not match('/static_text/about')
56
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to_not match('/plain.txt')
57
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to_not match('/files/profile.jpg')
58
+ end
59
+ end
60
+
61
+ describe '.regex_for_pattern_page_1' do
62
+ it '...' do
63
+ pattern = '/:slug'
64
+
65
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to match('/')
66
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to match('/page/1')
67
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to match('/about')
68
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to match('/about/us')
69
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to match('/static_text/about')
70
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to match('/static_text/about/us')
71
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to match('/2011/07/20/hello-world')
72
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to match('/blog/2011/07/20/hello-world')
73
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to match('/plain.txt')
74
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to match('/files/profile.jpg')
75
+ end
76
+ end
77
+
78
+ describe '.regex_for_pattern_page_2' do
79
+ it '...' do
80
+ pattern = '/static_text/:slug'
81
+
82
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to match('/static_text/page/123')
83
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to match('/static_text/page/xyz')
84
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to match('/static_text/about')
85
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to match('/static_text/about/us')
86
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to match('/static_text/plain.txt')
87
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to match('/static_text/files/profile.jpg')
88
+
89
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to_not match('/')
90
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to_not match('/about')
91
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to_not match('/blog/2011/07/20/hello-world')
92
+ end
93
+ end
94
+
95
+ describe '.regex_for_pattern_post_1' do
96
+ it '...' do
97
+ pattern = '/:year/:month/:day/:title'
98
+
99
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to match('/2011/07/20/hello-world')
100
+
101
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to_not match('/about')
102
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to_not match('/static_text/about/us')
103
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to_not match('/blog/2011/07/20/hello-world')
104
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to_not match('/plain.txt')
105
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to_not match('/files/profile.jpg')
106
+ end
107
+ end
108
+
109
+ describe '.regex_for_pattern_post_2' do
110
+ it '...' do
111
+ pattern = '/blog/:year/:month/:day/:title'
112
+
113
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to match('/blog/2011/07/20/hello-world')
114
+
115
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to_not match('/')
116
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to_not match('/about/us')
117
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to_not match('/blog/about')
118
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to_not match('/2011/07/20/hello-world')
119
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to_not match('/plain.txt')
120
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to_not match('/files/profile.jpg')
121
+ end
122
+ end
123
+
124
+ describe '.regex_for_pattern_post_3' do
125
+ it '...' do
126
+ pattern = '/:year/:title'
127
+
128
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to match('/2011/hello-world')
129
+
130
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to_not match('/')
131
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to_not match('/about/us')
132
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to_not match('/blog/2011/hello-world')
133
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to_not match('/2011/07/20/hello-world')
134
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to_not match('/plain.txt')
135
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to_not match('/files/profile.jpg')
136
+ end
137
+ end
138
+
139
+ describe '.regex_for_pattern_post_4' do
140
+ it '...' do
141
+ pattern = '/blog/:year/:title'
142
+
143
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to match('/blog/2011/hello-world')
144
+
145
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to_not match('/')
146
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to_not match('/about/us')
147
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to_not match('/2011/hello-world')
148
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to_not match('/2011/07/20/hello-world')
149
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to_not match('/blog/2011/07/20/hello-world')
150
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to_not match('/plain.txt')
151
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to_not match('/files/profile.jpg')
152
+ end
153
+ end
154
+
155
+ describe '.regex_for_pattern_tag_1' do
156
+ it '...' do
157
+ pattern = '/tag/:name(/page/:number)?'
158
+
159
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to match('/tag/programming')
160
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to match('/tag/programming/page/0')
161
+
162
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to_not match('/')
163
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to_not match('/about/us')
164
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to_not match('/static_text/about')
165
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to_not match('/2011/07/20/hello-world')
166
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to_not match('/something/tag/programming')
167
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to_not match('/plain.txt')
168
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to_not match('/files/profile.jpg')
169
+ end
170
+ end
171
+
172
+ describe '.regex_for_pattern_tag_2' do
173
+ it '...' do
174
+ pattern = '/something/tag/:name(/page/:number)?'
175
+
176
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to match('/something/tag/programming')
177
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to match('/something/tag/programming/page/123456')
178
+
179
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to_not match('/about/us')
180
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to_not match('/static_text/about/us')
181
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to_not match('/2011/07/20/hello-world')
182
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to_not match('/tag/programming')
183
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to_not match('/plain.txt')
184
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to_not match('/files/profile.jpg')
185
+ end
186
+ end
187
+
188
+ describe '.regex_for_pattern_category_1' do
189
+ it '...' do
190
+ pattern = '/category/:name(/page/:number)?'
191
+
192
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to match('/category/programming')
193
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to match('/category/programming/page/5')
194
+
195
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to_not match('/about')
196
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to_not match('/static_text/about/us')
197
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to_not match('/2011/07/20/hello-world')
198
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to_not match('/blog/2011/07/20/hello-world')
199
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to_not match('/plain.txt')
200
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to_not match('/files/profile.jpg')
201
+ end
202
+ end
203
+
204
+ describe '.regex_for_pattern_category_2' do
205
+ it '...' do
206
+ pattern = '/blog/category/:name(/page/:number)?'
207
+
208
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to match('/blog/category/programming')
209
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to match('/blog/category/programming/page/20')
210
+
211
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to_not match('/about/us')
212
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to_not match('/static_text/about')
213
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to_not match('/blog/2011/07/20/hello-world')
214
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to_not match('/category/programming')
215
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to_not match('/plain.txt')
216
+ expect(Staticpress::Route.regex_for_pattern(pattern)).to_not match('/files/profile.jpg')
217
+ end
218
+ end
219
+ end