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.
- 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
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe Path, "core extensions" do
|
3
|
+
|
4
|
+
def load(file)
|
5
|
+
(fixtures_path / "data" / file).load
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'loads json correctly' do
|
9
|
+
load('data.json').should eq("kind" => "json")
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'loads yaml correctly' do
|
13
|
+
load('data.yaml').should eq("kind" => "yaml")
|
14
|
+
load('data.yml').should eq("kind" => "yml")
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'loads ruby correctly' do
|
18
|
+
load('data.ruby').should eq("kind" => "ruby")
|
19
|
+
load('data.rb').should eq("kind" => "rb")
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'load .md correctly, when no front matter' do
|
23
|
+
load('text.md').should eq("content" => "This is the text")
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'load .md correctly, when empty front matter' do
|
27
|
+
load('empty.md').should eq("content" => "This is the text\n")
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'load .md correctly, when a front matter' do
|
31
|
+
load('data.md').should eq("kind" => "md", "content" => "This is the text")
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Polygon
|
3
|
+
describe Database, "entries" do
|
4
|
+
|
5
|
+
let(:database){ Database.new fixtures_path }
|
6
|
+
|
7
|
+
subject{ database.entries }
|
8
|
+
|
9
|
+
it 'is returned by dataset' do
|
10
|
+
subject.should eq(database.dataset(:entries))
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'returns a Alf::Iterator' do
|
14
|
+
subject.should be_a(Alf::Iterator)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'iterates tuples with entries' do
|
18
|
+
subject.each do |tuple|
|
19
|
+
tuple.should have_key(:entry)
|
20
|
+
tuple[:entry].should be_a(Entry)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'iterates tuples with entries of different paths' do
|
25
|
+
paths = subject.map{|t| t[:entry].relative_path.to_s }.uniq
|
26
|
+
paths.size.should eq(subject.to_a.size)
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Polygon
|
3
|
+
describe Database, "entries" do
|
4
|
+
|
5
|
+
let(:database){ Database.new fixtures_path }
|
6
|
+
|
7
|
+
subject{ database.sitemap }
|
8
|
+
|
9
|
+
it 'is returned by dataset' do
|
10
|
+
subject.should eq(database.dataset(:sitemap))
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'returns a Alf::Iterator' do
|
14
|
+
subject.should be_a(Alf::Iterator)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'iterates tuples with entries, path and lastmod' do
|
18
|
+
subject.each do |tuple|
|
19
|
+
tuple.should have_key(:entry)
|
20
|
+
tuple[:entry].should be_a(Entry)
|
21
|
+
|
22
|
+
tuple.should have_key(:path)
|
23
|
+
tuple[:path].should be_a(String)
|
24
|
+
|
25
|
+
tuple.should have_key(:lastmod)
|
26
|
+
tuple[:lastmod].should be_a(String)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Polygon
|
3
|
+
describe Entry, 'ancestors_or_self' do
|
4
|
+
|
5
|
+
subject{ entry.ancestors_or_self(filter) }
|
6
|
+
|
7
|
+
context 'when a normal entry in root' do
|
8
|
+
let(:filter){ false }
|
9
|
+
let(:entry){ Entry.new(Path.dir, Path.here % Path.dir) }
|
10
|
+
it "should contain all index files" do
|
11
|
+
expected = entry.index_files.map{|index|
|
12
|
+
Entry.new(Path.dir, index)
|
13
|
+
} + [ entry ]
|
14
|
+
subject.should eq(expected)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'when filtered' do
|
19
|
+
let(:filter){ true }
|
20
|
+
let(:entry){ Entry.new(Path.dir, Path.here % Path.dir) }
|
21
|
+
it "should contain only existing files" do
|
22
|
+
subject.should eq([ entry ])
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'when the root and not filtered' do
|
27
|
+
let(:filter){ false }
|
28
|
+
let(:entry){ Entry.new(Path.dir, 'index.yml') }
|
29
|
+
it "should be the singleton" do
|
30
|
+
subject.should eq([entry])
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'when the root and filtered' do
|
35
|
+
let(:filter){ true }
|
36
|
+
let(:entry){ Entry.new(Path.dir, "index.yml") }
|
37
|
+
it "should be empty" do
|
38
|
+
subject.should eq([])
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Polygon
|
3
|
+
describe Entry, 'divide' do
|
4
|
+
|
5
|
+
let(:entry){ Entry.new(Path.dir, Path.dir) }
|
6
|
+
|
7
|
+
subject{ entry / path }
|
8
|
+
|
9
|
+
context "when it stays inside the root" do
|
10
|
+
let(:path){ "somewhere/somefile.yml" }
|
11
|
+
it 'should return an Entry instance' do
|
12
|
+
subject.should be_a(Entry)
|
13
|
+
end
|
14
|
+
it 'should return the correct instance' do
|
15
|
+
subject.path.should eq(Path.dir / "somewhere/somefile.yml")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "when it exits the root" do
|
20
|
+
let(:path){ "../somefile.yml" }
|
21
|
+
it 'should return nil' do
|
22
|
+
subject.should be_nil
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Polygon
|
3
|
+
describe Entry, '==' do
|
4
|
+
|
5
|
+
subject{ left == right }
|
6
|
+
|
7
|
+
context 'when the same entries' do
|
8
|
+
let(:left) { Entry.new(Path.dir, Path.here % Path.dir) }
|
9
|
+
let(:right){ Entry.new(Path.dir, Path.here % Path.dir) }
|
10
|
+
it{ should be_true }
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'when not the same entries' do
|
14
|
+
let(:left) { Entry.new(Path.dir, Path.here % Path.dir) }
|
15
|
+
let(:right){ Entry.new(Path.dir, "another one") }
|
16
|
+
it{ should be_false }
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'when bad comparison' do
|
20
|
+
let(:left) { Entry.new(Path.dir, Path.here % Path.dir) }
|
21
|
+
let(:right){ 12 }
|
22
|
+
it{ should be_false }
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Polygon
|
3
|
+
describe Entry, 'exist?' do
|
4
|
+
|
5
|
+
subject{ entry.exist? }
|
6
|
+
|
7
|
+
context 'when it exists' do
|
8
|
+
let(:entry){ Entry.new(Path.dir, Path.here % Path.dir) }
|
9
|
+
it{ should be_true }
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'when it does not exists' do
|
13
|
+
let(:entry){ Entry.new(Path.dir, "nosuchone.md") }
|
14
|
+
it{ should be_false }
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Polygon
|
3
|
+
describe Entry, 'extensions' do
|
4
|
+
|
5
|
+
let(:entry){ Entry.new(Path.dir, Path.here % Path.dir, options) }
|
6
|
+
|
7
|
+
subject{ entry.extensions }
|
8
|
+
|
9
|
+
before do
|
10
|
+
subject.should be_a(Array)
|
11
|
+
subject.all?{|e| e.should be_a(String) }
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'with default options' do
|
15
|
+
let(:options){ {} }
|
16
|
+
it 'should contain expected extensions' do
|
17
|
+
subject.should eq(['yml', 'md'])
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'with explicit options' do
|
22
|
+
let(:options){ {:extensions => ["yml", "rb"]} }
|
23
|
+
it 'should contain expected extensions' do
|
24
|
+
subject.should eq(['yml', 'rb'])
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Polygon
|
3
|
+
describe Entry, 'hash' do
|
4
|
+
|
5
|
+
it 'should be consistent with ==' do
|
6
|
+
e = Entry.new(Path.dir, Path.here % Path.dir)
|
7
|
+
f = Entry.new(Path.dir, Path.here % Path.dir)
|
8
|
+
g = Entry.new(Path.dir, 'another one')
|
9
|
+
e.hash.should eq(f.hash)
|
10
|
+
e.hash.should_not eq(g.hash)
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Polygon
|
3
|
+
describe Entry, 'index?' do
|
4
|
+
|
5
|
+
subject{ entry.index? }
|
6
|
+
|
7
|
+
context 'when an index file' do
|
8
|
+
let(:entry){ Entry.new(Path.dir, "index.yml") }
|
9
|
+
it{ should be_true }
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'when not an index file' do
|
13
|
+
let(:entry){ Entry.new(Path.dir, "nosuchone.md") }
|
14
|
+
it{ should be_false }
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Polygon
|
3
|
+
describe Entry, 'index_files' do
|
4
|
+
|
5
|
+
let(:entry){ Entry.new(Path.dir, Path.here % Path.dir, options) }
|
6
|
+
|
7
|
+
subject{ entry.index_files }
|
8
|
+
|
9
|
+
before do
|
10
|
+
subject.should be_a(Array)
|
11
|
+
subject.all?{|e| e.should be_a(String) }
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'with default options' do
|
15
|
+
let(:options){ {} }
|
16
|
+
it 'should contain expected index files' do
|
17
|
+
subject.should eq(['index.yml', 'index.md'])
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'with explicit options' do
|
22
|
+
let(:options){ {:extensions => ["yml", "rb"]} }
|
23
|
+
it 'should contain expected index files' do
|
24
|
+
subject.should eq(['index.yml', 'index.rb'])
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Polygon
|
3
|
+
describe Entry, 'parent' do
|
4
|
+
|
5
|
+
subject{ entry.parent }
|
6
|
+
|
7
|
+
before do
|
8
|
+
subject.should be_a(Entry) unless subject.nil?
|
9
|
+
end
|
10
|
+
|
11
|
+
context 'when a normal entry' do
|
12
|
+
let(:entry){ Entry.new(Path.dir, Path.here % Path.dir) }
|
13
|
+
it "should be the last index file" do
|
14
|
+
subject.path.should eq(Path.dir / entry.index_file(-1))
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'when the second index file' do
|
19
|
+
let(:entry){ Entry.new(Path.dir, "index.md") }
|
20
|
+
it "should be the first index file" do
|
21
|
+
subject.path.should eq(Path.dir / entry.index_file(0))
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'when the first index file and not in root' do
|
26
|
+
let(:entry){ Entry.new(Path.dir, Path("subfolder") / "index.yml") }
|
27
|
+
it "should be the last index of the parent" do
|
28
|
+
subject.path.should eq(Path.dir / entry.index_file(-1))
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'when the first index file and not in' do
|
33
|
+
let(:entry){ Entry.new(Path.dir, "index.yml") }
|
34
|
+
it "should be nil" do
|
35
|
+
subject.should be_nil
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Polygon
|
3
|
+
describe Entry, 'path' do
|
4
|
+
|
5
|
+
let(:entry){ Entry.new(Path.dir, Path.here % Path.dir) }
|
6
|
+
|
7
|
+
subject{ entry.path }
|
8
|
+
|
9
|
+
it 'is a path instance' do
|
10
|
+
subject.should be_a(Path)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "is the concatenation of root and relative_path" do
|
14
|
+
subject.should eq(entry.root / entry.relative_path)
|
15
|
+
subject.should eq(Path.here)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Polygon
|
3
|
+
describe Entry, 'to_hash' do
|
4
|
+
|
5
|
+
let(:fixtures){ Entry.new(fixtures_path, "") }
|
6
|
+
|
7
|
+
subject{ entry.to_hash }
|
8
|
+
|
9
|
+
context 'on with_index_yml/say-hello.md' do
|
10
|
+
let(:entry){ fixtures / "with_index_yml/say-hello.md" }
|
11
|
+
it 'should take all data along ancestors' do
|
12
|
+
expected = {
|
13
|
+
"title" => "Say Hello",
|
14
|
+
"content" => "# How to Say Hello to World?\n\nThis way!\n",
|
15
|
+
"keywords" => ["say-hello", "with_index_yml/index.yml", "root"]
|
16
|
+
}
|
17
|
+
subject.should eq(expected)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/spec/spec_helper.rb
CHANGED
@@ -1,2 +1,18 @@
|
|
1
1
|
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
2
2
|
require 'polygon'
|
3
|
+
|
4
|
+
class Polygon::Entry
|
5
|
+
public :extensions, :index_files, :index_file
|
6
|
+
end
|
7
|
+
|
8
|
+
module Helpers
|
9
|
+
|
10
|
+
def fixtures_path
|
11
|
+
Path.dir / "fixtures"
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
RSpec.configure do |c|
|
17
|
+
c.include Helpers
|
18
|
+
end
|
data/spec/test_polygon.rb
CHANGED
@@ -5,4 +5,14 @@ describe Polygon do
|
|
5
5
|
Polygon.const_defined?(:VERSION).should be_true
|
6
6
|
end
|
7
7
|
|
8
|
+
def markdown(x)
|
9
|
+
x.upcase
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'installs a friendly html dialect' do
|
13
|
+
tpl = Tilt['wlang'].new{ "~{content}" }
|
14
|
+
got = tpl.render(self, :content => "hello world!")
|
15
|
+
got.should eq("HELLO WORLD!")
|
16
|
+
end
|
17
|
+
|
8
18
|
end
|
data/tasks/yard.rake
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# Installs a rake task to generate API documentation using yard.
|
2
|
+
#
|
3
|
+
# This file installs the 'rake yard' task. It is automatically generated by Noe from
|
4
|
+
# your .noespec file, and should therefore be configured there, under the
|
5
|
+
# variables/rake_tasks/yard entry, as illustrated below:
|
6
|
+
#
|
7
|
+
# variables:
|
8
|
+
# rake_tasks:
|
9
|
+
# yard:
|
10
|
+
# files: lib/**/*.rb
|
11
|
+
# options: []
|
12
|
+
# ...
|
13
|
+
#
|
14
|
+
# If you have specific needs requiring manual intervention on this file,
|
15
|
+
# don't forget to set safe-override to false in your noe specification:
|
16
|
+
#
|
17
|
+
# template-info:
|
18
|
+
# manifest:
|
19
|
+
# tasks/yard.rake:
|
20
|
+
# safe-override: false
|
21
|
+
#
|
22
|
+
# This file has been written to conform to yard v0.6.4. More information about
|
23
|
+
# yard and the rake task installed below can be found on http://yardoc.org/
|
24
|
+
#
|
25
|
+
begin
|
26
|
+
require "yard"
|
27
|
+
desc "Generate yard documentation"
|
28
|
+
YARD::Rake::YardocTask.new(:yard) do |t|
|
29
|
+
# Array of options passed to yardoc commandline. See 'yardoc --help' about this
|
30
|
+
t.options = ["--output-dir", "doc/api", "-", "README.md", "CHANGELOG.md", "LICENCE.md"]
|
31
|
+
|
32
|
+
# Array of ruby source files (and any extra documentation files
|
33
|
+
# separated by '-')
|
34
|
+
t.files = ["lib/**/*.rb"]
|
35
|
+
|
36
|
+
# A proc to call before running the task
|
37
|
+
# t.before = proc{ }
|
38
|
+
|
39
|
+
# A proc to call after running the task
|
40
|
+
# r.after = proc{ }
|
41
|
+
|
42
|
+
# An optional lambda to run against all objects being generated.
|
43
|
+
# Any object that the lambda returns false for will be excluded
|
44
|
+
# from documentation.
|
45
|
+
# t.verifier = lambda{|obj| true}
|
46
|
+
end
|
47
|
+
rescue LoadError
|
48
|
+
task :yard do
|
49
|
+
abort 'yard is not available. In order to run yard, you must: gem install yard'
|
50
|
+
end
|
51
|
+
end
|