markun 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/Gemfile +9 -0
- data/LICENSE.txt +22 -0
- data/README.md +124 -0
- data/Rakefile +1 -0
- data/bin/markun +31 -0
- data/doc_image/parent1.png +0 -0
- data/doc_image/sub1.png +0 -0
- data/lib/markun/version.rb +5 -0
- data/lib/markun_core.rb +106 -0
- data/lib/markun_dsl.rb +28 -0
- data/lib/markun_dsl_model.rb +13 -0
- data/markun.gemspec +30 -0
- data/sample/sample_after/Markunfile +7 -0
- data/sample/sample_after/parent1.html +31 -0
- data/sample/sample_after/parent1.md +16 -0
- data/sample/sample_after/parent2.html +31 -0
- data/sample/sample_after/parent2.md +16 -0
- data/sample/sample_after/sub/sub1.html +31 -0
- data/sample/sample_after/sub/sub1.md +16 -0
- data/sample/sample_after/sub/sub2.html +31 -0
- data/sample/sample_after/sub/sub2.md +16 -0
- data/sample/sample_bofore/Markunfile +7 -0
- data/sample/sample_bofore/parent1.md +16 -0
- data/sample/sample_bofore/parent2.md +16 -0
- data/sample/sample_bofore/sub/sub1.md +16 -0
- data/sample/sample_bofore/sub/sub2.md +16 -0
- data/spec/markun_core_spec.rb +158 -0
- data/spec/spec_helper.rb +10 -0
- metadata +168 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 tbpgr
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
# Markun
|
2
|
+
|
3
|
+
Markun is Markdown bulk converter with menu link
|
4
|
+
|
5
|
+
## Purpose
|
6
|
+
* Markun convert all Markdown-files to html-files with menu link.
|
7
|
+
|
8
|
+
(If you do not want to create menu link, set Markunfile's have_menu to 'false'.)
|
9
|
+
|
10
|
+
* Target is All of the '*.md'files and subdirectories.
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
Add this line to your application's Gemfile:
|
15
|
+
|
16
|
+
gem 'markun'
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
$ gem install markun
|
25
|
+
|
26
|
+
## Structure
|
27
|
+
### before convert
|
28
|
+
~~~
|
29
|
+
.
|
30
|
+
┗ Target
|
31
|
+
┠ Markunfile :dsl setting file
|
32
|
+
┠ some1.md
|
33
|
+
┠ some2.md
|
34
|
+
┗ sub
|
35
|
+
sub1.md
|
36
|
+
sub2.md
|
37
|
+
~~~
|
38
|
+
|
39
|
+
### after convert
|
40
|
+
~~~
|
41
|
+
.
|
42
|
+
┗ Target
|
43
|
+
┠ Markunfile :dsl setting file
|
44
|
+
┠ some1.md
|
45
|
+
┠ some1.html
|
46
|
+
┠ some2.md
|
47
|
+
┠ some2.html
|
48
|
+
┗ sub
|
49
|
+
┠ sub1.md
|
50
|
+
┠ sub1.html
|
51
|
+
┠ sub2.md
|
52
|
+
┗ sub2.html
|
53
|
+
~~~
|
54
|
+
|
55
|
+
## Usage
|
56
|
+
### Before Structure
|
57
|
+
~~~bash
|
58
|
+
$ tree
|
59
|
+
.
|
60
|
+
┠ parent1.md
|
61
|
+
┠ parent2.md
|
62
|
+
┗ sub
|
63
|
+
┠ sub1.md
|
64
|
+
┗ sub2.md
|
65
|
+
~~~
|
66
|
+
|
67
|
+
### Steps
|
68
|
+
* markun init
|
69
|
+
* confirm generated Markunfile
|
70
|
+
|
71
|
+
~~~ruby
|
72
|
+
# encoding: utf-8
|
73
|
+
|
74
|
+
# have menu or not
|
75
|
+
# have_menu allow only String
|
76
|
+
# have_menu's default value => "false"
|
77
|
+
have_menu "false"
|
78
|
+
~~~
|
79
|
+
|
80
|
+
* edit Markunfile
|
81
|
+
|
82
|
+
~~~ruby
|
83
|
+
# encoding: utf-8
|
84
|
+
have_menu "true"
|
85
|
+
~~~
|
86
|
+
|
87
|
+
* execute markun
|
88
|
+
|
89
|
+
~~~bash
|
90
|
+
$ markun execute
|
91
|
+
$ tree
|
92
|
+
┠ Markunfile
|
93
|
+
┠ parent1.html
|
94
|
+
┠ parent1.md
|
95
|
+
┠ parent2.html
|
96
|
+
┠ parent2.md
|
97
|
+
┗ sub
|
98
|
+
┠ sub1.html
|
99
|
+
┠ sub1.md
|
100
|
+
┠ sub2.html
|
101
|
+
┗ sub2.md
|
102
|
+
~~~
|
103
|
+
|
104
|
+
### Result Caputure Sample
|
105
|
+
* parent1.html
|
106
|
+
|
107
|
+
<img src="./doc_image/parent1.png" />
|
108
|
+
|
109
|
+
---
|
110
|
+
|
111
|
+
* sub/sub1.html
|
112
|
+
|
113
|
+
<img src="./doc_image/sub1.png" />
|
114
|
+
|
115
|
+
## Notes
|
116
|
+
* Markun uses kramdown gem for markdown converter.
|
117
|
+
|
118
|
+
## Contributing
|
119
|
+
|
120
|
+
1. Fork it
|
121
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
122
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
123
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
124
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/markun
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
require 'markun_core'
|
5
|
+
require 'markun/version'
|
6
|
+
require 'thor'
|
7
|
+
|
8
|
+
module Markun
|
9
|
+
# = Markun CLI
|
10
|
+
class CLI < Thor
|
11
|
+
class_option :help, type: :boolean, aliases: '-h', desc: 'help message.'
|
12
|
+
class_option :version, type: :boolean, desc: 'version'
|
13
|
+
|
14
|
+
desc 'execute', 'convert markdown to html with menu-link'
|
15
|
+
def execute
|
16
|
+
Markun::Core.new.execute
|
17
|
+
end
|
18
|
+
|
19
|
+
desc 'init', 'generate Markunfile'
|
20
|
+
def init
|
21
|
+
Markun::Core.new.init
|
22
|
+
end
|
23
|
+
|
24
|
+
desc 'version', 'version'
|
25
|
+
def version
|
26
|
+
p Markun::VERSION
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
Markun::CLI.start(ARGV)
|
Binary file
|
data/doc_image/sub1.png
ADDED
Binary file
|
data/lib/markun_core.rb
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'markun_dsl'
|
3
|
+
require 'erb'
|
4
|
+
require 'kramdown'
|
5
|
+
require 'pathname'
|
6
|
+
|
7
|
+
module Markun
|
8
|
+
# Markun Core
|
9
|
+
class Core
|
10
|
+
MARKUN_FILE = 'Markunfile'
|
11
|
+
MARKUN_TEMPLATE = <<-EOS
|
12
|
+
# encoding: utf-8
|
13
|
+
|
14
|
+
# have menu or not
|
15
|
+
# have_menu allow only String
|
16
|
+
# have_menu's default value => "false"
|
17
|
+
have_menu "false"
|
18
|
+
|
19
|
+
EOS
|
20
|
+
|
21
|
+
HTML_TEMPLATE = <<-EOS
|
22
|
+
<!doctype html>
|
23
|
+
<html>
|
24
|
+
<head>
|
25
|
+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
26
|
+
<title><%=title%></title>
|
27
|
+
<link href="markdown.css" rel="stylesheet" />
|
28
|
+
</head>
|
29
|
+
<body>
|
30
|
+
<%=menu%>
|
31
|
+
<%=contents%>
|
32
|
+
</body>
|
33
|
+
</html>
|
34
|
+
EOS
|
35
|
+
|
36
|
+
# == generate Markunfile to current directory.
|
37
|
+
def init
|
38
|
+
File.open(MARKUN_FILE, 'w') { |f|f.puts MARKUN_TEMPLATE }
|
39
|
+
end
|
40
|
+
|
41
|
+
# == execute markdown convert
|
42
|
+
def execute
|
43
|
+
src = read_dsl
|
44
|
+
dsl = Markun::Dsl.new
|
45
|
+
dsl.instance_eval src
|
46
|
+
convert_markdown_to_html dsl.markun.have_menu
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def read_dsl
|
52
|
+
File.open(MARKUN_FILE) { |f|f.read }
|
53
|
+
end
|
54
|
+
|
55
|
+
def convert_markdown_to_html(have_menu)
|
56
|
+
Dir.glob('**/*.md').each do |file|
|
57
|
+
md = File.read(file)
|
58
|
+
contents = Kramdown::Document.new(md.force_encoding('utf-8')).to_html
|
59
|
+
menu = get_menu(file, have_menu)
|
60
|
+
html = get_html_template(File.basename(file, '.md'), contents, menu)
|
61
|
+
html_file_name = file.gsub('.md', '.html')
|
62
|
+
File.open(html_file_name, 'w:utf-8') { |f|f.puts html.encode('utf-8') }
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def get_menu(file, have_menu)
|
67
|
+
return '' unless have_menu == 'true'
|
68
|
+
absolute_path = File.dirname(File.absolute_path(file))
|
69
|
+
base = Pathname.new(absolute_path)
|
70
|
+
create_menu base
|
71
|
+
end
|
72
|
+
|
73
|
+
def get_html_template(title, contents, menu)
|
74
|
+
erb = ERB.new(HTML_TEMPLATE)
|
75
|
+
erb.result(binding)
|
76
|
+
end
|
77
|
+
|
78
|
+
def create_menu(base)
|
79
|
+
urls = get_urls([])
|
80
|
+
urls_to_menu(urls, base)
|
81
|
+
end
|
82
|
+
|
83
|
+
def get_urls(urls)
|
84
|
+
urls += get_each_urls
|
85
|
+
Dir.glob('*/') do |d|
|
86
|
+
Dir.chdir(d)
|
87
|
+
urls = get_urls(urls)
|
88
|
+
Dir.chdir('../')
|
89
|
+
end
|
90
|
+
urls
|
91
|
+
end
|
92
|
+
|
93
|
+
def get_each_urls
|
94
|
+
Dir.glob('./*.md').map { |f|File.absolute_path(f) }
|
95
|
+
end
|
96
|
+
|
97
|
+
def urls_to_menu(urls, base)
|
98
|
+
ret = []
|
99
|
+
urls.each do |f|
|
100
|
+
_filename = Pathname.new(f.gsub('md', 'html')).relative_path_from(base)
|
101
|
+
ret << "<a href='#{_filename}'>#{_filename}</a><br />"
|
102
|
+
end
|
103
|
+
ret.join('') + '<hr />'
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
data/lib/markun_dsl.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'markun_dsl_model'
|
3
|
+
|
4
|
+
module Markun
|
5
|
+
# =Markun::Dsl
|
6
|
+
class Dsl
|
7
|
+
attr_accessor :markun
|
8
|
+
|
9
|
+
# String Define
|
10
|
+
[:have_menu].each do |f|
|
11
|
+
define_method f do |value|
|
12
|
+
eval "@markun.#{f.to_s} = '#{value}'", binding
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# Array/Hash Define
|
17
|
+
[].each do |f|
|
18
|
+
define_method f do |value|
|
19
|
+
eval "@markun.#{f.to_s} = #{value}", binding
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def initialize
|
24
|
+
@markun = Markun::DslModel.new
|
25
|
+
@markun.have_menu = 'false'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/markun.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'markun/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "markun"
|
8
|
+
spec.version = Markun::VERSION
|
9
|
+
spec.authors = ["tbpgr"]
|
10
|
+
spec.email = ["tbpgr@tbpgr.jp"]
|
11
|
+
spec.description = %q{Markun is Markdown bulk converter with menu link}
|
12
|
+
spec.summary = %q{Markun is Markdown bulk converter with menu link}
|
13
|
+
spec.homepage = "https://github.com/tbpgr/markun"
|
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_runtime_dependency "thor", "~> 0.18.1"
|
22
|
+
spec.add_runtime_dependency "activesupport", "~> 4.0.1"
|
23
|
+
spec.add_runtime_dependency "activemodel", "~> 4.0.2"
|
24
|
+
spec.add_runtime_dependency "kramdown", "~> 1.3.0"
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
27
|
+
spec.add_development_dependency "rake"
|
28
|
+
spec.add_development_dependency "simplecov", "~> 0.8.2"
|
29
|
+
spec.add_development_dependency "rspec", "~> 2.14.1"
|
30
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
<!doctype html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
5
|
+
<title>parent1</title>
|
6
|
+
<link href="markdown.css" rel="stylesheet" />
|
7
|
+
</head>
|
8
|
+
<body>
|
9
|
+
<a href='parent1.html'>parent1.html</a><br /><a href='parent2.html'>parent2.html</a><br /><a href='sub/sub1.html'>sub/sub1.html</a><br /><a href='sub/sub2.html'>sub/sub2.html</a><br /><hr />
|
10
|
+
<h1 id="parent1">Parent1</h1>
|
11
|
+
|
12
|
+
<h2 id="sumamry">Sumamry</h2>
|
13
|
+
<ul>
|
14
|
+
<li>list1</li>
|
15
|
+
<li>list2</li>
|
16
|
+
</ul>
|
17
|
+
|
18
|
+
<hr />
|
19
|
+
|
20
|
+
<h2 id="contents">Contents</h2>
|
21
|
+
<ul>
|
22
|
+
<li>count1</li>
|
23
|
+
<li>count2</li>
|
24
|
+
</ul>
|
25
|
+
|
26
|
+
<pre><code>pre1
|
27
|
+
pre2
|
28
|
+
</code></pre>
|
29
|
+
|
30
|
+
</body>
|
31
|
+
</html>
|
@@ -0,0 +1,31 @@
|
|
1
|
+
<!doctype html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
5
|
+
<title>parent2</title>
|
6
|
+
<link href="markdown.css" rel="stylesheet" />
|
7
|
+
</head>
|
8
|
+
<body>
|
9
|
+
<a href='parent1.html'>parent1.html</a><br /><a href='parent2.html'>parent2.html</a><br /><a href='sub/sub1.html'>sub/sub1.html</a><br /><a href='sub/sub2.html'>sub/sub2.html</a><br /><hr />
|
10
|
+
<h1 id="parent1">Parent1</h1>
|
11
|
+
|
12
|
+
<h2 id="sumamry">Sumamry</h2>
|
13
|
+
<ul>
|
14
|
+
<li>list1</li>
|
15
|
+
<li>list2</li>
|
16
|
+
</ul>
|
17
|
+
|
18
|
+
<hr />
|
19
|
+
|
20
|
+
<h2 id="contents">Contents</h2>
|
21
|
+
<ul>
|
22
|
+
<li>count1</li>
|
23
|
+
<li>count2</li>
|
24
|
+
</ul>
|
25
|
+
|
26
|
+
<pre><code>pre1
|
27
|
+
pre2
|
28
|
+
</code></pre>
|
29
|
+
|
30
|
+
</body>
|
31
|
+
</html>
|
@@ -0,0 +1,31 @@
|
|
1
|
+
<!doctype html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
5
|
+
<title>sub1</title>
|
6
|
+
<link href="markdown.css" rel="stylesheet" />
|
7
|
+
</head>
|
8
|
+
<body>
|
9
|
+
<a href='../parent1.html'>../parent1.html</a><br /><a href='../parent2.html'>../parent2.html</a><br /><a href='sub1.html'>sub1.html</a><br /><a href='sub2.html'>sub2.html</a><br /><hr />
|
10
|
+
<h1 id="parent1">Parent1</h1>
|
11
|
+
|
12
|
+
<h2 id="sumamry">Sumamry</h2>
|
13
|
+
<ul>
|
14
|
+
<li>list1</li>
|
15
|
+
<li>list2</li>
|
16
|
+
</ul>
|
17
|
+
|
18
|
+
<hr />
|
19
|
+
|
20
|
+
<h2 id="contents">Contents</h2>
|
21
|
+
<ul>
|
22
|
+
<li>count1</li>
|
23
|
+
<li>count2</li>
|
24
|
+
</ul>
|
25
|
+
|
26
|
+
<pre><code>pre1
|
27
|
+
pre2
|
28
|
+
</code></pre>
|
29
|
+
|
30
|
+
</body>
|
31
|
+
</html>
|
@@ -0,0 +1,31 @@
|
|
1
|
+
<!doctype html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
5
|
+
<title>sub2</title>
|
6
|
+
<link href="markdown.css" rel="stylesheet" />
|
7
|
+
</head>
|
8
|
+
<body>
|
9
|
+
<a href='../parent1.html'>../parent1.html</a><br /><a href='../parent2.html'>../parent2.html</a><br /><a href='sub1.html'>sub1.html</a><br /><a href='sub2.html'>sub2.html</a><br /><hr />
|
10
|
+
<h1 id="parent1">Parent1</h1>
|
11
|
+
|
12
|
+
<h2 id="sumamry">Sumamry</h2>
|
13
|
+
<ul>
|
14
|
+
<li>list1</li>
|
15
|
+
<li>list2</li>
|
16
|
+
</ul>
|
17
|
+
|
18
|
+
<hr />
|
19
|
+
|
20
|
+
<h2 id="contents">Contents</h2>
|
21
|
+
<ul>
|
22
|
+
<li>count1</li>
|
23
|
+
<li>count2</li>
|
24
|
+
</ul>
|
25
|
+
|
26
|
+
<pre><code>pre1
|
27
|
+
pre2
|
28
|
+
</code></pre>
|
29
|
+
|
30
|
+
</body>
|
31
|
+
</html>
|
@@ -0,0 +1,158 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'markun_core'
|
4
|
+
require 'fileutils'
|
5
|
+
|
6
|
+
describe Markun::Core do
|
7
|
+
|
8
|
+
context :init do
|
9
|
+
OUTPUT_DSL_TMP_DIR = 'generate_dsl'
|
10
|
+
cases = [
|
11
|
+
{
|
12
|
+
case_no: 1,
|
13
|
+
case_title: 'valid case',
|
14
|
+
expected_files: [
|
15
|
+
Markun::Core::MARKUN_FILE,
|
16
|
+
],
|
17
|
+
expected_contents: [
|
18
|
+
Markun::Core::MARKUN_TEMPLATE,
|
19
|
+
],
|
20
|
+
},
|
21
|
+
]
|
22
|
+
|
23
|
+
cases.each do |c|
|
24
|
+
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
25
|
+
begin
|
26
|
+
case_before c
|
27
|
+
|
28
|
+
# -- given --
|
29
|
+
markun_core = Markun::Core.new
|
30
|
+
|
31
|
+
# -- when --
|
32
|
+
markun_core.init
|
33
|
+
|
34
|
+
# -- then --
|
35
|
+
c[:expected_files].each_with_index do |f, index|
|
36
|
+
actual = File.read("./#{f}")
|
37
|
+
expect(actual).to eq(c[:expected_contents][index])
|
38
|
+
end
|
39
|
+
ensure
|
40
|
+
case_after c
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def case_before(c)
|
46
|
+
Dir.mkdir(OUTPUT_DSL_TMP_DIR) unless Dir.exists? OUTPUT_DSL_TMP_DIR
|
47
|
+
Dir.chdir(OUTPUT_DSL_TMP_DIR)
|
48
|
+
end
|
49
|
+
|
50
|
+
def case_after(c)
|
51
|
+
Dir.chdir('../')
|
52
|
+
FileUtils.rm_rf(OUTPUT_DSL_TMP_DIR) if Dir.exists? OUTPUT_DSL_TMP_DIR
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context :execute do
|
58
|
+
OUTPUT_MARKDOWN_TMP_DIR = 'tmp_markdown'
|
59
|
+
MARKUNFILE_CASE1 = <<-EOS
|
60
|
+
# encoding: utf-8
|
61
|
+
have_menu "false"
|
62
|
+
EOS
|
63
|
+
MARKUNFILE_CASE2 = <<-EOS
|
64
|
+
# encoding: utf-8
|
65
|
+
have_menu "true"
|
66
|
+
EOS
|
67
|
+
|
68
|
+
MARKDOWN1 = <<-EOS
|
69
|
+
# Title
|
70
|
+
|
71
|
+
## Subtitle1
|
72
|
+
* list1
|
73
|
+
* list2
|
74
|
+
|
75
|
+
## Subtitle2
|
76
|
+
EOS
|
77
|
+
|
78
|
+
MARKDOWN2 = <<-EOS
|
79
|
+
# Title
|
80
|
+
|
81
|
+
## Subtitle1
|
82
|
+
* list1
|
83
|
+
* list2
|
84
|
+
|
85
|
+
~~~
|
86
|
+
pre1
|
87
|
+
pre2
|
88
|
+
~~~
|
89
|
+
|
90
|
+
## Subtitle2
|
91
|
+
|
92
|
+
---
|
93
|
+
line
|
94
|
+
|
95
|
+
---
|
96
|
+
|
97
|
+
EOS
|
98
|
+
|
99
|
+
cases = [
|
100
|
+
{
|
101
|
+
case_no: 1,
|
102
|
+
case_title: 'flat case',
|
103
|
+
markunfile: MARKUNFILE_CASE1,
|
104
|
+
inputs_filenames: ['markdown1.md', 'markdown2.md'],
|
105
|
+
inputs_contents: [MARKDOWN1, MARKDOWN2],
|
106
|
+
expected_files: ['markdown1.html', 'markdown2.html'],
|
107
|
+
},
|
108
|
+
{
|
109
|
+
case_no: 2,
|
110
|
+
case_title: 'multi case',
|
111
|
+
markunfile: MARKUNFILE_CASE2,
|
112
|
+
inputs_filenames: ['markdown1.md', './sub/markdown2.md'],
|
113
|
+
inputs_contents: [MARKDOWN1, MARKDOWN2],
|
114
|
+
expected_files: ['markdown1.html', './sub/markdown2.html'],
|
115
|
+
},
|
116
|
+
]
|
117
|
+
|
118
|
+
cases.each do |c|
|
119
|
+
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
120
|
+
begin
|
121
|
+
case_before c
|
122
|
+
|
123
|
+
# -- given --
|
124
|
+
markun_core = Markun::Core.new
|
125
|
+
|
126
|
+
# -- when --
|
127
|
+
markun_core.execute
|
128
|
+
|
129
|
+
# -- then --
|
130
|
+
c[:expected_files].each_with_index do |f, index|
|
131
|
+
actual = File.exists?("#{f}")
|
132
|
+
expect(actual).to be_true
|
133
|
+
end
|
134
|
+
ensure
|
135
|
+
case_after c
|
136
|
+
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def case_before(c)
|
141
|
+
Dir.mkdir(OUTPUT_MARKDOWN_TMP_DIR) unless Dir.exists? OUTPUT_MARKDOWN_TMP_DIR
|
142
|
+
Dir.chdir(OUTPUT_MARKDOWN_TMP_DIR)
|
143
|
+
c[:inputs_filenames].each_with_index do |file, index|
|
144
|
+
dir = File.dirname(file)
|
145
|
+
FileUtils.mkdir_p dir unless File.exists?(dir)
|
146
|
+
File.open(file, 'w') { |f|f.print c[:inputs_contents][index] }
|
147
|
+
end
|
148
|
+
File.open(Markun::Core::MARKUN_FILE, 'w') { |f|f.print c[:markunfile] }
|
149
|
+
end
|
150
|
+
|
151
|
+
def case_after(c)
|
152
|
+
Dir.chdir('../')
|
153
|
+
FileUtils.rm_rf(OUTPUT_MARKDOWN_TMP_DIR) if Dir.exists? OUTPUT_MARKDOWN_TMP_DIR
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'simplecov'
|
3
|
+
SimpleCov.start 'rails'
|
4
|
+
|
5
|
+
RSpec.configure do |config|
|
6
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
7
|
+
config.run_all_when_everything_filtered = true
|
8
|
+
config.filter_run :focus
|
9
|
+
config.order = 'random'
|
10
|
+
end
|
metadata
ADDED
@@ -0,0 +1,168 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: markun
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- tbpgr
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-12-26 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: thor
|
16
|
+
requirement: &22486656 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.18.1
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *22486656
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: activesupport
|
27
|
+
requirement: &22485588 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 4.0.1
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *22485588
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: activemodel
|
38
|
+
requirement: &22484676 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 4.0.2
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *22484676
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: kramdown
|
49
|
+
requirement: &22484400 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.3.0
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *22484400
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: bundler
|
60
|
+
requirement: &22484064 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ~>
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '1.3'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *22484064
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: &22483596 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *22483596
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: simplecov
|
82
|
+
requirement: &22483188 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ~>
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: 0.8.2
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: *22483188
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
name: rspec
|
93
|
+
requirement: &22482756 !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ~>
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: 2.14.1
|
99
|
+
type: :development
|
100
|
+
prerelease: false
|
101
|
+
version_requirements: *22482756
|
102
|
+
description: Markun is Markdown bulk converter with menu link
|
103
|
+
email:
|
104
|
+
- tbpgr@tbpgr.jp
|
105
|
+
executables:
|
106
|
+
- markun
|
107
|
+
extensions: []
|
108
|
+
extra_rdoc_files: []
|
109
|
+
files:
|
110
|
+
- .gitignore
|
111
|
+
- .rspec
|
112
|
+
- Gemfile
|
113
|
+
- LICENSE.txt
|
114
|
+
- README.md
|
115
|
+
- Rakefile
|
116
|
+
- bin/markun
|
117
|
+
- doc_image/parent1.png
|
118
|
+
- doc_image/sub1.png
|
119
|
+
- lib/markun/version.rb
|
120
|
+
- lib/markun_core.rb
|
121
|
+
- lib/markun_dsl.rb
|
122
|
+
- lib/markun_dsl_model.rb
|
123
|
+
- markun.gemspec
|
124
|
+
- sample/sample_after/Markunfile
|
125
|
+
- sample/sample_after/parent1.html
|
126
|
+
- sample/sample_after/parent1.md
|
127
|
+
- sample/sample_after/parent2.html
|
128
|
+
- sample/sample_after/parent2.md
|
129
|
+
- sample/sample_after/sub/sub1.html
|
130
|
+
- sample/sample_after/sub/sub1.md
|
131
|
+
- sample/sample_after/sub/sub2.html
|
132
|
+
- sample/sample_after/sub/sub2.md
|
133
|
+
- sample/sample_bofore/Markunfile
|
134
|
+
- sample/sample_bofore/parent1.md
|
135
|
+
- sample/sample_bofore/parent2.md
|
136
|
+
- sample/sample_bofore/sub/sub1.md
|
137
|
+
- sample/sample_bofore/sub/sub2.md
|
138
|
+
- spec/markun_core_spec.rb
|
139
|
+
- spec/spec_helper.rb
|
140
|
+
homepage: https://github.com/tbpgr/markun
|
141
|
+
licenses:
|
142
|
+
- MIT
|
143
|
+
post_install_message:
|
144
|
+
rdoc_options: []
|
145
|
+
require_paths:
|
146
|
+
- lib
|
147
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
148
|
+
none: false
|
149
|
+
requirements:
|
150
|
+
- - ! '>='
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
|
+
none: false
|
155
|
+
requirements:
|
156
|
+
- - ! '>='
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '0'
|
159
|
+
requirements: []
|
160
|
+
rubyforge_project:
|
161
|
+
rubygems_version: 1.8.11
|
162
|
+
signing_key:
|
163
|
+
specification_version: 3
|
164
|
+
summary: Markun is Markdown bulk converter with menu link
|
165
|
+
test_files:
|
166
|
+
- spec/markun_core_spec.rb
|
167
|
+
- spec/spec_helper.rb
|
168
|
+
has_rdoc:
|