marsdawn 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- 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,44 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
class Marsdawn::Storage::Base
|
4
|
+
|
5
|
+
def initialize config, opts
|
6
|
+
@config = config
|
7
|
+
@opts = opts
|
8
|
+
end
|
9
|
+
|
10
|
+
def key
|
11
|
+
@opts[:key]
|
12
|
+
end
|
13
|
+
|
14
|
+
def lang
|
15
|
+
@opts[:lang]
|
16
|
+
end
|
17
|
+
|
18
|
+
def version
|
19
|
+
@opts[:version]
|
20
|
+
end
|
21
|
+
|
22
|
+
def finalize
|
23
|
+
end
|
24
|
+
|
25
|
+
def clean_up
|
26
|
+
end
|
27
|
+
|
28
|
+
def set_document_info doc_info
|
29
|
+
raise NotImplementedError.new("#{self.class.name}#set_document_info() is not implemented.")
|
30
|
+
end
|
31
|
+
|
32
|
+
def set uri, content, exvars, sysinfo
|
33
|
+
raise NotImplementedError.new("#{self.class.name}#set() is not implemented.")
|
34
|
+
end
|
35
|
+
|
36
|
+
def get_document_info
|
37
|
+
raise NotImplementedError.new("#{self.class.name}#get_document_info() is not implemented.")
|
38
|
+
end
|
39
|
+
|
40
|
+
def get uri
|
41
|
+
raise NotImplementedError.new("#{self.class.name}#get() is not implemented.")
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'marsdawn/storage/base'
|
4
|
+
require 'yaml'
|
5
|
+
|
6
|
+
class Marsdawn::Storage::FileSystem < Marsdawn::Storage::Base
|
7
|
+
|
8
|
+
def initialize config, opts={}
|
9
|
+
@config = {
|
10
|
+
tmp_dir: '/tmp',
|
11
|
+
mode_dir: 0755,
|
12
|
+
mode_file: 0644
|
13
|
+
}.merge(config)
|
14
|
+
raise "Not specify the local storage path name." unless @config.key?(:path)
|
15
|
+
@path = File.absolute_path(@config[:path])
|
16
|
+
raise "There is no directory to build to '#{@path}'." unless File.exists?(@path)
|
17
|
+
@opts = {
|
18
|
+
key: '-',
|
19
|
+
lang: 'en',
|
20
|
+
version: '0.0.1'
|
21
|
+
}.merge(opts)
|
22
|
+
set_target_path
|
23
|
+
end
|
24
|
+
|
25
|
+
def prepare
|
26
|
+
setup_tmp_dir
|
27
|
+
end
|
28
|
+
|
29
|
+
def finalize
|
30
|
+
target_dir = File.dirname(@target_path)
|
31
|
+
FileUtils.mkdir_p target_dir, :mode => @config[:mode_dir] unless File.exists?(target_dir)
|
32
|
+
FileUtils.remove_entry_secure @target_path if File.exists?(@target_path)
|
33
|
+
FileUtils.mv @tmproot, @target_path
|
34
|
+
end
|
35
|
+
|
36
|
+
def clean_up
|
37
|
+
FileUtils.remove_entry_secure @tmproot
|
38
|
+
end
|
39
|
+
|
40
|
+
def set_document_info doc_info
|
41
|
+
File.write @tmp_doc_info_file, YAML.dump(doc_info)
|
42
|
+
end
|
43
|
+
|
44
|
+
def set uri, content, front_matter, sysinfo
|
45
|
+
fullpath = tmp_page_file(uri)
|
46
|
+
dir = File.dirname(fullpath)
|
47
|
+
FileUtils.mkdir_p dir, :mode => @config[:mode_dir] unless File.exists?(dir)
|
48
|
+
data = {content: content, front_matter: front_matter, sysinfo: sysinfo}
|
49
|
+
File.write fullpath, YAML.dump(data)
|
50
|
+
end
|
51
|
+
|
52
|
+
def get_document_info
|
53
|
+
YAML.load_file @doc_info_file
|
54
|
+
end
|
55
|
+
|
56
|
+
def get uri
|
57
|
+
fullpath = page_file(uri)
|
58
|
+
YAML.load_file fullpath if File.exists?(fullpath)
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
def set_target_path
|
63
|
+
@target_path = File.join(@path, key, lang, version)
|
64
|
+
@doc_info_file = File.join(@target_path, '.info.yml')
|
65
|
+
end
|
66
|
+
|
67
|
+
def setup_tmp_dir
|
68
|
+
tmp_dir = @config[:tmp_dir]
|
69
|
+
"The work directory '#{tmp_dir}' does not exist." unless File.exists?(tmp_dir)
|
70
|
+
@tmproot = File.join(tmp_dir, "__tmp_#{$$}_#{Time.now.to_i}")
|
71
|
+
Dir.mkdir @tmproot, @config[:mode_dir]
|
72
|
+
@tmp_doc_info_file = File.join(@tmproot, '.info.yml')
|
73
|
+
end
|
74
|
+
|
75
|
+
def tmp_page_file uri
|
76
|
+
File.join(@tmproot, "#{uri}_.mdd")
|
77
|
+
end
|
78
|
+
|
79
|
+
def page_file uri
|
80
|
+
File.join(@target_path, "#{uri}_.mdd")
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
File without changes
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "marsdawn/storage/base"
|
4
|
+
|
5
|
+
class Marsdawn::Storage::Test < Marsdawn::Storage::Base
|
6
|
+
|
7
|
+
def initialize config, opts
|
8
|
+
super
|
9
|
+
@storage = {}
|
10
|
+
end
|
11
|
+
|
12
|
+
def set path, page, exvars, sysinfo
|
13
|
+
@storage[path] = {:page => page, :exvars => exvars, :sysinfo => sysinfo}
|
14
|
+
end
|
15
|
+
|
16
|
+
def get path
|
17
|
+
@storage[path]
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
class Marsdawn::Storage
|
4
|
+
|
5
|
+
def self.get config, opts={}
|
6
|
+
opts = {key: 'default', lang: 'en', version: '0.0.1'}.merge(opts)
|
7
|
+
config = handle_config(config, opts)
|
8
|
+
raise "No storage type is specified." unless config.key?(:type)
|
9
|
+
class_name = config[:type]
|
10
|
+
@@base_path ||= File.join(File.dirname(__FILE__), 'storage')
|
11
|
+
Marsdawn::Util.adapter(self, class_name, @@base_path).new config, opts
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.handle_config config, opts
|
15
|
+
if config.nil?
|
16
|
+
Marsdawn::Config.new.get(opts[:key], :storage)
|
17
|
+
else
|
18
|
+
Marsdawn::Util.hash_symbolize_keys(config)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
class Marsdawn::Util
|
4
|
+
|
5
|
+
def self.hash_symbolize_keys hash, deep=false
|
6
|
+
hash.each_with_object({}) do |(key, val), ret|
|
7
|
+
val = hash_symbolize_keys(val, deep) if deep && val.kind_of?(Hash)
|
8
|
+
ret[key.to_sym] = val
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.hash_symbolize_keys_deep hash
|
13
|
+
hash_symbolize_keys hash, true
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.class_to_underscore class_name
|
17
|
+
class_name.gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').gsub(/([a-z\d])([A-Z])/,'\1_\2').tr('-','_').downcase
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.strip_tags text
|
21
|
+
text.gsub(/<[^>]*>/ui, '')
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.html_escape str
|
25
|
+
CGI.escapeHTML str
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.attr_escape str
|
29
|
+
str.gsub(/"/, '\"')
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.adapter namespace, class_name, base_path
|
33
|
+
unless namespace.const_defined?(class_name, false)
|
34
|
+
require File.join(base_path, class_to_underscore(class_name))
|
35
|
+
end
|
36
|
+
namespace.const_get(class_name)
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
data/lib/marsdawn.rake
ADDED
data/lib/marsdawn.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
load "marsdawn.rake"
|
4
|
+
require "marsdawn/version"
|
5
|
+
require "marsdawn/util"
|
6
|
+
require "marsdawn/config"
|
7
|
+
require "marsdawn/storage"
|
8
|
+
require "marsdawn/site"
|
9
|
+
require "marsdawn/search"
|
10
|
+
|
11
|
+
module Marsdawn
|
12
|
+
|
13
|
+
# load lib file from lib/marsdawn directory
|
14
|
+
# @param [String] require file under lib/marsdawn directory
|
15
|
+
def self.require_lib path
|
16
|
+
@@base_path ||= File.expand_path(File.join(File.dirname(__FILE__), 'marsdawn'))
|
17
|
+
require File.join(@@base_path, path)
|
18
|
+
end
|
19
|
+
|
20
|
+
# build document source
|
21
|
+
# @param [String] key of config file entry
|
22
|
+
def self.build *keys
|
23
|
+
require "marsdawn/builder"
|
24
|
+
if block_given?
|
25
|
+
conf = {}
|
26
|
+
yield conf
|
27
|
+
configs = [conf]
|
28
|
+
else
|
29
|
+
configs = configs_from_file(keys)
|
30
|
+
end
|
31
|
+
configs.each do |conf|
|
32
|
+
Marsdawn::Builder.build conf
|
33
|
+
end
|
34
|
+
puts "[MarsDawn] Build complete."
|
35
|
+
rescue => e
|
36
|
+
puts "[MarsDawn] ERROR: #{e.message}"
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
def self.configs_from_file keys
|
41
|
+
[].tap do |ret|
|
42
|
+
config = Marsdawn::Config.new
|
43
|
+
if keys.size > 0
|
44
|
+
keys.each do |key|
|
45
|
+
ret << config.to_hash(key)
|
46
|
+
end
|
47
|
+
else
|
48
|
+
config.each do |key, conf|
|
49
|
+
ret << conf
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
data/marsdawn.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'marsdawn/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "marsdawn"
|
8
|
+
spec.version = Marsdawn::VERSION
|
9
|
+
spec.authors = ["Naohiko MORI"]
|
10
|
+
spec.email = ["naohiko.mori@gmail.com"]
|
11
|
+
spec.summary = %q{Easy static document builder & traverser.}
|
12
|
+
spec.description = %q{Make it easy to create static document site by building markdown documents and traverse them.}
|
13
|
+
spec.homepage = "https://github.com/nao58/marsdawn"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.3"
|
23
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
24
|
+
spec.add_dependency "kramdown", "~> 1.3"
|
25
|
+
end
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
{::front_matter title="Test Document 01" link_key="top" /}
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
lorem ipsum dolor sit amet
|
data/spec/_tmp/.gitkeep
ADDED
File without changes
|
@@ -0,0 +1,144 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path(File.join('../../', 'spec_helper'), File.dirname(__FILE__))
|
4
|
+
Marsdawn.require_lib 'command'
|
5
|
+
|
6
|
+
describe Marsdawn::Command do
|
7
|
+
|
8
|
+
def command argv
|
9
|
+
Marsdawn::Command.exec(argv)
|
10
|
+
end
|
11
|
+
|
12
|
+
def cmd
|
13
|
+
@cmd ||= Marsdawn::Command.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def chdir path
|
17
|
+
Dir.chdir File.expand_path(path)
|
18
|
+
end
|
19
|
+
|
20
|
+
def file_exists? path
|
21
|
+
File.exists?(File.expand_path(path))
|
22
|
+
end
|
23
|
+
|
24
|
+
before :each do
|
25
|
+
Dir.chdir($TMP_DIR)
|
26
|
+
Dir.glob("*").each do |entry|
|
27
|
+
path = File.expand_path(entry)
|
28
|
+
FileUtils.remove_entry(path, true) if File.exists?(path)
|
29
|
+
end
|
30
|
+
@cmd = nil
|
31
|
+
end
|
32
|
+
|
33
|
+
context '#exec' do
|
34
|
+
it 'should parse rightly.' do
|
35
|
+
expect(command(%w(debug options --num 100 -e))).to eq(num:'100', edit:true)
|
36
|
+
expect(command(%w(debug options num 100 -e))).to eq(num:'100', edit:true)
|
37
|
+
expect(command(%w(debug options -n 100 -e))).to eq(num:'100', edit:true)
|
38
|
+
expect(command(%w(debug options --num 200 -n 100 -e))).to eq(num:'100', edit:true)
|
39
|
+
expect(command(%w(debug options))).to eq({})
|
40
|
+
expect(command(%w(debug))).to be_nil
|
41
|
+
end
|
42
|
+
it 'should raise error when option is invalid.' do
|
43
|
+
expect{command(%w(debug options --foo bar))}.to raise_error(Marsdawn::Command::ParamError)
|
44
|
+
end
|
45
|
+
it 'should raise error when command is invalid.' do
|
46
|
+
expect{command(%w(foo))}.to raise_error(Marsdawn::Command::ParamError)
|
47
|
+
end
|
48
|
+
it 'should raise error when command is not given.' do
|
49
|
+
expect{command(%w())}.to raise_error(Marsdawn::Command::ParamError)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'with command .create' do
|
54
|
+
it 'should create new directory, .marsdawn.yml and .index.md' do
|
55
|
+
cmd.create 'Test Document'
|
56
|
+
expect(file_exists?('test-document')).to be_truthy
|
57
|
+
expect(file_exists?('test-document/.marsdawn.yml')).to be_truthy
|
58
|
+
expect(file_exists?('test-document/.index.md')).to be_truthy
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'with command .page' do
|
63
|
+
before :each do
|
64
|
+
cmd.create 'Test Document'
|
65
|
+
chdir './test-document'
|
66
|
+
end
|
67
|
+
it 'should create new page.' do
|
68
|
+
cmd.page 'About this test document'
|
69
|
+
cmd.page 'Getting Start'
|
70
|
+
expect(file_exists?('about-this-test-document.md')).to be_truthy
|
71
|
+
expect(file_exists?('getting-start.md')).to be_truthy
|
72
|
+
end
|
73
|
+
it 'should create new page.' do
|
74
|
+
cmd.page 'About this test document', num: true
|
75
|
+
cmd.page 'Getting Start', num: true
|
76
|
+
cmd.page 'Appendix 1', num: "100", file: 'omake'
|
77
|
+
cmd.page 'Appendix 2', num: true, file: 'furoku'
|
78
|
+
expect(file_exists?('010_about-this-test-document.md')).to be_truthy
|
79
|
+
expect(file_exists?('020_getting-start.md')).to be_truthy
|
80
|
+
expect(file_exists?('100_omake.md')).to be_truthy
|
81
|
+
expect(file_exists?('110_furoku.md')).to be_truthy
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context 'with command .dir' do
|
86
|
+
before :each do
|
87
|
+
cmd.create 'Test Document'
|
88
|
+
chdir './test-document'
|
89
|
+
end
|
90
|
+
it 'should create new directory.' do
|
91
|
+
cmd.page 'About this test document'
|
92
|
+
cmd.dir 'Getting Start'
|
93
|
+
expect(file_exists?('about-this-test-document.md')).to be_truthy
|
94
|
+
expect(file_exists?('getting-start')).to be_truthy
|
95
|
+
expect(file_exists?('getting-start/.index.md')).to be_truthy
|
96
|
+
end
|
97
|
+
it 'should create new page.' do
|
98
|
+
cmd.page 'About this test document', num: true
|
99
|
+
cmd.dir 'Getting Start', num: true
|
100
|
+
cmd.dir 'Appendix 1', num: "100", file: 'omake'
|
101
|
+
cmd.page 'Appendix 2', num: true, step: 5, file: 'furoku'
|
102
|
+
expect(file_exists?('010_about-this-test-document.md')).to be_truthy
|
103
|
+
expect(file_exists?('020_getting-start')).to be_truthy
|
104
|
+
expect(file_exists?('020_getting-start/.index.md')).to be_truthy
|
105
|
+
expect(file_exists?('100_omake')).to be_truthy
|
106
|
+
expect(file_exists?('100_omake/.index.md')).to be_truthy
|
107
|
+
expect(file_exists?('105_furoku.md')).to be_truthy
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
context 'with command .renum' do
|
112
|
+
before :each do
|
113
|
+
cmd.create 'Test Document'
|
114
|
+
chdir './test-document'
|
115
|
+
end
|
116
|
+
it 'should do re-numbering.' do
|
117
|
+
cmd.page 'About this test document', num: "15"
|
118
|
+
cmd.dir 'Getting Start', num: "20"
|
119
|
+
cmd.dir 'Appendix 1', num: "100"
|
120
|
+
cmd.page 'Appendix 2', num: true, step: 5
|
121
|
+
cmd.renum nil
|
122
|
+
expect(file_exists?('010_about-this-test-document.md')).to be_truthy
|
123
|
+
expect(file_exists?('020_getting-start')).to be_truthy
|
124
|
+
expect(file_exists?('020_getting-start/.index.md')).to be_truthy
|
125
|
+
expect(file_exists?('030_appendix-1')).to be_truthy
|
126
|
+
expect(file_exists?('030_appendix-1/.index.md')).to be_truthy
|
127
|
+
expect(file_exists?('040_appendix-2.md')).to be_truthy
|
128
|
+
end
|
129
|
+
it 'should do re-numbering with step.' do
|
130
|
+
cmd.page 'About this test document', num: "15"
|
131
|
+
cmd.dir 'Getting Start', num: "20"
|
132
|
+
cmd.dir 'Appendix 1', num: "100"
|
133
|
+
cmd.page 'Appendix 2', num: true, step: 5
|
134
|
+
cmd.renum "15"
|
135
|
+
expect(file_exists?('015_about-this-test-document.md')).to be_truthy
|
136
|
+
expect(file_exists?('030_getting-start')).to be_truthy
|
137
|
+
expect(file_exists?('030_getting-start/.index.md')).to be_truthy
|
138
|
+
expect(file_exists?('045_appendix-1')).to be_truthy
|
139
|
+
expect(file_exists?('045_appendix-1/.index.md')).to be_truthy
|
140
|
+
expect(file_exists?('060_appendix-2.md')).to be_truthy
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path(File.join('../../', 'spec_helper'), File.dirname(__FILE__))
|
4
|
+
|
5
|
+
describe Marsdawn::Config do
|
6
|
+
|
7
|
+
before do
|
8
|
+
@conf_data = {
|
9
|
+
'test_docs01' => {
|
10
|
+
source: '/path/to/source01',
|
11
|
+
storage: {type: 'FileSystem', path: '/path/to/storage01'}
|
12
|
+
},
|
13
|
+
'test_docs02' => {
|
14
|
+
source: '/path/to/source02',
|
15
|
+
storage: {type: 'FileSystem', path: '/path/to/storage02'}
|
16
|
+
}
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
def config
|
21
|
+
@config ||= Marsdawn::Config.new(File.join($TEST_DOC_DIR, 'config.yml'))
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should raise error when the config file does not exist.' do
|
25
|
+
expect{Marsdawn::Config.new}.to raise_error(/^Cannot find a config file for marsdawn./)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should raise errro when the config key does not exist in the yaml.' do
|
29
|
+
expect{config.to_hash('no_exists')}.to raise_error(/^Cannot find the configuration/)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should raise errro when the config entry does not exist at the config.' do
|
33
|
+
expect{config.get('test_docs01', :no_exists)}.to raise_error(/^No entry 'no_exists' in the setting file/)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should return the config data from key.' do
|
37
|
+
expect(config.get('test_docs01', :source)).to eq(@conf_data['test_docs01'][:source])
|
38
|
+
expect(config.get('test_docs02', :storage)).to eq(@conf_data['test_docs02'][:storage])
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|