vandamme 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
data/Changelog.md CHANGED
@@ -1,3 +1,10 @@
1
+ # 2013-01-06 0.0.2
2
+
3
+ * Fix gem dependencies (to githup-markup)
4
+ * Allow users to specify :match_group for dirty changelogs
5
+ * Improved documentation
6
+ * ```:version_header_exp``` can be a real Regexp now
7
+
1
8
  # 2013-01-02 0.0.1
2
9
 
3
10
  Initial release
data/Gemfile CHANGED
@@ -2,6 +2,3 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in vandamme.gemspec
4
4
  gemspec
5
- gem 'rspec'
6
- gem 'github-markup'
7
- gem 'redcarpet'
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Vandamme
2
2
 
3
3
  [![Dependency Status](https://gemnasium.com/tech-angels/vandamme.png)](https://gemnasium.com/tech-angels/vandamme)
4
+ [![Build Status](https://travis-ci.org/tech-angels/vandamme.png?branch=master)](https://travis-ci.org/tech-angels/vandamme)
4
5
 
5
6
  Vandamme is a changelog parser gem, used in the [Gemnasium project](https://gemnasium.com)
6
7
 
@@ -24,7 +25,44 @@ The Parser initializer will use 3 options:
24
25
 
25
26
  * **:changelog**: full raw content of the changelog file
26
27
  * **:version_header_exp**: regexp to match the versions lines in changelog
27
- * **:format** (*optional*): if you want to use the html converter, you must provide the original format of the changelog
28
+ * **:format** (*optional*): if you want to use the html converter, you must provide the original format of the changelog. (default: 'raw')
29
+ * **:group_match** (*optional*): Number of the match group is used for version matching. (default: 0)
30
+
31
+ ### Regex format
32
+
33
+ **version_header_exp** will be converted to a new Regex object if it wasn't one.
34
+ Therefore,
35
+
36
+ Vandamme::Parser.new(changelog: changelog, version_header_exp: '\d{4}-\d{2}-\d{2} \((\d\.\d+\.\d+)\)')
37
+
38
+ is equivalent to:
39
+
40
+ Vandamme::Parser.new(changelog: changelog, version_header_exp: /\d{4}-\d{2}-\d{2} \((\d\.\d+\.\d+)\)/)
41
+
42
+ Be careful with how ruby is handling escaped caracters in a string: ```"\d"``` if different from ```'\d'```!
43
+
44
+ ### Version Matching
45
+
46
+ By default, the first match of the Regexp will be considered as the version number.
47
+ ie:
48
+
49
+ 'Release (\d+\.\d+\.\d+)'
50
+
51
+ will match lines like:
52
+
53
+ Release 1.3.5
54
+
55
+ and '1.3.5' will be used as a key in the Hash returned by the ```parse``` method.
56
+ Starting Vandamme 0.0.2, it's possible to specify which match group must be
57
+ used for the version number, by passing the option **:match_group** to the
58
+ initializer:
59
+
60
+ Vandamme::Parser.new([...], :matching_group => 1)
61
+
62
+ The default match group is 0: this is the first group matched (0 being the
63
+ original string), because we are using ```String#scan``` instead of
64
+ ```Regexp.match```.
65
+
28
66
 
29
67
  ## Examples
30
68
 
@@ -52,3 +90,10 @@ Vandamme is bundled with Redcarpet by default (for markdown), you must add the n
52
90
  3. Commit your changes (`git commit -am 'Add some feature'`)
53
91
  4. Push to the branch (`git push origin my-new-feature`)
54
92
  5. Create new Pull Request
93
+
94
+ ## Credits
95
+
96
+ Philippe Lafoucrière @ Tech-angels - http://www.tech-angels.com/
97
+
98
+ [![Tech-Angels](http://media.tumblr.com/tumblr_m5ay3bQiER1qa44ov.png)](http://www.tech-angels.com)
99
+
@@ -7,26 +7,32 @@ module Vandamme
7
7
  # Create a new changelog parser
8
8
  #
9
9
  # Options:
10
- # * +changelog+: uri of file to be parsed
11
- # * +version_header_exp+: regexp to match the starting line of version
12
- # * +format+: (optional). One of "raw", "markdown", "rdoc"
10
+ # * +changelog+:: Changelog content as a +String+.
11
+ # * +version_header_exp+:: regexp to match the starting line of version.
12
+ # * +format+ (optional):: One of "raw", "markdown", "rdoc"
13
13
  #
14
+ #
14
15
  def initialize(options={})
15
16
  @changelog = options.fetch :changelog
16
- @version_header_exp = Regexp.new(/#{options.fetch :version_header_exp}/)
17
+ regexp = options.fetch :version_header_exp
18
+ @version_header_exp = regexp.is_a?(Regexp) ? regexp : Regexp.new(/#{regexp}/)
19
+ @match_group = options[:match_group] || 0
17
20
  @format = options[:format] || :raw
18
21
  @changelog_hash = {}
19
22
  end
20
23
 
24
+ # call-seq:
25
+ # parse => aHash
26
+ #
21
27
  # Parse changelog file, filling +@changelog_hash+ with
22
28
  # versions as keys, and version changelog as content.
23
29
  #
24
30
  def parse
25
- @changelog.scan(@version_header_exp) do
31
+ @changelog.scan(@version_header_exp) do |match|
26
32
  version_content = $~.post_match
27
33
  changelog_scanner = StringScanner.new(version_content)
28
34
  changelog_scanner.scan_until(@version_header_exp)
29
- @changelog_hash[$1]= (changelog_scanner.pre_match || version_content).gsub(/^\n+/, '')
35
+ @changelog_hash[match[@match_group]]= (changelog_scanner.pre_match || version_content).gsub(/^\n+/, '')
30
36
  end
31
37
  @changelog_hash
32
38
  end
@@ -1,3 +1,3 @@
1
1
  module Vandamme
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -68,4 +68,44 @@ describe Vandamme::Parser do
68
68
  expect(@parser.to_html).to eq(changelog_as_html_hash)
69
69
  end
70
70
  end
71
+
72
+ context "with changelog changing convention (md)" do
73
+ let(:changelog_file) {
74
+ <<-eos
75
+ # Version 1.0.0 - 2013-01-06
76
+
77
+ * First stable version.
78
+
79
+ # Release 0.9.9
80
+
81
+ * Last Beta before stable.
82
+ eos
83
+ }
84
+ let(:changelog_as_hash) {
85
+ {
86
+ "1.0.0" => "* First stable version.\n",
87
+ "0.9.9" => "* Last Beta before stable.\n"
88
+ }
89
+ }
90
+
91
+ let(:changelog_as_html_hash) {
92
+ {
93
+ "1.0.0" => "<ul>\n<li>First stable version.</li>\n</ul>\n",
94
+ "0.9.9" => "<ul>\n<li>Last Beta before stable.</li>\n</ul>\n"
95
+ }
96
+ }
97
+
98
+ before do
99
+ @parser = Vandamme::Parser.new(changelog: changelog_file, version_header_exp: '# (Version|Release) (\d.\d+\.\d+)( - \d{4}-\d{2}-\d{2})?', format: 'md', match_group: 1)
100
+ @changelog_parsed = @parser.parse
101
+ end
102
+
103
+ it "should parse file and fill changelog hash" do
104
+ expect(@changelog_parsed).to eq(changelog_as_hash)
105
+ end
106
+
107
+ it "should provide html content" do
108
+ expect(@parser.to_html).to eq(changelog_as_html_hash)
109
+ end
110
+ end
71
111
  end
data/vandamme.gemspec CHANGED
@@ -16,4 +16,10 @@ Gem::Specification.new do |gem|
16
16
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ["lib"]
19
+
20
+ gem.add_development_dependency 'rspec','~> 2.12.0'
21
+ gem.add_development_dependency 'rake','~> 10.0.2'
22
+
23
+ gem.add_dependency 'github-markup', '~> 0.7.5'
24
+ gem.add_dependency 'redcarpet', '~> 2.2.2'
19
25
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vandamme
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,72 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-02 00:00:00.000000000 Z
13
- dependencies: []
12
+ date: 2013-01-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.12.0
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 2.12.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 10.0.2
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 10.0.2
46
+ - !ruby/object:Gem::Dependency
47
+ name: github-markup
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 0.7.5
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.7.5
62
+ - !ruby/object:Gem::Dependency
63
+ name: redcarpet
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 2.2.2
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 2.2.2
14
78
  description: Vandamme is aware of files content, and will be mostly used to parse
15
79
  changelog files and extract relevant content.
16
80
  email:
@@ -20,6 +84,7 @@ extensions: []
20
84
  extra_rdoc_files: []
21
85
  files:
22
86
  - .gitignore
87
+ - .travis.yml
23
88
  - Changelog.md
24
89
  - Gemfile
25
90
  - LICENSE.txt