staticpress 0.3.0 → 0.4.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.
- data.tar.gz.sig +0 -0
- data/docs/Gemfile +8 -0
- data/{tests/sample_sites/test_blog → docs}/README.markdown +0 -0
- data/{tests/sample_sites/test_blog → docs}/config.ru +0 -0
- data/docs/config.yml +2 -0
- data/docs/content/docs/diving-deeper.markdown +3 -0
- data/docs/content/docs/setup.markdown +15 -0
- data/docs/content/index.markdown +1 -0
- data/features/happy_path.feature +36 -1
- data/features/step_definitions/staticpress_steps.rb +1 -1
- data/lib/skeleton/Gemfile +0 -2
- data/lib/staticpress/booter.rb +1 -1
- data/lib/staticpress/cli.rb +2 -2
- data/lib/staticpress/content/base.rb +66 -23
- data/lib/staticpress/content/category.rb +12 -3
- data/lib/staticpress/content/collection_content.rb +0 -4
- data/lib/staticpress/content/index.rb +10 -3
- data/lib/staticpress/content/page.rb +32 -17
- data/lib/staticpress/content/post.rb +22 -27
- data/lib/staticpress/content/resource_content.rb +11 -3
- data/lib/staticpress/content/static_content.rb +10 -4
- data/lib/staticpress/content/tag.rb +12 -3
- data/lib/staticpress/content/theme.rb +17 -19
- data/lib/staticpress/helpers.rb +4 -0
- data/lib/staticpress/route.rb +21 -95
- data/lib/staticpress/server.rb +1 -3
- data/lib/staticpress/site.rb +20 -16
- data/lib/staticpress/version.rb +1 -1
- data/tests/staticpress/configuration_test.rb +4 -0
- data/tests/staticpress/content/base_test.rb +271 -0
- data/tests/staticpress/content/category_test.rb +29 -0
- data/tests/staticpress/content/index_test.rb +6 -0
- data/tests/staticpress/content/page_test.rb +37 -0
- data/tests/staticpress/content/post_test.rb +45 -0
- data/tests/staticpress/content/tag_test.rb +33 -0
- data/tests/staticpress/content/theme_test.rb +29 -0
- data/tests/{lib/staticpress → staticpress}/helpers_test.rb +2 -2
- data/tests/staticpress/js_object_test.rb +43 -0
- data/tests/staticpress/metadata_test.rb +16 -0
- data/tests/staticpress/plugin_test.rb +4 -0
- data/tests/staticpress/pusher_test.rb +9 -0
- data/tests/{lib/staticpress → staticpress}/route_test.rb +19 -41
- data/tests/{lib/staticpress → staticpress}/server_test.rb +5 -14
- data/tests/staticpress/site_test.rb +21 -0
- data/tests/staticpress/theme_test.rb +86 -0
- data/tests/staticpress/view_helpers_test.rb +28 -0
- data/tests/{lib/staticpress_test.rb → staticpress_test.rb} +3 -3
- data/tests/{sample_sites/test_blog → test_blog}/Gemfile +0 -2
- data/tests/test_blog/README.markdown +21 -0
- data/tests/test_blog/config.ru +8 -0
- data/tests/{sample_sites/test_blog → test_blog}/config.yml +0 -0
- data/tests/{sample_sites/test_blog → test_blog}/content/_posts/2011-07-20-hello.markdown +0 -0
- data/tests/{sample_sites/test_blog → test_blog}/content/_posts/2011-08-01-announcing-staticpress.markdown +0 -0
- data/tests/{sample_sites/test_blog → test_blog}/content/_posts/2011-08-02-staticpress.markdown +0 -0
- data/tests/{sample_sites/test_blog → test_blog}/content/_posts/2011-08-06-blogging-with-staticpress.markdown +0 -0
- data/tests/{sample_sites/test_blog → test_blog}/content/_posts/2011-08-06-conferences.markdown +0 -0
- data/tests/{sample_sites/test_blog → test_blog}/content/_posts/2011-08-06-in-charlotte.markdown +0 -0
- data/tests/{sample_sites/test_blog → test_blog}/content/_posts/2011-08-20-forever.markdown +0 -0
- data/tests/{sample_sites/test_blog → test_blog}/content/about.markdown +0 -0
- data/tests/{sample_sites/test_blog → test_blog}/content/contact.markdown +0 -0
- data/tests/{sample_sites/test_blog → test_blog}/content/foo/bar/baz.markdown +0 -0
- data/tests/test_blog/content/index.markdown +1 -0
- data/tests/{sample_sites/test_blog → test_blog}/content/plain.txt +0 -0
- data/tests/{sample_sites/test_blog → test_blog}/content/ruby.png +0 -0
- data/tests/{sample_sites/test_blog → test_blog}/content/style1.css +0 -0
- data/tests/{sample_sites/test_blog → test_blog}/content/style2.css.sass +0 -0
- data/tests/{sample_sites/test_blog → test_blog}/content/style3.sass +0 -0
- data/tests/{sample_sites/test_blog → test_blog}/themes/test_theme/assets/scripts/application.js +0 -0
- data/tests/{sample_sites/test_blog → test_blog}/themes/test_theme/assets/styles/all.sass +0 -0
- data/tests/{sample_sites/test_blog → test_blog}/themes/test_theme/includes/list_posts.haml +0 -0
- data/tests/{sample_sites/test_blog → test_blog}/themes/test_theme/layouts/archive.haml +0 -0
- data/tests/{sample_sites/test_blog → test_blog}/themes/test_theme/layouts/atom.haml +0 -0
- data/tests/{sample_sites/test_blog → test_blog}/themes/test_theme/layouts/default.haml +0 -0
- data/tests/{sample_sites/test_blog → test_blog}/themes/test_theme/layouts/index.haml +0 -0
- data/tests/{sample_sites/test_blog → test_blog}/themes/test_theme/layouts/post_index.haml +0 -0
- data/tests/{sample_sites/test_blog → test_blog}/themes/test_theme/views/default.haml +0 -0
- data/tests/{test_helper.rb → test_case.rb} +9 -5
- metadata +81 -73
- metadata.gz.sig +0 -0
- data/tests/lib/staticpress/configuration_test.rb +0 -4
- data/tests/lib/staticpress/content/base_test.rb +0 -6
- data/tests/lib/staticpress/content/category_test.rb +0 -62
- data/tests/lib/staticpress/content/index_test.rb +0 -45
- data/tests/lib/staticpress/content/page_test.rb +0 -147
- data/tests/lib/staticpress/content/post_test.rb +0 -89
- data/tests/lib/staticpress/content/tag_test.rb +0 -60
- data/tests/lib/staticpress/content/theme_test.rb +0 -114
- data/tests/lib/staticpress/js_object_test.rb +0 -45
- data/tests/lib/staticpress/metadata_test.rb +0 -19
- data/tests/lib/staticpress/plugin_test.rb +0 -4
- data/tests/lib/staticpress/pusher_test.rb +0 -9
- data/tests/lib/staticpress/site_test.rb +0 -26
- data/tests/lib/staticpress/theme_test.rb +0 -86
- data/tests/lib/staticpress/view_helpers_test.rb +0 -33
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require_relative '../../test_case'
|
|
2
|
+
|
|
3
|
+
require 'staticpress/content/category'
|
|
4
|
+
require 'staticpress/content/post'
|
|
5
|
+
|
|
6
|
+
class ContentCategoryTest < TestCase
|
|
7
|
+
let(:category) { Staticpress::Content::Category.new :name => 'programming' }
|
|
8
|
+
|
|
9
|
+
def test_categories
|
|
10
|
+
assert_equal [ 'programming', 'travel' ], Staticpress::Content::Category.categories
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def test_sub_content
|
|
14
|
+
assert_equal 3, category.sub_content.count
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def test_all
|
|
18
|
+
assert_equal 2, Staticpress::Content::Category.all.count
|
|
19
|
+
assert Staticpress::Content::Category.all.include?(category)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def test_content_by_category
|
|
23
|
+
[
|
|
24
|
+
Staticpress::Content::Post.new(:year => '2011', :month => '08', :day => '01', :title => 'announcing-staticpress'),
|
|
25
|
+
Staticpress::Content::Post.new(:year => '2011', :month => '08', :day => '02', :title => 'staticpress'),
|
|
26
|
+
Staticpress::Content::Post.new(:year => '2011', :month => '08', :day => '06', :title => 'blogging-with-staticpress')
|
|
27
|
+
].each { |content| assert_includes Staticpress::Content::Category.content_by_category['programming'], content }
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
require_relative '../../test_case'
|
|
2
|
+
|
|
3
|
+
require 'staticpress/content/page'
|
|
4
|
+
require 'staticpress/helpers'
|
|
5
|
+
|
|
6
|
+
class ContentPageTest < TestCase
|
|
7
|
+
include Staticpress::Helpers
|
|
8
|
+
|
|
9
|
+
let(:page_dir) { Staticpress.blog_path + config.source_path }
|
|
10
|
+
|
|
11
|
+
let(:page) { Staticpress::Content::Page.new :slug => 'about' }
|
|
12
|
+
let(:second_page) { Staticpress::Content::Page.new :slug => 'contact' }
|
|
13
|
+
let(:index_page) { Staticpress::Content::Page.new :slug => '' }
|
|
14
|
+
let(:style2) { Staticpress::Content::Page.new :slug => 'style2.css' }
|
|
15
|
+
let(:nested) { Staticpress::Content::Page.new :slug => 'foo/bar/baz' }
|
|
16
|
+
let(:static_bin) { Staticpress::Content::Page.new :slug => 'ruby.png' }
|
|
17
|
+
let(:static_txt) { Staticpress::Content::Page.new :slug => 'plain.txt' }
|
|
18
|
+
|
|
19
|
+
let(:fake) { Staticpress::Content::Page.new :slug => 'i/dont/exist' }
|
|
20
|
+
|
|
21
|
+
def test_all
|
|
22
|
+
assert_equal 9, Staticpress::Content::Page.all.count
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def test_find_by_path
|
|
26
|
+
assert_equal page, Staticpress::Content::Page.find_by_path(page_dir + 'about.markdown')
|
|
27
|
+
assert_equal index_page, Staticpress::Content::Page.find_by_path(page_dir + 'index.markdown')
|
|
28
|
+
assert_nil Staticpress::Content::Page.find_by_path(page_dir + 'i' + 'dont' + 'exist.markdown')
|
|
29
|
+
assert_equal static_bin, Staticpress::Content::Page.find_by_path(page_dir + 'ruby.png')
|
|
30
|
+
assert_nil Staticpress::Content::Page.find_by_path(page_dir + 'i' + 'dont' + 'exist.jpg')
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def test_template_path
|
|
34
|
+
assert_equal page_dir + 'index.markdown', index_page.template_path
|
|
35
|
+
assert_equal page_dir + 'about.markdown', page.template_path
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
require_relative '../../test_case'
|
|
2
|
+
|
|
3
|
+
require 'staticpress/content/post'
|
|
4
|
+
require 'staticpress/helpers'
|
|
5
|
+
|
|
6
|
+
class ContentPostTest < TestCase
|
|
7
|
+
include Staticpress::Helpers
|
|
8
|
+
|
|
9
|
+
let(:post_dir) { Staticpress.blog_path + config.posts_source_path }
|
|
10
|
+
|
|
11
|
+
let(:post) { Staticpress::Content::Post.new(:year => '2011', :month => '07', :day => '20', :title => 'hello') }
|
|
12
|
+
let(:another_post) { Staticpress::Content::Post.new(:year => '2011', :month => '08', :day => '20', :title => 'forever') }
|
|
13
|
+
let(:long_title_post) { Staticpress::Content::Post.new(:year => '2011', :month => '08', :day => '06', :title => 'blogging-with-staticpress') }
|
|
14
|
+
|
|
15
|
+
def test__spaceship
|
|
16
|
+
assert_operator post, :<=>, another_post
|
|
17
|
+
assert_operator another_post, :<=>, post
|
|
18
|
+
assert_equal [ post, another_post ], [ post, another_post ].sort
|
|
19
|
+
assert_equal [ post, another_post ], [ another_post, post ].sort
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def test_created_at
|
|
23
|
+
assert_equal Time.utc(2011, 7, 20, 13, 9, 52), post.created_at
|
|
24
|
+
assert_equal Time.utc(2011, 8, 20), another_post.created_at
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_created_on
|
|
28
|
+
assert_equal Time.utc(2011, 7, 20), post.created_on
|
|
29
|
+
assert_equal Time.utc(2011, 8, 20), another_post.created_on
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def test_find_by_path
|
|
33
|
+
assert_equal post, Staticpress::Content::Post.find_by_path(post_dir + '2011-07-20-hello.markdown')
|
|
34
|
+
assert_nil Staticpress::Content::Post.find_by_path(post_dir + '2011-07-20-goodbye.markdown')
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def test_template_path
|
|
38
|
+
assert_equal (Staticpress.blog_path + config.posts_source_path + '2011-07-20-hello.markdown'), post.template_path
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def test_title
|
|
42
|
+
assert_equal 'Hello, World', post.title
|
|
43
|
+
assert_equal 'Blogging With Staticpress', long_title_post.title
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require_relative '../../test_case'
|
|
2
|
+
|
|
3
|
+
require 'staticpress/content/post'
|
|
4
|
+
require 'staticpress/content/tag'
|
|
5
|
+
|
|
6
|
+
class ContentTagTest < TestCase
|
|
7
|
+
let(:tag) { Staticpress::Content::Tag.new :name => 'charlotte' }
|
|
8
|
+
|
|
9
|
+
def test_tags
|
|
10
|
+
assert_equal [ 'charlotte' ], Staticpress::Content::Tag.tags
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def test_optional_param_defaults
|
|
14
|
+
expected = { :number => 1 }
|
|
15
|
+
assert_equal expected, Staticpress::Content::Tag.new(:name => 'charlotte').optional_param_defaults
|
|
16
|
+
assert_equal expected, Staticpress::Content::Tag.new(:name => 'charlotte', :number => nil).optional_param_defaults
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def test_sub_content
|
|
20
|
+
assert_equal 1, tag.sub_content.count
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def test_all
|
|
24
|
+
assert_equal 1, Staticpress::Content::Tag.all.count
|
|
25
|
+
assert Staticpress::Content::Tag.all.include?(tag)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def test_content_by_tag
|
|
29
|
+
[
|
|
30
|
+
Staticpress::Content::Post.new(:year => '2011', :month => '08', :day => '06', :title => 'in-charlotte')
|
|
31
|
+
].each { |content| assert_includes Staticpress::Content::Tag.content_by_tag['charlotte'], content }
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require_relative '../../test_case'
|
|
2
|
+
|
|
3
|
+
require 'staticpress/content/theme'
|
|
4
|
+
require 'staticpress/helpers'
|
|
5
|
+
|
|
6
|
+
class ContentThemeTest < TestCase
|
|
7
|
+
include Staticpress::Helpers
|
|
8
|
+
|
|
9
|
+
let(:theme_dir) { Staticpress::Theme.theme.root }
|
|
10
|
+
|
|
11
|
+
let(:asset_style) { Staticpress::Content::Theme.new :theme => 'test_theme', :asset_type => 'styles', :slug => 'all' }
|
|
12
|
+
let(:asset_script) { Staticpress::Content::Theme.new :theme => 'test_theme', :asset_type => 'scripts', :slug => 'application.js' }
|
|
13
|
+
|
|
14
|
+
def setup
|
|
15
|
+
super
|
|
16
|
+
config.theme = :test_theme
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def test_all
|
|
20
|
+
assert_equal 2, Staticpress::Content::Theme.all.count
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def test_find_by_path
|
|
24
|
+
assert_equal asset_style, Staticpress::Content::Theme.find_by_path(theme_dir + 'assets' + 'styles' + 'all.sass')
|
|
25
|
+
assert_nil Staticpress::Content::Theme.find_by_path(theme_dir + 'i' + 'dont' + 'exist.markdown')
|
|
26
|
+
actual = Staticpress::Content::Theme.find_by_path(theme_dir + 'assets' + 'scripts' + 'application.js')
|
|
27
|
+
assert_equal actual, asset_script
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
require_relative '
|
|
1
|
+
require_relative '../test_case'
|
|
2
2
|
|
|
3
3
|
require 'pathname'
|
|
4
4
|
|
|
5
5
|
require 'staticpress/helpers'
|
|
6
6
|
|
|
7
|
-
class HelpersTest <
|
|
7
|
+
class HelpersTest < TestCase
|
|
8
8
|
include Staticpress::Helpers
|
|
9
9
|
|
|
10
10
|
def test_extensionless_basename
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
require_relative '../test_case'
|
|
2
|
+
|
|
3
|
+
require 'staticpress/js_object'
|
|
4
|
+
|
|
5
|
+
class JSObjectTest < TestCase
|
|
6
|
+
JSO = Staticpress::JSObject
|
|
7
|
+
|
|
8
|
+
let(:js_object) { JSO.new :key => :value, :nested => { :a => :b } }
|
|
9
|
+
|
|
10
|
+
def test__minus
|
|
11
|
+
assert_equal(JSO.new({ :key => :value, :nested => { :a => :b } }), js_object - {})
|
|
12
|
+
assert_equal(JSO.new({ :nested => { :a => :b } }), js_object - { :key => :value })
|
|
13
|
+
assert_equal(JSO.new({ :key => :value }), js_object - { :nested => { :a => :b } })
|
|
14
|
+
assert_equal(JSO.new({}), js_object - { :key => :value, :nested => { :a => :b } })
|
|
15
|
+
|
|
16
|
+
assert_equal(JSO.new({ :key => :value, :nested => { :a => :b } }), js_object - JSO.new({}))
|
|
17
|
+
assert_equal(JSO.new({ :nested => { :a => :b } }), js_object - JSO.new({ :key => :value }))
|
|
18
|
+
assert_equal(JSO.new({ :key => :value }), js_object - JSO.new({ :nested => { :a => :b } }))
|
|
19
|
+
assert_equal(JSO.new({}), js_object - JSO.new({ :key => :value, :nested => { :a => :b } }))
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def test__squares
|
|
23
|
+
assert_nil js_object[:some_random]
|
|
24
|
+
assert_equal :value, js_object[:key]
|
|
25
|
+
assert_equal :value, js_object['key']
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def test_regular_access
|
|
29
|
+
assert_equal :value, js_object.key
|
|
30
|
+
assert_equal :b, js_object.nested.a
|
|
31
|
+
assert_nil js_object.nested.other
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def test_assignment
|
|
35
|
+
assert_nil js_object.hoopla
|
|
36
|
+
js_object.hoopla = :hullabaloo
|
|
37
|
+
assert_equal :hullabaloo, js_object.hoopla
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def test_to_hash
|
|
41
|
+
assert_equal({ :key => :value, :nested => { :a => :b } }, js_object.to_hash)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require_relative '../test_case'
|
|
2
|
+
|
|
3
|
+
require 'staticpress/metadata'
|
|
4
|
+
|
|
5
|
+
class MetadataTest < TestCase
|
|
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
|
+
def test__chevron
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def test_inspect
|
|
13
|
+
assert_equal '#<Staticpress::Metadata>', meta.inspect
|
|
14
|
+
assert_equal '#<Staticpress::Metadata categories=["programming"], layout="post_index", tags=["code", "tutorial"]>', another_meta.inspect
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -1,55 +1,34 @@
|
|
|
1
|
-
require_relative '
|
|
1
|
+
require_relative '../test_case'
|
|
2
2
|
|
|
3
3
|
require 'staticpress/route'
|
|
4
4
|
|
|
5
|
-
class RouteTest <
|
|
6
|
-
def
|
|
7
|
-
|
|
5
|
+
class RouteTest < TestCase
|
|
6
|
+
def test_extract_params_index
|
|
7
|
+
pattern = '/(page/:number)?'
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
@route_category_2 = Staticpress::Route.new :content_type => Staticpress::Content::Category, :name => 'programming', :number => '2'
|
|
12
|
-
@route_page = Staticpress::Route.new :content_type => Staticpress::Content::Page, :slug => 'about'
|
|
13
|
-
@route_post = Staticpress::Route.new :content_type => Staticpress::Content::Post, :year => '2011', :month => '07', :day => '20', :title => 'hello'
|
|
14
|
-
end
|
|
9
|
+
assert_equal({ :number => nil }, Staticpress::Route.extract_params(pattern, '/'))
|
|
10
|
+
assert_equal({ :number => '2' }, Staticpress::Route.extract_params(pattern, '/page/2'))
|
|
15
11
|
|
|
16
|
-
|
|
17
|
-
assert_operator @route_category_0, :==, @route_category_1
|
|
18
|
-
refute_operator @route_category_0, :==, @route_category_2
|
|
19
|
-
assert_operator @route_page, :==, Staticpress::Route.new(:content_type => Staticpress::Content::Page, :slug => 'about')
|
|
20
|
-
refute_operator @route_page, :==, @route_post
|
|
21
|
-
refute_operator @route_page, :==, nil
|
|
12
|
+
assert_nil nil, Staticpress::Route.extract_params(pattern, '/plain.txt')
|
|
22
13
|
end
|
|
23
14
|
|
|
24
|
-
def
|
|
25
|
-
|
|
26
|
-
assert_equal Staticpress::Content::Post.new(@route_post, :markdown), @route_post.content
|
|
27
|
-
end
|
|
15
|
+
def test_extract_params_page
|
|
16
|
+
pattern = '/:slug'
|
|
28
17
|
|
|
29
|
-
|
|
30
|
-
assert_equal '
|
|
31
|
-
assert_equal '#<Staticpress::Route url_path=/2011/07/20/hello, content_type=Staticpress::Content::Post, params={:day=>"20", :month=>"07", :title=>"hello", :year=>"2011"}>', @route_post.inspect
|
|
18
|
+
assert_equal({ :slug => '' }, Staticpress::Route.extract_params(pattern, '/'))
|
|
19
|
+
assert_equal({ :slug => 'hello' }, Staticpress::Route.extract_params(pattern, '/hello'))
|
|
32
20
|
end
|
|
33
21
|
|
|
34
|
-
def
|
|
35
|
-
|
|
36
|
-
assert_equal({ :content_type => Staticpress::Content::Category, :name => 'programming', :number => '1' }, @route_category_1.params)
|
|
37
|
-
assert_equal({ :content_type => Staticpress::Content::Page, :slug => 'about' }, @route_page.params)
|
|
38
|
-
assert_equal({ :content_type => Staticpress::Content::Post, :year => '2011', :month => '07', :day => '20', :title => 'hello' }, @route_post.params)
|
|
39
|
-
end
|
|
22
|
+
def test_extract_params_post
|
|
23
|
+
pattern = '/:year/:month/:day/:title'
|
|
40
24
|
|
|
41
|
-
|
|
42
|
-
assert_equal '/category/programming', @route_category_0.url_path
|
|
43
|
-
assert_equal '/category/programming', @route_category_1.url_path
|
|
44
|
-
assert_equal '/category/programming/page/2', @route_category_2.url_path
|
|
45
|
-
assert_equal '/about', @route_page.url_path
|
|
46
|
-
assert_equal '/2011/07/20/hello', @route_post.url_path
|
|
25
|
+
assert_equal({ :year => '2011', :month => '11', :day => '11', :title => 'hello-world' }, Staticpress::Route.extract_params(pattern, '/2011/11/11/hello-world'))
|
|
47
26
|
end
|
|
48
27
|
|
|
49
|
-
def
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
28
|
+
def test_extract_params_theme
|
|
29
|
+
pattern = '/assets/:theme/:asset_type/:slug'
|
|
30
|
+
|
|
31
|
+
assert_equal({ :theme => 'default', :asset_type => 'styles', :slug => 'screen.css' }, Staticpress::Route.extract_params(pattern, '/assets/default/styles/screen.css'))
|
|
53
32
|
end
|
|
54
33
|
|
|
55
34
|
def test_regex_for_pattern_index
|
|
@@ -71,6 +50,7 @@ class RouteTest < TestHelper
|
|
|
71
50
|
def test_regex_for_pattern_page_1
|
|
72
51
|
pattern = '/:slug'
|
|
73
52
|
|
|
53
|
+
assert_match Staticpress::Route.regex_for_pattern(pattern), '/'
|
|
74
54
|
assert_match Staticpress::Route.regex_for_pattern(pattern), '/page/1'
|
|
75
55
|
assert_match Staticpress::Route.regex_for_pattern(pattern), '/about'
|
|
76
56
|
assert_match Staticpress::Route.regex_for_pattern(pattern), '/about/us'
|
|
@@ -80,8 +60,6 @@ class RouteTest < TestHelper
|
|
|
80
60
|
assert_match Staticpress::Route.regex_for_pattern(pattern), '/blog/2011/07/20/hello-world'
|
|
81
61
|
assert_match Staticpress::Route.regex_for_pattern(pattern), '/plain.txt'
|
|
82
62
|
assert_match Staticpress::Route.regex_for_pattern(pattern), '/files/profile.jpg'
|
|
83
|
-
|
|
84
|
-
refute_match Staticpress::Route.regex_for_pattern(pattern), '/'
|
|
85
63
|
end
|
|
86
64
|
|
|
87
65
|
def test_regex_for_pattern_page_2
|
|
@@ -1,27 +1,18 @@
|
|
|
1
|
-
require_relative '
|
|
1
|
+
require_relative '../test_case'
|
|
2
2
|
|
|
3
3
|
require 'staticpress/server'
|
|
4
4
|
|
|
5
|
-
class ServerTest <
|
|
6
|
-
|
|
7
|
-
super
|
|
8
|
-
@server = Staticpress::Server.new
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def env(path)
|
|
12
|
-
{
|
|
13
|
-
'REQUEST_PATH' => path
|
|
14
|
-
}
|
|
15
|
-
end
|
|
5
|
+
class ServerTest < TestCase
|
|
6
|
+
let(:server) { Staticpress::Server.new }
|
|
16
7
|
|
|
17
8
|
def test_call_root
|
|
18
|
-
response =
|
|
9
|
+
response = server.call(env('/'))
|
|
19
10
|
assert_equal 200, response.first
|
|
20
11
|
assert_equal 'text/html', response[1]['Content-Type']
|
|
21
12
|
end
|
|
22
13
|
|
|
23
14
|
def test_call_image
|
|
24
|
-
response =
|
|
15
|
+
response = server.call(env('/ruby.png'))
|
|
25
16
|
assert_equal 200, response.first
|
|
26
17
|
assert_equal 'image/png', response[1]['Content-Type']
|
|
27
18
|
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require_relative '../test_case'
|
|
2
|
+
|
|
3
|
+
require 'staticpress/content/page'
|
|
4
|
+
require 'staticpress/content/post'
|
|
5
|
+
require 'staticpress/route'
|
|
6
|
+
require 'staticpress/site'
|
|
7
|
+
|
|
8
|
+
class SiteTest < TestCase
|
|
9
|
+
let(:site) { Staticpress::Site.new }
|
|
10
|
+
|
|
11
|
+
let(:index) { Staticpress::Content::Page.new :slug => '' }
|
|
12
|
+
let(:page) { Staticpress::Content::Page.new :slug => 'about' }
|
|
13
|
+
let(:post) { Staticpress::Content::Post.new :year => '2011', :month => '07', :day => '20', :title => 'hello' }
|
|
14
|
+
|
|
15
|
+
def test_find_content_by_env
|
|
16
|
+
assert_equal index, site.find_content_by_env(env('/'))
|
|
17
|
+
assert_equal page, site.find_content_by_env(env('/about'))
|
|
18
|
+
assert_equal post, site.find_content_by_env(env('/2011/07/20/hello'))
|
|
19
|
+
assert_nil site.find_content_by_env(env('/i/dont/exist'))
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
require_relative '../test_case'
|
|
2
|
+
|
|
3
|
+
require 'staticpress/helpers'
|
|
4
|
+
require 'staticpress/theme'
|
|
5
|
+
|
|
6
|
+
class ThemeTest < TestCase
|
|
7
|
+
include Staticpress::Helpers
|
|
8
|
+
|
|
9
|
+
let(:theme) { Staticpress::Theme.new :test_theme }
|
|
10
|
+
|
|
11
|
+
def setup
|
|
12
|
+
super
|
|
13
|
+
config.theme = :test_theme
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def test__equalsequals
|
|
17
|
+
assert_operator theme, :==, Staticpress::Theme.new(:test_theme)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def test_root
|
|
21
|
+
assert_equal theme.root, (Staticpress.blog_path + 'themes' + 'test_theme')
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def test_theme
|
|
25
|
+
assert_equal theme, Staticpress::Theme.theme
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def test_default_include
|
|
30
|
+
refute_respond_to theme, :default_include
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def test_keyed_includes
|
|
34
|
+
assert_equal((theme.root + 'includes' + 'list_posts.haml'), theme.keyed_includes['list_posts'])
|
|
35
|
+
assert_nil theme.keyed_includes['fake']
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def test_include_for
|
|
39
|
+
assert_equal (theme.root + 'includes' + 'list_posts.haml'), theme.include_for(:list_posts)
|
|
40
|
+
assert_nil theme.include_for(:fake)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def test_includes
|
|
44
|
+
assert_equal 1, theme.includes.count
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def test_default_layout
|
|
49
|
+
assert_equal (theme.root + 'layouts' + 'default.haml'), theme.default_layout
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def test_keyed_layouts
|
|
53
|
+
assert_equal((theme.root + 'layouts' + 'default.haml'), theme.keyed_layouts['default'])
|
|
54
|
+
assert_equal((theme.root + 'layouts' + 'post_index.haml'), theme.keyed_layouts['post_index'])
|
|
55
|
+
assert_nil theme.keyed_layouts['fake']
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def test_layout_for
|
|
59
|
+
assert_equal (theme.root + 'layouts' + 'default.haml'), theme.layout_for(:default)
|
|
60
|
+
assert_equal (theme.root + 'layouts' + 'post_index.haml'), theme.layout_for(:post_index)
|
|
61
|
+
assert_nil theme.layout_for(:fake)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def test_layouts
|
|
65
|
+
assert_equal 5, theme.layouts.count
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def test_default_view
|
|
70
|
+
assert_equal (theme.root + 'views' + 'default.haml'), theme.default_view
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def test_keyed_views
|
|
74
|
+
assert_equal((theme.root + 'views' + 'default.haml'), theme.keyed_views['default'])
|
|
75
|
+
assert_nil theme.keyed_views['fake']
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def test_view_for
|
|
79
|
+
assert_equal (theme.root + 'views' + 'default.haml'), theme.view_for(:default)
|
|
80
|
+
assert_nil theme.view_for(:fake)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def test_views
|
|
84
|
+
assert_equal 1, theme.views.count
|
|
85
|
+
end
|
|
86
|
+
end
|