stepmod-utils 0.1.8 → 0.2.6

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.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rake.yml +42 -0
  3. data/.github/workflows/release.yml +23 -20
  4. data/Gemfile +2 -0
  5. data/Makefile +5 -0
  6. data/README.adoc +136 -2
  7. data/exe/stepmod-annotate-all +39 -0
  8. data/exe/stepmod-build-resource-docs-cache +19 -0
  9. data/exe/stepmod-convert-express-description +33 -0
  10. data/exe/stepmod-convert-express-resource +33 -0
  11. data/exe/stepmod-extract-terms +56 -14
  12. data/exe/stepmod-find-express-files +23 -0
  13. data/lib/stepmod/utils/cleaner.rb +11 -0
  14. data/lib/stepmod/utils/converters/a.rb +47 -0
  15. data/lib/stepmod/utils/converters/blockquote.rb +22 -0
  16. data/lib/stepmod/utils/converters/br.rb +15 -0
  17. data/lib/stepmod/utils/converters/bypass.rb +81 -0
  18. data/lib/stepmod/utils/converters/code.rb +19 -0
  19. data/lib/stepmod/utils/converters/comment.rb +16 -0
  20. data/lib/stepmod/utils/converters/dd.rb +15 -0
  21. data/lib/stepmod/utils/converters/def.rb +11 -4
  22. data/lib/stepmod/utils/converters/dl.rb +31 -0
  23. data/lib/stepmod/utils/converters/drop.rb +22 -0
  24. data/lib/stepmod/utils/converters/dt.rb +17 -0
  25. data/lib/stepmod/utils/converters/em_express_description.rb +22 -0
  26. data/lib/stepmod/utils/converters/eqn.rb +97 -0
  27. data/lib/stepmod/utils/converters/example.rb +1 -6
  28. data/lib/stepmod/utils/converters/express_g.rb +49 -0
  29. data/lib/stepmod/utils/converters/express_ref_express_description.rb +13 -0
  30. data/lib/stepmod/utils/converters/ext_description.rb +17 -0
  31. data/lib/stepmod/utils/converters/ext_descriptions.rb +14 -0
  32. data/lib/stepmod/utils/converters/fund_cons.rb +21 -0
  33. data/lib/stepmod/utils/converters/head.rb +22 -0
  34. data/lib/stepmod/utils/converters/hr.rb +15 -0
  35. data/lib/stepmod/utils/converters/ignore.rb +16 -0
  36. data/lib/stepmod/utils/converters/introduction.rb +15 -0
  37. data/lib/stepmod/utils/converters/note.rb +1 -6
  38. data/lib/stepmod/utils/converters/ol.rb +3 -2
  39. data/lib/stepmod/utils/converters/p.rb +21 -0
  40. data/lib/stepmod/utils/converters/pass_through.rb +13 -0
  41. data/lib/stepmod/utils/converters/q.rb +16 -0
  42. data/lib/stepmod/utils/converters/resource.rb +14 -0
  43. data/lib/stepmod/utils/converters/schema.rb +19 -0
  44. data/lib/stepmod/utils/converters/schema_diag.rb +14 -0
  45. data/lib/stepmod/utils/converters/strong.rb +41 -0
  46. data/lib/stepmod/utils/converters/sub.rb +24 -0
  47. data/lib/stepmod/utils/converters/sup.rb +22 -0
  48. data/lib/stepmod/utils/converters/table.rb +62 -0
  49. data/lib/stepmod/utils/converters/text.rb +68 -0
  50. data/lib/stepmod/utils/html_to_asciimath.rb +157 -0
  51. data/lib/stepmod/utils/smrl_description_converter.rb +49 -0
  52. data/lib/stepmod/utils/smrl_resource_converter.rb +67 -0
  53. data/lib/stepmod/utils/stepmod_file_annotator.rb +78 -0
  54. data/lib/stepmod/utils/version.rb +1 -1
  55. data/migrating_from_cvs.adoc +190 -0
  56. data/stepmod-utils.gemspec +2 -0
  57. metadata +84 -9
  58. data/.github/workflows/macos.yml +0 -39
  59. data/.github/workflows/ubuntu.yml +0 -53
  60. data/.github/workflows/windows.yml +0 -41
@@ -5,12 +5,7 @@ module Stepmod
5
5
  module Converters
6
6
  class Example < ReverseAdoc::Converters::Base
7
7
  def convert(node, state = {})
8
- <<~TEMPLATE
9
- [example]
10
- ====
11
- #{treat_children(node, state).strip}
12
- ====
13
- TEMPLATE
8
+ "\n\n[example]\n====\n#{treat_children(node, state).strip}\n====\n\n"
14
9
  end
15
10
  end
16
11
  ReverseAdoc::Converters.register :example, Example.new
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stepmod
4
+ module Utils
5
+ module Converters
6
+ class ExpressG < ReverseAdoc::Converters::Base
7
+ def convert(node, state = {})
8
+ node.children.map do |child|
9
+ next unless child.name == 'imgfile'
10
+
11
+ parse_to_svg_reference(child['file'], state)
12
+ end.join("\n")
13
+ end
14
+
15
+ private
16
+
17
+ def parse_to_svg_reference(file, state)
18
+ return '' unless File.file?(file)
19
+
20
+ image_document = Nokogiri::XML(File.read(file))
21
+ svg_path = File.basename(image_document.xpath('//img').first['src'], '.*')
22
+ <<~SVGMAP
23
+
24
+ *)
25
+ (*"#{state.fetch(:schema_name)}.__expressg"
26
+ [.svgmap]
27
+ ====
28
+ image::#{svg_path}.svg[]
29
+
30
+ #{image_document.xpath('//img.area').map.with_index(1) {|n, i| schema_reference(n['href'], i) }.join("\n")}
31
+ ====
32
+ SVGMAP
33
+ end
34
+
35
+ def schema_reference(xml_path, index)
36
+ if xml_path =~ /#/
37
+ _,express_path_part = xml_path.split('#')
38
+ "* <<express:#{express_path_part.strip}>>; #{index}"
39
+ else
40
+ schema_name = File.basename(xml_path, '.*')
41
+ "* <<express:#{schema_name.strip}>>; #{index}"
42
+ end
43
+ end
44
+ end
45
+
46
+ ReverseAdoc::Converters.register 'express-g', ExpressG.new
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,13 @@
1
+ module Stepmod
2
+ module Utils
3
+ module Converters
4
+ class ExpressRefExpressDescription < ReverseAdoc::Converters::Base
5
+ def convert(node, _state = {})
6
+ parts = node['linkend'].to_s.split(':').last.split('.')
7
+ "<<express:#{parts.join('.').strip},#{parts.last.strip}>>"
8
+ end
9
+ end
10
+ ReverseAdoc::Converters.register :express_ref, ExpressRefExpressDescription.new
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,17 @@
1
+ module Stepmod
2
+ module Utils
3
+ module Converters
4
+ class ExtDescription < ReverseAdoc::Converters::Base
5
+ def convert(node, state = {})
6
+ state = state.merge(schema_name: node['linkend'])
7
+ <<~TEMPLATE
8
+ (*"#{node['linkend']}"
9
+ #{treat_children(node, state).strip}
10
+ *)
11
+ TEMPLATE
12
+ end
13
+ end
14
+ ReverseAdoc::Converters.register :ext_description, ExtDescription.new
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stepmod
4
+ module Utils
5
+ module Converters
6
+ class ExtDescriptions < ReverseAdoc::Converters::Base
7
+ def convert(node, state = {})
8
+ treat_children(node, state)
9
+ end
10
+ end
11
+ ReverseAdoc::Converters.register :ext_descriptions, ExtDescriptions.new
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stepmod
4
+ module Utils
5
+ module Converters
6
+ class FundCons < ReverseAdoc::Converters::Base
7
+ def convert(node, state = {})
8
+ <<~TEXT
9
+
10
+ *)
11
+ (*"#{state.fetch(:schema_name)}.__fund_cons"
12
+
13
+ #{treat_children(node, state).strip}
14
+ TEXT
15
+ end
16
+ end
17
+
18
+ ReverseAdoc::Converters.register :fund_cons, FundCons.new
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stepmod
4
+ module Utils
5
+ module Converters
6
+ class Head < ReverseAdoc::Converters::Base
7
+ def convert(node, state = {})
8
+ title = extract_title(node)
9
+ "= #{title}\n:stem:\n\n"
10
+ end
11
+
12
+ def extract_title(node)
13
+ title = node.at("./title")
14
+ return "(???)" if title.nil?
15
+ title.text
16
+ end
17
+ end
18
+
19
+ ReverseAdoc::Converters.register :head, Head.new
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stepmod
4
+ module Utils
5
+ module Converters
6
+ class Hr < ReverseAdoc::Converters::Base
7
+ def convert(node, state = {})
8
+ "\n* * *\n"
9
+ end
10
+ end
11
+
12
+ ReverseAdoc::Converters.register :hr, Hr.new
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stepmod
4
+ module Utils
5
+ module Converters
6
+ class Ignore < ReverseAdoc::Converters::Base
7
+ def convert(node, state = {})
8
+ '' # noop
9
+ end
10
+ end
11
+
12
+ ReverseAdoc::Converters.register :colgroup, Ignore.new
13
+ ReverseAdoc::Converters.register :col, Ignore.new
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stepmod
4
+ module Utils
5
+ module Converters
6
+ class Introduction < ReverseAdoc::Converters::Base
7
+ def convert(node, state = {})
8
+ treat_children(node, state)
9
+ end
10
+ end
11
+
12
+ ReverseAdoc::Converters.register :introduction, Introduction.new
13
+ end
14
+ end
15
+ end
@@ -5,12 +5,7 @@ module Stepmod
5
5
  module Converters
6
6
  class Note < ReverseAdoc::Converters::Base
7
7
  def convert(node, state = {})
8
- <<~TEMPLATE
9
- [NOTE]
10
- --
11
- #{treat_children(node, state).strip}
12
- --
13
- TEMPLATE
8
+ "\n\n[NOTE]\n--\n#{treat_children(node, state).strip}\n--\n\n"
14
9
  end
15
10
  end
16
11
  ReverseAdoc::Converters.register :note, Note.new
@@ -9,8 +9,9 @@ module Stepmod
9
9
  anchor = id ? "[[#{id}]]\n" : ""
10
10
  ol_count = state.fetch(:ol_count, 0) + 1
11
11
  attrs = ol_attrs(node)
12
- res = "\n#{anchor}#{attrs}#{treat_children(node, state.merge(ol_count: ol_count))}"
13
- res = "\n" + res if node.parent && node.parent.name == 'note'
12
+ res = "\n\n#{anchor}#{attrs}#{treat_children(node, state.merge(ol_count: ol_count, tdsinglepara: true))}\n"
13
+ # Why do we add this?
14
+ # res = "\n" + res if node.parent && node.parent.name == 'note'
14
15
  res
15
16
  end
16
17
 
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stepmod
4
+ module Utils
5
+ module Converters
6
+ class P < ReverseAdoc::Converters::Base
7
+ def convert(node, state = {})
8
+ id = node['id']
9
+ anchor = id ? "[[#{id}]]\n" : ""
10
+ if state[:tdsinglepara]
11
+ "#{anchor}#{treat_children(node, state).strip}"
12
+ else
13
+ "\n\n#{anchor}#{treat_children(node, state).strip}\n\n"
14
+ end
15
+ end
16
+ end
17
+
18
+ ReverseAdoc::Converters.register :p, P.new
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stepmod
4
+ module Utils
5
+ module Converters
6
+ class PassThrough < ReverseAdoc::Converters::Base
7
+ def convert(node, state = {})
8
+ node.to_s
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stepmod
4
+ module Utils
5
+ module Converters
6
+ class Q < ReverseAdoc::Converters::Base
7
+ def convert(node, state = {})
8
+ content = treat_children(node, state)
9
+ "#{content[/^\s*/]}\"#{content.strip}\"#{content[/\s*$/]}"
10
+ end
11
+ end
12
+
13
+ ReverseAdoc::Converters.register :q, Q.new
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stepmod
4
+ module Utils
5
+ module Converters
6
+ class Resource < ReverseAdoc::Converters::Base
7
+ def convert(node, state = {})
8
+ treat_children(node, state)
9
+ end
10
+ end
11
+ ReverseAdoc::Converters.register :resource, Resource.new
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stepmod
4
+ module Utils
5
+ module Converters
6
+ class Schema < ReverseAdoc::Converters::Base
7
+ def convert(node, state = {})
8
+ state = state.merge(schema_name: node['name'])
9
+ <<~TEMPLATE
10
+ (*"#{node['name']}"
11
+ #{treat_children(node, state).strip}
12
+ *)
13
+ TEMPLATE
14
+ end
15
+ end
16
+ ReverseAdoc::Converters.register :schema, Schema.new
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stepmod
4
+ module Utils
5
+ module Converters
6
+ class SchemaDiag < ReverseAdoc::Converters::Base
7
+ def convert(node, state = {})
8
+ treat_children(node, state).strip
9
+ end
10
+ end
11
+ ReverseAdoc::Converters.register :schema_diag, SchemaDiag.new
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stepmod
4
+ module Utils
5
+ module Converters
6
+ class Strong < ReverseAdoc::Converters::Base
7
+ BLANK_CHARS = "{blank}".freeze
8
+
9
+ def convert(node, state = {})
10
+ content = treat_children(node, state.merge(already_strong: true))
11
+ if content.strip.empty? || state[:already_strong]
12
+ content
13
+ else
14
+ handle_express_escape_seq(node, "#{content[/^\s*/]}*#{content.strip}*#{content[/\s*$/]}")
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def handle_express_escape_seq(node, content)
21
+ res = content
22
+ if braces_sibling?(node.previous, true)
23
+ res = "#{BLANK_CHARS}#{res}"
24
+ end
25
+ if braces_sibling?(node.next)
26
+ res = "#{res}#{BLANK_CHARS}"
27
+ end
28
+ res
29
+ end
30
+
31
+ def braces_sibling?(sibling, end_of_text = false)
32
+ match = end_of_text ? /\($/ : /^\)/
33
+ sibling && sibling.text? && sibling.text =~ match
34
+ end
35
+ end
36
+
37
+ ReverseAdoc::Converters.register :strong, Strong.new
38
+ ReverseAdoc::Converters.register :b, Strong.new
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stepmod
4
+ module Utils
5
+ module Converters
6
+ class Sub < ReverseAdoc::Converters::Base
7
+ def convert(node, state = {})
8
+ content = treat_children(node, state)
9
+ return stem_notation(content) if node.parent.name == 'eqn'
10
+
11
+ "#{content[/^\s*/]}~#{content.strip}~#{content[/\s*$/]}"
12
+ end
13
+
14
+ private
15
+
16
+ def stem_notation(content)
17
+ "_{#{content}}"
18
+ end
19
+ end
20
+
21
+ ReverseAdoc::Converters.register :sub, Sub.new
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stepmod
4
+ module Utils
5
+ module Converters
6
+ class Sup < ReverseAdoc::Converters::Base
7
+ def convert(node, state = {})
8
+ content = treat_children(node, state)
9
+ return stem_notation(content) if node.parent.name == 'eqn'
10
+
11
+ "#{content[/^\s*/]}^#{content.strip}^#{content[/\s*$/]}"
12
+ end
13
+
14
+ def stem_notation(content)
15
+ "^{#{content}}"
16
+ end
17
+ end
18
+
19
+ ReverseAdoc::Converters.register :sup, Sup.new
20
+ end
21
+ end
22
+ end