Class: Vandamme::Parser
- Inherits:
-
Object
- Object
- Vandamme::Parser
- Defined in:
- lib/vandamme/parser.rb
Constant Summary collapse
- DEFAULT_REGEXP =
Regexp.new('^#{0,3} ?([\w\d\.-]+\.[\w\d\.-]+[a-zA-Z0-9])(?: \W (\w+ \d{1,2}(?:st|nd|rd|th)?,\s\d{4}|\d{4}-\d{2}-\d{2}|\w+))?\n?[=-]*')
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Parser
constructor
Create a new changelog parser.
-
#parse ⇒ Object
call-seq: parse => aHash.
-
#to_html ⇒ Object
Convert @changelog_hash content to html using GitHub::Markup.
Constructor Details
#initialize(options = {}) ⇒ Parser
Create a new changelog parser
Options:
changelog
-
Changelog content as a
String
.
version_header_exp
(optional)-
regexp to match the starting line of version.
Defaults to /^#0,3 ?([wd.-]+.[a-zA-Z0-9])(?: / (w d1,2(?:st|nd|rd|th)?,sd4|d4-d2-d2|w+))?n?*/ See tech-angels.github.com/vandamme/#changelogs-convention
format
(optional)-
One of “raw”, “markdown”, “rdoc”
20 21 22 23 24 25 26 27 |
# File 'lib/vandamme/parser.rb', line 20 def initialize(={}) @changelog = .fetch :changelog regexp = [:version_header_exp] || DEFAULT_REGEXP @version_header_exp = regexp.is_a?(Regexp) ? regexp : Regexp.new(/#{regexp}/) @match_group = [:match_group] || 0 @format = [:format] || :raw @changelog_hash = {} end |
Instance Method Details
#parse ⇒ Object
call-seq:
parse => aHash
Parse changelog file, filling @changelog_hash with versions as keys, and version changelog as content.
35 36 37 38 39 40 41 42 43 |
# File 'lib/vandamme/parser.rb', line 35 def parse @changelog.scan(@version_header_exp) do |match| version_content = $~.post_match changelog_scanner = StringScanner.new(version_content) changelog_scanner.scan_until(@version_header_exp) @changelog_hash[match[@match_group]] = (changelog_scanner.pre_match || version_content).gsub(/(\A\n+|\n+\z)/, '') end @changelog_hash end |
#to_html ⇒ Object
Convert @changelog_hash content to html using GitHub::Markup. The @format is used to determine the input format (should be one of: “rdoc”, “md”, ‘markdown“, ”raw“, etc.) See github.com/github/markup/blob/master/lib/github/markups.rb for more formats. The corresponding gem must be bundled.
50 51 52 53 54 |
# File 'lib/vandamme/parser.rb', line 50 def to_html self.parse if @changelog_hash.empty? # GitHub Markup API is really weird, we MUST pass a file name for format detection as 1st arg: @changelog_hash.inject({}) { |h,(k,v)| h[k] = GitHub::Markup.render(".#{@format}", v); h } end |