brynary-features2cards 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,6 @@
1
+ === 1.0.0 / 2008-10-26
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday!
6
+
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Bryan Helmkamp
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ 'Software'), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,32 @@
1
+ = features2cards
2
+
3
+ * http://github.com/brynary/features2cards
4
+
5
+ == Description
6
+
7
+ Create PDF cards from Cucumber features and scenarios for printing. We use it as we kick
8
+ off our sprints to create index cards for our task board.
9
+
10
+ == Usage
11
+
12
+ features2cards features/scale.feature
13
+
14
+ == Install
15
+
16
+ If you haven't already added GitHub to your gem sources:
17
+
18
+ sudo gem sources -a http://gems.github.com
19
+
20
+ Then:
21
+
22
+ sudo gem install brynary-features2cards
23
+
24
+ == Authors
25
+
26
+ - Maintained by {Bryan Helmkamp}[mailto:bryan@brynary.com]
27
+ - Inspired by Luke Melia (http://www.lukemelia.com/blog/archives/2007/12/29/pdf-storycards-001-released-my-first-gem)
28
+
29
+ == License
30
+
31
+ Copyright (c) 2008 Bryan Helmkamp.
32
+ See MIT-LICENSE.txt in this directory.
@@ -0,0 +1,39 @@
1
+ require 'rubygems'
2
+ require "rake/gempackagetask"
3
+ require "rake/clean"
4
+ require './lib/features2cards.rb'
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"
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
39
+
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + "/../lib/features2cards")
4
+
5
+ Features2Cards::CLI.execute
@@ -0,0 +1,10 @@
1
+ require "rubygems"
2
+ require "prawn"
3
+
4
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__))) unless $LOAD_PATH.include?(File.expand_path(File.dirname(__FILE__)))
5
+
6
+ require "features2cards/cli"
7
+
8
+ module Features2Cards
9
+ VERSION = '0.1.0'
10
+ end
@@ -0,0 +1,23 @@
1
+ module Features2Cards
2
+ class Card
3
+
4
+ attr_reader :type
5
+ attr_reader :body
6
+ attr_reader :footer
7
+
8
+ def self.for_feature(feature)
9
+ new("Feature", feature.header.split("\n").first, "")
10
+ end
11
+
12
+ def self.for_scenario(scenario)
13
+ new("Scenario", scenario.name, scenario.feature.header.split("\n").first)
14
+ end
15
+
16
+ def initialize(type, body, footer = nil)
17
+ @type = type
18
+ @body = body
19
+ @footer = footer
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,70 @@
1
+ require "features2cards/card"
2
+ require "features2cards/prawn"
3
+
4
+ module Features2Cards
5
+ class CLI
6
+
7
+ def self.execute
8
+ load_cucumber
9
+ new.execute
10
+ 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
22
+ end
23
+
24
+ def execute
25
+ if files.empty?
26
+ usage
27
+ exit
28
+ end
29
+
30
+ generate_pdf(cards)
31
+ end
32
+
33
+ def cards
34
+ features_to_cards(features)
35
+ end
36
+
37
+ def features
38
+ files.map do |file|
39
+ parser.parse_feature(file)
40
+ end
41
+ end
42
+
43
+ def files
44
+ ARGV
45
+ end
46
+
47
+ def parser
48
+ @parser ||= Cucumber::TreetopParser::FeatureParser.new
49
+ end
50
+
51
+ def features_to_cards(features)
52
+ features.map do |feature|
53
+ [Card.for_feature(feature)] +
54
+ feature.scenarios.map do |scenario|
55
+ Card.for_scenario(scenario)
56
+ end
57
+ end.flatten
58
+ end
59
+
60
+ def generate_pdf(cards)
61
+ Prawn::Document.generate_cards(cards)
62
+ end
63
+
64
+ def usage
65
+ $stderr.puts "ERROR: No feature files given"
66
+ $stderr.puts "usage: features2cards <feature files>"
67
+ end
68
+
69
+ end
70
+ end
@@ -0,0 +1,61 @@
1
+ class Prawn::Document
2
+ CARD_WIDTH = 72 * 5 # 5 inches
3
+ CARD_HEIGHT = 72 * 3 # 3 inches
4
+
5
+ def self.generate_cards(cards)
6
+ generate("cards.pdf", :page_layout => :landscape) do
7
+ row = 2
8
+ col = 0
9
+
10
+ cards.each do |card|
11
+ if row == 0
12
+ start_new_page
13
+ row = 2
14
+ col = 0
15
+ end
16
+
17
+ draw_card(card, row, col)
18
+
19
+ col += 1
20
+
21
+ if col > 1
22
+ col = 0
23
+ row -= 1
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ def margin_box(margin, &block)
30
+ bounding_box [bounds.left + margin, bounds.top - margin],
31
+ :width => bounds.width - (margin * 2), :height => bounds.height - (margin * 2),
32
+ &block
33
+ end
34
+
35
+ def outline_box
36
+ stroke_rectangle bounds.top_left, bounds.width, bounds.height
37
+ end
38
+
39
+ def draw_card(card, row, col)
40
+ bounding_box [CARD_WIDTH * col, CARD_HEIGHT * row + ((bounds.height - (2*CARD_HEIGHT))/2)],
41
+ :width => CARD_WIDTH, :height => CARD_HEIGHT do
42
+
43
+ outline_box
44
+
45
+ margin_box 18 do
46
+ text card.type + ": ", :size => 14
47
+
48
+ margin_box 36 do
49
+ text card.body, :size => 16, :align => :center
50
+ end
51
+
52
+ unless card.footer.nil?
53
+ bounding_box [bounds.left, bounds.bottom + 18], :width => bounds.width, :height => 18 do
54
+ text card.footer, :align => :right
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+
61
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: brynary-features2cards
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Bryan Helmkamp
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-12-08 00:00:00 -08:00
13
+ default_executable: features2cards
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: prawn
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "0"
23
+ version:
24
+ description: features2cards. Generate printable PDF index cards from Cucumber feature files
25
+ email: bryan@brynary.com
26
+ executables:
27
+ - features2cards
28
+ extensions: []
29
+
30
+ extra_rdoc_files: []
31
+
32
+ files:
33
+ - History.txt
34
+ - MIT-LICENSE.txt
35
+ - README.rdoc
36
+ - Rakefile
37
+ - bin/features2cards
38
+ - lib/features2cards
39
+ - lib/features2cards/card.rb
40
+ - lib/features2cards/cli.rb
41
+ - lib/features2cards/prawn.rb
42
+ - lib/features2cards.rb
43
+ has_rdoc: false
44
+ homepage: http://github.com/brynary/features2cards
45
+ post_install_message:
46
+ rdoc_options: []
47
+
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: "0"
55
+ version:
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: "0"
61
+ version:
62
+ requirements: []
63
+
64
+ rubyforge_project:
65
+ rubygems_version: 1.2.0
66
+ signing_key:
67
+ specification_version: 2
68
+ summary: features2cards. Generate printable PDF index cards from Cucumber feature files
69
+ test_files: []
70
+