marsdawn 0.0.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.
- checksums.yaml +15 -0
- data/.coveralls.yml +2 -0
- data/.gitignore +20 -0
- data/.travis.yml +7 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +22 -0
- data/README.md +119 -0
- data/Rakefile +12 -0
- data/bin/marsdawn +6 -0
- data/lib/marsdawn/builder.rb +35 -0
- data/lib/marsdawn/command.rb +154 -0
- data/lib/marsdawn/config.rb +31 -0
- data/lib/marsdawn/search/rroonga.rb +83 -0
- data/lib/marsdawn/search.rb +16 -0
- data/lib/marsdawn/site/breadcrumb.rb +30 -0
- data/lib/marsdawn/site/indexer.rb +78 -0
- data/lib/marsdawn/site/link.rb +28 -0
- data/lib/marsdawn/site/page.rb +118 -0
- data/lib/marsdawn/site/page_nav.rb +24 -0
- data/lib/marsdawn/site/search_box.rb +27 -0
- data/lib/marsdawn/site/search_page.rb +35 -0
- data/lib/marsdawn/site.rb +70 -0
- data/lib/marsdawn/source/document.rb +36 -0
- data/lib/marsdawn/source/front_matter.rb +25 -0
- data/lib/marsdawn/source/kramdown/parser.rb +56 -0
- data/lib/marsdawn/source.rb +164 -0
- data/lib/marsdawn/storage/active_record/marsdawn.rb +20 -0
- data/lib/marsdawn/storage/active_record.rb +83 -0
- data/lib/marsdawn/storage/base.rb +44 -0
- data/lib/marsdawn/storage/file_system.rb +83 -0
- data/lib/marsdawn/storage/redis.rb +0 -0
- data/lib/marsdawn/storage/test.rb +20 -0
- data/lib/marsdawn/storage/test_not_implemented_error.rb +6 -0
- data/lib/marsdawn/storage.rb +22 -0
- data/lib/marsdawn/util.rb +39 -0
- data/lib/marsdawn/version.rb +3 -0
- data/lib/marsdawn.rake +9 -0
- data/lib/marsdawn.rb +55 -0
- data/marsdawn.gemspec +25 -0
- data/spec/_compiled_doc/.gitkeep +0 -0
- data/spec/_test_doc/config.yml +10 -0
- data/spec/_test_doc/docs01/.index.md +1 -0
- data/spec/_test_doc/docs01/.marsdawn.yml +4 -0
- data/spec/_test_doc/docs01/010_about.md +4 -0
- data/spec/_test_doc/docs01/020_tutorial/.index.md +0 -0
- data/spec/_test_doc/docs01/020_tutorial/010_install.md +6 -0
- data/spec/_test_doc/docs01/020_tutorial/020_getting_start.md +9 -0
- data/spec/_test_doc/docs01/030_reference/1up.md +0 -0
- data/spec/_test_doc/docs01/030_reference/each.md +0 -0
- data/spec/_test_doc/docs01/030_reference/z-index.md +0 -0
- data/spec/_test_doc/docs01/040_appendix.md +3 -0
- data/spec/_test_doc/no_config/.gitkeep +0 -0
- data/spec/_test_doc/no_key/.marsdawn.yml +3 -0
- data/spec/_test_doc/samples/010_sample-document.md +4 -0
- data/spec/_test_doc/samples/test_document.md +1 -0
- data/spec/_tmp/.gitkeep +0 -0
- data/spec/lib/marsdawn/command_spec.rb +144 -0
- data/spec/lib/marsdawn/config_spec.rb +41 -0
- data/spec/lib/marsdawn/site/page_spec.rb +122 -0
- data/spec/lib/marsdawn/site_spec.rb +67 -0
- data/spec/lib/marsdawn/source/document_spec.rb +178 -0
- data/spec/lib/marsdawn/source/front_matter_spec.rb +55 -0
- data/spec/lib/marsdawn/source_spec.rb +40 -0
- data/spec/lib/marsdawn/storage/active_record_spec.rb +47 -0
- data/spec/lib/marsdawn/storage/file_system_spec.rb +46 -0
- data/spec/lib/marsdawn/storage_spec.rb +29 -0
- data/spec/lib/marsdawn/util_spec.rb +57 -0
- data/spec/spec_helper.rb +12 -0
- data/spec/stubs/groonga.rb +17 -0
- data/spec/stubs/marsdawn_docs.rb +40 -0
- metadata +203 -0
@@ -0,0 +1,122 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path(File.join('../../../', 'spec_helper'), File.dirname(__FILE__))
|
4
|
+
|
5
|
+
describe Marsdawn::Site::Page do
|
6
|
+
|
7
|
+
before :all do
|
8
|
+
@source_path = File.join($TEST_DOC_DIR, 'docs01')
|
9
|
+
@storage_config = {type: 'FileSystem', path: $COMPILED_DOC_DIR}
|
10
|
+
Marsdawn.build do |config|
|
11
|
+
config[:source] = @source_path
|
12
|
+
config[:storage] = @storage_config
|
13
|
+
end
|
14
|
+
@site = Marsdawn::Site.new(key: 'test_docs01') do |config|
|
15
|
+
config[:storage] = @storage_config
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def site
|
20
|
+
@site
|
21
|
+
end
|
22
|
+
|
23
|
+
def page
|
24
|
+
@page
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'with top page' do
|
28
|
+
before :all do
|
29
|
+
@page = site.page('/')
|
30
|
+
end
|
31
|
+
it 'should return the page title.' do
|
32
|
+
expect(page.title).to eq('Test Document 01')
|
33
|
+
end
|
34
|
+
it 'should return the breadcrumb.' do
|
35
|
+
expect(page.breadcrumb).to eq({})
|
36
|
+
expect(page.breadcrumb.to_s).to eq('')
|
37
|
+
end
|
38
|
+
it 'should return the neighbor pages.' do
|
39
|
+
expect(page.neighbor.keys).to eq(%w(/about /tutorial /appendix))
|
40
|
+
end
|
41
|
+
it 'should return the top page.' do
|
42
|
+
expect(page.top.uri).to eq('/')
|
43
|
+
end
|
44
|
+
it 'should return the parent page.' do
|
45
|
+
expect(page.parent).to be_nil
|
46
|
+
end
|
47
|
+
it 'should return the under pages.' do
|
48
|
+
expect(page.under.keys).to eq(%w(/about /tutorial /tutorial/install /tutorial/getting_start /reference/1up /reference/each /reference/z-index /appendix))
|
49
|
+
end
|
50
|
+
it 'should return the page navigation.' do
|
51
|
+
expect(page.page_nav[:prev_page]).to be_nil
|
52
|
+
expect(page.page_nav[:next_page].uri).to eq('/about')
|
53
|
+
expect(page.page_nav.to_s).to match(/^<ul>.*<\/ul>$/m)
|
54
|
+
end
|
55
|
+
it 'should return the link object to this page.' do
|
56
|
+
expect(page.link.uri).to eq('/')
|
57
|
+
expect(page.link.to_s).to eq('<a href="/" title="Test Document 01">Test Document 01</a>')
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'with middle page' do
|
62
|
+
before :all do
|
63
|
+
@page = site.page('/tutorial')
|
64
|
+
end
|
65
|
+
it 'should return the breadcrumb.' do
|
66
|
+
expect(page.breadcrumb.keys).to eq(%w(/))
|
67
|
+
end
|
68
|
+
it 'should return the neighbor pages.' do
|
69
|
+
expect(page.neighbor.keys).to eq(%w(/about /tutorial /appendix))
|
70
|
+
end
|
71
|
+
it 'should return the top page.' do
|
72
|
+
expect(page.top.uri).to eq('/')
|
73
|
+
end
|
74
|
+
it 'should return the parent page.' do
|
75
|
+
expect(page.parent.uri).to eq('/')
|
76
|
+
end
|
77
|
+
it 'should return the under pages.' do
|
78
|
+
expect(page.under.keys).to eq(%w(/tutorial/install /tutorial/getting_start))
|
79
|
+
end
|
80
|
+
it 'should return the page navigation.' do
|
81
|
+
expect(page.page_nav[:prev_page].uri).to eq('/about')
|
82
|
+
expect(page.page_nav[:next_page].uri).to eq('/tutorial/install')
|
83
|
+
end
|
84
|
+
it 'should return the link object to this page.' do
|
85
|
+
expect(page.link.uri).to eq('/tutorial')
|
86
|
+
expect(page.link.to_s).to eq('<a href="/tutorial" title="Tutorial">Tutorial</a>')
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context 'with bottom page' do
|
91
|
+
before :all do
|
92
|
+
@page = site.page('/tutorial/install')
|
93
|
+
end
|
94
|
+
it 'should return the breadcrumb.' do
|
95
|
+
expect(page.breadcrumb.keys).to eq(%w(/ /tutorial))
|
96
|
+
end
|
97
|
+
it 'should return the neighbor pages.' do
|
98
|
+
expect(page.neighbor.keys).to eq(%w(/tutorial/install /tutorial/getting_start))
|
99
|
+
end
|
100
|
+
it 'should return the top page.' do
|
101
|
+
expect(page.top.uri).to eq('/')
|
102
|
+
end
|
103
|
+
it 'should return the parent page.' do
|
104
|
+
expect(page.parent.uri).to eq('/tutorial')
|
105
|
+
end
|
106
|
+
it 'should return the paretn pages.' do
|
107
|
+
expect(page.parent.uri).to eq('/tutorial')
|
108
|
+
end
|
109
|
+
it 'should return the under pages.' do
|
110
|
+
expect(page.under.keys).to eq(%w())
|
111
|
+
end
|
112
|
+
it 'should return the page navigation.' do
|
113
|
+
expect(page.page_nav[:prev_page].uri).to eq('/tutorial')
|
114
|
+
expect(page.page_nav[:next_page].uri).to eq('/tutorial/getting_start')
|
115
|
+
end
|
116
|
+
it 'should return the link object to this page.' do
|
117
|
+
expect(page.link.uri).to eq('/tutorial/install')
|
118
|
+
expect(page.link.to_s).to eq('<a href="/tutorial/install" title="Install">Install</a>')
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path(File.join('../../', 'spec_helper'), File.dirname(__FILE__))
|
4
|
+
|
5
|
+
describe Marsdawn::Site do
|
6
|
+
|
7
|
+
before :all do
|
8
|
+
@source_path = File.join($TEST_DOC_DIR, 'docs01')
|
9
|
+
@storage_config = {type: 'FileSystem', path: $COMPILED_DOC_DIR}
|
10
|
+
Marsdawn.build do |config|
|
11
|
+
config[:source] = @source_path
|
12
|
+
config[:storage] = @storage_config
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def site
|
17
|
+
@site
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'with default options' do
|
21
|
+
before :all do
|
22
|
+
@site = Marsdawn::Site.new(key: 'test_docs01') do |config|
|
23
|
+
config[:storage] = @storage_config
|
24
|
+
end
|
25
|
+
end
|
26
|
+
it 'should return the page.' do
|
27
|
+
expect(site.page('/tutorial/install')).to be_a_kind_of(Marsdawn::Site::Page)
|
28
|
+
end
|
29
|
+
it 'should return full path.' do
|
30
|
+
expect(site.full_path('/about')).to eq('/about')
|
31
|
+
expect(site.full_path('/reference/each')).to eq('/reference/each')
|
32
|
+
end
|
33
|
+
it 'should return the index.' do
|
34
|
+
expect(site.index).to be_a_kind_of(Marsdawn::Site::Indexer)
|
35
|
+
expect(site.index.to_s).to match(/<ul>.*<\/ul>/)
|
36
|
+
end
|
37
|
+
it 'should return the page title.' do
|
38
|
+
expect(site.page_title('/about')).to eq('About')
|
39
|
+
expect(site.page_title('/tutorial/getting_start')).to eq('Getting start using MarsDawn')
|
40
|
+
end
|
41
|
+
it 'should return the site title.' do
|
42
|
+
expect(site.title).to eq('Test Document')
|
43
|
+
end
|
44
|
+
it 'should return the site title link.' do
|
45
|
+
expect(site.title_link.uri).to eq('/')
|
46
|
+
end
|
47
|
+
it 'should return if the site is searchable.' do
|
48
|
+
expect(site.searchable?).to be_falsey
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'with base_path options' do
|
53
|
+
before :all do
|
54
|
+
@site = Marsdawn::Site.new(key: 'test_docs01', base_path: '/test') do |config|
|
55
|
+
config[:storage] = @storage_config
|
56
|
+
end
|
57
|
+
end
|
58
|
+
it 'should return full path.' do
|
59
|
+
expect(site.full_path('/about')).to eq('/test/about')
|
60
|
+
expect(site.full_path('/reference/each')).to eq('/test/reference/each')
|
61
|
+
end
|
62
|
+
it 'should return the site title link.' do
|
63
|
+
expect(site.title_link.uri).to eq('/test/')
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
@@ -0,0 +1,178 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path(File.join('../../../', 'spec_helper'), File.dirname(__FILE__))
|
4
|
+
Marsdawn.require_lib 'source/document'
|
5
|
+
|
6
|
+
describe Marsdawn::Source::Document, '#read' do
|
7
|
+
it 'should generate title attribute.' do
|
8
|
+
doc = Marsdawn::Source::Document.read(File.join($TEST_DOC_DIR, 'samples/test_document.md'))
|
9
|
+
expect(doc.front_matter).to eq({
|
10
|
+
title: 'Test document',
|
11
|
+
link_key: 'Test document'
|
12
|
+
})
|
13
|
+
end
|
14
|
+
it 'should generate title attribute for number prefix.' do
|
15
|
+
doc = Marsdawn::Source::Document.read(File.join($TEST_DOC_DIR, 'samples/010_sample-document.md'))
|
16
|
+
expect(doc.front_matter).to eq({
|
17
|
+
title: 'Sample document',
|
18
|
+
link_key: 'Test Document'
|
19
|
+
})
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe Marsdawn::Source::Document, '#new' do
|
24
|
+
context 'with front-matter' do
|
25
|
+
it 'should generate attributes.' do
|
26
|
+
doc = Marsdawn::Source::Document.new <<-'EOS'
|
27
|
+
---
|
28
|
+
foo: bar
|
29
|
+
---
|
30
|
+
Header
|
31
|
+
======
|
32
|
+
lorem ipsum
|
33
|
+
EOS
|
34
|
+
expect(doc.front_matter).to eq({
|
35
|
+
title:'Header',
|
36
|
+
link_key: 'Header',
|
37
|
+
anchors: {'Header' => 'header'},
|
38
|
+
foo: 'bar'
|
39
|
+
})
|
40
|
+
expect(doc.to_html).to eq("<h1 id=\"header\"><a name=\"header\"></a>Header</h1>\n<p>lorem ipsum</p>\n")
|
41
|
+
end
|
42
|
+
it 'should use front-matter title attribute.' do
|
43
|
+
doc = Marsdawn::Source::Document.new <<-'EOS'
|
44
|
+
---
|
45
|
+
title: Test Document
|
46
|
+
tags: [Ruby, Develop, String]
|
47
|
+
---
|
48
|
+
Header
|
49
|
+
======
|
50
|
+
lorem ipsum
|
51
|
+
EOS
|
52
|
+
expect(doc.front_matter).to eq({
|
53
|
+
title:'Test Document',
|
54
|
+
link_key: 'Header',
|
55
|
+
anchors: {'Header' => 'header'},
|
56
|
+
tags:['Ruby', 'Develop', 'String']
|
57
|
+
})
|
58
|
+
expect(doc.to_html).to eq("<h1 id=\"header\"><a name=\"header\"></a>Header</h1>\n<p>lorem ipsum</p>\n")
|
59
|
+
end
|
60
|
+
it 'should use front-matter link_key attribute.' do
|
61
|
+
doc = Marsdawn::Source::Document.new <<-'EOS'
|
62
|
+
---
|
63
|
+
link_key: Test Document Header
|
64
|
+
---
|
65
|
+
Header
|
66
|
+
======
|
67
|
+
lorem ipsum
|
68
|
+
EOS
|
69
|
+
expect(doc.front_matter).to eq({
|
70
|
+
title:'Header',
|
71
|
+
link_key: 'Test Document Header',
|
72
|
+
anchors: {'Header' => 'header'}
|
73
|
+
})
|
74
|
+
expect(doc.to_html).to eq("<h1 id=\"header\"><a name=\"header\"></a>Header</h1>\n<p>lorem ipsum</p>\n")
|
75
|
+
end
|
76
|
+
end
|
77
|
+
context 'without front-matter' do
|
78
|
+
it 'should generate attributes.' do
|
79
|
+
doc = Marsdawn::Source::Document.new <<-'EOS'
|
80
|
+
Sample Document
|
81
|
+
===============
|
82
|
+
lorem ipsum
|
83
|
+
EOS
|
84
|
+
expect(doc.front_matter).to eq({
|
85
|
+
title:'Sample Document',
|
86
|
+
link_key: 'Sample Document',
|
87
|
+
anchors: {'Sample Document' => 'sample-document'}
|
88
|
+
})
|
89
|
+
expect(doc.to_html).to eq("<h1 id=\"sample-document\"><a name=\"sample-document\"></a>Sample Document</h1>\n<p>lorem ipsum</p>\n")
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe Marsdawn::Source::Document, '#new' do
|
95
|
+
context 'with front-matter' do
|
96
|
+
it 'should generate attributes.' do
|
97
|
+
doc = Marsdawn::Source::Document.new <<-'EOS'
|
98
|
+
---
|
99
|
+
foo: bar
|
100
|
+
---
|
101
|
+
Header
|
102
|
+
======
|
103
|
+
lorem ipsum
|
104
|
+
EOS
|
105
|
+
expect(doc.front_matter).to eq({
|
106
|
+
title:'Header',
|
107
|
+
link_key: 'Header',
|
108
|
+
anchors: {'Header' => 'header'},
|
109
|
+
foo: 'bar'
|
110
|
+
})
|
111
|
+
expect(doc.to_html).to eq("<h1 id=\"header\"><a name=\"header\"></a>Header</h1>\n<p>lorem ipsum</p>\n")
|
112
|
+
end
|
113
|
+
it 'should use front-matter title attribute.' do
|
114
|
+
doc = Marsdawn::Source::Document.new <<-'EOS'
|
115
|
+
---
|
116
|
+
title: Test Document
|
117
|
+
tags: [Ruby, Develop, String]
|
118
|
+
---
|
119
|
+
Header
|
120
|
+
======
|
121
|
+
lorem ipsum
|
122
|
+
EOS
|
123
|
+
expect(doc.front_matter).to eq({
|
124
|
+
title:'Test Document',
|
125
|
+
link_key: 'Header',
|
126
|
+
anchors: {'Header' => 'header'},
|
127
|
+
tags:['Ruby', 'Develop', 'String']
|
128
|
+
})
|
129
|
+
expect(doc.to_html).to eq("<h1 id=\"header\"><a name=\"header\"></a>Header</h1>\n<p>lorem ipsum</p>\n")
|
130
|
+
end
|
131
|
+
it 'should use front-matter link_key attribute.' do
|
132
|
+
doc = Marsdawn::Source::Document.new <<-'EOS'
|
133
|
+
---
|
134
|
+
link_key: Test Document Header
|
135
|
+
---
|
136
|
+
Header
|
137
|
+
======
|
138
|
+
lorem ipsum
|
139
|
+
EOS
|
140
|
+
expect(doc.front_matter).to eq({
|
141
|
+
title:'Header',
|
142
|
+
link_key: 'Test Document Header',
|
143
|
+
anchors: {'Header' => 'header'}
|
144
|
+
})
|
145
|
+
expect(doc.to_html).to eq("<h1 id=\"header\"><a name=\"header\"></a>Header</h1>\n<p>lorem ipsum</p>\n")
|
146
|
+
end
|
147
|
+
end
|
148
|
+
context 'without front-matter' do
|
149
|
+
it 'should generate attributes.' do
|
150
|
+
doc = Marsdawn::Source::Document.new <<-'EOS'
|
151
|
+
Sample Document
|
152
|
+
===============
|
153
|
+
lorem ipsum
|
154
|
+
EOS
|
155
|
+
expect(doc.front_matter).to eq({
|
156
|
+
title:'Sample Document',
|
157
|
+
link_key: 'Sample Document',
|
158
|
+
anchors: {'Sample Document' => 'sample-document'}
|
159
|
+
})
|
160
|
+
expect(doc.to_html).to eq("<h1 id=\"sample-document\"><a name=\"sample-document\"></a>Sample Document</h1>\n<p>lorem ipsum</p>\n")
|
161
|
+
end
|
162
|
+
it 'should use front-matter and ex-tags.' do
|
163
|
+
doc = Marsdawn::Source::Document.new <<-'EOS'
|
164
|
+
{::front_matter title="Test Doc" /}
|
165
|
+
Header
|
166
|
+
======
|
167
|
+
lorem ipsum
|
168
|
+
EOS
|
169
|
+
expect(doc.front_matter).to eq({
|
170
|
+
title:'Test Doc',
|
171
|
+
link_key: 'Test Doc',
|
172
|
+
anchors: {'Header' => 'header'}
|
173
|
+
})
|
174
|
+
expect(doc.to_html).to eq("<h1 id=\"header\"><a name=\"header\"></a>Header</h1>\n<p>lorem ipsum</p>\n")
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path(File.join('../../../', 'spec_helper'), File.dirname(__FILE__))
|
4
|
+
Marsdawn.require_lib 'source/front_matter'
|
5
|
+
|
6
|
+
|
7
|
+
describe Marsdawn::Source::FrontMatter do
|
8
|
+
context 'with front-matter' do
|
9
|
+
it 'should parse the attributes.' do
|
10
|
+
doc = Marsdawn::Source::FrontMatter.new <<-'EOS'
|
11
|
+
---
|
12
|
+
title: Test Document
|
13
|
+
tags: [Ruby, Develop, String]
|
14
|
+
---
|
15
|
+
Header
|
16
|
+
======
|
17
|
+
lorem ipsum
|
18
|
+
EOS
|
19
|
+
expect(doc.attr).to eq({title:'Test Document', tags:['Ruby', 'Develop', 'String']})
|
20
|
+
expect(doc.content).to eq("Header\n======\nlorem ipsum\n")
|
21
|
+
end
|
22
|
+
it 'should parse the attributes with "---" content.' do
|
23
|
+
doc = Marsdawn::Source::FrontMatter.new <<-'EOS'
|
24
|
+
---
|
25
|
+
title: Test Document
|
26
|
+
tags: [Ruby, Develop, String]
|
27
|
+
---
|
28
|
+
Header
|
29
|
+
---
|
30
|
+
lorem ipsum
|
31
|
+
EOS
|
32
|
+
expect(doc.attr).to eq({title:'Test Document', tags:['Ruby', 'Develop', 'String']})
|
33
|
+
expect(doc.content).to eq("Header\n---\nlorem ipsum\n")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
context 'without front-matter' do
|
37
|
+
it 'should get content with empty attribute.' do
|
38
|
+
doc = Marsdawn::Source::FrontMatter.new <<-'EOS'
|
39
|
+
# Test Title
|
40
|
+
lorem ipsum
|
41
|
+
EOS
|
42
|
+
expect(doc.attr).to eq({})
|
43
|
+
expect(doc.content).to eq("# Test Title\nlorem ipsum\n")
|
44
|
+
end
|
45
|
+
it 'should get content with empty attribute even with "---" content.' do
|
46
|
+
doc = Marsdawn::Source::FrontMatter.new <<-'EOS'
|
47
|
+
Test Title
|
48
|
+
---
|
49
|
+
lorem ipsum
|
50
|
+
EOS
|
51
|
+
expect(doc.attr).to eq({})
|
52
|
+
expect(doc.content).to eq("Test Title\n---\nlorem ipsum\n")
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path(File.join('../../', 'spec_helper'), File.dirname(__FILE__))
|
4
|
+
require File.expand_path(File.join('../../../lib/marsdawn', 'source'), File.dirname(__FILE__))
|
5
|
+
|
6
|
+
describe Marsdawn::Source do
|
7
|
+
context 'when access to invalid source document' do
|
8
|
+
it 'should raise error when the specified path does not exist.' do
|
9
|
+
expect {Marsdawn::Source.new(File.join($TEST_DOC_DIR, 'dummy'))}.to raise_error(RuntimeError, /^No source directory/)
|
10
|
+
end
|
11
|
+
it 'should raise error when the doc_info file does not exist.' do
|
12
|
+
expect {Marsdawn::Source.new(File.join($TEST_DOC_DIR, 'no_config'))}.to raise_error(RuntimeError, /^There is no doc_info file/)
|
13
|
+
end
|
14
|
+
it 'should raise error when the document key is not specified in the config file.' do
|
15
|
+
expect {Marsdawn::Source.new(File.join($TEST_DOC_DIR, 'no_key'))}.to raise_error(RuntimeError, /^The document key should be specified/)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
context 'when access to valid source document' do
|
19
|
+
it 'should load config file.' do
|
20
|
+
mdx = Marsdawn::Source.new(File.join($TEST_DOC_DIR, 'docs01'))
|
21
|
+
info = mdx.doc_info
|
22
|
+
expect(info[:key]).to eq 'test_docs01'
|
23
|
+
expect(info[:lang]).to eq 'en'
|
24
|
+
expect(info[:title]).to eq 'Test Document'
|
25
|
+
expect(info[:version]).to eq '0.0.1'
|
26
|
+
end
|
27
|
+
it 'should use default options.' do
|
28
|
+
mdx = Marsdawn::Source.new(File.join($TEST_DOC_DIR, 'docs01'))
|
29
|
+
info = mdx.doc_info
|
30
|
+
expect(info[:markdown_extname]).to eq '.md'
|
31
|
+
expect(info[:encoding]).to eq 'utf-8'
|
32
|
+
expect(info[:link_defs]).to eq({})
|
33
|
+
end
|
34
|
+
it 'should read right source documents.' do
|
35
|
+
mdx = Marsdawn::Source.new(File.join($TEST_DOC_DIR, 'docs01'))
|
36
|
+
uris = %w(/ /about /tutorial /tutorial/install /tutorial/getting_start /reference/1up /reference/each /reference/z-index /appendix)
|
37
|
+
expect(mdx.local2uri.map{|k,v| v}).to eq(uris)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path(File.join('../../../', 'spec_helper'), File.dirname(__FILE__))
|
4
|
+
require File.expand_path(File.join('../../../', 'stubs', 'marsdawn_docs'), File.dirname(__FILE__))
|
5
|
+
Marsdawn.require_lib 'storage/active_record'
|
6
|
+
|
7
|
+
describe Marsdawn::Storage::ActiveRecord do
|
8
|
+
|
9
|
+
before do
|
10
|
+
conf = {}
|
11
|
+
opts = {key: 'unit_test'}
|
12
|
+
@storage = Marsdawn::Storage::ActiveRecord.new(conf, opts)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should write and read the document info.' do
|
16
|
+
doc_info = {foo: 'bar', xyz: 999, arr: %w(a b c)}
|
17
|
+
@storage.prepare
|
18
|
+
@storage.set_document_info doc_info
|
19
|
+
@storage.finalize
|
20
|
+
expect(@storage.get_document_info).to eq(doc_info)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should write and read the documents.' do
|
24
|
+
data = {}
|
25
|
+
data['/'] = {
|
26
|
+
content: "This is a test document.\nIt can include <tag>markup tag</tag>.",
|
27
|
+
front_matter: {title: 'Test Document'},
|
28
|
+
sysinfo: {type: 'develop'}}
|
29
|
+
data['/about'] = {
|
30
|
+
content: "",
|
31
|
+
front_matter: {title: 'About Page'},
|
32
|
+
sysinfo: {type: 'permanent'}}
|
33
|
+
@storage.prepare
|
34
|
+
data.each do |uri, d|
|
35
|
+
@storage.set uri, d[:content], d[:front_matter], d[:sysinfo]
|
36
|
+
end
|
37
|
+
@storage.finalize
|
38
|
+
data.each do |uri, d|
|
39
|
+
expect(@storage.get(uri)).to eq(d)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should return nil when the document does not exist.' do
|
44
|
+
expect(@storage.get('/not_exists')).to eq(nil)
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path(File.join('../../../', 'spec_helper'), File.dirname(__FILE__))
|
4
|
+
Marsdawn.require_lib 'storage/file_system'
|
5
|
+
|
6
|
+
describe Marsdawn::Storage::FileSystem do
|
7
|
+
|
8
|
+
before do
|
9
|
+
conf = {path: $COMPILED_DOC_DIR}
|
10
|
+
opts = {key: 'unit_test'}
|
11
|
+
@storage = Marsdawn::Storage::FileSystem.new(conf, opts)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should write and read the document info.' do
|
15
|
+
doc_info = {foo: 'bar', xyz: 999, arr: %w(a b c)}
|
16
|
+
@storage.prepare
|
17
|
+
@storage.set_document_info doc_info
|
18
|
+
@storage.finalize
|
19
|
+
expect(@storage.get_document_info).to eq(doc_info)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should write and read the documents.' do
|
23
|
+
data = {}
|
24
|
+
data['/'] = {
|
25
|
+
content: "This is a test document.\nIt can include <tag>markup tag</tag>.",
|
26
|
+
front_matter: {title: 'Test Document'},
|
27
|
+
sysinfo: {type: 'develop'}}
|
28
|
+
data['/about'] = {
|
29
|
+
content: "",
|
30
|
+
front_matter: {title: 'About Page'},
|
31
|
+
sysinfo: {type: 'permanent'}}
|
32
|
+
@storage.prepare
|
33
|
+
data.each do |uri, d|
|
34
|
+
@storage.set uri, d[:content], d[:front_matter], d[:sysinfo]
|
35
|
+
end
|
36
|
+
@storage.finalize
|
37
|
+
data.each do |uri, d|
|
38
|
+
expect(@storage.get(uri)).to eq(d)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should return nil when the document does not exist.' do
|
43
|
+
expect(@storage.get('/not_exists')).to eq(nil)
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path(File.join('../../', 'spec_helper'), File.dirname(__FILE__))
|
4
|
+
|
5
|
+
describe Marsdawn::Storage, 'when call get method' do
|
6
|
+
before do
|
7
|
+
@opts = {key:'test', lang:'en', version:'0.0.1'}
|
8
|
+
end
|
9
|
+
it 'should return appropriate instance.' do
|
10
|
+
expect(Marsdawn::Storage.get({:type=>'Test'},@opts)).to be_an_instance_of(Marsdawn::Storage::Test)
|
11
|
+
end
|
12
|
+
it 'can be specified existing file.' do
|
13
|
+
expect{Marsdawn::Storage.get({'type'=>'NotExistingStorage'},@opts)}.to raise_error(LoadError)
|
14
|
+
end
|
15
|
+
it 'can be specified existing class.' do
|
16
|
+
class Marsdawn::Storage::AddingStorage < Marsdawn::Storage::Base; end
|
17
|
+
expect(Marsdawn::Storage.get({'type'=>'AddingStorage'},@opts)).to be_an_instance_of(Marsdawn::Storage::AddingStorage)
|
18
|
+
end
|
19
|
+
it 'should be specified type name.' do
|
20
|
+
expect{Marsdawn::Storage.get({},@opts)}.to raise_error(RuntimeError, /^No storage type is specified/)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe Marsdawn::Storage, 'when storage class does not implemented essential methods' do
|
25
|
+
it 'should raise error.' do
|
26
|
+
expect{Marsdawn::Storage.get({'type'=>'TestNotImplementedError'}).set('/path', 'page', {}, {})}.to raise_error(NotImplementedError)
|
27
|
+
expect{Marsdawn::Storage.get({'type'=>'TestNotImplementedError'}).get('/path')}.to raise_error(NotImplementedError)
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path(File.join('../../', 'spec_helper'), File.dirname(__FILE__))
|
4
|
+
|
5
|
+
describe Marsdawn::Util, '#hash_symbolize_keys_deep' do
|
6
|
+
it 'should symbolize hash keys.' do
|
7
|
+
h = {'foo'=>'bar', 'val'=>123}
|
8
|
+
expect(Marsdawn::Util.hash_symbolize_keys_deep(h)).to eq({foo:'bar', val:123})
|
9
|
+
end
|
10
|
+
it 'should symbolize symbolized hash keys.' do
|
11
|
+
h = {'foo'=>'bar', :val=>123}
|
12
|
+
expect(Marsdawn::Util.hash_symbolize_keys_deep(h)).to eq({foo:'bar', val:123})
|
13
|
+
end
|
14
|
+
it 'should symbolize hash keys recursively.' do
|
15
|
+
h = {'foo'=>'bar', 'val'=>{'xyz'=>123}}
|
16
|
+
expect(Marsdawn::Util.hash_symbolize_keys_deep(h)).to eq({foo:'bar', val:{xyz:123}})
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe Marsdawn::Util, '#hash_symbolize_keys' do
|
21
|
+
it 'should symbolize hash keys.' do
|
22
|
+
h = {'foo'=>'bar', 'val'=>123}
|
23
|
+
expect(Marsdawn::Util.hash_symbolize_keys(h)).to eq({foo:'bar', val:123})
|
24
|
+
end
|
25
|
+
it 'should symbolize hash keys recursively.' do
|
26
|
+
h = {'foo'=>'bar', 'val'=>{'xyz'=>123}}
|
27
|
+
expect(Marsdawn::Util.hash_symbolize_keys(h)).to eq({foo:'bar', val:{'xyz'=>123}})
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe Marsdawn::Util, '#class_to_underscore' do
|
32
|
+
it 'should convert class name to underscored file name.' do
|
33
|
+
expect(Marsdawn::Util.class_to_underscore('Foo')).to eq('foo')
|
34
|
+
expect(Marsdawn::Util.class_to_underscore('FooBar')).to eq('foo_bar')
|
35
|
+
expect(Marsdawn::Util.class_to_underscore('Foo1Bar2')).to eq('foo1_bar2')
|
36
|
+
expect(Marsdawn::Util.class_to_underscore('FOOBar')).to eq('foo_bar')
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe Marsdawn::Util, '#strip_tags' do
|
41
|
+
it 'should remove tags.' do
|
42
|
+
expect(Marsdawn::Util.strip_tags('<html><div>abc</div></html>')).to eq('abc')
|
43
|
+
expect(Marsdawn::Util.strip_tags('<html><div>abc<b>d</b>efg<p><span>hij</span>klm</p></div></html>')).to eq('abcdefghijklm')
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe Marsdawn::Util, '#html_escape' do
|
48
|
+
it 'should escape html entities.' do
|
49
|
+
expect(Marsdawn::Util.html_escape('10<20')).to eq('10<20')
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe Marsdawn::Util, '#attr_escape' do
|
54
|
+
it 'should escape attributes.' do
|
55
|
+
expect(Marsdawn::Util.attr_escape('abc"d"efg')).to eq('abc\"d\"efg')
|
56
|
+
end
|
57
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'coveralls'
|
4
|
+
Coveralls.wear!
|
5
|
+
|
6
|
+
require 'rubygems'
|
7
|
+
|
8
|
+
require File.join(File.dirname(__FILE__), '../lib/marsdawn')
|
9
|
+
|
10
|
+
$TEST_DOC_DIR = File.join(File.dirname(__FILE__), '_test_doc')
|
11
|
+
$COMPILED_DOC_DIR = File.join(File.dirname(__FILE__), '_compiled_doc')
|
12
|
+
$TMP_DIR = File.join(File.dirname(__FILE__), '_tmp')
|