asciichem 0.21.0 → 0.22.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2dee0024c277879fed3b5695a76e336067660467724663c4a67f71ec87215e80
4
- data.tar.gz: 50d5a53fd8d4f64a0d3969c586e81552faed9221a8f209932cd6823a2a966327
3
+ metadata.gz: d1aef5e42c0840b8bff4d291220e84f76f9536a9dba1cca3445deacb696388b1
4
+ data.tar.gz: 92e28e623dfb7494080a9ee80d3545fa5a593d83d545775d890b7a9a5594c0bd
5
5
  SHA512:
6
- metadata.gz: 3afdd1db8e99729ca9a1a49be7a748fd56d1fdb666b5bfe10bb03a08c6d7db440ca82b3c900b6f22f09ac66901d7c086913a2a3e8c142bc6c7d776f21959c629
7
- data.tar.gz: ba3091db4ea3a3d7ba8dcd28f9689df323b135e1e1e4f0a3f3573f14350448461f9f3ade4e20fe4e7af9408d0ce40c1764bba4d609a05bd770705be431ca497b
6
+ metadata.gz: bab5532c9007d1a5bd2079b792a66458d411f48af5ac59f04ad9e4a9150c7b53844639e67a46494dac7e6ae05f3451904a8fbe927b711803184749f00ce40e7e
7
+ data.tar.gz: c0a9cb7f9f01e25dcce78f69894c23c8d5fe75d2d21fd20828d2daafa133186ebeb46d2aeb09bfc4246f43f851a3b982c4691cd013c40c56085634ca54f9db01
data/CHANGELOG.md CHANGED
@@ -3,6 +3,19 @@
3
3
  All notable changes to AsciiChem are documented here.
4
4
  This project follows [Semantic Versioning](https://semver.org/).
5
5
 
6
+ ## [0.22.0] - 2026-09-12
7
+
8
+ ### Added
9
+ - CLI `--from asciichem|smiles|molfile` on `convert`, plus
10
+ `model-json`, `smiles`, `molfile`, and `structural-svg` output
11
+ targets (TODO.impl 60).
12
+
13
+ ### Changed
14
+ - Conformance validation uses schemas vendored in `spec/schemas`
15
+ (json_schemer dev dependency); the asciichem-model rubygem
16
+ dependency is removed — the contract repository is no longer
17
+ distributed as a gem (TODO.impl 59).
18
+
6
19
  ## [0.21.0] - 2026-09-12
7
20
 
8
21
  ### Added
@@ -386,7 +399,8 @@ This project follows [Semantic Versioning](https://semver.org/).
386
399
  `version`.
387
400
  - Comprehensive RSpec suite with round-trip conformance.
388
401
 
389
- [Unreleased]: https://github.com/asciichem/asciichem-ruby/compare/v0.21.0...HEAD
402
+ [Unreleased]: https://github.com/asciichem/asciichem-ruby/compare/v0.22.0...HEAD
403
+ [0.22.0]: https://github.com/asciichem/asciichem-ruby/compare/v0.21.0...v0.22.0
390
404
  [0.21.0]: https://github.com/asciichem/asciichem-ruby/compare/v0.20.0...v0.21.0
391
405
  [0.20.0]: https://github.com/asciichem/asciichem-ruby/compare/v0.19.0...v0.20.0
392
406
  [0.18.1]: https://github.com/asciichem/asciichem-ruby/compare/v0.18.0...v0.18.1
data/Gemfile CHANGED
@@ -5,6 +5,7 @@ source "https://rubygems.org"
5
5
  gemspec
6
6
 
7
7
  group :development do
8
+ gem "json_schemer", "~> 2.4"
8
9
  gem "benchmark", "~> 0.4"
9
10
  gem "benchmark-ips", "~> 2.14", require: false
10
11
  gem "rake", "~> 13.2"
data/asciichem.gemspec CHANGED
@@ -41,5 +41,5 @@ Gem::Specification.new do |spec|
41
41
  spec.add_dependency "plurimath", "~> 0.8"
42
42
  spec.add_dependency "thor", "~> 1.3"
43
43
 
44
- spec.add_development_dependency "asciichem-model", "~> 0.3.4"
44
+ spec.add_development_dependency "json_schemer", "~> 2.4"
45
45
  end
data/lib/asciichem/cli.rb CHANGED
@@ -10,16 +10,22 @@ module AsciiChem
10
10
  # and command banners, matching the executable name.
11
11
  package_name "asciichem"
12
12
 
13
- desc "convert -i INPUT -t FORMAT", "Convert AsciiChem INPUT to FORMAT (mathml|text|html|latex|svg|cml)"
14
- method_option :input, aliases: "-i", type: :string, required: true,
15
- desc: "AsciiChem source text (or '-' for stdin)"
13
+ desc "convert -i INPUT -t FORMAT", "Convert INPUT to FORMAT (mathml|text|html|latex|svg|structural-svg|model-json|cml|smiles|molfile)"
14
+ method_option :input, aliases: "-i", type: :string,
15
+ desc: "Source text (or '-' for stdin)"
16
16
  method_option :file, aliases: "-f", type: :string,
17
- desc: "Read AsciiChem source from a file"
17
+ desc: "Read source from a file"
18
+ method_option :from, type: :string, default: "asciichem",
19
+ desc: "Input grammar: asciichem|smiles|molfile"
18
20
  method_option :format, aliases: "-t", type: :string, default: "mathml",
19
21
  desc: "Output format"
20
22
  def convert
23
+ unless options["input"] || options["file"]
24
+ raise AsciiChem::ParseError, "provide -i INPUT or -f FILE"
25
+ end
26
+
21
27
  source = read_source
22
- formula = AsciiChem.parse(source)
28
+ formula = ingest(source, options[:from])
23
29
  puts render(formula, options[:format])
24
30
  rescue AsciiChem::ParseError => e
25
31
  warn "Parse error: #{e.message}"
@@ -89,8 +95,31 @@ module AsciiChem
89
95
  options[:input]
90
96
  end
91
97
 
98
+ # One ingestion point per input grammar (TODO.v2 09): every
99
+ # grammar funnels into the same semantic model, so every output
100
+ # format works regardless of the input language.
101
+ def ingest(source, from)
102
+ case from.to_s
103
+ when "asciichem" then AsciiChem.parse(source)
104
+ when "smiles" then AsciiChem.parse_smiles(source)
105
+ when "molfile" then molfile_formula(source)
106
+ else
107
+ raise AsciiChem::ParseError, "unknown --from grammar: #{from}"
108
+ end
109
+ end
110
+
111
+ # parse_molfile returns a single Molecule; wrap it so every
112
+ # formatter's Formula contract holds.
113
+ def molfile_formula(source)
114
+ text = File.file?(source) ? File.read(source) : source
115
+ AsciiChem::Model::Formula.new(nodes: [AsciiChem.parse_molfile(text)])
116
+ end
117
+
92
118
  def render(formula, format)
93
119
  return formula.to_cml if format.to_sym == :cml
120
+ return formula.to_model_json if format.to_sym == :"model-json"
121
+ return formula.to_smiles if format.to_sym == :smiles
122
+ return formula.nodes.first.to_molfile if format.to_sym == :molfile
94
123
 
95
124
  AsciiChem::Formatter.render(format.to_sym, formula)
96
125
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AsciiChem
4
- VERSION = "0.21.0"
4
+ VERSION = "0.22.0"
5
5
  end
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env bash
2
+ # Re-vendor the asciichem-model v1 JSON Schemas (YAML) and examples.
3
+ # Usage: scripts/update-model-schemas.sh [model-tag] (default: main).
4
+ set -euo pipefail
5
+
6
+ tag="${1:-main}"
7
+ work="$(mktemp -d)"
8
+ trap 'rm -rf "$work"' EXIT
9
+
10
+ git clone --depth 1 --branch "$tag" https://github.com/asciichem/asciichem-model.git "$work/model"
11
+
12
+ python3 - "$work/model" <<'PY'
13
+ import os, shutil, sys
14
+ src = os.path.join(sys.argv[1], "schemas", "v1")
15
+ dst = "spec/schemas"
16
+ if os.path.exists(dst):
17
+ shutil.rmtree(dst)
18
+ os.makedirs(dst)
19
+ for name in os.listdir(src):
20
+ if name.endswith(".yaml"):
21
+ shutil.copy(os.path.join(src, name), os.path.join(dst, name))
22
+ shutil.copytree(os.path.join(src, "examples"), os.path.join(dst, "examples"))
23
+ print("vendored", len([f for f in os.listdir(dst) if f.endswith('.yaml')]), "schemas")
24
+ PY
25
+
26
+ echo "spec/schemas updated from asciichem-model $tag"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asciichem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.21.0
4
+ version: 0.22.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
@@ -114,19 +114,19 @@ dependencies:
114
114
  - !ruby/object:Gem::Version
115
115
  version: '1.3'
116
116
  - !ruby/object:Gem::Dependency
117
- name: asciichem-model
117
+ name: json_schemer
118
118
  requirement: !ruby/object:Gem::Requirement
119
119
  requirements:
120
120
  - - "~>"
121
121
  - !ruby/object:Gem::Version
122
- version: 0.3.4
122
+ version: '2.4'
123
123
  type: :development
124
124
  prerelease: false
125
125
  version_requirements: !ruby/object:Gem::Requirement
126
126
  requirements:
127
127
  - - "~>"
128
128
  - !ruby/object:Gem::Version
129
- version: 0.3.4
129
+ version: '2.4'
130
130
  description: AsciiChem is an ASCII syntax for representing chemical formulae, reactions,
131
131
  electron configurations, bonds, crystals, spectra, calculations, Z-matrices, and
132
132
  reaction mechanisms. It parses to a semantic model and renders to MathML, HTML,
@@ -245,6 +245,7 @@ files:
245
245
  - lib/asciichem/wire/identity.rb
246
246
  - lib/asciichem/wire_adapter.rb
247
247
  - lib/asciichem/xml_builder.rb
248
+ - scripts/update-model-schemas.sh
248
249
  homepage: https://www.asciichem.org
249
250
  licenses:
250
251
  - BSD-2-Clause