mizuho 0.9.11 → 0.9.12
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/mizuho +2 -1
- data/lib/mizuho/id_map.rb +106 -21
- data/lib/mizuho.rb +2 -2
- data/test/id_map_spec.rb +62 -8
- metadata +36 -51
data/bin/mizuho
CHANGED
data/lib/mizuho/id_map.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2011-
|
1
|
+
# Copyright (c) 2011-2013 Hongli Lai
|
2
2
|
#
|
3
3
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
4
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -80,24 +80,26 @@ class IdMap
|
|
80
80
|
|
81
81
|
def save(filename_or_io)
|
82
82
|
normal, orphaned = group_and_sort_entries
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
end
|
83
|
+
output = ""
|
84
|
+
output << BANNER
|
85
|
+
normal.each do |entry|
|
86
|
+
output << "# fuzzy\n" if entry.fuzzy?
|
87
|
+
output << "#{entry.title} => #{entry.id}\n"
|
88
|
+
output << "\n"
|
89
|
+
end
|
90
|
+
if !orphaned.empty?
|
91
|
+
output << "\n"
|
92
|
+
output << "### These sections appear to have been removed. Please check.\n"
|
93
|
+
output << "\n"
|
94
|
+
orphaned.each do |entry|
|
95
|
+
output << "# fuzzy\n" if entry.fuzzy?
|
96
|
+
output << "#{entry.title} => #{entry.id}\n"
|
97
|
+
output << "\n"
|
99
98
|
end
|
100
99
|
end
|
100
|
+
open_io(filename_or_io, :write) do |f|
|
101
|
+
f.write(output)
|
102
|
+
end
|
101
103
|
end
|
102
104
|
|
103
105
|
def associate(title)
|
@@ -108,12 +110,13 @@ class IdMap
|
|
108
110
|
entry.associated = true
|
109
111
|
id = entry.id
|
110
112
|
end
|
111
|
-
elsif
|
113
|
+
elsif (moved_entry = find_moved(title)) || (similar_entry = find_similar(title))
|
114
|
+
entry = (moved_entry || similar_entry)
|
112
115
|
@entries.delete(entry.title)
|
113
116
|
@entries[title] = entry
|
114
117
|
entry.title = title
|
115
118
|
entry.associated = true
|
116
|
-
entry.fuzzy = true
|
119
|
+
entry.fuzzy = true if similar_entry
|
117
120
|
id = entry.id
|
118
121
|
else
|
119
122
|
id = create_unique_id(title)
|
@@ -149,7 +152,64 @@ private
|
|
149
152
|
alias associated? associated
|
150
153
|
|
151
154
|
def <=>(other)
|
152
|
-
|
155
|
+
if (a = IdMap.extract_chapter(title)) &&
|
156
|
+
(b = IdMap.extract_chapter(other.title))
|
157
|
+
# Sort by chapter whenever possible.
|
158
|
+
a[0] = IdMap.chapter_to_int_array(a[0])
|
159
|
+
b[0] = IdMap.chapter_to_int_array(b[0])
|
160
|
+
return a <=> b
|
161
|
+
else
|
162
|
+
return title <=> other.title
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
def find_moved(title)
|
168
|
+
orig_chapter, orig_pure_title = extract_chapter(title)
|
169
|
+
return nil if !orig_chapter
|
170
|
+
|
171
|
+
# Find all possible matches.
|
172
|
+
orig_chapter_digits = chapter_to_int_array(orig_chapter)
|
173
|
+
matches = []
|
174
|
+
@entries.each_value do |entry|
|
175
|
+
next if entry.associated?
|
176
|
+
chapter, pure_title = extract_chapter(entry.title)
|
177
|
+
if chapter && orig_pure_title == pure_title
|
178
|
+
matches << {
|
179
|
+
:chapter_digits => chapter_to_int_array(chapter),
|
180
|
+
:pure_title => pure_title,
|
181
|
+
:entry => entry
|
182
|
+
}
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
# Iterate until we find the best match. We match the chapter
|
187
|
+
# digits from left to right.
|
188
|
+
digit_match_index = 0
|
189
|
+
while matches.size > 1
|
190
|
+
orig_digit = orig_chapter_digits[digit_match_index]
|
191
|
+
|
192
|
+
# Find closest digit in all matches.
|
193
|
+
tmp = matches.min do |a, b|
|
194
|
+
x = a[:chapter_digits][digit_match_index] - orig_digit
|
195
|
+
y = b[:chapter_digits][digit_match_index] - orig_digit
|
196
|
+
x.abs <=> y.abs
|
197
|
+
end
|
198
|
+
closest_digit = tmp[:chapter_digits][digit_match_index]
|
199
|
+
|
200
|
+
# Filter out all matches with this digit.
|
201
|
+
matches = matches.find_all do |m|
|
202
|
+
m[:chapter_digits][digit_match_index] == closest_digit
|
203
|
+
end
|
204
|
+
|
205
|
+
# If a next iteration is necessary, we check the next digit.
|
206
|
+
digit_match_index += 1
|
207
|
+
end
|
208
|
+
|
209
|
+
if matches.empty?
|
210
|
+
return nil
|
211
|
+
else
|
212
|
+
return matches[0][:entry]
|
153
213
|
end
|
154
214
|
end
|
155
215
|
|
@@ -171,7 +231,32 @@ private
|
|
171
231
|
return nil
|
172
232
|
end
|
173
233
|
end
|
174
|
-
|
234
|
+
|
235
|
+
# Given a title with a chapter number, e.g. "6.1 Installation using tarball",
|
236
|
+
# splits the two up.
|
237
|
+
def self.extract_chapter(title)
|
238
|
+
title =~ /^((\d+\.)*) (.+)$/
|
239
|
+
chapter = $1
|
240
|
+
pure_title = $3
|
241
|
+
if !chapter.nil? && !chapter.empty? && pure_title && !pure_title.empty?
|
242
|
+
return [chapter, pure_title]
|
243
|
+
else
|
244
|
+
return nil
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
def extract_chapter(title)
|
249
|
+
return IdMap.extract_chapter(title)
|
250
|
+
end
|
251
|
+
|
252
|
+
def self.chapter_to_int_array(chapter)
|
253
|
+
return chapter.split('.').map { |x| x.to_i }
|
254
|
+
end
|
255
|
+
|
256
|
+
def chapter_to_int_array(chapter)
|
257
|
+
return IdMap.chapter_to_int_array(chapter)
|
258
|
+
end
|
259
|
+
|
175
260
|
def slug(text)
|
176
261
|
text = text.downcase
|
177
262
|
text.gsub!(/^(\d+\.)+ /, '')
|
data/lib/mizuho.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2008-
|
1
|
+
# Copyright (c) 2008-2013 Hongli Lai
|
2
2
|
#
|
3
3
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
4
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -24,7 +24,7 @@ module Mizuho
|
|
24
24
|
TEMPLATES_DIR = "#{SOURCE_ROOT}/templates"
|
25
25
|
ASCIIDOC = "#{SOURCE_ROOT}/asciidoc/asciidoc.py"
|
26
26
|
|
27
|
-
VERSION_STRING = "0.9.
|
27
|
+
VERSION_STRING = "0.9.12"
|
28
28
|
|
29
29
|
if $LOAD_PATH.first != LIBDIR
|
30
30
|
$LOAD_PATH.unshift(LIBDIR)
|
data/test/id_map_spec.rb
CHANGED
@@ -22,9 +22,11 @@ require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
|
|
22
22
|
require 'stringio'
|
23
23
|
require 'mizuho/id_map'
|
24
24
|
|
25
|
-
|
25
|
+
module Mizuho
|
26
|
+
|
27
|
+
describe IdMap do
|
26
28
|
before :each do
|
27
|
-
@id_map =
|
29
|
+
@id_map = IdMap.new
|
28
30
|
end
|
29
31
|
|
30
32
|
describe "#associate" do
|
@@ -54,6 +56,39 @@ describe Mizuho::IdMap do
|
|
54
56
|
end
|
55
57
|
end
|
56
58
|
|
59
|
+
describe "if the same title exists in the map, but with a different section number" do
|
60
|
+
before :each do
|
61
|
+
@entry1 = @id_map.add("1.2. Installation using a tarball", nil, false, false)
|
62
|
+
@entry2 = @id_map.add("5.6. Installation using a tarball", nil, false, false)
|
63
|
+
@entry3 = @id_map.add("6.0. Installation using a tarball", nil, false, false)
|
64
|
+
@id1 = @id_map.associate "5.4. Installation using a tarball"
|
65
|
+
@id2 = @id_map.associate "2.1. Installation using a tarball"
|
66
|
+
end
|
67
|
+
|
68
|
+
it "associates with the title whose section number is closest to the new section number" do
|
69
|
+
@id1.should == @entry2.id
|
70
|
+
@id2.should == @entry1.id
|
71
|
+
end
|
72
|
+
|
73
|
+
it "changes the original entries' titles" do
|
74
|
+
@entry1.title.should == "2.1. Installation using a tarball"
|
75
|
+
@entry2.title.should == "5.4. Installation using a tarball"
|
76
|
+
@entry3.title.should == "6.0. Installation using a tarball"
|
77
|
+
end
|
78
|
+
|
79
|
+
it "marks the corresponding entry as associated" do
|
80
|
+
@entry1.should be_associated
|
81
|
+
@entry2.should be_associated
|
82
|
+
@entry3.should_not be_associated
|
83
|
+
end
|
84
|
+
|
85
|
+
it "doesn't mark the corresponding entry as fuzzy" do
|
86
|
+
@entry1.should_not be_fuzzy
|
87
|
+
@entry2.should_not be_fuzzy
|
88
|
+
@entry3.should_not be_fuzzy
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
57
92
|
describe "if one or more similar titles exist in the map" do
|
58
93
|
before :each do
|
59
94
|
@entry1 = @id_map.add("Installation using a tarball", nil, false, false)
|
@@ -118,17 +153,27 @@ describe Mizuho::IdMap do
|
|
118
153
|
describe "if the given title is in the map and it has been associated before" do
|
119
154
|
it "raises an error" do
|
120
155
|
@entry = @id_map.add("Installation", nil, false, true)
|
121
|
-
lambda { @id_map.associate "Installation" }.should raise_error(
|
156
|
+
lambda { @id_map.associate "Installation" }.should raise_error(IdMap::AlreadyAssociatedError)
|
122
157
|
end
|
123
158
|
end
|
124
159
|
end
|
125
160
|
|
161
|
+
describe "entries" do
|
162
|
+
specify "are sortable by chapter" do
|
163
|
+
array = []
|
164
|
+
array << IdMap::Entry.new('1. Extra chapter')
|
165
|
+
array << IdMap::Entry.new('10. Under the hood')
|
166
|
+
array << IdMap::Entry.new('2.1. Generic installation instructions')
|
167
|
+
array.sort!
|
168
|
+
array[0].title.should == '1. Extra chapter'
|
169
|
+
array[1].title.should == '2.1. Generic installation instructions'
|
170
|
+
array[2].title.should == '10. Under the hood'
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
126
174
|
describe "loading" do
|
127
175
|
before :each do
|
128
176
|
@io = StringIO.new
|
129
|
-
end
|
130
|
-
|
131
|
-
it "works" do
|
132
177
|
@io.puts "# This is a comment."
|
133
178
|
@io.puts ""
|
134
179
|
@io.puts "Installation => installation-1"
|
@@ -136,10 +181,17 @@ describe Mizuho::IdMap do
|
|
136
181
|
@io.puts "# fuzzy"
|
137
182
|
@io.puts "Troubleshooting => troubleshooting-1"
|
138
183
|
@io.rewind
|
184
|
+
end
|
185
|
+
|
186
|
+
it "marks all entries as 'not associated'" do
|
187
|
+
@id_map.load(@io)
|
188
|
+
@id_map.entries.each_value { |entry| entry.should_not be_associated }
|
189
|
+
end
|
190
|
+
|
191
|
+
it "works" do
|
139
192
|
@id_map.load(@io)
|
140
193
|
|
141
194
|
@id_map.entries.should have(3).items
|
142
|
-
@id_map.entries.each_value { |entry| entry.should_not be_associated }
|
143
195
|
|
144
196
|
entry = @id_map["Installation"]
|
145
197
|
entry.title.should == "Installation"
|
@@ -172,7 +224,7 @@ describe Mizuho::IdMap do
|
|
172
224
|
it "saves all entries in alphabetical order, marks fuzzy entries as such and puts unassociated (orphaned) entries at the bottom" do
|
173
225
|
@id_map.save(@io)
|
174
226
|
@io.string.should ==
|
175
|
-
|
227
|
+
IdMap::BANNER +
|
176
228
|
"0. Introduction => intro\n\n" +
|
177
229
|
"1. Installation => installation-1\n\n" +
|
178
230
|
"2. Configuration => configuration-2\n\n" +
|
@@ -186,3 +238,5 @@ describe Mizuho::IdMap do
|
|
186
238
|
end
|
187
239
|
end
|
188
240
|
end
|
241
|
+
|
242
|
+
end # module Mizuho
|
metadata
CHANGED
@@ -1,46 +1,42 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: mizuho
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.12
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 9
|
9
|
-
- 11
|
10
|
-
version: 0.9.11
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Hongli Lai
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2013-01-20 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
21
15
|
name: nokogiri
|
22
|
-
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
24
17
|
none: false
|
25
|
-
requirements:
|
26
|
-
- -
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
segments:
|
30
|
-
- 0
|
31
|
-
version: "0"
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
32
22
|
type: :runtime
|
33
|
-
|
34
|
-
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: A documentation formatting tool. Mizuho converts Asciidoc input files
|
31
|
+
into nicely outputted HTML, possibly one file per chapter. Multiple templates are
|
32
|
+
supported, so you can write your own.
|
35
33
|
email: hongli@phusion.nl
|
36
|
-
executables:
|
34
|
+
executables:
|
37
35
|
- mizuho
|
38
36
|
- mizuho-asciidoc
|
39
37
|
extensions: []
|
40
|
-
|
41
38
|
extra_rdoc_files: []
|
42
|
-
|
43
|
-
files:
|
39
|
+
files:
|
44
40
|
- README.markdown
|
45
41
|
- LICENSE.txt
|
46
42
|
- Rakefile
|
@@ -376,37 +372,26 @@ files:
|
|
376
372
|
- source-highlight/xorg.lang
|
377
373
|
homepage: https://github.com/FooBarWidget/mizuho
|
378
374
|
licenses: []
|
379
|
-
|
380
375
|
post_install_message:
|
381
376
|
rdoc_options: []
|
382
|
-
|
383
|
-
require_paths:
|
377
|
+
require_paths:
|
384
378
|
- lib
|
385
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
379
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
386
380
|
none: false
|
387
|
-
requirements:
|
388
|
-
- -
|
389
|
-
- !ruby/object:Gem::Version
|
390
|
-
|
391
|
-
|
392
|
-
- 0
|
393
|
-
version: "0"
|
394
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
381
|
+
requirements:
|
382
|
+
- - ! '>='
|
383
|
+
- !ruby/object:Gem::Version
|
384
|
+
version: '0'
|
385
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
395
386
|
none: false
|
396
|
-
requirements:
|
397
|
-
- -
|
398
|
-
- !ruby/object:Gem::Version
|
399
|
-
|
400
|
-
segments:
|
401
|
-
- 0
|
402
|
-
version: "0"
|
387
|
+
requirements:
|
388
|
+
- - ! '>='
|
389
|
+
- !ruby/object:Gem::Version
|
390
|
+
version: '0'
|
403
391
|
requirements: []
|
404
|
-
|
405
392
|
rubyforge_project:
|
406
|
-
rubygems_version: 1.8.
|
393
|
+
rubygems_version: 1.8.24
|
407
394
|
signing_key:
|
408
395
|
specification_version: 3
|
409
396
|
summary: Mizuho documentation formatting tool
|
410
397
|
test_files: []
|
411
|
-
|
412
|
-
has_rdoc:
|