Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for directives with all whitespace value #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/chordpro/html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ def title(title)
alias_method :t, :title

def subtitle(subtitle)
@html.h2(class: "subtitle") { |h2| h2.text! subtitle }
unless subtitle.match(/^\s*$/)
@html.h2(class: "subtitle") { |h2| h2.text! subtitle }
end
end
alias_method :st, :subtitle
alias_method :su, :subtitle
Expand Down
5 changes: 5 additions & 0 deletions lib/chordpro/transform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ class Transform < Parslet::Transform
Chordpro::Directive.new(directive_name, value.to_s)
end

rule(directive: {name: simple(:name), value: []}) do
directive_name = Directive.find(name) || Directive::Name.new(name.to_s)
Chordpro::Directive.new(directive_name, "")
end

rule(directive: {name: simple(:name)}) do
directive_name = Directive.find(name) || Directive::Name.new(name.to_s)
Chordpro::Directive.new(directive_name)
Expand Down
3 changes: 3 additions & 0 deletions spec/chordpro/html_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ def html(string)
it "renders h2 for #{name}" do
expect(html("{#{name}:The Beatles}").to_s).to eq('<h2 class="subtitle">The Beatles</h2>')
end
it "allows empty #{name}" do
expect(html("{#{name}: }").to_s).to eq('')
end
end

it "guards against xss in the subtitle" do
Expand Down