flavored_gherkin 0.1 → 0.3

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: 2984005e874db23498bb3a6ef00dd9a44d551182
4
- data.tar.gz: 2a5dc7a2f413282fe14a24ce1174fbe7f2db1bba
3
+ metadata.gz: c7000dd4a6449c98993ad1e828cb4fdcc91900bf
4
+ data.tar.gz: bb365294fe5c6fef118db1db563003f844a312e5
5
5
  SHA512:
6
- metadata.gz: a394260d7c3ff161c4b4e593104bd3c5637c866f20eaaac56caf99bc13c6ca578a43a416eb85641c06455de651e4b6c49590e3bcaebb92fab59af688fafb4911
7
- data.tar.gz: 88a4a62c3592fde1b8d28d8897c1af4acb8377112514199ba6ba977065362875c988a47ab35a95d0029d07fcb151598b90b366f2114fe0b06279f7b64d07299e
6
+ metadata.gz: 575f4b4a872d21dec210548439e766ba1c699028f848c1e29f479f756e0fa1da4bb59a8995fb956b69563176ad0d6a85afa6179105a4b1c27504339f85fdb004
7
+ data.tar.gz: 2c4797c56ea45f93db9cd59e7fc83e3dbe96e8c577a48cc5952b6109cb32f2aa88473e2788063f9363b9620f102eb09e0e8b4d5b93b6aa77e3f44632e68ccd14
data/README.md CHANGED
@@ -1,15 +1,17 @@
1
- # Flavored Gherkin
1
+ # FlavoredGherkin
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/flavored_gherkin.svg)](https://badge.fury.io/rb/flavored_gherkin)
4
4
  [![Build status](https://travis-ci.org/rajatthareja/FlavoredGherkin.svg?branch=master)](https://travis-ci.org/rajatthareja/FlavoredGherkin)
5
5
  [![Windows Build status](https://ci.appveyor.com/api/projects/status/agvyur7bg5ul1444/branch/master?svg=true)](https://ci.appveyor.com/project/rajatthareja/flavoredgherkin)
6
6
 
7
7
 
8
- Ruby gem to convert gherkin feature files into html flavour.
8
+ Ruby gem to convert gherkin feature files into html and pdf flavour.
9
9
 
10
- **[View Sample](http://flavoredgherkin.rajatthareja.com/sample/Flavored_Gherkin_Sample.html)**
10
+ **[Html Flavour Sample](http://flavoredgherkin.rajatthareja.com/sample/Flavored_Gherkin_Sample.html)**
11
11
 
12
- More flavours coming soon!
12
+ **[Pdf Flavour Sample](http://flavoredgherkin.rajatthareja.com/sample/Flavored_Gherkin_Sample.pdf)**
13
+
14
+ **More flavours coming soon!**
13
15
 
14
16
  ## Installation
15
17
 
@@ -33,12 +35,13 @@ gem install flavored_gherkin
33
35
  | title | [String] | 'Flavored Gherkin' | Flavored Gherkin Title |
34
36
  | feature_path / input_path | [String] | Present Working Directory | Feature Files Path |
35
37
  | output_path | [String] | Present Working Directory | Flavored Gherkin Output Path |
38
+ | flavour | [String] | 'Html' | 'Html' or 'Pdf' |
36
39
 
37
40
  ### Code Examples:
38
41
 
39
42
  ```ruby
40
43
 
41
- require 'report_builder'
44
+ require 'flavored_gherkin'
42
45
 
43
46
  # Example 1:
44
47
 
@@ -73,6 +76,7 @@ gem install flavored_gherkin
73
76
  FlavoredGherkin.title = 'My Features'
74
77
  FlavoredGherkin.feature_path = 'myFolder/features'
75
78
  FlavoredGherkin.output_path = 'myFolder/my_features'
79
+ FlavoredGherkin.flavour = 'pdf'
76
80
 
77
81
  FlavoredGherkin.build
78
82
 
@@ -85,6 +89,7 @@ gem install flavored_gherkin
85
89
  | -t, --source | TITLE | Flavored Gherkin Title |
86
90
  | -f, --features / -i, --in | FEATURE_PATH | Feature Files Path |
87
91
  | -o, --out | OUTPUT_PATH | Flavored Gherkin Output Path |
92
+ | -F, --flavour | FLAVOUR | 'Html' or 'Pdf' |
88
93
 
89
94
  ### CLI Example:
90
95
 
@@ -10,7 +10,7 @@ opt_parser = OptionParser.new do |opts|
10
10
  opts.separator 'Flavored Gherkin options:'
11
11
 
12
12
  opts.on('-F', '--flavour FLAVOUR', String, 'Flavored Gherkin Flavour') do |flavour|
13
- options[:flavour] = flavour
13
+ options[:flavour] = flavour.capitalize
14
14
  end
15
15
 
16
16
  opts.on('-f', '--features FEATURE_PATH', String, 'Feature Files Path') do |feature_path|
@@ -1,20 +1,22 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'flavored_gherkin'
3
- s.version = '0.1'
3
+ s.version = '0.3'
4
4
  s.bindir = 'bin'
5
- s.summary = 'Ruby gem to convert gherkin feature files into html flavour.'
6
- s.description = ''
5
+ s.summary = 'FlavoredGherkin'
6
+ s.description = 'Ruby gem to convert gherkin feature files into html and pdf flavour.'
7
+ s.post_install_message = 'More flavours coming soon!'
7
8
  s.authors = ['Rajat Thareja']
8
9
  s.email = 'rajat.thareja.1990@gmail.com'
9
10
  s.homepage = 'http://flavoredgherkin.rajatthareja.com'
10
11
  s.license = 'MIT'
11
- s.required_ruby_version = '>= 1.9.1'
12
+ s.required_ruby_version = '>= 2.1'
12
13
 
13
14
  s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(sample/|css/|js/|pkg/|testing/|coverage/|CNAME|.gitignore|appveyor.yml|.travis.yml|_config.yml|Gemfile|Rakefile|fg.ico)}) }
14
15
  s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
15
16
  s.test_files = s.files.grep(%r{^(testing)/})
16
17
 
17
- s.add_runtime_dependency 'gherkin', '>= 4.0.0'
18
+ s.add_runtime_dependency 'gherkin', '>= 3.2.0'
19
+ s.add_runtime_dependency 'prawn', '>= 2.2.0'
18
20
 
19
21
  s.add_development_dependency 'rake', '< 13.0'
20
22
  s.add_development_dependency 'rspec', '< 4.0'
@@ -1,5 +1,6 @@
1
1
  require 'pathname'
2
2
  require_relative 'flavored_gherkin/html_flavour'
3
+ require_relative 'flavored_gherkin/pdf_flavour'
3
4
 
4
5
  ##
5
6
  # Flavored Gherkin
@@ -49,7 +50,7 @@ module FlavoredGherkin
49
50
  #
50
51
  def self.flavour=(flavour)
51
52
  @options ||= {}
52
- @options[:flavour] = flavour
53
+ @options[:flavour] = flavour.capitalize
53
54
  end
54
55
 
55
56
  ##
@@ -126,7 +127,7 @@ module FlavoredGherkin
126
127
  elsif options.is_a? Hash
127
128
  @options.merge! options
128
129
  end
129
- const_get(flavour).new.build title, feature_files, output_path
130
+ const_get(flavour + 'Flavour').new.build title, feature_files, output_path
130
131
  end
131
132
 
132
133
  ##
@@ -136,7 +137,7 @@ module FlavoredGherkin
136
137
  #
137
138
  def self.flavour
138
139
  @options ||= {}
139
- ['HtmlFlavour'].include?(@options[:flavour]) ? @options[:flavour] : 'HtmlFlavour'
140
+ %w[Html Pdf].include?(@options[:flavour]) ? @options[:flavour] : 'Html'
140
141
  end
141
142
 
142
143
  ##
@@ -146,7 +147,7 @@ module FlavoredGherkin
146
147
  #
147
148
  def self.title
148
149
  @options ||= {}
149
- @options[:title] || (@options[:feature_path] || @options[:input_path] || 'Gherkin/Flavored').split('/').reverse[0..5].join(' ').gsub('.', '')
150
+ @options[:title] || (@options[:feature_path] || @options[:input_path] || 'Gherkin/Flavored').split('/').reverse[0..5].join(' ').delete('.')
150
151
  end
151
152
 
152
153
  ##
@@ -5,6 +5,13 @@ module FlavoredGherkin
5
5
  # Base for Flavored Gherkin Flavours
6
6
  #
7
7
  class Flavour
8
+ ##
9
+ # Parser Feature Files and Returns List of Gherkin Documents
10
+ #
11
+ # @param [Array] feature_files List of feature files
12
+ #
13
+ # @return [Array] List of Gherkin Documents
14
+ #
8
15
  def get_gherkins(feature_files)
9
16
  parser = Gherkin::Parser.new
10
17
  feature_files.map do |file|
@@ -0,0 +1,127 @@
1
+ require 'prawn'
2
+ require_relative 'flavour'
3
+
4
+ module FlavoredGherkin
5
+ ##
6
+ # PDF Flavored Gherkin
7
+ #
8
+ class PdfFlavour < Flavour
9
+ ##
10
+ # Build PDF Flavored Gherkin
11
+ #
12
+ def build(title, feature_files, output_path)
13
+ info = {
14
+ Title: title,
15
+ Author: 'FlavoredGherkin',
16
+ CreationDate: Time.now
17
+ }
18
+
19
+ gherkins = Flavour.new.get_gherkins(feature_files)
20
+
21
+ tags = {}
22
+
23
+ Prawn::Document.generate("#{output_path}.pdf", info: info) do |pdf|
24
+ pdf.font_size 30
25
+ pdf.text title, align: :center, color: '3a5b93', stylr: :bold
26
+ pdf.move_down 30
27
+
28
+ pdf.font_size 20
29
+ pdf.text 'Index', color: '3a5b93', stylr: :bold
30
+ pdf.move_down 10
31
+
32
+ pdf.font_size 12
33
+ pdf.bounding_box([10, pdf.cursor], width: pdf.bounds.right) do
34
+ gherkins.each_with_index do |g, fid|
35
+ pdf.move_down 10
36
+
37
+ pdf.text "<color rgb='3a5b93'>O</color> <link anchor='Feature #{fid}'>#{g[:feature][:name]}</link>", inline_format: true
38
+
39
+ pdf.bounding_box([10, pdf.cursor], width: pdf.bounds.right) do
40
+ g[:feature][:children].each_with_index do |scenario, sid|
41
+ next if scenario[:type] == :Background
42
+ pdf.text "<color rgb='3a5b93'>o</color> <link anchor='Scenario #{fid} #{sid}'>#{scenario[:name]}</link>", inline_format: true
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ gherkins.each_with_index do |g, fid|
49
+ pdf.start_new_page
50
+
51
+ pdf.add_dest "Feature #{fid}", pdf.dest_xyz(pdf.bounds.absolute_left, pdf.y)
52
+
53
+ feature_tags = g[:feature][:tags].map { |t| t[:name] }
54
+ pdf.text(feature_tags.join(' '), color: '00695c')
55
+ feature_tags.each do |tag|
56
+ count = 0
57
+ g[:feature][:children].each do |scenario|
58
+ next if scenario[:type] == :Background
59
+ count += scenario[:examples] ? scenario[:examples].map { |e| e[:tableBody] }.flatten.size : 1
60
+ end
61
+ tags[tag] ? tags[tag] += count : tags[tag] = count
62
+ end
63
+
64
+ pdf.font_size 14
65
+ pdf.text "<b><color rgb='3a5b93'>" + g[:feature][:keyword] + '</color></b> ' + g[:feature][:name], inline_format: true, style: :bold
66
+ pdf.font_size 12
67
+
68
+ pdf.bounding_box([10, pdf.cursor], width: pdf.bounds.right) do
69
+ pdf.text g[:feature][:description]
70
+
71
+ g[:feature][:children].each_with_index do |scenario, sid|
72
+ pdf.move_down 10
73
+
74
+ pdf.add_dest "Scenario #{fid} #{sid}", pdf.dest_xyz(pdf.bounds.absolute_left, pdf.y)
75
+
76
+ if scenario[:tags]
77
+ scenario_tags = scenario[:tags].map { |tag| tag[:name] }
78
+ pdf.text(scenario_tags.join(' '), color: '00695c')
79
+ scenario_tags.each do |tag|
80
+ count = scenario[:examples] ? scenario[:examples].map { |e| e[:tableBody] }.flatten.size : 1
81
+ tags[tag] ? tags[tag] += count : tags[tag] = count
82
+ end
83
+ end
84
+
85
+ pdf.text "<b><color rgb='3a5b93'>" + scenario[:keyword] + '</color></b> ' + scenario[:name], inline_format: true
86
+
87
+ scenario[:steps].each do |step|
88
+ pdf.bounding_box([10, pdf.cursor], width: pdf.bounds.right) do
89
+ pdf.text "<b><color rgb='3a5b93'>" + step[:keyword] + '</color></b> ' + step[:text].gsub('<', "<color rgb='558b2f'>").gsub('>', '</color>'), inline_format: true
90
+
91
+ if step[:argument]
92
+ pdf.bounding_box([10, pdf.cursor], width: pdf.bounds.right) do
93
+ step[:argument][:rows].each do |row|
94
+ pdf.text('| ' + row[:cells].map { |cell| cell[:value] }.join(' | ') + ' |')
95
+ end
96
+ end
97
+ end
98
+ end
99
+ end
100
+ next unless scenario[:examples]
101
+ scenario[:examples].each do |example|
102
+ pdf.text example[:keyword], color: '3a5b93', style: :bold
103
+
104
+ pdf.bounding_box([10, pdf.cursor], width: pdf.bounds.right) do
105
+ pdf.text('| ' + example[:tableHeader][:cells].map { |cell| cell[:value] }.join(' | ') + ' |', style: :bold, color: '558b2f')
106
+ example[:tableBody].each do |row|
107
+ pdf.text('| ' + row[:cells].map { |cell| cell[:value] }.join(' | ') + ' |')
108
+ end
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end
114
+ pdf.start_new_page
115
+
116
+ pdf.font_size 20
117
+ pdf.text 'Tags', color: '3a5b93', stylr: :bold
118
+ pdf.move_down 10
119
+
120
+ pdf.font_size 12
121
+ tags.each do |tag, count|
122
+ pdf.text "<b>#{tag} : </b>#{count}", inline_format: true
123
+ end
124
+ end
125
+ end
126
+ end
127
+ end
@@ -34,4 +34,4 @@
34
34
  });
35
35
  </script>
36
36
 
37
- <script type="text/javascript" src="https://cdn.rawgit.com/rajatthareja/FlavoredGherkin/4e2eb7d0c725b45eac6647de07d01403287771f7/js/flavored.gherkin.min.js"></script>
37
+ <script type="text/javascript" src="https://cdn.rawgit.com/rajatthareja/FlavoredGherkin/v0.1/js/flavored.gherkin.min.js"></script>
@@ -8,5 +8,5 @@
8
8
  <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
9
9
  <link href="https://cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css" rel="stylesheet">
10
10
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/css/materialize.min.css" media="screen,projection"/>
11
- <link href="https://cdn.rawgit.com/rajatthareja/FlavoredGherkin/4e2eb7d0c725b45eac6647de07d01403287771f7/css/flavored.gherkin.min.css" rel="stylesheet">
11
+ <link href="https://cdn.rawgit.com/rajatthareja/FlavoredGherkin/v0.1/css/flavored.gherkin.min.css" rel="stylesheet">
12
12
  </head>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flavored_gherkin
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: '0.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rajat Thareja
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-06 00:00:00.000000000 Z
11
+ date: 2018-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gherkin
@@ -16,14 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 4.0.0
19
+ version: 3.2.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 4.0.0
26
+ version: 3.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: prawn
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.2.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 2.2.0
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rake
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -52,7 +66,7 @@ dependencies:
52
66
  - - "<"
53
67
  - !ruby/object:Gem::Version
54
68
  version: '4.0'
55
- description: ''
69
+ description: Ruby gem to convert gherkin feature files into html and pdf flavour.
56
70
  email: rajat.thareja.1990@gmail.com
57
71
  executables:
58
72
  - flavored_gherkin
@@ -66,6 +80,7 @@ files:
66
80
  - lib/flavored_gherkin.rb
67
81
  - lib/flavored_gherkin/flavour.rb
68
82
  - lib/flavored_gherkin/html_flavour.rb
83
+ - lib/flavored_gherkin/pdf_flavour.rb
69
84
  - template/background.erb
70
85
  - template/feature.erb
71
86
  - template/footer.erb
@@ -80,7 +95,7 @@ homepage: http://flavoredgherkin.rajatthareja.com
80
95
  licenses:
81
96
  - MIT
82
97
  metadata: {}
83
- post_install_message:
98
+ post_install_message: More flavours coming soon!
84
99
  rdoc_options: []
85
100
  require_paths:
86
101
  - lib
@@ -88,7 +103,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
88
103
  requirements:
89
104
  - - ">="
90
105
  - !ruby/object:Gem::Version
91
- version: 1.9.1
106
+ version: '2.1'
92
107
  required_rubygems_version: !ruby/object:Gem::Requirement
93
108
  requirements:
94
109
  - - ">="
@@ -99,5 +114,5 @@ rubyforge_project:
99
114
  rubygems_version: 2.6.14
100
115
  signing_key:
101
116
  specification_version: 4
102
- summary: Ruby gem to convert gherkin feature files into html flavour.
117
+ summary: FlavoredGherkin
103
118
  test_files: []