-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ref #2
- Loading branch information
Showing
7 changed files
with
133 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module Gly | ||
class GregorioVersionDetector | ||
# Tries to determine version of available Gregorio. | ||
def self.version | ||
begin | ||
version_output = `gregorio --version` | ||
rescue Errno::ENOENT | ||
# 'gregorio' command not available | ||
return nil | ||
end | ||
|
||
version_output.match(/^Gregorio (\d+\.\d+\.\d+)/) do |m| | ||
return Gem::Version.new(m[1]) | ||
end | ||
|
||
# failed to parse gregorio version from the output | ||
nil | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
module Gly | ||
# Contains "strategies" for generation of GregorioTeX | ||
# commands depending on Gregorio version. | ||
module Tags | ||
# Receives Gregorio version (as `Gem::Version` instance or number), | ||
# returns strategy instance. | ||
def self.[](version) | ||
is4 = | ||
if version.is_a?(Gem::Version) | ||
Gem::Version.new('5') > version | ||
else | ||
5 > version | ||
end | ||
|
||
if is4 | ||
return Gregorio4.new | ||
end | ||
|
||
return Gregorio5.new | ||
end | ||
|
||
class Gregorio4 | ||
def commentary(str) | ||
"\\commentary{\\footnotesize{#{str}}}\n" | ||
end | ||
|
||
def annotations(first, second) | ||
"\\setfirstannotation{#{first}}" + | ||
"\\setsecondannotation{#{second}}" | ||
end | ||
|
||
def score(filename) | ||
# TODO: space between scores should not be hardcoded this way | ||
"\\includescore{#{filename}}\n\\vspace{1cm}" | ||
end | ||
end | ||
|
||
class Gregorio5 | ||
def commentary(str) | ||
"\\grecommentary{\\footnotesize{#{str}}}\n" | ||
end | ||
|
||
def annotations(first, second) | ||
"\\greannotation{#{first}}" + | ||
"\\greannotation{#{second}}" | ||
end | ||
|
||
def score(filename) | ||
# TODO: space between scores should not be hardcoded this way | ||
"\\gregorioscore{#{filename}}\n\\vspace{1cm}" | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
require_relative 'examples' | ||
require_relative 'no_crash' | ||
require_relative 'string_helpers_test' | ||
require_relative 'tags_test' | ||
require_relative 'parser' | ||
require_relative 'music_with_lyrics' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
require_relative 'test_helper' | ||
|
||
class TagsTest < MiniTest::Test | ||
# save some typing | ||
V = Gem::Version | ||
Gregorio4 = Gly::Tags::Gregorio4 | ||
Gregorio5 = Gly::Tags::Gregorio5 | ||
|
||
examples = [ | ||
['gregorio4', V.new('4'), Gregorio4], | ||
['gregorio4_semantic', V.new('4.1.2'), Gregorio4], | ||
['gregorio5', V.new('5'), Gregorio5], | ||
# integer works, too | ||
['integer_4', 4, Gregorio4], | ||
['integer_5', 5, Gregorio5], | ||
# for older versions Gregorio 4 strategy is used | ||
['gregorio1', V.new('1'), Gregorio4], | ||
['gregorio2', V.new('2'), Gregorio4], | ||
['gregorio3', V.new('3'), Gregorio4], | ||
# for versions newer than 5 use Gregorio 5 strategy | ||
['gregorio6', V.new('6'), Gregorio5], | ||
] | ||
|
||
examples.each do |e| | ||
name, given, expected = e | ||
define_method "test_#{name}" do | ||
assert_kind_of expected, Gly::Tags[given] | ||
end | ||
end | ||
|
||
invalid_examples = [ | ||
['nil', nil], | ||
['string', '1.1.0'], | ||
] | ||
|
||
invalid_examples.each do |e| | ||
name, given = e | ||
define_method "test_invalid_#{name}" do | ||
assert_raises ArgumentError do | ||
Gly::Tags[given] | ||
end | ||
end | ||
end | ||
end |