features2cards 0.1.1 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,15 @@
1
- === 1.0.0 / 2008-10-26
1
+ === 0.3.1 / 2009-06-12
2
+
3
+ The Kosmas Schütz Release.
4
+
5
+ * 4 major enhancements
6
+
7
+ * Upgraded to Cucumber > 0.3.x (Kosmas Schütz)
8
+ * Added language option to use the different languages cucumber supports. (Kosmas Schütz)
9
+ * Added out option to specify pdf file name. (Kosmas Schütz)
10
+ * Can handle directories and files (Kosmas Schütz)
11
+
12
+ === 0.1.0 / 2008-10-26
2
13
 
3
14
  * 1 major enhancement
4
15
 
@@ -9,11 +9,18 @@ off our sprints to create index cards for our task board.
9
9
 
10
10
  == Usage
11
11
 
12
- Example:
12
+ features2cards [options] [ [FILE|DIR] ]
13
13
 
14
- features2cards features/scale.feature
15
-
16
- This will generate a file called cards.pdf in the current directory.
14
+ Examples:
15
+ features2cards features2cards.feature
16
+ features2cards --out italian.pdf--language it examples/i18n/it
17
+
18
+ === Options
19
+
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
25
  == Install
19
26
 
@@ -23,7 +30,7 @@ This will generate a file called cards.pdf in the current directory.
23
30
 
24
31
  - Maintained by {Bryan Helmkamp}[mailto:bryan@brynary.com]
25
32
  - Inspired by Luke Melia (http://www.lukemelia.com/blog/archives/2007/12/29/pdf-storycards-001-released-my-first-gem)
26
-
33
+
27
34
  == License
28
35
 
29
36
  Copyright (c) 2008 Bryan Helmkamp.
data/Rakefile CHANGED
@@ -3,29 +3,5 @@ require "rake/gempackagetask"
3
3
  require "rake/clean"
4
4
  require './lib/features2cards.rb'
5
5
 
6
- spec = Gem::Specification.new do |s|
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", ">= 0.1.2"
18
- end
19
-
20
- Rake::GemPackageTask.new(spec) do |package|
21
- package.gem_spec = spec
22
- end
23
-
24
- CLEAN.include ["pkg", "*.gem", "doc", "ri", "coverage"]
25
-
26
- desc 'Install the package as a gem.'
27
- task :install_gem => [:clean, :package] do
28
- gem = Dir['pkg/*.gem'].first
29
- sh "sudo gem install --no-ri --no-rdoc --local #{gem}"
30
- end
6
+ Dir['rake_tasks/**/*.rake'].each { |rake| load rake }
31
7
 
@@ -2,4 +2,4 @@
2
2
 
3
3
  require File.expand_path(File.dirname(__FILE__) + "/../lib/features2cards")
4
4
 
5
- Features2Cards::CLI.execute
5
+ Features2Cards::CLI.execute(ARGV.dup)
@@ -1,9 +1,21 @@
1
1
  require "rubygems"
2
2
 
3
- $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__))) unless $LOAD_PATH.include?(File.expand_path(File.dirname(__FILE__)))
3
+ unless $LOAD_PATH.include?(File.expand_path(File.dirname(__FILE__)))
4
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__)))
5
+ end
4
6
 
7
+ require "features2cards/platform"
5
8
  require "features2cards/cli"
6
9
 
7
- module Features2Cards
8
- VERSION = '0.1.1'
10
+ module Features2Cards#:nodoc:
11
+ class VERSION #:nodoc:
12
+ MAJOR = 0
13
+ MINOR = 3
14
+ TINY = 1
15
+ PATCH = nil # Set to nil for official release
16
+
17
+ STRING = [MAJOR, MINOR, TINY, PATCH].compact.join('.')
18
+ STABLE_STRING = [MAJOR, MINOR, TINY].join('.')
19
+ end
9
20
  end
21
+
@@ -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
- new("Feature", feature.header.split("\n").first.gsub(/^\s*Feature:/, '').strip, "")
10
- end
11
-
12
- def self.for_scenario(scenario)
13
- new("Scenario", scenario.name, scenario.feature.header.split("\n").first)
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)
@@ -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
- def self.execute
8
- load_cucumber
9
- new.execute
8
+ attr_reader :paths
9
+ attr_reader :options
10
+
11
+ def self.execute(args)
12
+ new(args).execute!
10
13
  end
11
-
12
- def self.load_cucumber
13
- $LOAD_PATH.unshift(File.expand_path("./vendor/plugins/cucumber/lib"))
14
-
15
- require "cucumber"
16
- require "cucumber/treetop_parser/feature_en"
17
- Cucumber.load_language("en")
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
- if files.empty?
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
- files.map do |file|
39
- parser.parse_feature(file)
78
+ feature_files.map do |file|
79
+ parser.parse_file(file, {})
40
80
  end
41
81
  end
42
82
 
43
- def files
44
- ARGV
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::TreetopParser::FeatureParser.new
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
- $stderr.puts "ERROR: No feature files given"
66
- $stderr.puts "usage: features2cards <feature files>"
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
@@ -4,8 +4,8 @@ class Prawn::Document
4
4
  CARD_WIDTH = 72 * 5 # 5 inches
5
5
  CARD_HEIGHT = 72 * 3 # 3 inches
6
6
 
7
- def self.generate_cards(cards)
8
- generate("cards.pdf", :page_layout => :landscape) do
7
+ def self.generate_cards(outfile, cards)
8
+ generate(outfile, :page_layout => :landscape) do
9
9
  row = 2
10
10
  col = 0
11
11
 
@@ -44,16 +44,16 @@ class Prawn::Document
44
44
 
45
45
  outline_box
46
46
 
47
- margin_box 18 do
48
- text card.type + ": ", :size => 14
47
+ margin_box 8 do
48
+ text card.type, :size => 12
49
49
 
50
- margin_box 36 do
51
- text card.body, :size => 16, :align => :center
50
+ margin_box 16 do
51
+ text card.body, :size => 10, :align => :left
52
52
  end
53
53
 
54
54
  unless card.footer.nil?
55
- bounding_box [bounds.left, bounds.bottom + 18], :width => bounds.width, :height => 18 do
56
- 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
57
57
  end
58
58
  end
59
59
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: features2cards
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Helmkamp
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-20 00:00:00 -05:00
12
+ date: 2009-06-12 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -20,7 +20,7 @@ dependencies:
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 0.1.2
23
+ version: "0"
24
24
  version:
25
25
  description: features2cards. Generate printable PDF index cards from Cucumber feature files
26
26
  email: bryan@brynary.com
@@ -36,13 +36,15 @@ files:
36
36
  - README.rdoc
37
37
  - Rakefile
38
38
  - bin/features2cards
39
- - lib/features2cards
40
39
  - lib/features2cards/card.rb
41
40
  - lib/features2cards/cli.rb
41
+ - lib/features2cards/platform.rb
42
42
  - lib/features2cards/prawn.rb
43
43
  - lib/features2cards.rb
44
- has_rdoc: false
44
+ has_rdoc: true
45
45
  homepage: http://github.com/brynary/features2cards
46
+ licenses: []
47
+
46
48
  post_install_message:
47
49
  rdoc_options: []
48
50
 
@@ -63,9 +65,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
63
65
  requirements: []
64
66
 
65
67
  rubyforge_project:
66
- rubygems_version: 1.3.1
68
+ rubygems_version: 1.3.4
67
69
  signing_key:
68
- specification_version: 2
70
+ specification_version: 3
69
71
  summary: features2cards. Generate printable PDF index cards from Cucumber feature files
70
72
  test_files: []
71
73