LilyPond-Ruby 0.1.5 → 0.1.5.3

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: 162f200f9fd9c6999e2ac87636abde7d74208c865ac7e255b97742b2c8e52ba7
4
- data.tar.gz: 7b497c14668f852ada9ffcc2c0a7d359892412b6aa9dd25ca0a3b84f46cbb2b2
3
+ metadata.gz: 4d54f5369710cc4da48b7114204e186b85edeff67dd1cd8eda50066ff4495b2a
4
+ data.tar.gz: b3ff051ea699b01fb52c803c7d61159566d0484bb80b29d23f94ac2465f1a8f5
5
5
  SHA512:
6
- metadata.gz: a563f3505c5f6143583d14a6a5e2a0947f8387235fe1830cb8500deb25463ae0323c10f2dc70411f724355dec4d264bb91ecf1c651f4be5265ca7d11e3f843a2
7
- data.tar.gz: 5099230b556aaa98697e9e4619ef97185880942f37dd1962755a4a7224dd0bbc2d763837c415b3ee1fc0031bd884f2ef165d17ad2009a1c7e50d6040c764297c
6
+ metadata.gz: 4ffb4a7ab0157de96b1a22b5d44cc20288d3a4c874fee6c20784e5187a7437b2a9533e5f6c23ba423ba0ae0abff61054a8193d4fc70c02e635ed09e8c1174dd5
7
+ data.tar.gz: 1068a3ec0dea29a3a3e874d8f7e7b89c5d963d44224bddea5d4fc51d4cfce63984c3459f4d18db284a738bdf4f6cf271ba5ab495d70a4a45b022e944f00a3cdc
@@ -1,7 +1,7 @@
1
1
  require_relative "../lilypond-ruby.rb"
2
2
 
3
- # The LilyPond class provides an interface for generating LilyPond notation.
4
- class LilyPond
3
+ # The LilyPond module provides an interface for generating LilyPond notation.
4
+ module LilyPond
5
5
  # The Builder class is responsible for building LilyPond notation.
6
6
  class Builder
7
7
  # Creates a new LilyPond Builder object.
@@ -0,0 +1,23 @@
1
+ require_relative "../lilypond-ruby.rb"
2
+
3
+ module LilyPond
4
+ class << self
5
+ attr_accessor :configuration
6
+ end
7
+
8
+ def self.configuration
9
+ @configuration ||= Configuration.new
10
+ yield(@configuration) if block_given?
11
+ @configuration
12
+ end
13
+
14
+ class Configuration
15
+ attr_accessor :default_output, :destination_directory, :lilypond_path
16
+
17
+ def initialize
18
+ @default_output = :pdf
19
+ @destination_directory = "."
20
+ @lilypond_path = File.expand_path("../../../lilypond-2.24.1/bin/lilypond", __FILE__)
21
+ end
22
+ end
23
+ end
data/lib/lilypond-ruby.rb CHANGED
@@ -1,13 +1,12 @@
1
1
  require "open3"
2
2
  require "lilypond/builder"
3
+ require "lilypond/config"
3
4
  require "guile"
4
5
 
5
- class LilyPond
6
- LILYPOND_PATH = File.expand_path("../../lilypond-2.24.1/bin/lilypond", __FILE__)
6
+ module LilyPond
7
7
  class << self
8
-
9
8
  def version
10
- output, error, status = Open3.capture3(LILYPOND_PATH, "--version")
9
+ output, error, status = Open3.capture3(path, "--version")
11
10
  if status.success?
12
11
  puts output
13
12
  else
@@ -16,7 +15,7 @@ class LilyPond
16
15
  end
17
16
 
18
17
  def version_number
19
- output, error, status = Open3.capture3(LILYPOND_PATH, "--version")
18
+ output, error, status = Open3.capture3(path, "--version")
20
19
  if status.success?
21
20
  return output.match(/GNU LilyPond (\d+\.\d+\.\d+)/)[1]
22
21
  else
@@ -24,40 +23,58 @@ class LilyPond
24
23
  end
25
24
  end
26
25
 
27
- def generate_pdf_with_lilypond(file_name, lilypond_code)
26
+ # Approved output types: `[:pdf, :svg, :png]` If none is provided, it defaults to
27
+ # LilyPond.configuration.default_output, which initializes as `:pdf`
28
+ def generate_with_lilypond(file_name, lilypond_code, output_type = nil)
28
29
  tempfile = Tempfile.new(file_name)
29
30
  tempfile.write(lilypond_code)
30
31
  tempfile.close
31
- Open3.popen3(LILYPOND_PATH, "--pdf", tempfile.path) do |stdin, stdout, stderr, wait_thr|
32
- # Write the Lilypond code to stdin
33
- stdin.write(lilypond_code)
34
- stdin.close
35
-
36
- # Wait for the process to complete
37
- Process.detach(wait_thr.pid)
38
-
39
- # Read and process the output and error streams
40
- loop do
41
- # Wait for output to become available for reading
42
- ready = IO.select([stdout, stderr])
43
- next unless ready
44
-
45
- # Read available data from the streams
46
- ready[0].each do |stream|
47
- data = stream.read_nonblock(1024)
48
- puts data # or process the data as necessary
32
+ output_type ||= default_output
33
+ Dir.chdir(destination) do
34
+ Open3.popen3(path, "--#{output_type}", tempfile.path) do |stdin, stdout, stderr, wait_thr|
35
+ # Write the Lilypond code to stdin
36
+ stdin.write(lilypond_code)
37
+ stdin.close
38
+
39
+ # Wait for the process to complete
40
+ Process.detach(wait_thr.pid)
41
+
42
+ # Read and process the output and error streams
43
+ loop do
44
+ # Wait for output to become available for reading
45
+ ready = IO.select([stdout, stderr])
46
+ next unless ready
47
+
48
+ # Read available data from the streams
49
+ ready[0].each do |stream|
50
+ data = stream.read_nonblock(1024)
51
+ puts data # or process the data as necessary
52
+ end
53
+ rescue IO::WaitReadable, IO::WaitWritable
54
+ # Continue waiting if the streams are not yet ready
55
+ IO.select([stdout, stderr])
56
+ retry
57
+ rescue EOFError
58
+ # Stop waiting if the streams have been closed
59
+ break
49
60
  end
50
- rescue IO::WaitReadable, IO::WaitWritable
51
- # Continue waiting if the streams are not yet ready
52
- IO.select([stdout, stderr])
53
- retry
54
- rescue EOFError
55
- # Stop waiting if the streams have been closed
56
- break
57
61
  end
58
62
  end
59
63
  File.delete(tempfile.path)
60
64
  end
61
65
 
66
+ private
67
+ def default_output
68
+ LilyPond.configuration.default_output
69
+ end
70
+
71
+ def destination
72
+ LilyPond.configuration.destination_directory
73
+ end
74
+
75
+ def path
76
+ LilyPond.configuration.lilypond_path.to_s
77
+ end
78
+
62
79
  end # end self
63
80
  end # end LilyPond
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: LilyPond-Ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lee Whittaker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-09 00:00:00.000000000 Z
11
+ date: 2023-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -30,9 +30,10 @@ dependencies:
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
32
  version: 1.15.5
33
- description: "This gem provides a library to access and control Lilypond within Ruby.\nIt
34
- contains the libraries and binary files for LilyPond 2.24.1 and\nGuile 2.2.3. \n\n\nIt
35
- also provides a builder tool for generating LilyPond files dynamically\nwith Ruby.\n"
33
+ description: |
34
+ This gem provides a library to access and control Lilypond within Ruby.
35
+ It also provides a builder tool for generating LilyPond files dynamically
36
+ with Ruby.
36
37
  email: whittakerlee81@gmail.com
37
38
  executables: []
38
39
  extensions: []
@@ -41,6 +42,7 @@ files:
41
42
  - lib/guile.rb
42
43
  - lib/lilypond-ruby.rb
43
44
  - lib/lilypond/builder.rb
45
+ - lib/lilypond/config.rb
44
46
  - lilypond-2.24.1/bin/abc2ly
45
47
  - lilypond-2.24.1/bin/convert-ly
46
48
  - lilypond-2.24.1/bin/etf2ly