polygon 0.0.3 → 0.9.1

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 (58) hide show
  1. data/CHANGELOG.md +0 -12
  2. data/Gemfile +5 -2
  3. data/Gemfile.lock +25 -10
  4. data/lib/polygon/base.rb +10 -8
  5. data/lib/polygon/core_ext/path.rb +24 -0
  6. data/lib/polygon/core_ext/rack/nocache.rb +27 -0
  7. data/lib/polygon/core_ext.rb +2 -0
  8. data/lib/polygon/database.rb +57 -0
  9. data/lib/polygon/dialect.rb +13 -0
  10. data/lib/polygon/entry.rb +101 -0
  11. data/lib/polygon/helpers.rb +43 -10
  12. data/lib/polygon/loader.rb +4 -2
  13. data/lib/polygon/script/gsub.rb +59 -0
  14. data/lib/polygon/script/launch.rb +75 -0
  15. data/lib/polygon/script.rb +38 -0
  16. data/lib/polygon/version.rb +2 -2
  17. data/lib/polygon.rb +4 -13
  18. data/polygon.gemspec +5 -3
  19. data/polygon.noespec +6 -4
  20. data/spec/core_ext/test_epath.rb +34 -0
  21. data/spec/database/test_entries.rb +30 -0
  22. data/spec/database/test_sitemap.rb +31 -0
  23. data/spec/entry/test_ancestors_or_self.rb +43 -0
  24. data/spec/entry/test_divide.rb +27 -0
  25. data/spec/entry/test_equality.rb +26 -0
  26. data/spec/entry/test_exist.rb +18 -0
  27. data/spec/entry/test_extensions.rb +29 -0
  28. data/spec/entry/test_hash.rb +14 -0
  29. data/spec/entry/test_index.rb +18 -0
  30. data/spec/entry/test_index_files.rb +29 -0
  31. data/spec/entry/test_parent.rb +40 -0
  32. data/spec/entry/test_path.rb +19 -0
  33. data/spec/entry/test_to_hash.rb +22 -0
  34. data/{test → spec}/fixtures/data/data.json +0 -0
  35. data/{test → spec}/fixtures/data/data.md +0 -0
  36. data/{test → spec}/fixtures/data/data.rb +0 -0
  37. data/{test → spec}/fixtures/data/data.ruby +0 -0
  38. data/{test → spec}/fixtures/data/data.yaml +0 -0
  39. data/{test → spec}/fixtures/data/data.yml +0 -0
  40. data/spec/fixtures/data/empty.md +3 -0
  41. data/{test → spec}/fixtures/data/text.md +0 -0
  42. data/{test → spec}/fixtures/index.yml +0 -0
  43. data/{test → spec}/fixtures/with_index_md/index.md +0 -0
  44. data/{test → spec}/fixtures/with_index_yml/index.yml +0 -0
  45. data/{test → spec}/fixtures/with_index_yml/say-hello.md +0 -0
  46. data/{test → spec}/fixtures/without_index/hello.md +0 -0
  47. data/spec/spec_helper.rb +16 -0
  48. data/spec/test_polygon.rb +10 -0
  49. data/tasks/yard.rake +51 -0
  50. metadata +161 -78
  51. checksums.yaml +0 -7
  52. data/lib/polygon/content.rb +0 -131
  53. data/lib/polygon/content_loader.rb +0 -78
  54. data/test/content/test_entry.rb +0 -99
  55. data/test/helper.rb +0 -5
  56. data/test/runall.rb +0 -1
  57. data/test/test_content.rb +0 -45
  58. data/test/test_content_loader.rb +0 -39
@@ -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
@@ -1,5 +0,0 @@
1
- $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
- require 'test/unit'
3
- require 'polygon'
4
- module Helper
5
- end
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
@@ -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