easy-doc 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.mkd +93 -0
- data/Rakefile +14 -0
- data/VERSION +1 -0
- data/bin/easy-doc +57 -0
- data/easy-doc.gemspec +51 -0
- data/lib/easy_doc.rb +288 -0
- data/spec/easy_doc_spec.rb +139 -0
- metadata +70 -0
data/README.mkd
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
# easy-doc - Write a document easily
|
2
|
+
|
3
|
+
## Requirements
|
4
|
+
|
5
|
+
* Ruby (I'm debugging in 1.9.1)
|
6
|
+
* rpeg-markdown
|
7
|
+
|
8
|
+
## Install
|
9
|
+
|
10
|
+
__Not available yet. I'll push soon :)__
|
11
|
+
|
12
|
+
### Using rubygem
|
13
|
+
|
14
|
+
gem install easy-doc
|
15
|
+
|
16
|
+
__NOTE:__ Gemcutter is needed.
|
17
|
+
|
18
|
+
### Using git
|
19
|
+
|
20
|
+
git clone git://github.com/sorah/easy-doc.git
|
21
|
+
|
22
|
+
and write following line your shell's rc-file:
|
23
|
+
|
24
|
+
export RUBYLIB=/path/to/easy-doc/lib:$RUBYLIB
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
### Simple
|
29
|
+
|
30
|
+
Simple directory structure:
|
31
|
+
|
32
|
+
doc/ -- documentation directory
|
33
|
+
mkd/ -- markdown directory
|
34
|
+
index.mkd -- index
|
35
|
+
index.ja.mkd -- index(ja)
|
36
|
+
|
37
|
+
and run following command in doc directory:
|
38
|
+
|
39
|
+
easy-doc mkd html
|
40
|
+
|
41
|
+
the easy-doc command render a markdown (in mkd directory) files to html directory.
|
42
|
+
|
43
|
+
And new directory structure:
|
44
|
+
|
45
|
+
doc/ -- documentation directory
|
46
|
+
mkd/ -- markdown directory
|
47
|
+
index.mkd -- index
|
48
|
+
index.ja.mkd -- index(ja)
|
49
|
+
checksums -- checksum data for re-rendering
|
50
|
+
html/ -- html directory. html is generate by easy-doc command.
|
51
|
+
index.html -- index(rendered)
|
52
|
+
index.ja.html -- index(rendered)
|
53
|
+
|
54
|
+
## Licence
|
55
|
+
|
56
|
+
MIT Licence.
|
57
|
+
|
58
|
+
(c) Sora Harakami
|
59
|
+
|
60
|
+
>The MIT Licence {{{
|
61
|
+
>
|
62
|
+
>Permission is hereby granted, free of charge, to any person obtaining a copy
|
63
|
+
>of this software and associated documentation files (the "Software"), to deal
|
64
|
+
>in the Software without restriction, including without limitation the rights
|
65
|
+
>to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
66
|
+
>copies of the Software, and to permit persons to whom the Software is
|
67
|
+
>furnished to do so, subject to the following conditions:
|
68
|
+
>
|
69
|
+
>The above copyright notice and this permission notice shall be included in
|
70
|
+
>all copies or substantial portions of the Software.
|
71
|
+
>
|
72
|
+
>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
73
|
+
>IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
74
|
+
>FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
75
|
+
>AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
76
|
+
>LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
77
|
+
>OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
78
|
+
>THE SOFTWARE.
|
79
|
+
>
|
80
|
+
>}}}
|
81
|
+
|
82
|
+
## Develop
|
83
|
+
|
84
|
+
### Requirements
|
85
|
+
|
86
|
+
* Ruby 1.8.7+
|
87
|
+
* RSpec
|
88
|
+
|
89
|
+
### Usage
|
90
|
+
|
91
|
+
You can run spec by this command:
|
92
|
+
|
93
|
+
spec ./spec/easy_doc_spec.rb
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
begin
|
2
|
+
require 'jeweler'
|
3
|
+
Jeweler::Tasks.new do |gemspec|
|
4
|
+
gemspec.name = "easy-doc"
|
5
|
+
gemspec.summary = "Write a document easily"
|
6
|
+
gemspec.email = "sora134@gmail.com"
|
7
|
+
gemspec.homepage = "http://github.com/sorah/easy-doc"
|
8
|
+
gemspec.description = "Write a document easily. Write a document, run command to rendering."
|
9
|
+
gemspec.authors = ["Sora Harakami"]
|
10
|
+
gemspec.add_dependency 'rpeg-markdown'
|
11
|
+
end
|
12
|
+
rescue LoadError
|
13
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
14
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
data/bin/easy-doc
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#-*- coding: utf-8 -*-
|
3
|
+
# vim: filetype=ruby
|
4
|
+
require File.dirname(__FILE__) + '/../lib/easy_doc.rb'
|
5
|
+
|
6
|
+
def show_help_and_exit
|
7
|
+
puts <<-EOH
|
8
|
+
Usage: #{$0} [--force] [--quiet] [--help] [-f] [-q] [-h] (MARKDOWN_DIR HTML_DIR|MARKDOWN_AND_HTML_DIR)
|
9
|
+
|
10
|
+
--force, -f | Force update
|
11
|
+
--quiet, -q | Don't put anything
|
12
|
+
--help ,-h | Show this message
|
13
|
+
MARKDOWN_AND_HTML_DIR | Read markdown file and export html file here.
|
14
|
+
MARKDOWN_DIR | Read markdown files from here.
|
15
|
+
HTML_DIR | Export html files here.
|
16
|
+
EOH
|
17
|
+
exit
|
18
|
+
end
|
19
|
+
|
20
|
+
def option_loop(arg,options={})
|
21
|
+
case arg
|
22
|
+
when '--force','-f'
|
23
|
+
options[:force] = true
|
24
|
+
when '--quiet','-q'
|
25
|
+
options[:quiet] = true
|
26
|
+
when '--help' ,'-h', nil
|
27
|
+
show_help_and_exit
|
28
|
+
else
|
29
|
+
if options[:mkd_dir].nil?
|
30
|
+
options[:mkd_dir] = arg
|
31
|
+
abort "ERROR: markdown dir not exist!" unless File.exist?(options[:mkd_dir])
|
32
|
+
elsif options[:html_dir].nil?
|
33
|
+
options[:html_dir] = arg
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
na = ARGV.shift
|
38
|
+
unless na.nil? # loop
|
39
|
+
option_loop(na,options)
|
40
|
+
else # exit loop
|
41
|
+
unless options[:mkd_dir]
|
42
|
+
abort "ERROR: markdown dir not specified."
|
43
|
+
end
|
44
|
+
options[:html_dir] = options[:mkd_dir] unless options[:html_dir]
|
45
|
+
options
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# kick loop
|
50
|
+
o = option_loop(ARGV.shift,
|
51
|
+
{
|
52
|
+
:force => false,
|
53
|
+
:quiet => false
|
54
|
+
})
|
55
|
+
# Run
|
56
|
+
e = EasyDoc.new(o[:mkd_dir],o[:html_dir])
|
57
|
+
e.render(o[:quiet],o[:force])
|
data/easy-doc.gemspec
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{easy-doc}
|
8
|
+
s.version = "1.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Sora Harakami"]
|
12
|
+
s.date = %q{2010-03-17}
|
13
|
+
s.default_executable = %q{easy-doc}
|
14
|
+
s.description = %q{Write a document easily. Write a document, run command to rendering.}
|
15
|
+
s.email = %q{sora134@gmail.com}
|
16
|
+
s.executables = ["easy-doc"]
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"README.mkd"
|
19
|
+
]
|
20
|
+
s.files = [
|
21
|
+
"README.mkd",
|
22
|
+
"Rakefile",
|
23
|
+
"VERSION",
|
24
|
+
"bin/easy-doc",
|
25
|
+
"easy-doc.gemspec",
|
26
|
+
"lib/easy_doc.rb",
|
27
|
+
"spec/easy_doc_spec.rb"
|
28
|
+
]
|
29
|
+
s.homepage = %q{http://github.com/sorah/easy-doc}
|
30
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
31
|
+
s.require_paths = ["lib"]
|
32
|
+
s.rubygems_version = %q{1.3.5}
|
33
|
+
s.summary = %q{Write a document easily}
|
34
|
+
s.test_files = [
|
35
|
+
"spec/easy_doc_spec.rb"
|
36
|
+
]
|
37
|
+
|
38
|
+
if s.respond_to? :specification_version then
|
39
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
40
|
+
s.specification_version = 3
|
41
|
+
|
42
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
43
|
+
s.add_runtime_dependency(%q<rpeg-markdown>, [">= 0"])
|
44
|
+
else
|
45
|
+
s.add_dependency(%q<rpeg-markdown>, [">= 0"])
|
46
|
+
end
|
47
|
+
else
|
48
|
+
s.add_dependency(%q<rpeg-markdown>, [">= 0"])
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
data/lib/easy_doc.rb
ADDED
@@ -0,0 +1,288 @@
|
|
1
|
+
#
|
2
|
+
# easy-doc
|
3
|
+
# Author: Sora Harakami
|
4
|
+
# Licence: MIT Licence
|
5
|
+
# The MIT Licence {{{
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
# of this software and associated documentation files (the "Software"), to deal
|
8
|
+
# in the Software without restriction, including without limitation the rights
|
9
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
# copies of the Software, and to permit persons to whom the Software is
|
11
|
+
# furnished to do so, subject to the following conditions:
|
12
|
+
#
|
13
|
+
# The above copyright notice and this permission notice shall be included in
|
14
|
+
# all copies or substantial portions of the Software.
|
15
|
+
#
|
16
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22
|
+
# THE SOFTWARE.
|
23
|
+
# }}}
|
24
|
+
#
|
25
|
+
require 'rubygems'
|
26
|
+
require 'markdown' # rpeg-markdown
|
27
|
+
require 'yaml'
|
28
|
+
require 'digest/md5'
|
29
|
+
require 'erb'
|
30
|
+
require 'pathname'
|
31
|
+
require 'fileutils'
|
32
|
+
|
33
|
+
class EasyDoc
|
34
|
+
class MakeDirectoryError < Exception; end
|
35
|
+
|
36
|
+
def initialize(mkd_path,html_path)
|
37
|
+
raise ArgumentError, 'mkd_path is invalid' unless File.directory?(mkd_path) && html_path.kind_of?(String)
|
38
|
+
raise ArgumentError, 'html_path is invalid' unless html_path.kind_of?(String)
|
39
|
+
@mkd_path = File.expand_path(mkd_path ).gsub(/\/$/,"")
|
40
|
+
@html_path = File.expand_path(html_path).gsub(/\/$/,"")
|
41
|
+
init_config
|
42
|
+
end
|
43
|
+
|
44
|
+
def init_config
|
45
|
+
@config = { #Default config
|
46
|
+
:default_lang => "default"
|
47
|
+
}
|
48
|
+
@changed_config = changed_config
|
49
|
+
@config.merge!(load_config)
|
50
|
+
end
|
51
|
+
|
52
|
+
def render(quiet=true,force=false)
|
53
|
+
puts "Checking changed markdown files..." unless quiet
|
54
|
+
f = (force || @changed_config.include?(:default_lang)) ? markdown_files : changed_markdown_files
|
55
|
+
f.each do |n|
|
56
|
+
puts "Rendering: #{n}" unless quiet
|
57
|
+
render_file(n)
|
58
|
+
end
|
59
|
+
self
|
60
|
+
end
|
61
|
+
|
62
|
+
def layout
|
63
|
+
if File.exist?("#{@mkd_path}/layout.erb")
|
64
|
+
File.read("#{@mkd_path}/layout.erb")
|
65
|
+
else
|
66
|
+
### Default layout ###
|
67
|
+
return <<-EOB
|
68
|
+
<html>
|
69
|
+
<head>
|
70
|
+
<title><%= title %></title>
|
71
|
+
<style type="text/css">
|
72
|
+
body {
|
73
|
+
font-family: sans-serif;
|
74
|
+
font-size: 18px;
|
75
|
+
}
|
76
|
+
|
77
|
+
h1 { font-size: 28px; }
|
78
|
+
h2 { font-size: 26px; }
|
79
|
+
h3 { font-size: 24px; }
|
80
|
+
h4 { font-size: 22px; }
|
81
|
+
h5 { font-size: 20px; }
|
82
|
+
h6 { font-size: 17px; }
|
83
|
+
|
84
|
+
.header {
|
85
|
+
padding-bottom: 10px;
|
86
|
+
border-bottom: 1px solid gray;
|
87
|
+
margin-bottom: 10px;
|
88
|
+
}
|
89
|
+
|
90
|
+
.lang_bar {
|
91
|
+
text-align: right;
|
92
|
+
font-size: 13px;
|
93
|
+
}
|
94
|
+
|
95
|
+
.title {
|
96
|
+
font-size: 24px;
|
97
|
+
margin-top: 5px;
|
98
|
+
}
|
99
|
+
</style>
|
100
|
+
</head>
|
101
|
+
<body>
|
102
|
+
<!-- Document rendered by easy_doc http://github.com/sorah/easy-doc -->
|
103
|
+
<div class="header">
|
104
|
+
<div class="lang_bar">
|
105
|
+
<%= lang_bar %>
|
106
|
+
</div>
|
107
|
+
<!--<div class="title"><%= title %></div>-->
|
108
|
+
</div>
|
109
|
+
<div class="doc_body">
|
110
|
+
<%= body %>
|
111
|
+
</div>
|
112
|
+
</body>
|
113
|
+
</html>
|
114
|
+
EOB
|
115
|
+
######### End #########
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def markdown_files(lp=true)
|
120
|
+
Dir.glob("#{@mkd_path}/**/*.mkd").map{|x| lp ? mkd_local_path(x) : x }
|
121
|
+
end
|
122
|
+
|
123
|
+
def delete_htmls(quiet=true)
|
124
|
+
fs = deleted_markdown_files
|
125
|
+
fs.each do |f|
|
126
|
+
h = f.gsub(/\.mkd$/,'.html')
|
127
|
+
puts "Removing: #{h}" unless quiet
|
128
|
+
FileUtils.remove(html_expand_path(h))
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
attr_reader :config
|
133
|
+
|
134
|
+
private
|
135
|
+
|
136
|
+
def html_create_dir(p)
|
137
|
+
FileUtils.mkdir_p(html_expand_path(p).gsub(/\/[^\/]+$/,""))
|
138
|
+
end
|
139
|
+
|
140
|
+
def render_file(f,force_other_lang=false)
|
141
|
+
mkd = File.read(mkd_expand_path(f))
|
142
|
+
title = mkd.scan(/^# (.+)/).flatten[0]
|
143
|
+
body = Markdown.new(mkd).to_html
|
144
|
+
body.gsub!(/<a href="(.+)">/) do |s|
|
145
|
+
u = $1
|
146
|
+
nu =
|
147
|
+
if /^\// =~ u
|
148
|
+
Pathname(mkd_expand_path(u)) \
|
149
|
+
.relative_path_from( \
|
150
|
+
Pathname(mkd_expand_path(File.dirname(f)
|
151
|
+
.gsub(/\/\.$/,'')))).to_s \
|
152
|
+
.gsub(/\.mkd$/,'.html')
|
153
|
+
else
|
154
|
+
u
|
155
|
+
end
|
156
|
+
"<a href='#{nu}'>"
|
157
|
+
end
|
158
|
+
t = File.basename(f)
|
159
|
+
lang_bar_ary = []
|
160
|
+
unless force_other_lang
|
161
|
+
Dir.glob("#{mkd_expand_path(File.dirname(f))}/*.mkd") \
|
162
|
+
.delete_if{|m| mkd_local_path(m) == f ||
|
163
|
+
/^#{Regexp.escape(t.gsub(/\..*mkd/,""))}/ !~ mkd_local_path(m)} \
|
164
|
+
.each do |m|
|
165
|
+
render_file(mkd_local_path(m),true)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
Dir.glob("#{mkd_expand_path(File.dirname(f))}/*.mkd") \
|
169
|
+
.map{|m| File.basename(m) } \
|
170
|
+
.delete_if{|m| /^#{Regexp.escape(t.gsub(/\..*mkd/,""))}/ !~ m}.each do |m|
|
171
|
+
la = m.scan(/(\..+)?\.mkd$/).flatten
|
172
|
+
l = la.include?(nil) ? @config[:default_lang] : la[0].gsub(/^\./,"")
|
173
|
+
ls = ""
|
174
|
+
unless t == m
|
175
|
+
ls += '<a href="'
|
176
|
+
ls += m.gsub(/\.mkd/,".html")
|
177
|
+
ls += '">'
|
178
|
+
end
|
179
|
+
ls += l
|
180
|
+
unless t == m
|
181
|
+
ls += '</a>'
|
182
|
+
end
|
183
|
+
lang_bar_ary << ls
|
184
|
+
end
|
185
|
+
lang_bar = lang_bar_ary.join(' | ')
|
186
|
+
hl = f.gsub(/\.mkd$/,'.html')
|
187
|
+
|
188
|
+
html_create_dir(hl)
|
189
|
+
open(html_expand_path(hl),'w') do |f|
|
190
|
+
f.puts ERB.new(layout()).result(binding)
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
def calcuate_checksums
|
195
|
+
a = markdown_files(false)
|
196
|
+
h = {}
|
197
|
+
a.each do |f|
|
198
|
+
h[mkd_local_path(f)] = Digest::MD5.new.update(File.read(f)).to_s
|
199
|
+
end
|
200
|
+
h
|
201
|
+
end
|
202
|
+
|
203
|
+
def save_checksums(h=nil)
|
204
|
+
if h.nil?
|
205
|
+
h = calcuate_checksums
|
206
|
+
end
|
207
|
+
open("#{@mkd_path}/.easy-doc_checksums",'w') do |f|
|
208
|
+
f.puts h.to_yaml
|
209
|
+
end
|
210
|
+
self
|
211
|
+
end
|
212
|
+
|
213
|
+
def load_checksums
|
214
|
+
if File.exist?("#{@mkd_path}/.easy-doc_checksums")
|
215
|
+
YAML.load_file("#{@mkd_path}/.easy-doc_checksums")
|
216
|
+
else
|
217
|
+
{}
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
|
222
|
+
def mkd_local_path(path)
|
223
|
+
path.gsub(/^#{Regexp.escape(@mkd_path)}\//,'').gsub(/^\.\//,"")
|
224
|
+
end
|
225
|
+
|
226
|
+
def mkd_expand_path(path)
|
227
|
+
@mkd_path + '/' + path.gsub(/^\//,'')
|
228
|
+
end
|
229
|
+
|
230
|
+
def html_local_path(path)
|
231
|
+
path.gsub(/^#{Regexp.escape(@html_path)}\//,'')
|
232
|
+
end
|
233
|
+
|
234
|
+
def html_expand_path(path)
|
235
|
+
@html_path + '/' + path.gsub(/^\//,'')
|
236
|
+
end
|
237
|
+
|
238
|
+
def changed_markdown_files(sv=true)
|
239
|
+
n = calcuate_checksums
|
240
|
+
o = load_checksums
|
241
|
+
r = []
|
242
|
+
n.each do |f,c| # exists file
|
243
|
+
if o[f] != c
|
244
|
+
r << f
|
245
|
+
end
|
246
|
+
end
|
247
|
+
save_checksums(n) if sv
|
248
|
+
@changed_config.include?(:default_lang) ? markdown_files : r + (n.keys - o.keys)
|
249
|
+
end
|
250
|
+
|
251
|
+
def old_load_config
|
252
|
+
h = {}
|
253
|
+
if File.exist?(mkd_expand_path('.bup_config.yml'))
|
254
|
+
YAML.load_file(mkd_expand_path('.bup_config.yml')).each do |k,v|
|
255
|
+
h[k.to_sym] = v
|
256
|
+
end
|
257
|
+
end
|
258
|
+
h
|
259
|
+
end
|
260
|
+
|
261
|
+
def changed_config
|
262
|
+
o = old_load_config
|
263
|
+
n = load_config(false)
|
264
|
+
a = []
|
265
|
+
n.each do |k,v|
|
266
|
+
a << k unless v == o[k]
|
267
|
+
end
|
268
|
+
a
|
269
|
+
end
|
270
|
+
|
271
|
+
def load_config(s=true)
|
272
|
+
h = {}
|
273
|
+
if File.exist?(mkd_expand_path('config.yml'))
|
274
|
+
YAML.load_file(mkd_expand_path('config.yml')).each do |k,v|
|
275
|
+
h[k.to_sym] = v
|
276
|
+
end
|
277
|
+
FileUtils.copy(mkd_expand_path('config.yml'),mkd_expand_path('.bup_config.yml')) if s
|
278
|
+
end
|
279
|
+
h
|
280
|
+
end
|
281
|
+
|
282
|
+
def deleted_markdown_files(sv=false)
|
283
|
+
n = calcuate_checksums
|
284
|
+
o = load_checksums
|
285
|
+
save_checksums(n) if sv
|
286
|
+
o.keys - n.keys
|
287
|
+
end
|
288
|
+
end
|
@@ -0,0 +1,139 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../lib/easy_doc.rb'
|
2
|
+
require 'tmpdir'
|
3
|
+
require 'fileutils'
|
4
|
+
require 'thread'
|
5
|
+
|
6
|
+
describe EasyDoc do
|
7
|
+
before(:all) do
|
8
|
+
@mpath = Dir.mktmpdir("easy_doc_spec_mkd" )
|
9
|
+
@hpath = Dir.mktmpdir("easy_doc_spec_html")
|
10
|
+
open(@mpath+'/index.mkd','w') {|f| f.puts "# hi" }
|
11
|
+
end
|
12
|
+
|
13
|
+
before do
|
14
|
+
@e = EasyDoc.new(@mpath,@hpath)
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#markdown_files' do
|
18
|
+
it 'take markdown files' do
|
19
|
+
@e.markdown_files.should include('index.mkd')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#init_config' do
|
24
|
+
it 'reload config' do
|
25
|
+
open(@mpath+"/config.yml",'w') do |f|
|
26
|
+
f.puts 'piyo: foobar'
|
27
|
+
end
|
28
|
+
@e.init_config
|
29
|
+
@e.config[:piyo].should == 'foobar'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '#render' do
|
34
|
+
it 'render markdown file' do
|
35
|
+
@e.render
|
36
|
+
File.exist?(@hpath+'/index.html').should be_true
|
37
|
+
File.read(@hpath+'/index.html').should match('<h1>hi</h1>')
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'must save checksums' do
|
41
|
+
File.exist?(@mpath+'/.easy-doc_checksums').should be_true
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'must not render not edited markdown file' do
|
45
|
+
t = File.mtime("#{@hpath}/index.html")
|
46
|
+
sleep 1 # TODO: Refactoring this.
|
47
|
+
@e.render
|
48
|
+
t.should == File.mtime("#{@hpath}/index.html")
|
49
|
+
end
|
50
|
+
|
51
|
+
it 're-render edited markdown files' do
|
52
|
+
open(@mpath+'/index.mkd','w') {|f| f.puts "# hi\n\n('.v.')" }
|
53
|
+
@e.render
|
54
|
+
File.read(@hpath+'/index.html').should match("<p>\\('\\.v\\.'\\)</p>")
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'force render' do
|
58
|
+
t = File.mtime("#{@hpath}/index.html")
|
59
|
+
sleep 1 # TODO: Refactoring this.
|
60
|
+
@e.render(true,true)
|
61
|
+
t.should < File.mtime("#{@hpath}/index.html")
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'render with layout file' do
|
65
|
+
open(@mpath+'/layout.erb','w') do |f|
|
66
|
+
f.puts <<-EOF
|
67
|
+
<html>
|
68
|
+
<body>
|
69
|
+
^q^<br>
|
70
|
+
<%=body%>
|
71
|
+
</body>
|
72
|
+
</html>
|
73
|
+
EOF
|
74
|
+
end
|
75
|
+
@e.render(true,true)
|
76
|
+
File.read(@hpath+'/index.html').should match("\\^q\\^")
|
77
|
+
FileUtils.rm(@mpath+'/layout.erb')
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'put messages' do
|
81
|
+
g, $stdout = IO.pipe
|
82
|
+
t = Thread.new do
|
83
|
+
["Checking changed markdown files","Rendering: index.mkd"].each do |m|
|
84
|
+
s = g.gets
|
85
|
+
s.should match(m)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
@e.render(false,true)
|
89
|
+
t.join
|
90
|
+
$stdout = STDOUT
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'render multiple languages' do
|
94
|
+
open(@mpath+'/index.ja.mkd','w') do |f|
|
95
|
+
f.puts "# Konnnitiha."
|
96
|
+
end
|
97
|
+
@e.render
|
98
|
+
File.read(@hpath+'/index.ja.html').should match('<a href="index.html">default</a>')
|
99
|
+
File.read(@hpath+'/index.html').should match('<a href="index.ja.html">ja</a>')
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'set default languages' do
|
103
|
+
open(@mpath+'/config.yml','w') do |f|
|
104
|
+
f.puts "default_lang: en"
|
105
|
+
end
|
106
|
+
@e.init_config
|
107
|
+
@e.render
|
108
|
+
File.read(@hpath+'/index.ja.html').should match('<a href="index.html">en</a>')
|
109
|
+
File.read(@hpath+'/index.html').should match('en')
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'generate relative path in <a>' do
|
113
|
+
Dir.mkdir(@mpath+'/foo').should == 0
|
114
|
+
File.exist?(@mpath+'/foo').should be_true
|
115
|
+
open(@mpath+'/foo/bar.mkd','w') do |f|
|
116
|
+
f.puts "# Foo\n\n# bar\n\n cool"
|
117
|
+
end
|
118
|
+
open(@mpath+'/index.mkd','w') {|f| f.puts "# hi\n\n[foobar!](/foo/bar.mkd)" }
|
119
|
+
@e.render(true,true)
|
120
|
+
File.read(@hpath+'/index.html').should match("<a href='foo/bar.html'>")
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
describe '#delete_htmls' do
|
125
|
+
it 'deletes deleted markdown file\'s html' do
|
126
|
+
open(@mpath+'/hoge.mkd','w') {|f| f.puts "# hi"}
|
127
|
+
@e.render
|
128
|
+
File.exist?(@hpath+'/hoge.html').should be_true
|
129
|
+
FileUtils.remove(@mpath+'/hoge.mkd')
|
130
|
+
@e.delete_htmls
|
131
|
+
File.exist?(@hpath+'/hoge.html').should be_false
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
after(:all) do
|
136
|
+
FileUtils.remove_entry_secure @mpath
|
137
|
+
FileUtils.remove_entry_secure @hpath
|
138
|
+
end
|
139
|
+
end
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: easy-doc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sora Harakami
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-03-17 00:00:00 +09:00
|
13
|
+
default_executable: easy-doc
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rpeg-markdown
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
description: Write a document easily. Write a document, run command to rendering.
|
26
|
+
email: sora134@gmail.com
|
27
|
+
executables:
|
28
|
+
- easy-doc
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- README.mkd
|
33
|
+
files:
|
34
|
+
- README.mkd
|
35
|
+
- Rakefile
|
36
|
+
- VERSION
|
37
|
+
- bin/easy-doc
|
38
|
+
- easy-doc.gemspec
|
39
|
+
- lib/easy_doc.rb
|
40
|
+
- spec/easy_doc_spec.rb
|
41
|
+
has_rdoc: true
|
42
|
+
homepage: http://github.com/sorah/easy-doc
|
43
|
+
licenses: []
|
44
|
+
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options:
|
47
|
+
- --charset=UTF-8
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: "0"
|
55
|
+
version:
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: "0"
|
61
|
+
version:
|
62
|
+
requirements: []
|
63
|
+
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 1.3.5
|
66
|
+
signing_key:
|
67
|
+
specification_version: 3
|
68
|
+
summary: Write a document easily
|
69
|
+
test_files:
|
70
|
+
- spec/easy_doc_spec.rb
|