chordproko 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d96af770f5a7ae0615269a3b09207a6a3d2dd8f0
4
- data.tar.gz: 9608370884791fd3bb1a1feeab07fdc9056ce345
3
+ metadata.gz: aefa543a5043450020a858771369ea9baaa6087f
4
+ data.tar.gz: 2141d68a44e41b6afa4dfd54d1df05d7decfddfc
5
5
  SHA512:
6
- metadata.gz: 3b91a886179279f72ade0e3de9ed5cf9ab588208de27095e04283ec708517438cfe73b275872f335c3d7ed0efe3c1b5ec358e41518a69dcbd52932c7b0546d3d
7
- data.tar.gz: 36b3c3427068a64239b2e8febf458a8d5effde2f786b6dd324b8b7298d68ec763f3011f4b534436cd327fb07c0ecc242e80769002aa451375cfd54de285c6872
6
+ metadata.gz: cbfaebf6f7eba0b9ff694ba871eb3e4b54bdbc2eb614535794996d2cc5b28f8dbd73498ab7a9dc0af916de2dfda68b1437aef46aadf9c4cd2d4d528f8f57be54
7
+ data.tar.gz: f390f1ed16cb172af35b68b9af6c5af1b301821a00e8c5ec285d715630f346375db65b5bc142e16bd1e44d82ceaca6b04edb7c1f3924ee3a4300f0bcaa180f75
data/README.md CHANGED
@@ -1,3 +1,4 @@
1
+ [![Gem Version](https://badge.fury.io/rb/chordproko.svg)](https://badge.fury.io/rb/chordproko)
1
2
  # Chordproko
2
3
 
3
4
  Chordproko is a parser for ruby. It converts chordpro format to a readable text format.
@@ -50,17 +51,46 @@ parsed = Chordproko::Parser.new.parse(file.read)
50
51
  ```
51
52
  Then, create your own **Transform** class.
52
53
 
53
- ## TODO
54
+ ### Extending PlainSong Formatter
55
+ ```ruby
56
+ class MyPlainSong < Chordproko::PlainSong
57
+ def initialize transformed, options={}
58
+ super(transformed, options)
59
+ end
60
+ def chord_group_format str
61
+ "<span>#{str}</span>"
62
+ end
63
+ def lyric_line_format str
64
+ "<div>#{str}</div>"
65
+ end
66
+ end
67
+ ```
54
68
 
55
- + Enable you to extend PlainSong class
69
+ Set the Chordproko formatter class. This will globally set our formatter.
56
70
 
57
71
  ```ruby
58
- class MySongFormat < Chordproko::PlainSong
59
- ...
60
- end
72
+ Chordproko.set_formatter_class("PlainSong")
61
73
  ```
62
74
 
63
- PlainSong is responsible in formatting the ChordPro format to a readable plain text format.
75
+ Then use the Chordproko ```.text``` method
76
+
77
+ Aside from those two methods, you can override these to modify your song sheet.
78
+
79
+ ```ruby
80
+ def chord_line_format str
81
+ ...
82
+ end
83
+ def comment_format str
84
+ ...
85
+ end
86
+ def directive_format str
87
+ ...
88
+ end
89
+ def lyric_format str
90
+ ...
91
+ end
92
+ ```
93
+ ## TODO
64
94
 
65
95
  + Improve specs
66
96
  + Improve documentations
data/_config.yml ADDED
@@ -0,0 +1 @@
1
+ theme: jekyll-theme-midnight
data/lib/chordproko.rb CHANGED
@@ -12,10 +12,15 @@ require "chordproko/sheet"
12
12
  require "chordproko/transform"
13
13
  require "chordproko/version"
14
14
  module Chordproko
15
+ @@formatter = "Chordproko::PlainSong"
16
+
17
+ def self.set_formatter_class formatter
18
+ @@formatter = formatter
19
+ end
15
20
  def self.text song, options={}
16
21
  parsed = Chordproko::Parser.new.parse(song)
17
22
  transformed = Transform.new.apply(parsed)
18
- sheet = PlainSong.new(transformed, options)
23
+ sheet = Object.const_get(@@formatter).new(transformed, options)
19
24
  sheet.to_s
20
25
  end
21
26
  end
@@ -26,9 +26,9 @@ module Chordproko
26
26
  textified += item.to_s
27
27
  when "Chordproko::ChordGroup"
28
28
  item.key = @options[:transpose] if @options[:transpose] rescue 0
29
- chord_group = item.to_s
30
- chords += (" " * (prev_lyrics.size - prev_chord.size).abs)+ chord_group
31
- prev_chord = chord_group
29
+ cgroup = item.to_s
30
+ chords += (" " * (prev_lyrics.size - prev_chord.size).abs) + chord_group_format(cgroup)
31
+ prev_chord = cgroup
32
32
 
33
33
  when "Chordproko::Lyric"
34
34
  prev_lyrics = item.to_s
@@ -37,12 +37,31 @@ module Chordproko
37
37
  end #case
38
38
  end #line
39
39
  chord_lyrics = []
40
- chord_lyrics << chords if chords.size > 0
41
- chord_lyrics << lyrics if lyrics.size > 0
40
+ chord_lyrics << chord_line_format(chords) if chords.size > 0
41
+ chord_lyrics << lyric_line_format(lyrics) if lyrics.size > 0
42
42
  textified += chord_lyrics.join("\n")
43
43
  textified += "\n"
44
44
  end #sheet
45
45
  textified
46
46
  end
47
+
48
+ def chord_group_format str
49
+ str
50
+ end
51
+ def lyric_line_format str
52
+ str
53
+ end
54
+ def chord_line_format str
55
+ str
56
+ end
57
+ def comment_format str
58
+ str
59
+ end
60
+ def directive_format str
61
+ str
62
+ end
63
+ def lyric_format str
64
+ str
65
+ end
47
66
  end
48
67
  end
@@ -1,3 +1,3 @@
1
1
  module Chordproko
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chordproko
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joseph Nelson Valeros
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-08-16 00:00:00.000000000 Z
11
+ date: 2017-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parslet
@@ -82,6 +82,7 @@ files:
82
82
  - LICENSE.txt
83
83
  - README.md
84
84
  - Rakefile
85
+ - _config.yml
85
86
  - bin/console
86
87
  - bin/setup
87
88
  - chordproko.gemspec