sisu 7.1.7 → 7.1.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (180) hide show
  1. checksums.yaml +4 -4
  2. data/data/sisu/version.yml +3 -3
  3. data/lib/sisu/air.rb +10 -12
  4. data/lib/sisu/ao.rb +10 -12
  5. data/lib/sisu/ao_appendices.rb +10 -12
  6. data/lib/sisu/ao_character_check.rb +10 -12
  7. data/lib/sisu/ao_composite.rb +10 -12
  8. data/lib/sisu/ao_doc_objects.rb +10 -12
  9. data/lib/sisu/ao_doc_str.rb +10 -12
  10. data/lib/sisu/ao_endnotes.rb +10 -12
  11. data/lib/sisu/ao_expand_insertions.rb +10 -12
  12. data/lib/sisu/ao_hash_digest.rb +10 -12
  13. data/lib/sisu/ao_idx.rb +10 -12
  14. data/lib/sisu/ao_images.rb +10 -12
  15. data/lib/sisu/ao_metadata.rb +10 -12
  16. data/lib/sisu/ao_misc_arrange.rb +10 -12
  17. data/lib/sisu/ao_numbering.rb +10 -12
  18. data/lib/sisu/ao_persist.rb +10 -12
  19. data/lib/sisu/ao_syntax.rb +10 -12
  20. data/lib/sisu/cgi.rb +10 -12
  21. data/lib/sisu/cgi_pgsql.rb +10 -12
  22. data/lib/sisu/cgi_sql_common.rb +16 -18
  23. data/lib/sisu/cgi_sqlite.rb +10 -12
  24. data/lib/sisu/conf.rb +10 -12
  25. data/lib/sisu/constants.rb +12 -13
  26. data/lib/sisu/css.rb +10 -12
  27. data/lib/sisu/db_columns.rb +10 -12
  28. data/lib/sisu/db_create.rb +10 -12
  29. data/lib/sisu/db_dbi.rb +10 -12
  30. data/lib/sisu/db_drop.rb +10 -12
  31. data/lib/sisu/db_import.rb +10 -12
  32. data/lib/sisu/db_indexes.rb +10 -12
  33. data/lib/sisu/db_load_tuple.rb +10 -12
  34. data/lib/sisu/db_remove.rb +10 -12
  35. data/lib/sisu/db_select.rb +10 -12
  36. data/lib/sisu/db_sqltxt.rb +10 -12
  37. data/lib/sisu/db_tests.rb +10 -12
  38. data/lib/sisu/dbi.rb +10 -12
  39. data/lib/sisu/dbi_discrete.rb +10 -12
  40. data/lib/sisu/digests.rb +10 -12
  41. data/lib/sisu/dp.rb +15 -14
  42. data/lib/sisu/dp_identify_markup.rb +10 -12
  43. data/lib/sisu/dp_make.rb +11 -13
  44. data/lib/sisu/embedded.rb +10 -12
  45. data/lib/sisu/errors.rb +10 -12
  46. data/lib/sisu/generic_parts.rb +10 -12
  47. data/lib/sisu/git.rb +10 -12
  48. data/lib/sisu/html.rb +10 -12
  49. data/lib/sisu/html_concordance.rb +10 -12
  50. data/lib/sisu/html_format.rb +10 -12
  51. data/lib/sisu/html_harvest.rb +10 -12
  52. data/lib/sisu/html_harvest_author_format.rb +10 -12
  53. data/lib/sisu/html_harvest_authors.rb +10 -12
  54. data/lib/sisu/html_harvest_topics.rb +10 -12
  55. data/lib/sisu/html_lite_shared.rb +10 -12
  56. data/lib/sisu/html_manifest.rb +10 -12
  57. data/lib/sisu/html_minitoc.rb +10 -12
  58. data/lib/sisu/html_parts.rb +10 -12
  59. data/lib/sisu/html_persist.rb +10 -12
  60. data/lib/sisu/html_promo.rb +10 -12
  61. data/lib/sisu/html_scroll.rb +10 -12
  62. data/lib/sisu/html_segments.rb +10 -12
  63. data/lib/sisu/html_shared.rb +10 -12
  64. data/lib/sisu/html_table.rb +10 -12
  65. data/lib/sisu/html_tune.rb +10 -12
  66. data/lib/sisu/hub.rb +12 -13
  67. data/lib/sisu/hub_actions.rb +26 -12
  68. data/lib/sisu/hub_loop_markup_files.rb +10 -12
  69. data/lib/sisu/hub_options.rb +19 -12
  70. data/lib/sisu/i18n.rb +10 -12
  71. data/lib/sisu/json.rb +415 -0
  72. data/lib/sisu/json_format.rb +478 -0
  73. data/lib/sisu/json_parts.rb +88 -0
  74. data/lib/sisu/json_persist.rb +124 -0
  75. data/lib/sisu/json_shared.rb +681 -0
  76. data/lib/sisu/manpage.rb +11 -13
  77. data/lib/sisu/manpage_format.rb +10 -12
  78. data/lib/sisu/object_munge.rb +10 -12
  79. data/lib/sisu/prog_text_translation.rb +10 -12
  80. data/lib/sisu/qrcode.rb +10 -12
  81. data/lib/sisu/relaxng.rb +16 -18
  82. data/lib/sisu/remote.rb +10 -12
  83. data/lib/sisu/rexml.rb +10 -12
  84. data/lib/sisu/se.rb +10 -12
  85. data/lib/sisu/se_cleanoutput.rb +10 -12
  86. data/lib/sisu/se_clear.rb +10 -12
  87. data/lib/sisu/se_createsite.rb +10 -12
  88. data/lib/sisu/se_css.rb +10 -12
  89. data/lib/sisu/se_date.rb +10 -12
  90. data/lib/sisu/se_db.rb +10 -12
  91. data/lib/sisu/se_envcall.rb +10 -12
  92. data/lib/sisu/se_file_op.rb +69 -12
  93. data/lib/sisu/se_filemap.rb +10 -12
  94. data/lib/sisu/se_get_init.rb +10 -12
  95. data/lib/sisu/se_hub_particulars.rb +10 -12
  96. data/lib/sisu/se_info_env.rb +10 -12
  97. data/lib/sisu/se_info_port.rb +10 -12
  98. data/lib/sisu/se_info_system.rb +10 -12
  99. data/lib/sisu/se_load.rb +10 -12
  100. data/lib/sisu/se_processing.rb +10 -12
  101. data/lib/sisu/se_programs.rb +10 -12
  102. data/lib/sisu/se_remotes.rb +10 -12
  103. data/lib/sisu/se_standardise_lang.rb +10 -12
  104. data/lib/sisu/se_version.rb +10 -12
  105. data/lib/sisu/shared_images.rb +10 -12
  106. data/lib/sisu/shared_markup_alt.rb +10 -12
  107. data/lib/sisu/shared_metadata.rb +22 -12
  108. data/lib/sisu/shared_sem.rb +10 -12
  109. data/lib/sisu/sitemaps.rb +10 -12
  110. data/lib/sisu/src_kdissert_share.rb +10 -12
  111. data/lib/sisu/src_po4a_share.rb +10 -12
  112. data/lib/sisu/src_po4a_shelf.rb +10 -12
  113. data/lib/sisu/src_po4a_shelf_set.rb +10 -12
  114. data/lib/sisu/src_po4a_sst_ao_sst.rb +10 -12
  115. data/lib/sisu/src_po4a_sst_ao_sst_set.rb +10 -12
  116. data/lib/sisu/src_po4a_sstm.rb +10 -12
  117. data/lib/sisu/src_shared.rb +10 -12
  118. data/lib/sisu/src_sisupod_make.rb +10 -12
  119. data/lib/sisu/src_sisupod_sstm.rb +10 -12
  120. data/lib/sisu/sst_convert_markup.rb +10 -12
  121. data/lib/sisu/sst_do_inline_footnotes.rb +10 -12
  122. data/lib/sisu/sst_from_xml.rb +10 -12
  123. data/lib/sisu/sst_identify_markup.rb +10 -12
  124. data/lib/sisu/sst_to_s_xml_sax.rb +10 -12
  125. data/lib/sisu/termsheet.rb +10 -12
  126. data/lib/sisu/texinfo.rb +10 -12
  127. data/lib/sisu/texinfo_format.rb +10 -12
  128. data/lib/sisu/texpdf.rb +10 -12
  129. data/lib/sisu/texpdf_format.rb +10 -12
  130. data/lib/sisu/texpdf_parts.rb +10 -12
  131. data/lib/sisu/txt_asciidoc.rb +10 -12
  132. data/lib/sisu/txt_asciidoc_decorate.rb +10 -12
  133. data/lib/sisu/txt_markdown.rb +10 -12
  134. data/lib/sisu/txt_markdown_decorate.rb +10 -12
  135. data/lib/sisu/txt_orgmode.rb +36 -22
  136. data/lib/sisu/txt_orgmode_decorate.rb +10 -12
  137. data/lib/sisu/txt_output.rb +10 -12
  138. data/lib/sisu/txt_plain.rb +10 -12
  139. data/lib/sisu/txt_plain_decorate.rb +10 -12
  140. data/lib/sisu/txt_read.rb +10 -12
  141. data/lib/sisu/txt_rst.rb +10 -12
  142. data/lib/sisu/txt_rst_decorate.rb +10 -12
  143. data/lib/sisu/txt_shared.rb +10 -12
  144. data/lib/sisu/txt_textile.rb +10 -12
  145. data/lib/sisu/txt_textile_decorate.rb +10 -12
  146. data/lib/sisu/update.rb +10 -12
  147. data/lib/sisu/urls.rb +23 -12
  148. data/lib/sisu/utils.rb +10 -11
  149. data/lib/sisu/utils_composite.rb +10 -12
  150. data/lib/sisu/utils_response.rb +10 -12
  151. data/lib/sisu/utils_screen_text_color.rb +10 -12
  152. data/lib/sisu/utils_spell.rb +10 -12
  153. data/lib/sisu/webrick.rb +10 -12
  154. data/lib/sisu/wikispeak.rb +10 -12
  155. data/lib/sisu/xhtml.rb +10 -12
  156. data/lib/sisu/xhtml_epub2.rb +10 -12
  157. data/lib/sisu/xhtml_epub2_concordance.rb +10 -12
  158. data/lib/sisu/xhtml_epub2_format.rb +10 -12
  159. data/lib/sisu/xhtml_epub2_persist.rb +10 -12
  160. data/lib/sisu/xhtml_epub2_segments.rb +10 -12
  161. data/lib/sisu/xhtml_epub2_tune.rb +10 -12
  162. data/lib/sisu/xhtml_parts.rb +10 -12
  163. data/lib/sisu/xhtml_shared.rb +10 -12
  164. data/lib/sisu/xhtml_table.rb +10 -12
  165. data/lib/sisu/xml_docbook5.rb +10 -12
  166. data/lib/sisu/xml_dom.rb +10 -12
  167. data/lib/sisu/xml_fictionbook2.rb +10 -12
  168. data/lib/sisu/xml_format.rb +10 -12
  169. data/lib/sisu/xml_md_oai_pmh_dc.rb +10 -12
  170. data/lib/sisu/xml_odf_odt.rb +10 -12
  171. data/lib/sisu/xml_odf_odt_format.rb +10 -12
  172. data/lib/sisu/xml_parts.rb +10 -12
  173. data/lib/sisu/xml_persist.rb +10 -12
  174. data/lib/sisu/xml_sax.rb +10 -12
  175. data/lib/sisu/xml_scaffold_structure_collapsed.rb +10 -12
  176. data/lib/sisu/xml_scaffold_structure_sisu.rb +10 -12
  177. data/lib/sisu/xml_shared.rb +10 -12
  178. data/lib/sisu/xml_tables.rb +10 -12
  179. data/lib/sisu/zap.rb +10 -12
  180. metadata +9 -4
@@ -9,11 +9,11 @@
9
9
  *** hub
10
10
 
11
11
  ** Author: Ralph Amissah
12
- <ralph@amissah.com>
13
- <ralph.amissah@gmail.com>
12
+ [ralph@amissah.com]
13
+ [ralph.amissah@gmail.com]
14
14
 
15
15
  ** Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
16
- 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Ralph Amissah,
16
+ 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Ralph Amissah,
17
17
  All Rights Reserved.
18
18
 
19
19
  ** License: GPL 3 or later:
@@ -33,14 +33,12 @@
33
33
  more details.
34
34
 
35
35
  You should have received a copy of the GNU General Public License along with
36
- this program. If not, see <http://www.gnu.org/licenses/>.
36
+ this program. If not, see [http://www.gnu.org/licenses/].
37
37
 
38
38
  If you have Internet connection, the latest version of the GPL should be
39
39
  available at these locations:
40
- <http://www.fsf.org/licensing/licenses/gpl.html>
41
- <http://www.gnu.org/licenses/gpl.html>
42
-
43
- <http://www.sisudoc.org/sisu/en/manifest/gpl.fsf.html>
40
+ [http://www.fsf.org/licensing/licenses/gpl.html]
41
+ [http://www.gnu.org/licenses/gpl.html]
44
42
 
45
43
  ** SiSU uses:
46
44
  * Standard SiSU markup syntax,
@@ -48,12 +46,12 @@
48
46
  * Standard SiSU object citation numbering and system
49
47
 
50
48
  ** Hompages:
51
- <http://www.jus.uio.no/sisu>
52
- <http://www.sisudoc.org>
49
+ [http://www.jus.uio.no/sisu]
50
+ [http://www.sisudoc.org]
53
51
 
54
52
  ** Git
55
- <http://git.sisudoc.org/gitweb/?p=code/sisu.git;a=summary>
56
- <http://git.sisudoc.org/gitweb/?p=code/sisu.git;a=blob;f=lib/sisu/hub_options.rb;hb=HEAD>
53
+ [http://git.sisudoc.org/gitweb/?p=code/sisu.git;a=summary]
54
+ [http://git.sisudoc.org/gitweb/?p=code/sisu.git;a=blob;f=lib/sisu/hub_options.rb;hb=HEAD]
57
55
 
58
56
  =end
59
57
  module SiSU_Commandline
@@ -638,6 +636,9 @@ module SiSU_Commandline
638
636
  if ch =~/j/ then select_arr << '--images'
639
637
  ch=ch.gsub(/[j]/,'')
640
638
  end
639
+ if ch =~/J/ then select_arr << '--json'
640
+ ch=ch.gsub(/[J]/,'')
641
+ end
641
642
  if ch =~/N/ then select_arr << '--digests'
642
643
  ch=ch.gsub(/[N]/,'')
643
644
  end
@@ -1024,6 +1025,10 @@ module SiSU_Commandline
1024
1025
  =~/"--images"/) \
1025
1026
  ? { bool: true, set: :on }
1026
1027
  : { bool: false, set: :na }
1028
+ act[:json]=(select_arr.inspect \
1029
+ =~/"--json"/) \
1030
+ ? { bool: true, set: :on }
1031
+ : { bool: false, set: :na }
1027
1032
  if select_arr.inspect \
1028
1033
  =~/"--pdf"/
1029
1034
  if select_arr.inspect \
@@ -1490,6 +1495,7 @@ module SiSU_Commandline
1490
1495
  || act[:html][:set]==:on \
1491
1496
  || act[:html_seg][:set]==:on \
1492
1497
  || act[:html_scroll][:set]==:on \
1498
+ || act[:json][:set]==:on \
1493
1499
  || act[:texinfo][:set]==:on \
1494
1500
  || act[:manpage][:set]==:on \
1495
1501
  || act[:hash_digests][:set]==:on \
@@ -1540,6 +1546,7 @@ module SiSU_Commandline
1540
1546
  || act[:html][:set]==:on \
1541
1547
  || act[:html_seg][:set]==:on \
1542
1548
  || act[:html_scroll][:set]==:on \
1549
+ || act[:json][:set]==:on \
1543
1550
  || act[:texinfo][:set]==:on \
1544
1551
  || act[:manpage][:set]==:on \
1545
1552
  || act[:hash_digests][:set]==:on \
@@ -7,11 +7,11 @@
7
7
  *** internationalisation
8
8
 
9
9
  ** Author: Ralph Amissah
10
- <ralph@amissah.com>
11
- <ralph.amissah@gmail.com>
10
+ [ralph@amissah.com]
11
+ [ralph.amissah@gmail.com]
12
12
 
13
13
  ** Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
14
- 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Ralph Amissah,
14
+ 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Ralph Amissah,
15
15
  All Rights Reserved.
16
16
 
17
17
  ** License: GPL 3 or later:
@@ -31,14 +31,12 @@
31
31
  more details.
32
32
 
33
33
  You should have received a copy of the GNU General Public License along with
34
- this program. If not, see <http://www.gnu.org/licenses/>.
34
+ this program. If not, see [http://www.gnu.org/licenses/].
35
35
 
36
36
  If you have Internet connection, the latest version of the GPL should be
37
37
  available at these locations:
38
- <http://www.fsf.org/licensing/licenses/gpl.html>
39
- <http://www.gnu.org/licenses/gpl.html>
40
-
41
- <http://www.sisudoc.org/sisu/en/manifest/gpl.fsf.html>
38
+ [http://www.fsf.org/licensing/licenses/gpl.html]
39
+ [http://www.gnu.org/licenses/gpl.html]
42
40
 
43
41
  ** SiSU uses:
44
42
  * Standard SiSU markup syntax,
@@ -46,12 +44,12 @@
46
44
  * Standard SiSU object citation numbering and system
47
45
 
48
46
  ** Hompages:
49
- <http://www.jus.uio.no/sisu>
50
- <http://www.sisudoc.org>
47
+ [http://www.jus.uio.no/sisu]
48
+ [http://www.sisudoc.org]
51
49
 
52
50
  ** Git
53
- <http://git.sisudoc.org/gitweb/?p=code/sisu.git;a=summary>
54
- <http://git.sisudoc.org/gitweb/?p=code/sisu.git;a=blob;f=lib/sisu/i18n.rb;hb=HEAD>
51
+ [http://git.sisudoc.org/gitweb/?p=code/sisu.git;a=summary]
52
+ [http://git.sisudoc.org/gitweb/?p=code/sisu.git;a=blob;f=lib/sisu/i18n.rb;hb=HEAD]
55
53
 
56
54
  =end
57
55
  module SiSU_i18n
@@ -0,0 +1,415 @@
1
+ # encoding: utf-8
2
+ =begin
3
+
4
+ * Name: SiSU
5
+
6
+ ** Description: documents, structuring, processing, publishing, search
7
+ *** Description: json output logic, flow
8
+
9
+ ** Author: Ralph Amissah
10
+ [ralph@amissah.com]
11
+ [ralph.amissah@gmail.com]
12
+
13
+ ** Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
14
+ 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Ralph Amissah,
15
+ All Rights Reserved.
16
+
17
+ ** License: GPL 3 or later:
18
+
19
+ SiSU, a framework for document structuring, publishing and search
20
+
21
+ Copyright (C) Ralph Amissah
22
+
23
+ This program is free software: you can redistribute it and/or modify it
24
+ under the terms of the GNU General Public License as published by the Free
25
+ Software Foundation, either version 3 of the License, or (at your option)
26
+ any later version.
27
+
28
+ This program is distributed in the hope that it will be useful, but WITHOUT
29
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
30
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
31
+ more details.
32
+
33
+ You should have received a copy of the GNU General Public License along with
34
+ this program. If not, see [http://www.gnu.org/licenses/].
35
+
36
+ If you have Internet connection, the latest version of the GPL should be
37
+ available at these locations:
38
+ [http://www.fsf.org/licensing/licenses/gpl.html]
39
+ [http://www.gnu.org/licenses/gpl.html]
40
+
41
+ ** SiSU uses:
42
+ * Standard SiSU markup syntax,
43
+ * Standard SiSU meta-markup syntax, and the
44
+ * Standard SiSU object citation numbering and system
45
+
46
+ ** Hompages:
47
+ [http://www.jus.uio.no/sisu]
48
+ [http://www.sisudoc.org]
49
+
50
+ ** Git
51
+ [http://git.sisudoc.org/gitweb/?p=code/sisu.git;a=summary]
52
+ [http://git.sisudoc.org/gitweb/?p=code/sisu.git;a=blob;f=lib/sisu/json.rb;hb=HEAD]
53
+
54
+ =end
55
+ module SiSU_JSON
56
+ require_relative 'se_hub_particulars' # se_hub_particulars.rb
57
+ include SiSU_Particulars
58
+ require_relative 'se' # se.rb
59
+ include SiSU_Env
60
+ require_relative 'json_shared' # json_shared.rb
61
+ include SiSU_JSON_Munge
62
+ require_relative 'json_format' # json_format.rb
63
+ include SiSU_JSON_Format
64
+ require_relative 'json_persist' # json_persist.rb
65
+ require_relative 'shared_metadata' # shared_metadata.rb
66
+ @@alt_id_count=0
67
+ @@tablefoot=''
68
+ class Source
69
+ def initialize(opt)
70
+ @opt=opt
71
+ @particulars=SiSU_Particulars::CombinedSingleton.instance.get_all(opt)
72
+ end
73
+ def read
74
+ begin
75
+ @env,@md,@ao_array=@particulars.env,@particulars.md,@particulars.ao_array
76
+ unless @opt.act[:quiet][:set]==:on
77
+ tool=if (@opt.act[:verbose_plus][:set]==:on \
78
+ || @opt.act[:maintenance][:set]==:on)
79
+ @env.program.web_browser +
80
+ ' file://' +
81
+ @md.file.output_path.json.dir + '/' +
82
+ @md.file.base_filename.json
83
+ elsif @opt.act[:verbose][:set]==:on
84
+ @env.program.web_browser +
85
+ ' file://' +
86
+ @md.file.output_path.json.dir + '/' +
87
+ @md.file.base_filename.json
88
+ else "[#{@opt.f_pth[:lng_is]}] #{@opt.fno}"
89
+ end
90
+ (@opt.act[:verbose][:set]==:on \
91
+ || @opt.act[:verbose_plus][:set]==:on \
92
+ || @opt.act[:maintenance][:set]==:on) \
93
+ ? SiSU_Screen::Ansi.new(
94
+ @opt.act[:color_state][:set],
95
+ 'JSON',
96
+ tool
97
+ ).green_hi_blue
98
+ : SiSU_Screen::Ansi.new(
99
+ @opt.act[:color_state][:set],
100
+ 'JSON',
101
+ tool
102
+ ).green_title_hi
103
+ if (@opt.act[:verbose_plus][:set]==:on \
104
+ || @opt.act[:maintenance][:set]==:on)
105
+ SiSU_Screen::Ansi.new(
106
+ @opt.act[:color_state][:set],
107
+ @opt.fns,
108
+ '/' + @md.file.output_path.json.dir +
109
+ '/' + @md.file.base_filename.json
110
+ ).flow
111
+ end
112
+ end
113
+ SiSU_JSON::Source::Songsheet.new(@particulars).song
114
+ rescue
115
+ SiSU_Errors::Rescued.new($!,$@,@opt.selections.str,@opt.fns).location do
116
+ __LINE__.to_s + ':' + __FILE__
117
+ end
118
+ ensure
119
+ SiSU_Env::CreateSite.new(@opt).cp_css
120
+ Dir.chdir(@opt.f_pth[:pth])
121
+ end
122
+ end
123
+ private
124
+ class Songsheet
125
+ def initialize(particulars)
126
+ @env,@md,@ao_array,@particulars=
127
+ particulars.env,particulars.md,particulars.ao_array,particulars
128
+ @file=SiSU_Env::FileOp.new(@md)
129
+ end
130
+ def song
131
+ begin
132
+ SiSU_JSON::Source::Scroll.new(@particulars).songsheet
133
+ rescue
134
+ SiSU_Errors::Rescued.new($!,$@,@md.opt.selections.str,@md.fns).location do
135
+ __LINE__.to_s + ':' + __FILE__
136
+ end
137
+ ensure
138
+ end
139
+ end
140
+ end
141
+ class Scroll
142
+ require_relative 'json_shared' # json_shared.rb #check already called
143
+ require_relative 'txt_shared' # txt_shared.rb
144
+ include SiSU_TextUtils
145
+ require_relative 'css' # css.rb
146
+ def initialize(particulars)
147
+ @env,@md,@ao_array=particulars.env,particulars.md,particulars.ao_array
148
+ @tab="\t"
149
+ @trans=SiSU_JSON_Munge::Trans.new(@md)
150
+ @sys=SiSU_Env::SystemCall.new
151
+ @per=SiSU_JSON_Persist::Persist.new
152
+ end
153
+ def songsheet
154
+ begin
155
+ pre
156
+ @data=markup(@ao_array)
157
+ post
158
+ publish
159
+ ensure
160
+ SiSU_JSON_Persist::Persist.new.persist_init
161
+ end
162
+ end
163
+ protected
164
+ def embedded_endnotes(dob='')
165
+ dob.obj=dob.obj.gsub(/#{Mx[:en_a_o]}(\d+)\s+(.+?)#{Mx[:en_a_c]}/,
166
+ '<endnote><number>\1</number><note>\2</note></endnote> ').
167
+ gsub(/#{Mx[:en_b_o]}([*+]\d+)\s+(.+?)#{Mx[:en_b_c]}/,
168
+ '<endnote><symbol>\1</symbol><note>\2</note></endnote> ').
169
+ gsub(/#{Mx[:en_a_o]}([*+]+)\s+(.+?)#{Mx[:en_a_c]}/,
170
+ '<endnote><symbol>\1</symbol><note>\2</note></endnote> ')
171
+ end
172
+ def extract_endnotes(dob='')
173
+ notes=dob.obj.scan(/(?:#{Mx[:en_a_o]}|#{Mx[:en_b_o]})([\d*+]+\s+.+?)(?:#{Mx[:en_a_c]}|#{Mx[:en_b_c]})/)
174
+ notes.flatten.each do |e|
175
+ s=e.to_s
176
+ util=SiSU_JSONutils::Clean.new(s)
177
+ wrap=util.line_json_clean
178
+ wrap=wrap.gsub(/^(\d+)\s+(.+?)\s*\Z/m, <<-WOK
179
+ \\n[\\1.] \\2
180
+ WOK
181
+ ).
182
+ gsub(/^([*+]\d+)\s+(.+?)\s*\Z/m, <<-WOK
183
+ \\n[\\1.] \\2
184
+ WOK
185
+ ).
186
+ gsub(/^([*+]+)\s+(.+?)\s*\Z/m, <<-WOK
187
+ \\n[\\1.] \\2
188
+ WOK
189
+ ).strip
190
+ #KEEP alternative presentation of endnotes
191
+ # wrap=wrap.gsub(/^(\d+)\s+(.+?)\s*\Z/m, <<WOK
192
+ ##{Ax[:tab]*1}<p class="endnote" notenumber="\\1">
193
+ ##{Ax[:tab]*2}\\1. \\2
194
+ ##{Ax[:tab]*1}</p>
195
+ #WOK
196
+ #)
197
+ @endnotes << wrap
198
+ end
199
+ end
200
+ def json_head
201
+ #metadata=SiSU_Metadata::Summary.new(@md).json.metadata
202
+ #@per.head << metadata
203
+ end
204
+ def name_tags(dob)
205
+ tags=''
206
+ if defined? dob.tags \
207
+ and dob.tags.length > 0 # insert tags "hypertargets"
208
+ dob.tags.each do |t|
209
+ tags=tags << %{<named id="#{t}" />}
210
+ end
211
+ end
212
+ tags
213
+ end
214
+ def json_structure(dob,attrib=nil)
215
+ if dob.is ==:para \
216
+ || dob.is ==:heading
217
+ if dob.is==:heading
218
+ lv=dob.ln
219
+ dob.ln + 2
220
+ else lv=nil
221
+ end
222
+ extract_endnotes(dob)
223
+ dob.obj=dob.obj.
224
+ gsub(/#{Mx[:en_a_o]}([\d*+]+)\s+(?:.+?)#{Mx[:en_a_c]}/,'<en>\1</en>'). #footnote/endnote clean
225
+ gsub(/#{Mx[:en_b_o]}([\d*+]+)\s+(?:.+?)#{Mx[:en_b_c]}/,'<en>\1</en>')
226
+ util=SiSU_JSONutils::Clean.new(dob.obj)
227
+ wrapped=util.line_json_clean
228
+ @per.body << Ax[:tab]*1 + '{'
229
+ if defined? dob.ocn and dob.ocn
230
+ @per.body << Ax[:tab]*2 + '"ocn": ' + dob.ocn.to_s + '",'
231
+ end
232
+ if lv # main text, contents, body KEEP
233
+ @per.body <<
234
+ Ax[:tab]*2 + %{"object": "<h#{lv}>} + wrapped + %{</h#{lv}>} +
235
+ ((@endnotes.length > 0) ? '",' : '"')
236
+ else
237
+ @per.body <<
238
+ Ax[:tab]*2 + '"object": "' + wrapped +
239
+ ((@endnotes.length > 0) ? '",' : '"')
240
+ end
241
+ if @endnotes.length > 0 # main text, endnotes KEEP
242
+ @per.body <<
243
+ Ax[:tab]*2 + '"endnotes": "' +
244
+ @endnotes.compact.join.strip + '"'
245
+ end
246
+ @per.body << Ax[:tab]*1 + '},' # unless is last object then '}'
247
+ @endnotes=[]
248
+ end
249
+ end
250
+ def block_structure(dob)
251
+ dob=@trans.markup_block(dob)
252
+ dob.obj=dob.obj.strip.
253
+ gsub(/#{Mx[:en_a_o]}([\d*+]+)\s+(?:.+?)#{Mx[:en_a_c]}/,'<en>\1</en>'). #footnote/endnote clean
254
+ gsub(/#{Mx[:en_b_o]}([\d*+]+)\s+(?:.+?)#{Mx[:en_b_c]}/,'<en>\1</en>') #footnote/endnote clean
255
+ @per.body << Ax[:tab]*1 + '{'
256
+ if defined? dob.ocn and dob.ocn
257
+ @per.body << Ax[:tab]*2 + '"ocn": ' + dob.ocn.to_s + '",'
258
+ end
259
+ @per.body <<
260
+ Ax[:tab]*2 + '"object": "' + dob.obj + '"'
261
+ #((@endnotes.length > 0) ? '",' : '"')
262
+ @per.body << Ax[:tab]*1 + '},' # unless is last object then '}'
263
+ end
264
+ def group_structure(dob)
265
+ dob=@trans.markup_group(dob)
266
+ dob.obj=dob.obj.strip.
267
+ gsub(/#{Mx[:en_a_o]}([\d*+]+)\s+(?:.+?)#{Mx[:en_a_c]}/,'<en>\1</en>'). #footnote/endnote clean
268
+ gsub(/#{Mx[:en_b_o]}([\d*+]+)\s+(?:.+?)#{Mx[:en_b_c]}/,'<en>\1</en>') #footnote/endnote clean
269
+ @per.body << Ax[:tab]*1 + '{'
270
+ if defined? dob.ocn and dob.ocn
271
+ @per.body << Ax[:tab]*2 + '"ocn": ' + dob.ocn.to_s + '",'
272
+ end
273
+ @per.body <<
274
+ Ax[:tab]*2 + '"object": "' + dob.obj + '"'
275
+ #((@endnotes.length > 0) ? '",' : '"')
276
+ @per.body << Ax[:tab]*1 + '},' # unless is last object then '}'
277
+ end
278
+ def poem_structure(dob)
279
+ dob=@trans.markup_group(dob)
280
+ dob.obj=dob.obj.strip
281
+ @per.body << Ax[:tab]*1 + '{'
282
+ if defined? dob.ocn and dob.ocn
283
+ @per.body << Ax[:tab]*2 + '"ocn": ' + dob.ocn.to_s + '",'
284
+ end
285
+ @per.body <<
286
+ Ax[:tab]*2 + '"object": "' + dob.obj + '"'
287
+ #((@endnotes.length > 0) ? '",' : '"')
288
+ @per.body << Ax[:tab]*1 + '},' # unless is last object then '}'
289
+ end
290
+ def code_structure(dob)
291
+ dob=@trans.markup_group(dob)
292
+ dob.obj=dob.obj.gsub(/\s\s/,'&#160;&#160;').strip
293
+ @per.body << Ax[:tab]*1 + '{'
294
+ if defined? dob.ocn and dob.ocn
295
+ @per.body << Ax[:tab]*2 + '"ocn": ' + dob.ocn.to_s + '",'
296
+ end
297
+ @per.body <<
298
+ Ax[:tab]*2 + '"object": "' + dob.obj + '"'
299
+ #((@endnotes.length > 0) ? '",' : '"')
300
+ @per.body << Ax[:tab]*1 + '},' # unless is last object then '}'
301
+ end
302
+ def table_structure(dob)
303
+ table=SiSU_JSON_Shared::TableJSON.new(dob)
304
+ @per.body << Ax[:tab]*1 + '{'
305
+ if defined? dob.ocn and dob.ocn
306
+ @per.body << Ax[:tab]*2 + '"ocn": ' + dob.ocn.to_s + '",'
307
+ end
308
+ @per.body <<
309
+ Ax[:tab]*2 + '"object": "' + table.table.obj + '"'
310
+ #((@endnotes.length > 0) ? '",' : '"')
311
+ @per.body << Ax[:tab]*1 + '},' # unless is last object then '}'
312
+ end
313
+ def markup(data)
314
+ @endnotes=[]
315
+ @rcdc=false
316
+ @level,@cont,@copen,@json_contents_close=[],[],[],[]
317
+ json_head
318
+ (0..7).each { |x| @cont[x]=@level[x]=false }
319
+ (4..7).each { |x| @json_contents_close[x]='' }
320
+ data.each_with_index do |dob,i|
321
+ dob=@trans.char_enc.utf8(dob) if @sys.locale =~/utf-?8/i #% utf8
322
+ dob=@trans.markup(dob)
323
+ if @rcdc==false \
324
+ and (dob.obj =~/~meta/ \
325
+ and dob.obj =~/Document Information/)
326
+ @rcdc=true
327
+ end
328
+ if dob.obj !~/(^#{Rx[:meta]}|#{Mx[:br_eof]}|#{Mx[:br_endnotes]})/
329
+ if not @rcdc
330
+ x=SiSU_JSON_Format::FormatTextObject.new(@md,dob)
331
+ if dob.is==:heading
332
+ json_structure(dob)
333
+ dob.obj=case dob.ln
334
+ when 0 then x.heading_body0
335
+ when 1 then x.heading_body1
336
+ when 2 then x.heading_body2
337
+ when 3 then x.heading_body3
338
+ when 4 then x.heading_body4
339
+ when 5 then x.heading_body5
340
+ when 6 then x.heading_body6
341
+ when 7 then x.heading_body7
342
+ end
343
+ else
344
+ if dob.is ==:verse
345
+ poem_structure(dob)
346
+ elsif dob.is ==:group
347
+ group_structure(dob)
348
+ elsif dob.is ==:block
349
+ block_structure(dob)
350
+ elsif dob.is ==:code
351
+ code_structure(dob)
352
+ elsif dob.is ==:table
353
+ table_structure(dob)
354
+ elsif dob.is ==:para \
355
+ and dob.indent.to_s =~/[1-9]/ \
356
+ and dob.bullet_==true
357
+ json_structure(dob,"indent_bullet#{dob.indent}")
358
+ elsif dob.is ==:para \
359
+ and dob.indent.to_s =~/[1-9]/ \
360
+ and dob.indent == dob.hang
361
+ json_structure(dob,"indent#{dob.indent}")
362
+ elsif dob.is==:para \
363
+ and dob.hang.to_s =~/[0-9]/ \
364
+ and dob.indent != dob.hang
365
+ json_structure(dob,"hang#{dob.hang.to_s}_indent#{dob.indent.to_s}")
366
+ else json_structure(dob)
367
+ end
368
+ end
369
+ end
370
+ dob.obj=dob.obj.gsub(/#{Mx[:pa_o]}:\S+#{Mx[:pa_c]}/,'') if dob.obj
371
+ end
372
+ end
373
+ 6.downto(4) do |x|
374
+ y=x - 1; v=x - 3
375
+ @per.body << "#{Ax[:tab]*5}</content>\n#{Ax[:tab]*y}</contents#{v}>" if @level[x]==true
376
+ end
377
+ 3.downto(1) do |x|
378
+ y=x - 1
379
+ @per.body << "#{Ax[:tab]*y}</heading#{x}>" if @level[x]==true
380
+ end
381
+ end
382
+ def pre
383
+ @per.head,@per.body=[],[]
384
+ @per.open = '{'
385
+ end
386
+ def post
387
+ @per.close = '}'
388
+ end
389
+ def publish
390
+ content=[]
391
+ @per.body[-1] = @per.body[-1].gsub(/,$/, '') #= Ax[:tab]*1 + '}'
392
+ content << @per.open << @per.head << @per.body << @per.metadata
393
+ content << @per.tail << @per.close
394
+ content=content.flatten.compact
395
+ Output.new(content,@md).json
396
+ end
397
+ end
398
+ class Output
399
+ def initialize(data,md)
400
+ @data,@md=data,md
401
+ @file=SiSU_Env::FileOp.new(@md)
402
+ end
403
+ def json
404
+ SiSU_Env::FileOp.new(@md).mkdir
405
+ filename_json=@file.write_file.json
406
+ @data.each do |str|
407
+ str=str.gsub(/\A\s+\Z/m,'') #str.gsub(/^\s+$/,'')
408
+ filename_json.puts str unless str.empty?
409
+ end
410
+ filename_json.close
411
+ end
412
+ end
413
+ end
414
+ end
415
+ __END__