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 blocks to parse/to_html for custom behaviour #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Allow blocks to parse/to_html for custom behaviour #16

wants to merge 1 commit into from

Conversation

rgarner
Copy link

@rgarner rgarner commented Oct 9, 2017

The default Vandamme::Parser#parse behaviour only allows the output of
hashes containing one key – either version or release date – via use of
the :match_group option to Vandamme::Parser#initialize. This makes it hard
to get a hash with all of: versions, date, and content.

Without breaking the current interface requiring a major version change,
allow custom behaviour to both #parse and #to_html by allowing blocks.

For #parse, yield the changelog hash, the header match, and the current
content. This means

parser.parse do |result, header_match, content|
  result[header_match[0]] = { date: header_match[1], content: content }
end

can produce a hash such as:

{
  '1.0.0' => { date: '2017-09-19', content: "* My\n* Changes" }
}

and a corresponding

parser.to_html { |hash| hash[:content] }

can generate its html.

The default Vandamme::Parser#parse behaviour only allows the output of
hashes containing one key – either version or release date – via use of
the :match_group option to Vandamme::Parser#initialize.

Without breaking the current interface requiring a major version change,
allow custom behaviour to both #parse and #to_html by allowing blocks.

For #parse, yield the changelog hash, the header match, and the current
content. This means

parser.parse do |result, header_match, content|
  result[header_match[0]] = { date: header_match[1], content: content }
end

can produce a hash such as:

{
  '1.0.0' => { date: '2017-09-19', content: "* My\n* Changes" }
}

and a corresponding

parser.to_html { |hash| hash[:content] }

can generate its html.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant