brynary-features2cards 0.1.0 → 0.3.0.0
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/History.txt +8 -1
- data/README.rdoc +13 -8
- data/Rakefile +1 -33
- data/bin/features2cards +1 -1
- data/lib/features2cards.rb +15 -4
- data/lib/features2cards/card.rb +32 -6
- data/lib/features2cards/cli.rb +78 -28
- data/lib/features2cards/platform.rb +14 -0
- data/lib/features2cards/prawn.rb +10 -8
- metadata +5 -3
data/History.txt
CHANGED
@@ -1,4 +1,11 @@
|
|
1
|
-
===
|
1
|
+
=== 0.3.0.0 / 2009-05-28
|
2
|
+
|
3
|
+
* Upgraded to Cucumber > 0.3.x
|
4
|
+
* Added language option to use the different languages cucumber supports.
|
5
|
+
* Added out option to specify pdf file name.
|
6
|
+
* Can handle directories and files
|
7
|
+
|
8
|
+
=== 0.1.0 / 2008-10-26
|
2
9
|
|
3
10
|
* 1 major enhancement
|
4
11
|
|
data/README.rdoc
CHANGED
@@ -9,23 +9,28 @@ off our sprints to create index cards for our task board.
|
|
9
9
|
|
10
10
|
== Usage
|
11
11
|
|
12
|
-
features2cards
|
12
|
+
features2cards [options] [ [FILE|DIR] ]
|
13
13
|
|
14
|
-
|
14
|
+
Examples:
|
15
|
+
features2cards features2cards.feature
|
16
|
+
features2cards --out italian.pdf--language it examples/i18n/it
|
17
|
+
|
18
|
+
=== Options
|
15
19
|
|
16
|
-
|
20
|
+
-l [LANG], --language [LANG] Specify language for features (Default: en)
|
21
|
+
-o, --out [FILE] Specify pdf output file (Default: cards.pdf).
|
22
|
+
--version Show version
|
23
|
+
-h, --help Show help
|
17
24
|
|
18
|
-
|
19
|
-
|
20
|
-
Then:
|
25
|
+
== Install
|
21
26
|
|
22
|
-
sudo gem install
|
27
|
+
sudo gem install features2cards
|
23
28
|
|
24
29
|
== Authors
|
25
30
|
|
26
31
|
- Maintained by {Bryan Helmkamp}[mailto:bryan@brynary.com]
|
27
32
|
- Inspired by Luke Melia (http://www.lukemelia.com/blog/archives/2007/12/29/pdf-storycards-001-released-my-first-gem)
|
28
|
-
|
33
|
+
|
29
34
|
== License
|
30
35
|
|
31
36
|
Copyright (c) 2008 Bryan Helmkamp.
|
data/Rakefile
CHANGED
@@ -3,37 +3,5 @@ require "rake/gempackagetask"
|
|
3
3
|
require "rake/clean"
|
4
4
|
require './lib/features2cards.rb'
|
5
5
|
|
6
|
-
|
7
|
-
s.name = "features2cards"
|
8
|
-
s.version = Features2Cards::VERSION
|
9
|
-
s.author = "Bryan Helmkamp"
|
10
|
-
s.email = "bryan" + "@" + "brynary.com"
|
11
|
-
s.homepage = "http://github.com/brynary/features2cards"
|
12
|
-
s.summary = "features2cards. Generate printable PDF index cards from Cucumber feature files"
|
13
|
-
s.description = s.summary
|
14
|
-
s.executables = "features2cards"
|
15
|
-
s.files = %w[History.txt MIT-LICENSE.txt README.rdoc Rakefile] + Dir["bin/*"] + Dir["lib/**/*"] + Dir["vendor/**/*"]
|
16
|
-
|
17
|
-
s.add_dependency "prawn"
|
18
|
-
end
|
19
|
-
|
20
|
-
Rake::GemPackageTask.new(spec) do |package|
|
21
|
-
package.gem_spec = spec
|
22
|
-
end
|
23
|
-
|
24
|
-
desc 'Show information about the gem.'
|
25
|
-
task :write_gemspec do
|
26
|
-
File.open("features2cards.gemspec", 'w') do |f|
|
27
|
-
f.write spec.to_ruby
|
28
|
-
end
|
29
|
-
puts "Generated: features2cards.gemspec"
|
30
|
-
end
|
31
|
-
|
32
|
-
CLEAN.include ["pkg", "*.gem", "doc", "ri", "coverage"]
|
33
|
-
|
34
|
-
desc 'Install the package as a gem.'
|
35
|
-
task :install_gem => [:clean, :package] do
|
36
|
-
gem = Dir['pkg/*.gem'].first
|
37
|
-
sh "sudo gem install --local #{gem}"
|
38
|
-
end
|
6
|
+
Dir['rake_tasks/**/*.rake'].each { |rake| load rake }
|
39
7
|
|
data/bin/features2cards
CHANGED
data/lib/features2cards.rb
CHANGED
@@ -1,10 +1,21 @@
|
|
1
1
|
require "rubygems"
|
2
|
-
require "prawn"
|
3
2
|
|
4
|
-
|
3
|
+
unless $LOAD_PATH.include?(File.expand_path(File.dirname(__FILE__)))
|
4
|
+
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__)))
|
5
|
+
end
|
5
6
|
|
7
|
+
require "features2cards/platform"
|
6
8
|
require "features2cards/cli"
|
7
9
|
|
8
|
-
module Features2Cards
|
9
|
-
VERSION
|
10
|
+
module Features2Cards#:nodoc:
|
11
|
+
class VERSION #:nodoc:
|
12
|
+
MAJOR = 0
|
13
|
+
MINOR = 3
|
14
|
+
TINY = 0
|
15
|
+
PATCH = 0 # Set to nil for official release
|
16
|
+
|
17
|
+
STRING = [MAJOR, MINOR, TINY, PATCH].compact.join('.')
|
18
|
+
STABLE_STRING = [MAJOR, MINOR, TINY].join('.')
|
19
|
+
end
|
10
20
|
end
|
21
|
+
|
data/lib/features2cards/card.rb
CHANGED
@@ -5,12 +5,38 @@ module Features2Cards
|
|
5
5
|
attr_reader :body
|
6
6
|
attr_reader :footer
|
7
7
|
|
8
|
-
def self.for_feature(feature)
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
def self.for_feature(feature, lang)
|
9
|
+
actual_feature = feature.to_sexp()
|
10
|
+
actual_feature.shift
|
11
|
+
actual_feature.shift
|
12
|
+
title = actual_feature[0].split("\n").first
|
13
|
+
footer = title
|
14
|
+
body = actual_feature[0].gsub(/^\s*#{title}\n/, '')
|
15
|
+
card = [new(title, body, "")]
|
16
|
+
footer = title
|
17
|
+
|
18
|
+
actual_feature.shift
|
19
|
+
scenarios = actual_feature
|
20
|
+
|
21
|
+
scenarios.map do |scenario|
|
22
|
+
case(scenario[0])
|
23
|
+
when :scenario_outline
|
24
|
+
scenario.shift
|
25
|
+
when :scenario
|
26
|
+
scenario.shift
|
27
|
+
scenario.shift
|
28
|
+
end
|
29
|
+
title = scenario[0] + " " + scenario[1]
|
30
|
+
scenario.shift
|
31
|
+
scenario.shift
|
32
|
+
body = ""
|
33
|
+
scenario.map do |step|
|
34
|
+
body += step[2] + " " + step[3] + "\n" if step[0] == :step or step[0] == :step_invocation
|
35
|
+
end
|
36
|
+
card.push(new(title, body, footer))
|
37
|
+
end
|
38
|
+
|
39
|
+
return card
|
14
40
|
end
|
15
41
|
|
16
42
|
def initialize(type, body, footer = nil)
|
data/lib/features2cards/cli.rb
CHANGED
@@ -1,28 +1,29 @@
|
|
1
|
+
require "cucumber"
|
1
2
|
require "features2cards/card"
|
2
3
|
require "features2cards/prawn"
|
3
4
|
|
4
5
|
module Features2Cards
|
5
6
|
class CLI
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
attr_reader :paths
|
9
|
+
attr_reader :options
|
10
|
+
|
11
|
+
def self.execute(args)
|
12
|
+
new(args).execute!
|
10
13
|
end
|
11
|
-
|
12
|
-
def
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
Cucumber::Tree::Feature.class_eval do
|
20
|
-
attr_reader :scenarios
|
21
|
-
end
|
14
|
+
|
15
|
+
def initialize(args, out_stream = STDOUT, error_stream = STDERR)
|
16
|
+
@args = args
|
17
|
+
@out_stream = out_stream
|
18
|
+
@error_stream = error_stream
|
19
|
+
@paths = []
|
20
|
+
@options = default_options
|
22
21
|
end
|
23
22
|
|
24
|
-
def execute
|
25
|
-
|
23
|
+
def execute!
|
24
|
+
parse!(@args)
|
25
|
+
load_cucumber(@options[:lang])
|
26
|
+
if feature_files.empty?
|
26
27
|
usage
|
27
28
|
exit
|
28
29
|
end
|
@@ -30,40 +31,89 @@ module Features2Cards
|
|
30
31
|
generate_pdf(cards)
|
31
32
|
end
|
32
33
|
|
34
|
+
def parse!(args)
|
35
|
+
@args = args
|
36
|
+
@args.extend(::OptionParser::Arguable)
|
37
|
+
@args.options do |opts|
|
38
|
+
opts.banner = ["Usage: features2cards [options] [ [FILE|DIR] ]+", "",
|
39
|
+
"Examples:",
|
40
|
+
"features2cards features2cards.feature",
|
41
|
+
"features2cards --language it examples/i18n/it",
|
42
|
+
].join("\n")
|
43
|
+
opts.on("-l [LANG]", "--language [LANG]",
|
44
|
+
"Specify language for features (Default: #{@options[:lang]})") do |v|
|
45
|
+
@options[:lang] = v
|
46
|
+
end
|
47
|
+
opts.on("-o", "--out [FILE]",
|
48
|
+
"Specify pdf output file (Default: #{@options[:pdf_file]}).") do |v|
|
49
|
+
@options[:pdf_file] = v
|
50
|
+
end
|
51
|
+
opts.on_tail("--version", "Show version.") do
|
52
|
+
@out_stream.puts VERSION::STRING
|
53
|
+
Kernel.exit
|
54
|
+
end
|
55
|
+
opts.on_tail("-h", "--help", "You're looking at it.") do
|
56
|
+
@out_stream.puts opts.help
|
57
|
+
Kernel.exit
|
58
|
+
end
|
59
|
+
end.parse!
|
60
|
+
|
61
|
+
# Whatever is left after option parsing is the FILE arguments
|
62
|
+
@paths += args
|
63
|
+
end
|
64
|
+
|
65
|
+
def load_cucumber(lang)
|
66
|
+
Cucumber.load_language(lang)
|
67
|
+
|
68
|
+
Cucumber::Ast::Feature.class_eval do
|
69
|
+
attr_reader :scenarios
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
33
73
|
def cards
|
34
74
|
features_to_cards(features)
|
35
75
|
end
|
36
76
|
|
37
77
|
def features
|
38
|
-
|
39
|
-
parser.
|
78
|
+
feature_files.map do |file|
|
79
|
+
parser.parse_file(file, {})
|
40
80
|
end
|
41
81
|
end
|
42
82
|
|
43
|
-
def
|
44
|
-
|
83
|
+
def feature_files
|
84
|
+
potential_feature_files = @paths.map do |path|
|
85
|
+
path = path.gsub(/\\/, '/') # In case we're on windows. Globs don't work with backslashes.
|
86
|
+
path = path.chomp('/')
|
87
|
+
File.directory?(path) ? Dir["#{path}/**/*.feature"] : path
|
88
|
+
end.flatten.uniq
|
89
|
+
potential_feature_files
|
45
90
|
end
|
46
91
|
|
92
|
+
|
47
93
|
def parser
|
48
|
-
@parser ||= Cucumber::
|
94
|
+
@parser ||= Cucumber::Parser::FeatureParser.new
|
49
95
|
end
|
50
96
|
|
51
97
|
def features_to_cards(features)
|
52
98
|
features.map do |feature|
|
53
|
-
[Card.for_feature(feature)]
|
54
|
-
feature.scenarios.map do |scenario|
|
55
|
-
Card.for_scenario(scenario)
|
56
|
-
end
|
99
|
+
[Card.for_feature(feature, @options[:lang])]
|
57
100
|
end.flatten
|
58
101
|
end
|
59
102
|
|
60
103
|
def generate_pdf(cards)
|
61
|
-
Prawn::Document.generate_cards(cards)
|
104
|
+
Prawn::Document.generate_cards(@options[:pdf_file], cards)
|
62
105
|
end
|
63
106
|
|
64
107
|
def usage
|
65
|
-
|
66
|
-
|
108
|
+
@error_stream.puts "ERROR: No feature files given"
|
109
|
+
@error_stream.puts "Type 'features2cards --help' for usage."
|
110
|
+
end
|
111
|
+
|
112
|
+
def default_options
|
113
|
+
{
|
114
|
+
:lang => "en",
|
115
|
+
:pdf_file => "cards.pdf"
|
116
|
+
}
|
67
117
|
end
|
68
118
|
|
69
119
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# Detect the platform we're running on so we can tweak behaviour
|
2
|
+
# in various places.
|
3
|
+
require 'rbconfig'
|
4
|
+
|
5
|
+
module Features2Cards
|
6
|
+
BINARY = File.expand_path(File.dirname(__FILE__) + '/../../bin/features2cards')
|
7
|
+
JRUBY = defined?(JRUBY_VERSION)
|
8
|
+
IRONRUBY = Config::CONFIG['sitedir'] =~ /IronRuby/
|
9
|
+
WINDOWS = Config::CONFIG['host_os'] =~ /mswin|mingw/
|
10
|
+
WINDOWS_MRI = WINDOWS && !JRUBY && !IRONRUBY
|
11
|
+
RAILS = defined?(Rails)
|
12
|
+
RUBY_BINARY = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])
|
13
|
+
RUBY_1_9 = RUBY_VERSION =~ /^1\.9/
|
14
|
+
end
|
data/lib/features2cards/prawn.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
+
require "prawn"
|
2
|
+
|
1
3
|
class Prawn::Document
|
2
4
|
CARD_WIDTH = 72 * 5 # 5 inches
|
3
5
|
CARD_HEIGHT = 72 * 3 # 3 inches
|
4
6
|
|
5
|
-
def self.generate_cards(cards)
|
6
|
-
generate(
|
7
|
+
def self.generate_cards(outfile, cards)
|
8
|
+
generate(outfile, :page_layout => :landscape) do
|
7
9
|
row = 2
|
8
10
|
col = 0
|
9
11
|
|
@@ -42,16 +44,16 @@ class Prawn::Document
|
|
42
44
|
|
43
45
|
outline_box
|
44
46
|
|
45
|
-
margin_box
|
46
|
-
text card.type
|
47
|
+
margin_box 8 do
|
48
|
+
text card.type, :size => 12
|
47
49
|
|
48
|
-
margin_box
|
49
|
-
text card.body, :size =>
|
50
|
+
margin_box 16 do
|
51
|
+
text card.body, :size => 10, :align => :left
|
50
52
|
end
|
51
53
|
|
52
54
|
unless card.footer.nil?
|
53
|
-
bounding_box [bounds.left, bounds.bottom +
|
54
|
-
text card.footer, :align => :right
|
55
|
+
bounding_box [bounds.left, bounds.bottom + 10], :width => bounds.width, :height => 10 do
|
56
|
+
text card.footer, :size => 8, :align => :right
|
55
57
|
end
|
56
58
|
end
|
57
59
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: brynary-features2cards
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryan Helmkamp
|
@@ -9,11 +9,12 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2009-06-12 00:00:00 -07:00
|
13
13
|
default_executable: features2cards
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: prawn
|
17
|
+
type: :runtime
|
17
18
|
version_requirement:
|
18
19
|
version_requirements: !ruby/object:Gem::Requirement
|
19
20
|
requirements:
|
@@ -38,6 +39,7 @@ files:
|
|
38
39
|
- lib/features2cards
|
39
40
|
- lib/features2cards/card.rb
|
40
41
|
- lib/features2cards/cli.rb
|
42
|
+
- lib/features2cards/platform.rb
|
41
43
|
- lib/features2cards/prawn.rb
|
42
44
|
- lib/features2cards.rb
|
43
45
|
has_rdoc: false
|
@@ -64,7 +66,7 @@ requirements: []
|
|
64
66
|
rubyforge_project:
|
65
67
|
rubygems_version: 1.2.0
|
66
68
|
signing_key:
|
67
|
-
specification_version:
|
69
|
+
specification_version: 3
|
68
70
|
summary: features2cards. Generate printable PDF index cards from Cucumber feature files
|
69
71
|
test_files: []
|
70
72
|
|