polygon 0.0.3 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +0 -12
- data/Gemfile +5 -2
- data/Gemfile.lock +25 -10
- data/lib/polygon/base.rb +10 -8
- data/lib/polygon/core_ext/path.rb +24 -0
- data/lib/polygon/core_ext/rack/nocache.rb +27 -0
- data/lib/polygon/core_ext.rb +2 -0
- data/lib/polygon/database.rb +57 -0
- data/lib/polygon/dialect.rb +13 -0
- data/lib/polygon/entry.rb +101 -0
- data/lib/polygon/helpers.rb +43 -10
- data/lib/polygon/loader.rb +4 -2
- data/lib/polygon/script/gsub.rb +59 -0
- data/lib/polygon/script/launch.rb +75 -0
- data/lib/polygon/script.rb +38 -0
- data/lib/polygon/version.rb +2 -2
- data/lib/polygon.rb +4 -13
- data/polygon.gemspec +5 -3
- data/polygon.noespec +6 -4
- data/spec/core_ext/test_epath.rb +34 -0
- data/spec/database/test_entries.rb +30 -0
- data/spec/database/test_sitemap.rb +31 -0
- data/spec/entry/test_ancestors_or_self.rb +43 -0
- data/spec/entry/test_divide.rb +27 -0
- data/spec/entry/test_equality.rb +26 -0
- data/spec/entry/test_exist.rb +18 -0
- data/spec/entry/test_extensions.rb +29 -0
- data/spec/entry/test_hash.rb +14 -0
- data/spec/entry/test_index.rb +18 -0
- data/spec/entry/test_index_files.rb +29 -0
- data/spec/entry/test_parent.rb +40 -0
- data/spec/entry/test_path.rb +19 -0
- data/spec/entry/test_to_hash.rb +22 -0
- data/{test → spec}/fixtures/data/data.json +0 -0
- data/{test → spec}/fixtures/data/data.md +0 -0
- data/{test → spec}/fixtures/data/data.rb +0 -0
- data/{test → spec}/fixtures/data/data.ruby +0 -0
- data/{test → spec}/fixtures/data/data.yaml +0 -0
- data/{test → spec}/fixtures/data/data.yml +0 -0
- data/spec/fixtures/data/empty.md +3 -0
- data/{test → spec}/fixtures/data/text.md +0 -0
- data/{test → spec}/fixtures/index.yml +0 -0
- data/{test → spec}/fixtures/with_index_md/index.md +0 -0
- data/{test → spec}/fixtures/with_index_yml/index.yml +0 -0
- data/{test → spec}/fixtures/with_index_yml/say-hello.md +0 -0
- data/{test → spec}/fixtures/without_index/hello.md +0 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/test_polygon.rb +10 -0
- data/tasks/yard.rake +51 -0
- metadata +161 -78
- checksums.yaml +0 -7
- data/lib/polygon/content.rb +0 -131
- data/lib/polygon/content_loader.rb +0 -78
- data/test/content/test_entry.rb +0 -99
- data/test/helper.rb +0 -5
- data/test/runall.rb +0 -1
- data/test/test_content.rb +0 -45
- data/test/test_content_loader.rb +0 -39
data/test/content/test_entry.rb
DELETED
@@ -1,99 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
module Polygon
|
3
|
-
|
4
|
-
class Content::Entry
|
5
|
-
public :extensions, :index_files, :parent, :ancestors_or_self, :loader
|
6
|
-
end
|
7
|
-
|
8
|
-
class ContentEntryTest < Test::Unit::TestCase
|
9
|
-
include Helper
|
10
|
-
|
11
|
-
def setup
|
12
|
-
@root = Path.dir/"../fixtures"
|
13
|
-
@loader = ContentLoader.new
|
14
|
-
@loader.enable_yaml!(".yml")
|
15
|
-
@loader.enable_yaml_front_matter!(".md")
|
16
|
-
@content = Content.new(@root, @loader)
|
17
|
-
@fixtures = Content::Entry.new(@content, @root)
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_loader
|
21
|
-
assert_equal @loader, @fixtures.loader
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_extensions
|
25
|
-
assert_equal [".yml", ".md"], @fixtures.extensions
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_index_files
|
29
|
-
assert_equal @loader.extensions.map{|e| "index#{e}"},
|
30
|
-
@fixtures.index_files
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_divide
|
34
|
-
assert_equal @root/"index.yml", (@fixtures/"index.yml").path
|
35
|
-
assert_equal @loader, (@fixtures/"index.yml").loader
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_exist?
|
39
|
-
assert @fixtures.exist?
|
40
|
-
assert (@fixtures/"index.yml").exist?
|
41
|
-
assert !(@fixtures/"index.md").exist?
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_parent
|
45
|
-
assert_nil @fixtures.parent
|
46
|
-
assert_nil (@fixtures/"index.yml").parent
|
47
|
-
assert_equal @fixtures/"index.yml", (@fixtures/"index.md").parent
|
48
|
-
assert_equal @fixtures/"index.md", (@fixtures/"say-hello.md").parent
|
49
|
-
assert_equal @fixtures/"index.md", (@fixtures/"with_index_yml").parent
|
50
|
-
assert_equal @fixtures/"with_index_yml/index.md", (@fixtures/"with_index_yml/say-hello.md").parent
|
51
|
-
assert_equal @fixtures/"index.md", (@fixtures/"with_index_md").parent
|
52
|
-
assert_equal @fixtures/"with_index_md/index.yml", (@fixtures/"with_index_md/index.md").parent
|
53
|
-
end
|
54
|
-
|
55
|
-
def test_ancestors_or_self
|
56
|
-
assert_equal [ @fixtures ], @fixtures.ancestors_or_self
|
57
|
-
assert_equal [
|
58
|
-
@fixtures/"index.yml",
|
59
|
-
@fixtures/"index.md",
|
60
|
-
@fixtures/"with_index_yml/index.yml",
|
61
|
-
@fixtures/"with_index_yml/index.md",
|
62
|
-
@fixtures/"with_index_yml/say-hello.md",
|
63
|
-
], (@fixtures/"with_index_yml/say-hello.md").ancestors_or_self
|
64
|
-
assert_equal [
|
65
|
-
@fixtures/"index.yml",
|
66
|
-
@fixtures/"with_index_yml/index.yml",
|
67
|
-
@fixtures/"with_index_yml/say-hello.md",
|
68
|
-
], (@fixtures/"with_index_yml/say-hello.md").ancestors_or_self(true)
|
69
|
-
end
|
70
|
-
|
71
|
-
def test_to_hash
|
72
|
-
content = @fixtures/"with_index_yml/say-hello.md"
|
73
|
-
|
74
|
-
expected = {
|
75
|
-
"title" => "Say Hello",
|
76
|
-
"content" => "# How to Say Hello to World?\n\nThis way!\n",
|
77
|
-
"keywords" => ["say-hello", "with_index_yml/index.yml", "root"],
|
78
|
-
"__path__" => content.path,
|
79
|
-
"__url__" => "with_index_yml/say-hello" }
|
80
|
-
assert_equal expected, content.to_hash
|
81
|
-
assert_equal expected, content.to_hash(true)
|
82
|
-
|
83
|
-
expected = {
|
84
|
-
"title" => "Say Hello",
|
85
|
-
"content" => "# How to Say Hello to World?\n\nThis way!\n",
|
86
|
-
"keywords" => ["say-hello"],
|
87
|
-
"__path__" => content.path,
|
88
|
-
"__url__" => "with_index_yml/say-hello" }
|
89
|
-
assert_equal expected, content.to_hash(false)
|
90
|
-
end
|
91
|
-
|
92
|
-
def test_it_splits_md_files_correctly
|
93
|
-
content = (@fixtures/"without_index"/"hello.md").to_hash
|
94
|
-
assert_equal "Welcome!", content["title"]
|
95
|
-
assert_match /^Welcome to/, content["content"]
|
96
|
-
end
|
97
|
-
|
98
|
-
end
|
99
|
-
end
|
data/test/helper.rb
DELETED
data/test/runall.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
Dir[File.expand_path("../**/test_*.rb", __FILE__)].each{|f| load(f)}
|
data/test/test_content.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
module Polygon
|
3
|
-
class ContentTest < Test::Unit::TestCase
|
4
|
-
include Helper
|
5
|
-
|
6
|
-
def setup
|
7
|
-
@root = Path.dir/"../fixtures"
|
8
|
-
@loader = ContentLoader.new
|
9
|
-
@loader.enable_yaml!(".yml")
|
10
|
-
@loader.enable_yaml_front_matter!(".md")
|
11
|
-
@content = Content.new(@root, @loader)
|
12
|
-
end
|
13
|
-
|
14
|
-
def assert_entry(entry)
|
15
|
-
assert_instance_of Content::Entry, entry
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_initialize
|
19
|
-
assert_instance_of Content, Content.new(@root)
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_entry_should_be_a_factory
|
23
|
-
entry = @content.entry(@root/"index.yml")
|
24
|
-
assert_entry entry
|
25
|
-
assert_equal @content, entry.content
|
26
|
-
assert_equal @root/"index.yml", entry.path
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_entry_should_serve_relative_paths
|
30
|
-
relative = (@root/"index.yml").relative_to(@root)
|
31
|
-
assert_entry @content.entry(relative)
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_entry_should_serve_valid_absolute_paths
|
35
|
-
assert_entry @content.entry(@root/"index.yml")
|
36
|
-
assert_entry @content.entry(@root/:data/"data.yml")
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_entry_should_not_serve_outside_root
|
40
|
-
assert_nil @content.entry(Path.home)
|
41
|
-
assert_nil @content.entry(@root.parent)
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
45
|
-
end
|
data/test/test_content_loader.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
module Polygon
|
3
|
-
class ContentLoaderTest < Test::Unit::TestCase
|
4
|
-
include Helper
|
5
|
-
|
6
|
-
def setup
|
7
|
-
@loader = ContentLoader.new
|
8
|
-
@loader.enable_all!
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_load
|
12
|
-
fixtures = Path.dir/:fixtures/:data
|
13
|
-
|
14
|
-
assert_equal({"kind" => "yml"}, @loader.load(fixtures/"data.yml"))
|
15
|
-
assert_equal({"kind" => "yaml"}, @loader.load(fixtures/"data.yaml"))
|
16
|
-
assert_equal({"kind" => "json"}, @loader.load(fixtures/"data.json"))
|
17
|
-
assert_equal({"kind" => "rb"}, @loader.load(fixtures/"data.rb"))
|
18
|
-
assert_equal({"kind" => "ruby"}, @loader.load(fixtures/"data.ruby"))
|
19
|
-
|
20
|
-
assert_equal({"kind" => "md", "content" => "This is the text"},
|
21
|
-
@loader.load(fixtures/"data.md"))
|
22
|
-
assert_equal({"content" => "This is the text"},
|
23
|
-
@loader.load(fixtures/"text.md"))
|
24
|
-
|
25
|
-
assert_raise(Errno::ENOENT){
|
26
|
-
@loader.load(fixtures/"no-such-one.yml")
|
27
|
-
}
|
28
|
-
assert_raise(RuntimeError, /Unable to load.*unrecognized extension/){
|
29
|
-
@loader.load(fixtures/"data.notarecognized")
|
30
|
-
}
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_extensions
|
34
|
-
assert_equal [".yml", ".yaml", ".json", ".rb", ".ruby", ".md"],
|
35
|
-
@loader.extensions
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
39
|
-
end
|