rsyntaxtree 1.3.1 → 1.3.2

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: d22d15ae9e17b8312dc6fdc9c37c4fe942e981854eb69589eb4b117acd1d781b
4
- data.tar.gz: 983152369ea224f73372c0e7f7754bc5db36e65fab6d20eec235757dde5a44b0
3
+ metadata.gz: b1d293f1051661467a4b39531bb7868073256fc6a40e60affa4dee8daa45187f
4
+ data.tar.gz: 79ececb16b1b9394f5027ccec1f4dcba9d4cd541fe8829276eb9c18d5a377c24
5
5
  SHA512:
6
- metadata.gz: 7d754218424e09ebf23c84471f192f5f3192dd0a94e1b277e3c28bfed2cdcd5ca5e0cb4785fd19f37584811943cd09e0eb9a22595f2b0c321add4d417bda08c3
7
- data.tar.gz: 024f6fd854639fee40d7377509b2f36b00cab56c86929c6d2c1b833aab7c0ad77b6a519a5506a679fa315c69c8b1fe7c16bf1665e425ac4747cb6714feb67c2a
6
+ metadata.gz: cd4e3ceb0efc58a58b87b4273525aa9456e6050c5b7dfe41bcc0b790018240d2e1c1a0f34a42c45f78faf6913441f41a57aef30f60daab8ce7cfc24182a8b3ce
7
+ data.tar.gz: 76b44cc2c343a43714ab9cfe52c3a04c524fc81296e901796e0b2aa7b8205b73de4b2a88001d269a5fa834a9267e62e3d2a034b2fbde7d7ca471be90d41524ae
data/README.md CHANGED
@@ -10,6 +10,7 @@ Documentation is currently available in the following languages:
10
10
  - [日本語ドキュメント](https://yohasebe.github.io/rsyntaxtree/documentation_ja)
11
11
 
12
12
  - [Example Gallery](https://yohasebe.github.io/rsyntaxtree/examples)
13
+
13
14
  ## Web Interface
14
15
 
15
16
  <img src='https://github.com/yohasebe/rsyntaxtree/blob/master/img/rsyntaxtree-web-screenshot.png?raw=true' width='700px'/>
@@ -56,9 +57,27 @@ See [RSyntaxTree Example Gallery](https://yohasebe.github.io/rsyntaxtree/example
56
57
 
57
58
  ## Installation
58
59
 
59
- `# gem install rsyntaxtree`
60
+ ```
61
+ gem install rsyntaxtree
62
+ ```
63
+
64
+ ### macOS Installation Notice
65
+
66
+ **Important for macOS users:** If you are installing the RSyntaxTree gem directly on macOS, you might encounter build errors for some native extensions (specifically for `gobject-introspection`, `cairo-gobject`, and `gio2`). These errors occur due to macOS linker requirements for dynamic symbol resolution. To work around this issue, please run the following commands in your terminal **before** installing RSyntaxTree:
67
+
68
+ ```bash
69
+ gem install gobject-introspection -- --with-ldflags="-Wl,-undefined,dynamic_lookup"
70
+ gem install cairo-gobject -- --with-ldflags="-Wl,-undefined,dynamic_lookup"
71
+ gem install gio2 -- --with-ldflags="-Wl,-undefined,dynamic_lookup"
72
+ ```
73
+
74
+ After executing these commands, you can install RSyntaxTree normally:
75
+
76
+ ```bash
77
+ gem install rsyntaxtree
78
+ ```
60
79
 
61
- **NOTE**: Currently, installation of the gem package on macOS is not recommended. Please use the [Docker image](https://hub.docker.com/r/yohasebe/rsyntaxtree) or the [web interface](https://yohasebe.com/rsyntaxtree).
80
+ Alternatively, if you prefer a smoother installation process, consider using the [Docker image](https://hub.docker.com/r/yohasebe/rsyntaxtree) or the [web interface](https://yohasebe.com/rsyntaxtree).
62
81
 
63
82
  ## Usage
64
83
 
data/Rakefile CHANGED
@@ -9,24 +9,58 @@ require_relative 'lib/rsyntaxtree/utils'
9
9
  # task default: "test"
10
10
 
11
11
  Rake::TestTask.new do |task|
12
- task.pattern = "test/*_test.rb"
13
- task.warning = false
12
+ task.pattern = "test/*_test.rb"
13
+ task.warning = false
14
14
  end
15
15
 
16
16
  desc "Generate SVG and PNG example images locally"
17
17
  task :generate do
18
- require_relative "dev/generate_examples"
18
+ require_relative "dev/generate_examples"
19
19
  end
20
20
 
21
21
  desc "Docker image Build"
22
22
  task :docker_build do
23
- `docker build ./ -t rsyntaxtree_devel`
23
+ `docker build ./ -t rsyntaxtree_devel`
24
24
  end
25
25
 
26
26
  desc "Generate SVG and PNG example images using Docker image"
27
27
  task :docker_generate do
28
- docpath = File.expand_path(File.join(__dir__, "docs"))
29
- `docker build ./ -t rsyntaxtree_devel`
30
- `docker run --rm -v #{docpath}:/rsyntaxtree/hostdocs rsyntaxtree_devel ruby /rsyntaxtree/dev/generate_examples.rb /rsyntaxtree/hostdocs`
31
- `cat #{docpath}/generate_examples.log`
28
+ docpath = File.expand_path(File.join(__dir__, "docs"))
29
+ `docker build ./ -t rsyntaxtree_devel`
30
+ `docker run --rm -v #{docpath}:/rsyntaxtree/hostdocs rsyntaxtree_devel ruby /rsyntaxtree/dev/generate_examples.rb /rsyntaxtree/hostdocs`
31
+ `cat #{docpath}/generate_examples.log`
32
+ end
33
+
34
+ # Add new task for macOS environment configuration
35
+
36
+ desc "Configure Bundler build options for macOS"
37
+ task :setup_macos do
38
+ require "rbconfig"
39
+ host_os = RbConfig::CONFIG['host_os']
40
+
41
+ # Check if the host OS is macOS (Darwin)
42
+
43
+ if host_os =~ /darwin/
44
+ puts "macOS detected. Setting up build options for native extensions..."
45
+
46
+ gems_with_options = {
47
+ "gobject-introspection" => '--with-ldflags=-Wl,-undefined,dynamic_lookup',
48
+ "cairo-gobject" => '--with-ldflags=-Wl,-undefined,dynamic_lookup',
49
+ "gio2" => '--with-ldflags=-Wl,-undefined,dynamic_lookup'
50
+ }
51
+
52
+ # Configure each gem with the necessary ldflags option using Bundler config command
53
+
54
+ gems_with_options.each do |gem_name, flags|
55
+ command = "bundle config build.#{gem_name} \"#{flags}\""
56
+ puts "Executing: #{command}"
57
+ unless system(command)
58
+ abort("Failed to execute command: #{command}")
59
+ end
60
+ end
61
+
62
+ puts "macOS setup complete. Please run 'bundle install' after this."
63
+ else
64
+ puts "This setup task is intended for macOS environments. Current OS: #{host_os}"
65
+ end
32
66
  end
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: "016"
3
- caption: "Tick-tac-toe"
3
+ caption: "Tic-tac-toe"
4
4
  color: "off"
5
5
  category: "Miscellaneous"
6
6
  polyline: "off"
@@ -13,29 +13,22 @@ font: "Noto Serif"
13
13
  ---
14
14
  ```
15
15
  [expr
16
- [id x
17
-
18
- ]
16
+ [id x]
19
17
  [suffix
20
18
  \[
21
- [id 2
22
-
23
- ]
19
+ [id 2 ]
24
20
  \]
25
21
  [suffix
26
22
  \[
27
- [id 3
28
-
29
- ]
23
+ [id 3 ]
30
24
  \]
31
25
  [suffix
32
26
  \[
33
- [id 4
34
-
35
- ]
27
+ [id 4 ]
36
28
  \]
37
29
  ]
38
30
  ]
39
31
  ]
40
32
  ]
33
+
41
34
  ```
@@ -7,7 +7,7 @@
7
7
  # Parses an element list into an SVG tree.
8
8
  # Copyright (c) 2007-2024 Yoichiro Hasebe <yohasebe@gmail.com>
9
9
 
10
- require "tempfile"
10
+ # No tempfile usage in this file
11
11
  require_relative 'base_graph'
12
12
  require_relative 'utils'
13
13
 
@@ -53,7 +53,9 @@ module FontMetrics
53
53
  gca.interline_spacing = 0
54
54
  gca.interword_spacing = 0
55
55
  end
56
- gc.get_multiline_type_metrics(background, text)
56
+ metrics = gc.get_multiline_type_metrics(background, text)
57
+ background.destroy! # Explicitly destroy the image
58
+ metrics
57
59
  end
58
60
  module_function :get_metrics
59
61
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RSyntaxTree
4
- VERSION = "1.3.1"
4
+ VERSION = "1.3.2"
5
5
  end
data/lib/rsyntaxtree.rb CHANGED
@@ -160,11 +160,12 @@ module RSyntaxTree
160
160
  context.render_rsvg_handle(rsvg)
161
161
  b = StringIO.new
162
162
  surface.write_to_png(b)
163
- if binary
164
- b
165
- else
166
- b.string
167
- end
163
+ result = binary ? b : b.string
164
+ # Clean up resources
165
+ b.close unless binary
166
+ surface.finish
167
+ context.destroy
168
+ result
168
169
  rescue Cairo::InvalidSize
169
170
  raise RSTError, +"Error: the result syntree is too big"
170
171
  end
@@ -178,11 +179,11 @@ module RSyntaxTree
178
179
  context = Cairo::Context.new(surface)
179
180
  context.render_rsvg_handle(rsvg)
180
181
  surface.finish
181
- if binary
182
- b
183
- else
184
- b.string
185
- end
182
+ result = binary ? b : b.string
183
+ # Clean up resources
184
+ b.close unless binary
185
+ context.destroy
186
+ result
186
187
  rescue Cairo::InvalidSize
187
188
  raise RSTError, +"Error: the result syntree is too big"
188
189
  end
@@ -200,10 +201,12 @@ module RSyntaxTree
200
201
  image, _data = Magick::Image.from_blob(svg) do |im|
201
202
  im.format = 'svg'
202
203
  end
203
- image.to_blob do |im|
204
+ blob = image.to_blob do |im|
204
205
  im.format = @params[:format].upcase
205
206
  end
206
- image
207
+ # Clean up resources
208
+ image.destroy!
209
+ blob
207
210
  end
208
211
  end
209
212
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rsyntaxtree
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yoichiro Hasebe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-10-24 00:00:00.000000000 Z
11
+ date: 2025-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: optimist
@@ -358,7 +358,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
358
358
  - !ruby/object:Gem::Version
359
359
  version: '0'
360
360
  requirements: []
361
- rubygems_version: 3.5.9
361
+ rubygems_version: 3.4.13
362
362
  signing_key:
363
363
  specification_version: 4
364
364
  summary: RSyntaxTree is a graphical syntax tree generator written in Ruby