jekyll-lilypond-converter 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b5f177cb881ed3ffe14dc792e6b4a7e977f52c63
4
+ data.tar.gz: f95a2466a47ae5b05e4a840d1165b8ab0a116836
5
+ SHA512:
6
+ metadata.gz: db985a70e7b851de222f26d9fa3fd61aeb6fe8cd0c5e4b16d756ec2b153fcb75af0a0634ca535e3cf27c93dfd3313071f5e55c6d3f9276b4158f3be178ace649
7
+ data.tar.gz: fb67ac2e237bf9be7733d4e43933073d896f5fb897dfb19acf1af42e9b36f57869c9c4701380da5aacc5ee3eb89feee708c2a882280baa06dbe80e5de15535da
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --order random
@@ -0,0 +1 @@
1
+ 2.4.0
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,73 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ jekyll-lilypond-converter (0.1.0)
5
+ jekyll (~> 3.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.5.1)
11
+ public_suffix (~> 2.0, >= 2.0.2)
12
+ colorator (1.1.0)
13
+ diff-lcs (1.3)
14
+ ffi (1.9.18)
15
+ forwardable-extended (2.6.0)
16
+ jekyll (3.5.2)
17
+ addressable (~> 2.4)
18
+ colorator (~> 1.0)
19
+ jekyll-sass-converter (~> 1.0)
20
+ jekyll-watch (~> 1.1)
21
+ kramdown (~> 1.3)
22
+ liquid (~> 4.0)
23
+ mercenary (~> 0.3.3)
24
+ pathutil (~> 0.9)
25
+ rouge (~> 1.7)
26
+ safe_yaml (~> 1.0)
27
+ jekyll-sass-converter (1.5.0)
28
+ sass (~> 3.4)
29
+ jekyll-watch (1.5.0)
30
+ listen (~> 3.0, < 3.1)
31
+ kramdown (1.14.0)
32
+ liquid (4.0.0)
33
+ listen (3.0.8)
34
+ rb-fsevent (~> 0.9, >= 0.9.4)
35
+ rb-inotify (~> 0.9, >= 0.9.7)
36
+ mercenary (0.3.6)
37
+ pathutil (0.14.0)
38
+ forwardable-extended (~> 2.6)
39
+ public_suffix (2.0.5)
40
+ rb-fsevent (0.10.2)
41
+ rb-inotify (0.9.10)
42
+ ffi (>= 0.5.0, < 2)
43
+ rouge (1.11.1)
44
+ rspec (3.6.0)
45
+ rspec-core (~> 3.6.0)
46
+ rspec-expectations (~> 3.6.0)
47
+ rspec-mocks (~> 3.6.0)
48
+ rspec-core (3.6.0)
49
+ rspec-support (~> 3.6.0)
50
+ rspec-expectations (3.6.0)
51
+ diff-lcs (>= 1.2.0, < 2.0)
52
+ rspec-support (~> 3.6.0)
53
+ rspec-mocks (3.6.0)
54
+ diff-lcs (>= 1.2.0, < 2.0)
55
+ rspec-support (~> 3.6.0)
56
+ rspec-support (3.6.0)
57
+ safe_yaml (1.0.4)
58
+ sass (3.5.1)
59
+ sass-listen (~> 4.0.0)
60
+ sass-listen (4.0.0)
61
+ rb-fsevent (~> 0.9, >= 0.9.4)
62
+ rb-inotify (~> 0.9, >= 0.9.7)
63
+
64
+ PLATFORMS
65
+ ruby
66
+
67
+ DEPENDENCIES
68
+ bundler (~> 1.14)
69
+ jekyll-lilypond-converter!
70
+ rspec (~> 3.6)
71
+
72
+ BUNDLED WITH
73
+ 1.14.6
@@ -0,0 +1,31 @@
1
+ # Jekyll LilyPond Converter
2
+
3
+ Add `lily` code blocks to your markdown blog post and automatically convert the code to sheet music using [LilyPond][].
4
+
5
+ ### Installation and Usage
6
+
7
+ - [Install LilyPond][] and ensure the `lilypond` executable is on your `$PATH`
8
+ - Add this gem to your Jekyll-based static site repository's Gemfile
9
+ - Add `lily_images/` to your `.gitignore`
10
+ - Add the converter to your `_config.yml` file:
11
+
12
+ gems:
13
+ - jekyll-lilypond-converter
14
+
15
+ - (Optional) specify LilyPond image format in `_config.yml` (default is `svg`, alternative option is `png`)
16
+
17
+ lilypond-image-format: png
18
+
19
+ - Add lily code to a markdown post:
20
+
21
+ This is a C major chord:
22
+
23
+ ```lilypond
24
+ \relative {
25
+ <c' e g>
26
+ }
27
+ ```
28
+
29
+
30
+ [LilyPond]: http://lilypond.org/
31
+ [Install LilyPond]: http://lilypond.org/download.html
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "jekyll-lilypond-converter"
8
+ spec.version = JekyllLilyPondConverter::VERSION
9
+ spec.authors = ["Mike Knepper"]
10
+ spec.email = ["michaelrknepper@gmail.com"]
11
+
12
+ spec.summary = "Convert LilyPond snippets in blog posts to images"
13
+ spec.description = "Automatically identify LilyPond code snippets in Markdown blog posts and, during conversion to HTML, replace snippets with links to generated SVG images"
14
+ spec.homepage = "https://github.com/mikeknep/jekyll-lilypond-converter"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.require_paths = ["lib", "lib/jekyll_ext/", "lib/jekyll_lilypond_converter/"]
21
+
22
+ spec.add_dependency "jekyll", "~> 3.0"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.14"
25
+ spec.add_development_dependency "rspec", "~> 3.6"
26
+ end
@@ -0,0 +1,8 @@
1
+ require "jekyll_lilypond_converter/errors"
2
+ require "jekyll_lilypond_converter/lily"
3
+ require "jekyll_lilypond_converter/handler"
4
+ require "jekyll_lilypond_converter/site_manager"
5
+ require "jekyll_lilypond_converter/naming_policy"
6
+ require "jekyll_ext/converter"
7
+ require "jekyll_ext/generator"
8
+ require "jekyll_ext/lily_pond_static_file_builder"
@@ -0,0 +1,47 @@
1
+ require "jekyll"
2
+
3
+ module Jekyll
4
+ class LilyPondConverter < Converter
5
+ priority :high
6
+
7
+ DEFAULT_CONFIG = {
8
+ "lilypond-image-format" => "svg"
9
+ }
10
+
11
+ def initialize(config = {})
12
+ @config = Jekyll::Utils.deep_merge_hashes(DEFAULT_CONFIG, config)
13
+ end
14
+
15
+ def matches(ext)
16
+ /md|markdown/.match?(ext)
17
+ end
18
+
19
+ def output_ext(ext)
20
+ ".html"
21
+ end
22
+
23
+ def convert(content)
24
+ ensure_valid_image_format(image_format)
25
+
26
+ ::JekyllLilyPondConverter::Handler.new(
27
+ content: content,
28
+ naming_policy: ::JekyllLilyPondConverter::NamingPolicy.new,
29
+ image_format: image_format,
30
+ site_manager: ::JekyllLilyPondConverter::SiteManager.instance,
31
+ static_file_builder: Jekyll::LilyPondStaticFileBuilder
32
+ ).execute
33
+ end
34
+
35
+ private
36
+
37
+ def image_format
38
+ @config["lilypond-image-format"]
39
+ end
40
+
41
+ def ensure_valid_image_format(image_format)
42
+ unless ["svg", "png"].include?(image_format)
43
+ raise ::JekyllLilyPondConverter::INVALID_IMAGE_FORMAT_ERROR
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,24 @@
1
+ require "jekyll"
2
+
3
+ module Jekyll
4
+ class LilyPondGenerator < Generator
5
+ def generate(site)
6
+ ::JekyllLilyPondConverter::SiteManager.instance.site = site
7
+ setup_lily_images_directory
8
+ remove_stale_lily_image_references(site)
9
+ end
10
+
11
+ private
12
+
13
+ def setup_lily_images_directory
14
+ system("rm", "-rf", "lily_images/")
15
+ system("mkdir", "lily_images/")
16
+ end
17
+
18
+ def remove_stale_lily_image_references(site)
19
+ site.static_files.reject! do |static_file|
20
+ /lily_images\/.*\.(svg|png)/.match?(static_file.path)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,14 @@
1
+ require "jekyll"
2
+
3
+ module Jekyll
4
+ class LilyPondStaticFileBuilder
5
+ def self.build(site, filename)
6
+ StaticFile.new(
7
+ site,
8
+ site.source,
9
+ "lily_images",
10
+ filename
11
+ )
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,10 @@
1
+ module JekyllLilyPondConverter
2
+ class INVALID_IMAGE_FORMAT_ERROR < StandardError
3
+ def message
4
+ <<-ERROR
5
+ Invalid lilypond-image-format option selected.
6
+ Valid options are 'svg' (default) and 'png'.
7
+ ERROR
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,58 @@
1
+ module JekyllLilyPondConverter
2
+ class Handler
3
+ def initialize(content:, naming_policy:, image_format:, site_manager:, static_file_builder:)
4
+ @content = content
5
+ @naming_policy = naming_policy
6
+ @image_format = image_format
7
+ @site_manager = site_manager
8
+ @static_file_builder = static_file_builder
9
+ end
10
+
11
+ def execute
12
+ lilies.each do |lily|
13
+ write_lily_code_file(lily)
14
+ generate_lily_image(lily)
15
+ add_lily_image_to_site(lily)
16
+ replace_snippet_with_image_link(lily)
17
+ end
18
+ content
19
+ end
20
+
21
+ private
22
+ attr_reader :content, :naming_policy, :image_format, :site_manager, :static_file_builder
23
+
24
+ def write_lily_code_file(lily)
25
+ open(lily.code_filename, 'w') do |code_file|
26
+ code_file.puts(lily.code)
27
+ end
28
+ end
29
+
30
+ def generate_lily_image(lily)
31
+ system("lilypond", lilypond_output_format_option, lily.code_filename)
32
+ system("mv", lily.image_filename, "lily_images/")
33
+ system("rm", lily.code_filename)
34
+ end
35
+
36
+ def add_lily_image_to_site(lily)
37
+ site_manager.add_image(static_file_builder, lily.image_filename)
38
+ end
39
+
40
+ def replace_snippet_with_image_link(lily)
41
+ content.gsub!(lily.snippet, lily.image_link)
42
+ end
43
+
44
+ def lilies
45
+ lily_snippets.map do |snippet|
46
+ Lily.new(naming_policy.generate_name, image_format, snippet)
47
+ end
48
+ end
49
+
50
+ def lily_snippets
51
+ content.scan(/```lilypond.+?```\n/m)
52
+ end
53
+
54
+ def lilypond_output_format_option
55
+ image_format == "png" ? "--png" : "-dbackend=svg"
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,34 @@
1
+ module JekyllLilyPondConverter
2
+ class Lily
3
+ attr_reader :snippet
4
+
5
+ def initialize(id, extension, snippet)
6
+ @id = id
7
+ @extension = extension
8
+ @snippet = snippet
9
+ end
10
+
11
+ def code_filename
12
+ "#{id}.ly"
13
+ end
14
+
15
+ def image_filename
16
+ "#{id}.#{extension}"
17
+ end
18
+
19
+ def image_link
20
+ "![](/lily_images/#{image_filename})\n"
21
+ end
22
+
23
+ def code
24
+ strip_delimiters(snippet)
25
+ end
26
+
27
+ private
28
+ attr_reader :id, :extension
29
+
30
+ def strip_delimiters(snippet)
31
+ snippet.gsub(/```lilypond\n/, "").gsub(/```\n/, "")
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,9 @@
1
+ require "securerandom"
2
+
3
+ module JekyllLilyPondConverter
4
+ class NamingPolicy
5
+ def generate_name
6
+ SecureRandom.uuid
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ require "singleton"
2
+
3
+ module JekyllLilyPondConverter
4
+ class SiteManager
5
+ include Singleton
6
+
7
+ attr_accessor :site
8
+
9
+ def add_image(builder, filename)
10
+ site.static_files << builder.build(site, filename)
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ module JekyllLilyPondConverter
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-lilypond-converter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Mike Knepper
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-09-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jekyll
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.14'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.14'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.6'
55
+ description: Automatically identify LilyPond code snippets in Markdown blog posts
56
+ and, during conversion to HTML, replace snippets with links to generated SVG images
57
+ email:
58
+ - michaelrknepper@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".rspec"
64
+ - ".ruby-version"
65
+ - Gemfile
66
+ - Gemfile.lock
67
+ - README.md
68
+ - jekyll_lilypond_converter.gemspec
69
+ - lib/jekyll-lilypond-converter.rb
70
+ - lib/jekyll_ext/converter.rb
71
+ - lib/jekyll_ext/generator.rb
72
+ - lib/jekyll_ext/lily_pond_static_file_builder.rb
73
+ - lib/jekyll_lilypond_converter/errors.rb
74
+ - lib/jekyll_lilypond_converter/handler.rb
75
+ - lib/jekyll_lilypond_converter/lily.rb
76
+ - lib/jekyll_lilypond_converter/naming_policy.rb
77
+ - lib/jekyll_lilypond_converter/site_manager.rb
78
+ - lib/version.rb
79
+ homepage: https://github.com/mikeknep/jekyll-lilypond-converter
80
+ licenses:
81
+ - MIT
82
+ metadata: {}
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ - lib/jekyll_ext/
88
+ - lib/jekyll_lilypond_converter/
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 2.6.13
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: Convert LilyPond snippets in blog posts to images
105
+ test_files: []