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.
@@ -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
@@ -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
- next if %w(. ..).include?(dirname) || File.file?(text_dir + "/#{dirname}")
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}/*.markdown"] + Dir["#{text_dir}/#{dirname}/*.textile"]
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?
@@ -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
- [title, Bookmaker::Base.to_permalink(title)]
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.first }.each do |items|
83
+ titles.sort_by {|items| items.last }.each do |items|
73
84
  puts items.first
74
85
  puts %(##{items.last})
75
86
  puts
@@ -2,7 +2,7 @@ module Bookmaker #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- TINY = 9
5
+ TINY = 10
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fnando-bookmaker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira