musedown 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: bec6c7c82ddd63eea5b707b3717619a51dea5acde6f941636a1e88101b61e6a4
4
+ data.tar.gz: 2057163776d5399bde0113ef213e5b0623996e90c0f202ddc3ea41606d9cec80
5
+ SHA512:
6
+ metadata.gz: f04e4ec3986d5e8f4e6a1da60fee3cf87acbeedc24bf395b9c43c357f3ec18db2a8853a9a063f29414ce464d015b681f550c035ed7fe94f901871e487cd19b52
7
+ data.tar.gz: 27c1fb3a50183af547d6bf4456bb33701de743e00e6e53799d53aa4ec391f46a2e1f7f0cd6a36239dcc89dcfce8ed6ac250fcea611c1b38eb6206e61eada8caf
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ .DS_Store
@@ -0,0 +1 @@
1
+ 2.7.1
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in musedown.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
@@ -0,0 +1,21 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ musedown (0.1.0)
5
+ thor (~> 0.20)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ rake (12.3.3)
11
+ thor (0.20.3)
12
+
13
+ PLATFORMS
14
+ ruby
15
+
16
+ DEPENDENCIES
17
+ musedown!
18
+ rake (~> 12.0)
19
+
20
+ BUNDLED WITH
21
+ 2.1.4
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Erick Durán
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,53 @@
1
+ # Musedown
2
+ This is a simple MuseScore CLI wrapper to easily build markdown files with music notation (and preserve for changes).
3
+
4
+ ## Installation
5
+ To install the `gem` directly:
6
+ ```bash
7
+ gem install musedown
8
+ ```
9
+
10
+ Or build directly from the source code:
11
+ ```bash
12
+ rake install
13
+ ```
14
+
15
+ ## Usage
16
+ The `musedown` CLI will use MuseScore's CLI (`mscore`) to convert your `.mscz` files into `.png` files and replace them in your markdown file.
17
+
18
+ To use:
19
+ 1. Embed the `.mscz` file into your markdown like this:
20
+ ```markdown
21
+ ![Awesome score](hello.mscz)
22
+ ```
23
+ 2. Run `musedown`:
24
+ ```
25
+ musedown build hello.md
26
+ ```
27
+ 3. And your markdown file will now be like this:
28
+ ```markdown
29
+ ![Awesome score](hello-mscz-1.png)
30
+ ```
31
+ And the `hello-mscz-1.png` will be automatically generated. You may keep the `hello.mscz`, perform changes and re-run the command to refresh the `.png` file.
32
+
33
+ ### Commands
34
+ To parse a file, simply run:
35
+ ```bash
36
+ musedown build FILE_NAME
37
+ ```
38
+
39
+ To route the output to another file:
40
+ ```bash
41
+ musedown build examples/hello.md -o result.md
42
+ ```
43
+
44
+ If `mscore` is not available, you can directly pass the executable with the `-c` flag:
45
+ ```bash
46
+ musedown build examples/hello.md -o examples/output.md -c "/Applications/MuseScore\ 3.app/Contents/MacOS/mscore"
47
+ ```
48
+
49
+ ## Contributing
50
+ Bug reports and pull requests are welcome on GitHub at https://github.com/erickduran/musedown.
51
+
52
+ ## License
53
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "musedown"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require "musedown"
3
+
4
+ md = Musedown::CLI.start(ARGV)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
Binary file
@@ -0,0 +1,5 @@
1
+ # Hello World!
2
+
3
+ This is my cool file.
4
+
5
+ ![](hello.mscz)
Binary file
@@ -0,0 +1,5 @@
1
+ # Hello World!
2
+
3
+ This is my cool file.
4
+
5
+ ![](hello-mscz-1.png)
@@ -0,0 +1,93 @@
1
+ require "musedown/version"
2
+ require "thor"
3
+
4
+ module Musedown
5
+ class Score
6
+ attr_accessor :score_file
7
+ attr_accessor :relative_score_file
8
+ attr_accessor :relative_image_file
9
+ attr_reader :prebuilt
10
+
11
+ def initialize(prebuilt)
12
+ @score_file = nil
13
+ @relative_score_file = nil
14
+ @relative_image_file = nil
15
+ @prebuilt = prebuilt
16
+ end
17
+
18
+ def build(command)
19
+ begin
20
+ image_file = "#{@score_file.gsub(".mscz", "-mscz")}.png"
21
+ result = `#{command} #{@score_file} -o #{image_file}`
22
+ rescue Errno::ENOENT => error
23
+ puts("⚠️ Error building #{@score_file}: #{error}")
24
+ end
25
+
26
+ if $?.success?
27
+ if !prebuilt
28
+ @relative_image_file = @relative_score_file.sub(/.*\K\.mscz/, "-mscz-1.png")
29
+ end
30
+ else
31
+ puts("⚠️ Failed to convert #{@score_file}")
32
+ end
33
+ return $?.success?
34
+ end
35
+ end
36
+
37
+ class CLI < Thor
38
+ desc("build [FILE_NAME]", "build markdown file")
39
+ option(:output, :type => :string, :required => false, :desc => "output file", :aliases => "-o")
40
+ option(:command, :type => :string, :default => "mscore", :desc => "musescore command, default: mscore", :aliases => "-c")
41
+ def build(file_name)
42
+ output_file = file_name
43
+ if options[:output]
44
+ puts("✏️ Output file will be #{options[:output]}")
45
+ output_file = options[:output]
46
+ end
47
+
48
+ puts("👷‍♂️ Building file #{file_name}...")
49
+ contents = nil
50
+ File.open(file_name) do |file|
51
+ contents = file.read
52
+ end
53
+ scores = []
54
+
55
+ prebuilt_expression = /!\[.*\]\((?<file_name>.*\-mscz-1\.png)\)/
56
+ prebuilt_matches = contents.scan(prebuilt_expression)
57
+
58
+ puts("🔍 Found #{prebuilt_matches.length} previously built images...")
59
+ prebuilt_matches.each do |match|
60
+ score = Score.new(true)
61
+ score.relative_image_file = match[0]
62
+ resolved_image_file = File.join(File.dirname(file_name), score.relative_image_file)
63
+ score.score_file = resolved_image_file.gsub("-mscz-1.png", ".mscz")
64
+ scores << score
65
+ end
66
+
67
+ expression = /!\[.*\]\((?<file_name>.*\.mscz)\)/
68
+ matches = contents.scan(expression)
69
+
70
+ puts("🔍 Found unbuilt #{matches.length} score files...")
71
+ matches.each do |match|
72
+ score = Score.new(false)
73
+ score.relative_score_file = match[0]
74
+ score.score_file = File.join(File.dirname(file_name), score.relative_score_file)
75
+ scores << score
76
+ end
77
+
78
+ scores.each do |score|
79
+ sucess = score.build(options[:command])
80
+ if !score.prebuilt and sucess
81
+ contents = contents.gsub(score.relative_score_file, score.relative_image_file)
82
+ end
83
+ end
84
+
85
+ puts("💾 Saving...")
86
+ File.open(output_file, "w") do |file|
87
+ file.write(contents)
88
+ end
89
+
90
+ puts "✅ Done!"
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,3 @@
1
+ module Musedown
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,29 @@
1
+ require_relative 'lib/musedown/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "musedown"
5
+ spec.version = Musedown::VERSION
6
+ spec.authors = ["Erick Durán"]
7
+ spec.email = ["me@erickduran.com"]
8
+
9
+ spec.summary = %q{A music notation markdown builder.}
10
+ spec.description = %q{A music notation markdown builder.}
11
+ spec.homepage = "https://github.com/erickduran/musedown"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/erickduran/musedown"
19
+ spec.metadata["changelog_uri"] = "https://github.com/erickduran/musedown"
20
+
21
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ end
24
+
25
+ spec.executables = ["musedown"]
26
+ spec.require_paths = ["lib"]
27
+
28
+ spec.add_dependency "thor", "~> 0.20"
29
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: musedown
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Erick Durán
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-06-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.20'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.20'
27
+ description: A music notation markdown builder.
28
+ email:
29
+ - me@erickduran.com
30
+ executables:
31
+ - musedown
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - ".gitignore"
36
+ - ".ruby-version"
37
+ - Gemfile
38
+ - Gemfile.lock
39
+ - LICENSE
40
+ - README.md
41
+ - Rakefile
42
+ - bin/console
43
+ - bin/musedown
44
+ - bin/setup
45
+ - examples/hello-mscz-1.png
46
+ - examples/hello.md
47
+ - examples/hello.mscz
48
+ - examples/output.md
49
+ - lib/musedown.rb
50
+ - lib/musedown/version.rb
51
+ - musedown.gemspec
52
+ homepage: https://github.com/erickduran/musedown
53
+ licenses:
54
+ - MIT
55
+ metadata:
56
+ allowed_push_host: https://rubygems.org
57
+ homepage_uri: https://github.com/erickduran/musedown
58
+ source_code_uri: https://github.com/erickduran/musedown
59
+ changelog_uri: https://github.com/erickduran/musedown
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 2.3.0
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubygems_version: 3.1.2
76
+ signing_key:
77
+ specification_version: 4
78
+ summary: A music notation markdown builder.
79
+ test_files: []