fnando-bookmaker 0.0.9 → 0.0.10
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.
- data/History.txt +6 -1
- data/lib/bookmaker/base.rb +13 -2
- data/lib/bookmaker/tasks.rb +13 -2
- data/lib/bookmaker/version.rb +1 -1
- metadata +1 -1
data/History.txt
CHANGED
@@ -47,4 +47,9 @@
|
|
47
47
|
|
48
48
|
== 0.0.9 2008-07-25
|
49
49
|
* 1 bug fix
|
50
|
-
* Toc#to_s raised an error if book had no h2-h6 tags (thanks @rferraz)
|
50
|
+
* Toc#to_s raised an error if book had no h2-h6 tags (thanks @rferraz)
|
51
|
+
|
52
|
+
== 0.0.10
|
53
|
+
* 2 bug fixes
|
54
|
+
* generator was ignoring directories inside chapter
|
55
|
+
* repeated titles are now numerated to keep id uniqueness
|
data/lib/bookmaker/base.rb
CHANGED
@@ -99,10 +99,20 @@ module Bookmaker
|
|
99
99
|
return [contents, nil] unless Object.const_defined?('Hpricot') && Object.const_defined?('Unicode')
|
100
100
|
|
101
101
|
doc = Hpricot(contents)
|
102
|
+
counter = {}
|
102
103
|
|
103
104
|
(doc/"h2, h3, h4, h5, h6").each do |node|
|
104
105
|
title = node.inner_text
|
105
106
|
permalink = Bookmaker::Base.to_permalink(title)
|
107
|
+
|
108
|
+
# initialize and increment counter
|
109
|
+
counter[permalink] ||= 0
|
110
|
+
counter[permalink] += 1
|
111
|
+
|
112
|
+
# set a incremented permalink if more than one occurrence
|
113
|
+
# is found
|
114
|
+
permalink = "#{permalink}-#{counter[permalink]}" if counter[permalink] > 1
|
115
|
+
|
106
116
|
node.set_attribute(:id, permalink)
|
107
117
|
end
|
108
118
|
|
@@ -125,14 +135,15 @@ module Bookmaker
|
|
125
135
|
# first, get all chapters; then, get all parsed markdown
|
126
136
|
# files from this chapter and group them into a <div class="chapter"> tag
|
127
137
|
Dir.entries(text_dir).sort.each do |dirname|
|
128
|
-
|
138
|
+
# ignore files and some directories
|
139
|
+
next if %w(. .. .svn .git).include?(dirname) || File.file?(text_dir + "/#{dirname}")
|
129
140
|
|
130
141
|
# gets all parsed markdown files to wrap in a
|
131
142
|
# chapter element
|
132
143
|
chapter = ""
|
133
144
|
|
134
145
|
# merge all markdown and textile files into a single list
|
135
|
-
markup_files = Dir["#{text_dir}/#{dirname}
|
146
|
+
markup_files = Dir["#{text_dir}/#{dirname}/**/*.markdown"] + Dir["#{text_dir}/#{dirname}/**/*.textile"]
|
136
147
|
|
137
148
|
# no files, so skip it!
|
138
149
|
next if markup_files.empty?
|
data/lib/bookmaker/tasks.rb
CHANGED
@@ -63,13 +63,24 @@ namespace :book do
|
|
63
63
|
task :titles => :html do
|
64
64
|
contents = File.new(Bookmaker::Base.html_path).read
|
65
65
|
doc = Hpricot(contents)
|
66
|
+
counter = {}
|
66
67
|
|
67
68
|
titles = (doc/"h2, h3, h4, h5, h6").collect do |node|
|
68
69
|
title = node.inner_text
|
69
|
-
|
70
|
+
permalink = Bookmaker::Base.to_permalink(title)
|
71
|
+
|
72
|
+
# initialize and increment counter
|
73
|
+
counter[permalink] ||= 0
|
74
|
+
counter[permalink] += 1
|
75
|
+
|
76
|
+
# set a incremented permalink if more than one occurrence
|
77
|
+
# is found
|
78
|
+
permalink = "#{permalink}-#{counter[permalink]}" if counter[permalink] > 1
|
79
|
+
|
80
|
+
[title, permalink]
|
70
81
|
end
|
71
82
|
|
72
|
-
titles.sort_by {|items| items.
|
83
|
+
titles.sort_by {|items| items.last }.each do |items|
|
73
84
|
puts items.first
|
74
85
|
puts %(##{items.last})
|
75
86
|
puts
|
data/lib/bookmaker/version.rb
CHANGED