From 7f0d5e934f7887eff0319db14e8583dac7078a47 Mon Sep 17 00:00:00 2001
From: Ralph Amissah <ralph@amissah.com>
Date: Fri, 26 Dec 2014 21:41:22 -0500
Subject: c&d: po4a, book index, reinstate

---
 lib/sisu/current/po4a.rb | 76 ++++++++++++++++++++++++++++++++++++------------
 lib/sisu/develop/po4a.rb | 76 ++++++++++++++++++++++++++++++++++++------------
 2 files changed, 116 insertions(+), 36 deletions(-)

diff --git a/lib/sisu/current/po4a.rb b/lib/sisu/current/po4a.rb
index 097fb2c6..f7d89c2d 100644
--- a/lib/sisu/current/po4a.rb
+++ b/lib/sisu/current/po4a.rb
@@ -747,25 +747,65 @@ GSUB
         unwrapped=util.no_line_wrap_block
         @pot[:body] << unwrapped << br
       end
+      def pot_structure_idx_markup(idx)
+        struct=['={']
+        idx.sort.each do |x|
+          x.each_with_index do |y,i0|
+            case y
+            when String
+              struct << ';' unless struct[-1] =~/=\{/
+              struct << y
+              if x[i0+1].class == Hash \
+              and x[i0+1][:sub].length > 0
+                struct << ':'
+              end
+            when Hash
+              if y[:plus].to_i > 0
+                struct << '+' + y[:plus].to_s
+              end
+              if y[:sub].length > 0
+                y[:sub].each_with_index do |z,i1|
+                  z.each_with_index do |a,i2|
+                    #p a
+                    if z.length > 0
+                      struct << a[0]
+                      if a[1][:plus].to_i > 0
+                        struct << '+' + a[1][:plus].to_s
+                      end
+                      if (i1 + 1) < y[:sub].length
+                        struct << '|'
+                      end
+                    end
+                  end
+                end
+              end
+            end
+          end
+        end
+        struct << '}'
+        #puts struct.join
+        struct.join
+      end
       def pot_structure_idx(dob_src='',dob_trn='')                             #% used for book index but broken as original markup lost, already abstracted, fix
-        #mark="={ ... }"
-        #instruct=s_mark=''
-        #if @md.opt.act[:maintenance][:set]==:on
-        #  instruct="\n# the book index should be attached unwrapped to the preceding text block (there should be a new line, but no empty line)"
-        #  s_mark="\n# " + %{"\\n#{mark}\\n\\n"}
-        #end
-        #d='book-idx'
-        #desc="#{d}#{s_mark}#{instruct}"
-        #orig='={' + dob_src.idx + '}'
-        #trans=if defined? dob_trn.idx \
-        #and not dob_trn.idx.nil? \
-        #and not dob_trn.idx.empty?
-        #  '={' + dob_trn.idx + '}'
-        #else ''
-        #end
-        #util=pot_structure(desc,orig,trans)
-        #unwrapped=util.no_line_wrap_block
-        #@pot[:body] << unwrapped << br
+        mark="={ ... }"
+        instruct=s_mark=''
+        if @md.opt.act[:maintenance][:set]==:on
+          instruct=%{\n# the book index should be attached unwrapped to the preceding text block } \
+          + %{(there should be a new line, but no empty line)}
+          s_mark="\n# " + %{"\\n#{mark}\\n\\n"}
+        end
+        d='book-idx'
+        desc="#{d}#{s_mark}#{instruct}"
+        orig=pot_structure_idx_markup(dob_src.idx) #'={' + dob_src.idx + '}'
+        trans=if defined? dob_trn.idx \
+        and not dob_trn.idx.nil? \
+        and not dob_trn.idx.empty?
+          pot_structure_idx_markup(dob_trn.idx) #'={' + dob_trn.idx + '}'
+        else ''
+        end
+        util=pot_structure(desc,orig,trans)
+        unwrapped=util.no_line_wrap_block
+        @pot[:body] << unwrapped << br
       end
       def pot_markup(data_src,data_trn)
         #@endnotes,@copen,@pot_contents_close=Array.new(3){[]}
diff --git a/lib/sisu/develop/po4a.rb b/lib/sisu/develop/po4a.rb
index e0b31ce0..a302e02e 100644
--- a/lib/sisu/develop/po4a.rb
+++ b/lib/sisu/develop/po4a.rb
@@ -747,25 +747,65 @@ GSUB
         unwrapped=util.no_line_wrap_block
         @pot[:body] << unwrapped << br
       end
+      def pot_structure_idx_markup(idx)
+        struct=['={']
+        idx.sort.each do |x|
+          x.each_with_index do |y,i0|
+            case y
+            when String
+              struct << ';' unless struct[-1] =~/=\{/
+              struct << y
+              if x[i0+1].class == Hash \
+              and x[i0+1][:sub].length > 0
+                struct << ':'
+              end
+            when Hash
+              if y[:plus].to_i > 0
+                struct << '+' + y[:plus].to_s
+              end
+              if y[:sub].length > 0
+                y[:sub].each_with_index do |z,i1|
+                  z.each_with_index do |a,i2|
+                    #p a
+                    if z.length > 0
+                      struct << a[0]
+                      if a[1][:plus].to_i > 0
+                        struct << '+' + a[1][:plus].to_s
+                      end
+                      if (i1 + 1) < y[:sub].length
+                        struct << '|'
+                      end
+                    end
+                  end
+                end
+              end
+            end
+          end
+        end
+        struct << '}'
+        #puts struct.join
+        struct.join
+      end
       def pot_structure_idx(dob_src='',dob_trn='')                             #% used for book index but broken as original markup lost, already abstracted, fix
-        #mark="={ ... }"
-        #instruct=s_mark=''
-        #if @md.opt.act[:maintenance][:set]==:on
-        #  instruct="\n# the book index should be attached unwrapped to the preceding text block (there should be a new line, but no empty line)"
-        #  s_mark="\n# " + %{"\\n#{mark}\\n\\n"}
-        #end
-        #d='book-idx'
-        #desc="#{d}#{s_mark}#{instruct}"
-        #orig='={' + dob_src.idx + '}'
-        #trans=if defined? dob_trn.idx \
-        #and not dob_trn.idx.nil? \
-        #and not dob_trn.idx.empty?
-        #  '={' + dob_trn.idx + '}'
-        #else ''
-        #end
-        #util=pot_structure(desc,orig,trans)
-        #unwrapped=util.no_line_wrap_block
-        #@pot[:body] << unwrapped << br
+        mark="={ ... }"
+        instruct=s_mark=''
+        if @md.opt.act[:maintenance][:set]==:on
+          instruct=%{\n# the book index should be attached unwrapped to the preceding text block } \
+          + %{(there should be a new line, but no empty line)}
+          s_mark="\n# " + %{"\\n#{mark}\\n\\n"}
+        end
+        d='book-idx'
+        desc="#{d}#{s_mark}#{instruct}"
+        orig=pot_structure_idx_markup(dob_src.idx) #'={' + dob_src.idx + '}'
+        trans=if defined? dob_trn.idx \
+        and not dob_trn.idx.nil? \
+        and not dob_trn.idx.empty?
+          pot_structure_idx_markup(dob_trn.idx) #'={' + dob_trn.idx + '}'
+        else ''
+        end
+        util=pot_structure(desc,orig,trans)
+        unwrapped=util.no_line_wrap_block
+        @pot[:body] << unwrapped << br
       end
       def pot_markup(data_src,data_trn)
         #@endnotes,@copen,@pot_contents_close=Array.new(3){[]}
-- 
cgit v1.2.3