stepmod-utils 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 880200eb71c0f0fea4fd506d07736dfa24a8097c576ad9d114ae31bbc643b761
4
- data.tar.gz: b722f8e73182c0d2e7a333711b6b0d63c9bee6a9bd4c8f8bd4ad35c76fb34c59
3
+ metadata.gz: 7d3544c6e6b2eca6cab5ab08050b9985b80f62d597604d6961cbb388a712160a
4
+ data.tar.gz: 6afde6fbd52b996a37a6d8bc88607adf97b760c0835d7eae5cee849a8911d8cb
5
5
  SHA512:
6
- metadata.gz: 83e7020b06805b67cef6181534b2c77554a0320b8d7ef53e31795214f6d03dc0f9b300269f2a88c4d167072597c879b217c338a3d11564ed2ae737ffe2c9c89f
7
- data.tar.gz: 4ac53f1c23a263c9078461570ba315be2d20f90229fbe109c4cc15d9d806cab6524daed10ee89de0dd85d194c2c27d0598fec0ec58893dc00c1ceb57fc14e755
6
+ metadata.gz: c5631d5e7587e4d26d62425f623433147ad372f4f53ebc5d9f2e0c1414d0b84599b6655d242028fbc4df872637b2db2a23df31b905ddd48136a9add7de4d0a9b
7
+ data.tar.gz: d48868104b0fd44e74ec8459f9d45e1ed51b835b749bc3986c185c376d798ecb28da0d2a1813ebeb9faacc9e1432a0117adaa5101ade901e965424a101903bcc
@@ -30,7 +30,9 @@ jobs:
30
30
  os: 'macos-latest'
31
31
  experimental: true
32
32
  steps:
33
- - uses: actions/checkout@master
33
+ - uses: actions/checkout@v2
34
+ with:
35
+ submodules: true
34
36
 
35
37
  - uses: ruby/setup-ruby@v1
36
38
  with:
@@ -38,14 +40,3 @@ jobs:
38
40
  bundler-cache: true
39
41
 
40
42
  - run: bundle exec rake
41
-
42
- tests-passed:
43
- needs: rake
44
- runs-on: ubuntu-latest
45
- steps:
46
- - uses: peter-evans/repository-dispatch@v1
47
- with:
48
- token: ${{ secrets.METANORMA_CI_PAT_TOKEN || secrets.GITHUB_TOKEN }}
49
- repository: ${{ github.repository }}
50
- event-type: notify
51
- client-payload: '{"ref": "${{ github.ref }}", "sha": "${{ github.sha }}"}'
@@ -1,3 +1,5 @@
1
+ # Auto-generated by Cimas: Do not edit it manually!
2
+ # See https://github.com/metanorma/cimas
1
3
  name: release
2
4
 
3
5
  on:
@@ -8,6 +10,8 @@ on:
8
10
  Next release version. Possible values: x.y.z, major, minor, patch or pre|rc|etc
9
11
  required: true
10
12
  default: 'patch'
13
+ push:
14
+ tags: [ v* ]
11
15
 
12
16
  jobs:
13
17
  release:
@@ -19,9 +23,10 @@ jobs:
19
23
  with:
20
24
  ruby-version: '2.6'
21
25
 
22
- - run: gem install gem-release
26
+ - run: gem install gem-release
23
27
 
24
- - run: |
28
+ - if: ${{ github.event_name == 'workflow_dispatch' }}
29
+ run: |
25
30
  git config user.name github-actions
26
31
  git config user.email github-actions@github.com
27
32
  gem bump --version ${{ github.event.inputs.next_version }} --tag --push
data/Makefile CHANGED
@@ -1,2 +1,5 @@
1
1
  convert_stepmod_repo:
2
- bundle exec ./exe/stepmod-annotate-all ../iso-10303-stepmod
2
+ bundle exec ./exe/stepmod-annotate-all $(10303_stepmod_path)
3
+
4
+ create_svgs:
5
+ java -jar $(stepmod2mn_jar_path) $(10303_stepmod_path) -svg
@@ -24,12 +24,12 @@ files.each_slice(MAX_QUEUE_SIZE) do |batch|
24
24
  puts("Queueing next batch")
25
25
  batch.each do |file|
26
26
  pool.post do
27
- puts("Queued processing #{file}")
27
+ puts("#{Thread.current.object_id}: Queued processing #{file}")
28
28
  annotated = Stepmod::Utils::StepmodFileAnnotator.new(express_file: file, resource_docs_cache_file: resource_docs_cache_file, stepmod_dir: stepmod_dir).call
29
29
  File.open(File.join(File.dirname(file), "#{File.basename(file, '.exp')}_annotated.exp"), 'w') do |file|
30
30
  file.puts(annotated)
31
31
  end
32
- puts("Done processing #{file}")
32
+ puts("#{Thread.current.object_id}: Done processing #{file}")
33
33
  end
34
34
  end
35
35
  pool.shutdown
@@ -44,7 +44,7 @@ module Stepmod
44
44
  first_strong_node.next.content = first_strong_node.next.content.gsub(/\s?:/, '')
45
45
  term = first_strong_node.text.strip
46
46
  first_strong_node.remove
47
- "#{term}:: #{treat_children(cloned_node, state)}"
47
+ "\n\n#{term}:: #{remove_trash_symbols(treat_children(cloned_node, state))}\n"
48
48
  end
49
49
 
50
50
  def stem_converted(cloned_node, state)
@@ -69,6 +69,7 @@ module Stepmod
69
69
  .strip
70
70
  .gsub(/\(\d\)$/, '')
71
71
  .gsub(/\b(\w*?[_]+\w+)\b/, '"\1"')
72
+ .gsub(/([^\s])\s+_{/, '\1_{')
72
73
  .strip
73
74
  end
74
75
 
@@ -79,14 +80,14 @@ module Stepmod
79
80
  TAGS_NOT_IN_CONTEXT.each do |tag_name|
80
81
  node
81
82
  .children
82
- .xpath("./#{tag_name}")
83
- .map do |n|
84
- n.tap{ |n| n.add_previous_sibling(n.children) }.remove
83
+ .each do |n|
84
+ remove_tags_not_in_context(n) if n.children.length > 0
85
+ next if n.name != tag_name
86
+
87
+ n.add_previous_sibling(n.children)
88
+ n.unlink
85
89
  end
86
90
  end
87
- node.traverse do |descendant|
88
- descendant.content = descendant.content.gsub('#8195;', '')
89
- end
90
91
  end
91
92
  end
92
93
 
@@ -8,18 +8,21 @@ module Stepmod
8
8
  node.children.map do |child|
9
9
  next unless child.name == 'imgfile'
10
10
 
11
- parse_to_svg_reference(child['file'])
11
+ parse_to_svg_reference(child['file'], state)
12
12
  end.join("\n")
13
13
  end
14
14
 
15
15
  private
16
16
 
17
- def parse_to_svg_reference(file)
17
+ def parse_to_svg_reference(file, state)
18
18
  return '' unless File.file?(file)
19
19
 
20
20
  image_document = Nokogiri::XML(File.read(file))
21
21
  svg_path = File.basename(image_document.xpath('//img').first['src'], '.*')
22
22
  <<~SVGMAP
23
+ *)
24
+
25
+ (*"#{state.fetch(:schema_name)}.__expressg"
23
26
  [.svgmap]
24
27
  ====
25
28
  image::#{svg_path}.svg[]
@@ -3,6 +3,7 @@ module Stepmod
3
3
  module Converters
4
4
  class ExtDescription < ReverseAdoc::Converters::Base
5
5
  def convert(node, state = {})
6
+ state = state.merge(schema_name: node['linkend'])
6
7
  <<~TEMPLATE
7
8
  (*"#{node['linkend']}"
8
9
  #{treat_children(node, state).strip}
@@ -5,7 +5,13 @@ module Stepmod
5
5
  module Converters
6
6
  class FundCons < ReverseAdoc::Converters::Base
7
7
  def convert(node, state = {})
8
- "\n\n== Fundamental concerns\n\n#{treat_children(node, state).strip}\n\n"
8
+ <<~TEXT
9
+ *)
10
+
11
+ (*"#{state.fetch(:schema_name)}.__fund_cons"
12
+
13
+ #{treat_children(node, state).strip}
14
+ TEXT
9
15
  end
10
16
  end
11
17
 
@@ -5,7 +5,7 @@ module Stepmod
5
5
  module Converters
6
6
  class Introduction < ReverseAdoc::Converters::Base
7
7
  def convert(node, state = {})
8
- "\n\n== Introduction\n\n#{treat_children(node, state).strip}\n\n"
8
+ treat_children(node, state)
9
9
  end
10
10
  end
11
11
 
@@ -9,7 +9,7 @@ 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\n#{anchor}#{attrs}#{treat_children(node, state.merge(ol_count: ol_count))}\n"
12
+ res = "\n\n#{anchor}#{attrs}#{treat_children(node, state.merge(ol_count: ol_count, tdsinglepara: true))}\n"
13
13
  # Why do we add this?
14
14
  # res = "\n" + res if node.parent && node.parent.name == 'note'
15
15
  res
@@ -5,6 +5,7 @@ module Stepmod
5
5
  module Converters
6
6
  class Schema < ReverseAdoc::Converters::Base
7
7
  def convert(node, state = {})
8
+ state = state.merge(schema_name: node['name'])
8
9
  <<~TEMPLATE
9
10
  (*"#{node['name']}"
10
11
  #{treat_children(node, state).strip}
@@ -4,13 +4,33 @@ module Stepmod
4
4
  module Utils
5
5
  module Converters
6
6
  class Strong < ReverseAdoc::Converters::Base
7
+ BLANK_CHARS = "{blank}".freeze
8
+
7
9
  def convert(node, state = {})
8
10
  content = treat_children(node, state.merge(already_strong: true))
9
11
  if content.strip.empty? || state[:already_strong]
10
12
  content
11
13
  else
12
- "#{content[/^\s*/]}*#{content.strip}*#{content[/\s*$/]}"
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}"
13
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
14
34
  end
15
35
  end
16
36
 
@@ -6,8 +6,16 @@ module Stepmod
6
6
  class Sub < ReverseAdoc::Converters::Base
7
7
  def convert(node, state = {})
8
8
  content = treat_children(node, state)
9
+ return stem_notation(content) if node.parent.name == 'eqn'
10
+
9
11
  "#{content[/^\s*/]}~#{content.strip}~#{content[/\s*$/]}"
10
12
  end
13
+
14
+ private
15
+
16
+ def stem_notation(content)
17
+ "_{#{content}}"
18
+ end
11
19
  end
12
20
 
13
21
  ReverseAdoc::Converters.register :sub, Sub.new
@@ -6,8 +6,14 @@ module Stepmod
6
6
  class Sup < ReverseAdoc::Converters::Base
7
7
  def convert(node, state = {})
8
8
  content = treat_children(node, state)
9
+ return stem_notation(content) if node.parent.name == 'eqn'
10
+
9
11
  "#{content[/^\s*/]}^#{content.strip}^#{content[/\s*$/]}"
10
12
  end
13
+
14
+ def stem_notation(content)
15
+ "^{#{content}}"
16
+ end
11
17
  end
12
18
 
13
19
  ReverseAdoc::Converters.register :sup, Sup.new
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stepmod
4
+ module Utils
5
+ module Converters
6
+ class Table < ReverseAdoc::Converters::Base
7
+ def convert(node, state = {})
8
+ id = node['id']
9
+ anchor = id ? "[[#{id}]]\n" : ""
10
+ title = node['caption'].to_s
11
+ title = ".#{title}\n" unless title.empty?
12
+ attrs = style(node)
13
+ "\n\n#{anchor}#{attrs}#{title}|===\n#{treat_children(node, state)}\n|===\n"
14
+ end
15
+
16
+ def frame(node)
17
+ case node["frame"]
18
+ when "void"
19
+ "frame=none"
20
+ when "hsides"
21
+ "frame=topbot"
22
+ when "vsides"
23
+ "frame=sides"
24
+ when "box", "border"
25
+ "frame=all"
26
+ else
27
+ nil
28
+ end
29
+ end
30
+
31
+ def rules(node)
32
+ case node["rules"]
33
+ when "all"
34
+ "rules=all"
35
+ when "rows"
36
+ "rules=rows"
37
+ when "cols"
38
+ "rules=cols"
39
+ when "none"
40
+ "rules=none"
41
+ else
42
+ nil
43
+ end
44
+ end
45
+
46
+ def style(node)
47
+ width = "width=#{node['width']}" if node['width']
48
+ attrs = []
49
+ frame_attr = frame(node)
50
+ rules_attr = rules(node)
51
+ attrs += width if width
52
+ attrs += frame_attr if frame_attr
53
+ attrs += rules_attr if rules_attr
54
+ return "" if attrs.empty?
55
+ "[#{attrs.join(',')}]\n"
56
+ end
57
+ end
58
+
59
+ ReverseAdoc::Converters.register :table, Table.new
60
+ end
61
+ end
62
+ end
@@ -32,13 +32,13 @@ require 'stepmod/utils/converters/schema'
32
32
  require 'stepmod/utils/converters/strong'
33
33
  require 'stepmod/utils/converters/sub'
34
34
  require 'stepmod/utils/converters/sup'
35
+ require 'stepmod/utils/converters/table'
35
36
  require 'stepmod/utils/converters/text'
36
37
  require 'stepmod/utils/cleaner'
37
38
 
38
39
  require 'reverse_adoc/converters/figure'
39
40
  require 'reverse_adoc/converters/img'
40
41
  require 'reverse_adoc/converters/li'
41
- require 'reverse_adoc/converters/table'
42
42
  require 'reverse_adoc/converters/tr'
43
43
  require 'reverse_adoc/converters/td'
44
44
  require 'reverse_adoc/converters/th'
@@ -24,31 +24,55 @@ module Stepmod
24
24
 
25
25
  if File.exists?(descriptions_file)
26
26
  descriptions = Nokogiri::XML(File.read(descriptions_file)).root
27
+ added_resource_descriptions = {}
27
28
  descriptions.xpath('ext_description').each do |description|
28
- unless description.text.strip.empty? then
29
- Dir.chdir(File.dirname(descriptions_file)) do
30
- wrapper = "<ext_descriptions>#{description.to_s}</ext_descriptions>"
31
- output_express << "\n" + Stepmod::Utils::SmrlDescriptionConverter.convert(wrapper)
32
- end
33
- else
34
- # remark is empty, fallback to resource_docs_cache
35
- resource_docs_dir = resource_docs_cache[description['linkend']]
36
- if resource_docs_dir
37
- resource_docs_file = File.join(stepmod_dir, 'data/resource_docs', resource_docs_dir, 'resource.xml')
38
- resource_docs = Nokogiri::XML(File.read(resource_docs_file)).root
39
- schema = resource_docs.xpath("schema[@name='#{description['linkend']}']")
40
-
41
- Dir.chdir(File.dirname(descriptions_file)) do
42
- wrapper = "<resource>#{schema.to_s}</resource>"
43
- output_express << "\n" + Stepmod::Utils::SmrlResourceConverter.convert(wrapper)
44
- end
29
+ # Add base resource from linked path if exists, eg "language_schema.language.wr:WR1" -> "language_schema"
30
+ base_linked = description['linkend'].to_s.split('.').first
31
+ if added_resource_descriptions[base_linked].nil?
32
+ base_reource_doc_dir = resource_docs_cache[description['linkend'].to_s.split('.').first]
33
+ if base_reource_doc_dir
34
+ output_express << convert_from_resource_file(base_reource_doc_dir, stepmod_dir, base_linked, descriptions_file)
45
35
  end
36
+ added_resource_descriptions[base_linked] = true
37
+ end
38
+ resource_docs_dir = resource_docs_cache[description['linkend']]
39
+ # Convert content description
40
+ # when a schema description is available from resource.xml and also descriptions.xml, the description from resource.xml is only used.
41
+ # https://github.com/metanorma/annotated-express/issues/32#issuecomment-792609078
42
+ if description.text.strip.length.positive? && resource_docs_dir.nil?
43
+ output_express << convert_from_description_text(descriptions_file, description)
44
+ end
45
+ # Add converted description from exact linked path
46
+ if resource_docs_dir && added_resource_descriptions[description['linkend']].nil?
47
+ output_express << convert_from_resource_file(resource_docs_dir, stepmod_dir, description['linkend'], descriptions_file)
48
+ added_resource_descriptions[description['linkend']] = true
46
49
  end
47
50
  end
48
51
  end
49
52
 
50
53
  output_express
51
54
  end
55
+
56
+ private
57
+
58
+ def convert_from_description_text(descriptions_file, description)
59
+ Dir.chdir(File.dirname(descriptions_file)) do
60
+ wrapper = "<ext_descriptions>#{description.to_s}</ext_descriptions>"
61
+ "\n" + Stepmod::Utils::SmrlDescriptionConverter.convert(wrapper)
62
+ end
63
+ end
64
+
65
+ def convert_from_resource_file(resource_docs_dir, stepmod_dir, linked, descriptions_file)
66
+ resource_docs_file = File.join(stepmod_dir, 'data/resource_docs', resource_docs_dir, 'resource.xml')
67
+ puts(resource_docs_file)
68
+ resource_docs = Nokogiri::XML(File.read(resource_docs_file)).root
69
+ schema = resource_docs.xpath("schema[@name='#{linked}']")
70
+
71
+ Dir.chdir(File.dirname(descriptions_file)) do
72
+ wrapper = "<resource>#{schema.to_s}</resource>"
73
+ "\n" + Stepmod::Utils::SmrlResourceConverter.convert(wrapper)
74
+ end
75
+ end
52
76
  end
53
77
  end
54
78
  end
@@ -1,5 +1,5 @@
1
1
  module Stepmod
2
2
  module Utils
3
- VERSION = "0.2.4"
3
+ VERSION = "0.2.5"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stepmod-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-02-24 00:00:00.000000000 Z
11
+ date: 2021-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -82,11 +82,10 @@ dependencies:
82
82
  version: '11.1'
83
83
  description: 'Stepmod-utils is a toolkit that works on STEPmod data.
84
84
 
85
- '
85
+ '
86
86
  email:
87
87
  - open.source@ribose.com
88
88
  executables:
89
- - stepmod-annotate
90
89
  - stepmod-annotate-all
91
90
  - stepmod-build-resource-docs-cache
92
91
  - stepmod-convert-express-description
@@ -107,7 +106,6 @@ files:
107
106
  - Rakefile
108
107
  - bin/console
109
108
  - bin/setup
110
- - exe/stepmod-annotate
111
109
  - exe/stepmod-annotate-all
112
110
  - exe/stepmod-build-resource-docs-cache
113
111
  - exe/stepmod-convert-express-description
@@ -159,6 +157,7 @@ files:
159
157
  - lib/stepmod/utils/converters/sub.rb
160
158
  - lib/stepmod/utils/converters/sup.rb
161
159
  - lib/stepmod/utils/converters/synonym.rb
160
+ - lib/stepmod/utils/converters/table.rb
162
161
  - lib/stepmod/utils/converters/term.rb
163
162
  - lib/stepmod/utils/converters/text.rb
164
163
  - lib/stepmod/utils/html_to_asciimath.rb
@@ -174,7 +173,7 @@ homepage: https://github.com/metanorma/stepmod-utils
174
173
  licenses:
175
174
  - BSD-2-Clause
176
175
  metadata: {}
177
- post_install_message:
176
+ post_install_message:
178
177
  rdoc_options: []
179
178
  require_paths:
180
179
  - lib
@@ -189,8 +188,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
189
188
  - !ruby/object:Gem::Version
190
189
  version: '0'
191
190
  requirements: []
192
- rubygems_version: 3.0.3
193
- signing_key:
191
+ rubygems_version: 3.1.6
192
+ signing_key:
194
193
  specification_version: 4
195
194
  summary: Stepmod-utils is a toolkit that works on STEPmod data.
196
195
  test_files: []
data/exe/stepmod-annotate DELETED
@@ -1,44 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'json'
4
- require 'stepmod/utils/smrl_description_converter'
5
- require 'stepmod/utils/smrl_resource_converter'
6
-
7
- express_file = ARGV.shift
8
- resource_docs_cache_file = ARGV.shift # output of ./stepmod-build-resource-docs-cache
9
- stepmod_dir = ARGV.first || Dir.pwd
10
-
11
- match = File.basename(express_file).match('^(arm|mim|bom)\.exp$')
12
- descriptions_base = match ? "#{match.captures[0]}_descriptions.xml" : 'descriptions.xml'
13
- descriptions_file = File.join(File.dirname(express_file), descriptions_base)
14
-
15
- output_express = File.read(express_file)
16
-
17
- resource_docs_cache = JSON.parse(File.read(resource_docs_cache_file))
18
-
19
- if File.exists?(descriptions_file)
20
- descriptions = Nokogiri::XML(File.read(descriptions_file)).root
21
- descriptions.xpath('ext_description').each do |description|
22
- unless description.text.strip.empty? then
23
- Dir.chdir(File.dirname(descriptions_file)) do
24
- wrapper = "<ext_descriptions>#{description.to_s}</ext_descriptions>"
25
- output_express << "\n" + Stepmod::Utils::SmrlDescriptionConverter.convert(wrapper)
26
- end
27
- else
28
- # remark is empty, fallback to resource_docs_cache
29
- resource_docs_dir = resource_docs_cache[description['linkend']]
30
- if resource_docs_dir
31
- resource_docs_file = File.join(stepmod_dir, 'data/resource_docs', resource_docs_dir, 'resource.xml')
32
- resource_docs = Nokogiri::XML(File.read(resource_docs_file)).root
33
- schema = resource_docs.xpath("schema[@name='#{description['linkend']}']")
34
-
35
- Dir.chdir(File.dirname(descriptions_file)) do
36
- wrapper = "<resource>#{schema.to_s}</resource>"
37
- output_express << "\n" + Stepmod::Utils::SmrlResourceConverter.convert(wrapper)
38
- end
39
- end
40
- end
41
- end
42
- end
43
-
44
- puts output_express