From eaf6b76d0376ff7e86dde6dd5a2d9a145e0d85ca Mon Sep 17 00:00:00 2001 From: jeremylightsmith Date: Sun, 29 Mar 2009 21:11:52 -0700 Subject: [PATCH] making cards play nice w/ activesupport --- Manifest.txt | 13 ++---- lib/cards.rb | 18 +++++--- lib/cards/builder.rb | 9 ---- lib/cards/card.rb | 2 +- lib/cards/card_wall.rb | 10 ++-- lib/cards/{writers => }/dot_writer.rb | 0 lib/cards/extensions.rb | 14 ------ lib/cards/{writers => }/graffle_writer.rb | 4 ++ lib/cards/layouts/column_layout.rb | 48 ++++++++++---------- lib/cards/layouts/nil_layout.rb | 18 ++++---- lib/cards/layouts/row_layout.rb | 32 +++++++------ lib/cards/numbers_parser.rb | 3 ++ lib/cards/{writers => }/text_writer.rb | 0 spec/cards/card_spec.rb | 13 ++---- spec/cards/card_wall_spec.rb | 1 - spec/cards/{writers => }/dot_writer_spec.rb | 4 +- spec/cards/numbers_parser_spec.rb | 2 +- spec/cards/{writers => }/text_writer_spec.rb | 2 +- spec/spec_helper.rb | 7 +-- 19 files changed, 91 insertions(+), 109 deletions(-) delete mode 100644 lib/cards/builder.rb rename lib/cards/{writers => }/dot_writer.rb (100%) rename lib/cards/{writers => }/graffle_writer.rb (94%) rename lib/cards/{writers => }/text_writer.rb (100%) rename spec/cards/{writers => }/dot_writer_spec.rb (96%) rename spec/cards/{writers => }/text_writer_spec.rb (90%) diff --git a/Manifest.txt b/Manifest.txt index a093465..3152074 100644 --- a/Manifest.txt +++ b/Manifest.txt @@ -20,12 +20,13 @@ examples/numbers to omnigraffle examples/numbers to omnigraffle/generate_card_walls examples/numbers to omnigraffle/Voting Example.numbers lib/cards -lib/cards/builder.rb lib/cards/card.rb lib/cards/card_wall.rb lib/cards/csv_builder.rb lib/cards/csv_parser.rb +lib/cards/dot_writer.rb lib/cards/extensions.rb +lib/cards/graffle_writer.rb lib/cards/layouts lib/cards/layouts/column_layout.rb lib/cards/layouts/nil_layout.rb @@ -35,22 +36,18 @@ lib/cards/numbers_parser.rb lib/cards/swim_lanes.rb lib/cards/tabular_parser.rb lib/cards/text.rb +lib/cards/text_writer.rb lib/cards/tracker_csv.rb -lib/cards/writers -lib/cards/writers/dot_writer.rb -lib/cards/writers/graffle_writer.rb -lib/cards/writers/text_writer.rb lib/cards.rb spec/cards spec/cards/card_spec.rb spec/cards/card_wall_spec.rb spec/cards/csv_parser_spec.rb +spec/cards/dot_writer_spec.rb spec/cards/extensions_spec.rb spec/cards/numbers_parser_spec.rb spec/cards/swim_lanes_spec.rb -spec/cards/writers -spec/cards/writers/dot_writer_spec.rb -spec/cards/writers/text_writer_spec.rb +spec/cards/text_writer_spec.rb spec/fixtures spec/fixtures/Voting Example.numbers spec/spec_helper.rb \ No newline at end of file diff --git a/lib/cards.rb b/lib/cards.rb index 96ce089..523f9d5 100644 --- a/lib/cards.rb +++ b/lib/cards.rb @@ -1,25 +1,29 @@ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__)) -# this is making this a mac only distro, I'm afraid require 'rubygems' -gem 'rb-appscript' -require 'appscript' +gem 'activesupport' +require 'activesupport' require 'cards/extensions' -require 'cards/builder' require 'cards/csv_parser' -require 'cards/numbers_parser' +require 'cards/layouts/column_layout' +require 'cards/layouts/row_layout' +require 'cards/layouts/nil_layout' + +require 'cards/card' require 'cards/card_wall' -# writers require 'cards/writers/dot_writer' -require 'cards/writers/graffle_writer' # csv builders require 'cards/csv_builder' require 'cards/master_story_list' require 'cards/tracker_csv' +# osx specific - require them explicitly +#require 'cards/numbers_parser' +#require 'cards/writers/graffle_writer' + module Cards VERSION = "0.9.1" end \ No newline at end of file diff --git a/lib/cards/builder.rb b/lib/cards/builder.rb deleted file mode 100644 index 4a98d8f..0000000 --- a/lib/cards/builder.rb +++ /dev/null @@ -1,9 +0,0 @@ -require 'cards/card' -require 'cards/layouts/row_layout' -require 'cards/layouts/column_layout' -require 'cards/layouts/nil_layout' - -module Cards - class Builder - end -end diff --git a/lib/cards/card.rb b/lib/cards/card.rb index 3d86be2..a1a94a0 100644 --- a/lib/cards/card.rb +++ b/lib/cards/card.rb @@ -38,7 +38,7 @@ def cell=(cells) self.x, self.y = *cells; end private def my_layout - @layout || NilLayout.new + @layout || Layouts::NilLayout.new end end end \ No newline at end of file diff --git a/lib/cards/card_wall.rb b/lib/cards/card_wall.rb index c5e21f0..3918582 100644 --- a/lib/cards/card_wall.rb +++ b/lib/cards/card_wall.rb @@ -1,7 +1,5 @@ -require 'cards/builder' - module Cards - class CardWall < Builder + class CardWall def define(&block) DefinitionContext.new(self).instance_eval(&block) self @@ -34,7 +32,7 @@ def initialize @handlers = [] @layouts = [] @root = Card.new("root") - @root.layout = RowLayout.new + @root.layout = Layouts::RowLayout.new @root.y = -1 @last_cards = [@root] end @@ -76,13 +74,13 @@ def initialize(wraps) end def row(name, *options) - @this.add_handler(name, RowLayout.new(*options)) do |name, row| + @this.add_handler(name, Layouts::RowLayout.new(*options)) do |name, row| Card.new(name) end end def column(name, *options) - @this.add_handler(name, ColumnLayout.new(*options)) do |name, row| + @this.add_handler(name, Layouts::ColumnLayout.new(*options)) do |name, row| c = Card.new(name) yield c, row if block_given? c diff --git a/lib/cards/writers/dot_writer.rb b/lib/cards/dot_writer.rb similarity index 100% rename from lib/cards/writers/dot_writer.rb rename to lib/cards/dot_writer.rb diff --git a/lib/cards/extensions.rb b/lib/cards/extensions.rb index 7a23edf..46484db 100644 --- a/lib/cards/extensions.rb +++ b/lib/cards/extensions.rb @@ -1,8 +1,4 @@ class String - def blank? - self.size == 0 || self.strip.size == 0 - end - def no_spaces self.gsub(' ', '\\ ') end @@ -26,12 +22,6 @@ def run end class Array - def sum - s = 0 - each {|i| s += i} - s - end - def widths map {|c| c.width} end @@ -48,10 +38,6 @@ def inches # as points end class Object - def blank? - nil? - end - def dump_methods(ignore = Object) ignore = ignore.instance_methods if ignore.is_a? Class p (methods - ignore).sort diff --git a/lib/cards/writers/graffle_writer.rb b/lib/cards/graffle_writer.rb similarity index 94% rename from lib/cards/writers/graffle_writer.rb rename to lib/cards/graffle_writer.rb index e1f1114..1bdd2a3 100644 --- a/lib/cards/writers/graffle_writer.rb +++ b/lib/cards/graffle_writer.rb @@ -1,3 +1,7 @@ +# this is making this a mac only distro, I'm afraid +gem 'rb-appscript' +require 'appscript' + module Cards class GraffleWriter CARD_WALL_STENCIL = File.expand_path(File.dirname(__FILE__) + "/CardWall.gstencil") diff --git a/lib/cards/layouts/column_layout.rb b/lib/cards/layouts/column_layout.rb index f9f6c8f..b31e8b1 100644 --- a/lib/cards/layouts/column_layout.rb +++ b/lib/cards/layouts/column_layout.rb @@ -1,34 +1,36 @@ require 'enumerator' module Cards - class ColumnLayout - def initialize(options = {}) - @wrap_at = options.delete(:wrap_at) || 10 - end + module Layouts + class ColumnLayout + def initialize(options = {}) + @wrap_at = options.delete(:wrap_at) || 10 + end - def layout(card) - x = card.x - card.children.each_slice(@wrap_at) do |slice| - y = card.y + 1 - slice.each do |child| - child.x, child.y = x, y - child.layout - y += child.height + def layout(card) + x = card.x + card.children.each_slice(@wrap_at) do |slice| + y = card.y + 1 + slice.each do |child| + child.x, child.y = x, y + child.layout + y += child.height + end + x += slice.widths.max end - x += slice.widths.max end - end - def width(card) - width = 0 - card.children.each_slice(@wrap_at) do |slice| - width += slice.widths.max + def width(card) + width = 0 + card.children.each_slice(@wrap_at) do |slice| + width += slice.widths.max + end + width end - width - end - def height(card) - card.children.heights.sum + def height(card) + card.children.heights.sum + end end end -end +end \ No newline at end of file diff --git a/lib/cards/layouts/nil_layout.rb b/lib/cards/layouts/nil_layout.rb index 8c57617..4c7c170 100644 --- a/lib/cards/layouts/nil_layout.rb +++ b/lib/cards/layouts/nil_layout.rb @@ -1,14 +1,16 @@ module Cards - class NilLayout - def layout(card) - end + module Layouts + class NilLayout + def layout(card) + end - def width(card) - 1 - end + def width(card) + 1 + end - def height(card) - 1 + def height(card) + 1 + end end end end \ No newline at end of file diff --git a/lib/cards/layouts/row_layout.rb b/lib/cards/layouts/row_layout.rb index e91689e..1db11c2 100644 --- a/lib/cards/layouts/row_layout.rb +++ b/lib/cards/layouts/row_layout.rb @@ -1,21 +1,23 @@ module Cards - class RowLayout - def layout(card) - x = card.x - card.children.each_with_index do |child, i| - child.x = x - child.y = card.y + 1 - child.layout - x += child.width + module Layouts + class RowLayout + def layout(card) + x = card.x + card.children.each_with_index do |child, i| + child.x = x + child.y = card.y + 1 + child.layout + x += child.width + end end - end - def width(card) - card.children.map {|c| c.width}.sum - end + def width(card) + card.children.map {|c| c.width}.sum + end - def height(card) - card.children.map {|c| c.height}.max + def height(card) + card.children.map {|c| c.height}.max + end end end -end +end \ No newline at end of file diff --git a/lib/cards/numbers_parser.rb b/lib/cards/numbers_parser.rb index 82a75ce..b801e98 100644 --- a/lib/cards/numbers_parser.rb +++ b/lib/cards/numbers_parser.rb @@ -1,3 +1,6 @@ +# this is making this a mac only distro, I'm afraid +gem 'rb-appscript' +require 'appscript' require 'cards/tabular_parser' module Cards diff --git a/lib/cards/writers/text_writer.rb b/lib/cards/text_writer.rb similarity index 100% rename from lib/cards/writers/text_writer.rb rename to lib/cards/text_writer.rb diff --git a/spec/cards/card_spec.rb b/spec/cards/card_spec.rb index 487361b..81349aa 100644 --- a/spec/cards/card_spec.rb +++ b/spec/cards/card_spec.rb @@ -1,8 +1,5 @@ require File.dirname(__FILE__) + '/../spec_helper' -require 'cards/card' -require 'cards/layouts/row_layout' -require 'cards/layouts/column_layout' include Cards module Cards @@ -68,7 +65,7 @@ def cards_to_s(card) def new_card(name) c = Card.new(name) - c.layout = RowLayout.new + c.layout = Layouts::RowLayout.new c end end @@ -77,8 +74,8 @@ def new_card(name) include Cards before do - a.layout = RowLayout.new - @layout = ColumnLayout.new + a.layout = Layouts::RowLayout.new + @layout = Layouts::ColumnLayout.new end it "should have 1 column" do @@ -96,7 +93,7 @@ def new_card(name) it "should show with 2 rows and then columns" do a.add(b, c, d) - a.children.each {|child| child.layout = RowLayout.new} + a.children.each {|child| child.layout = Layouts::RowLayout.new} b.add(e, f, g) d.add(h) h.add(i, j) @@ -112,7 +109,7 @@ def new_card(name) end it "should wrap" do - @layout = ColumnLayout.new(:wrap_at => 3) + @layout = Layouts::ColumnLayout.new(:wrap_at => 3) a.add(b, c, d) c.add(e, f, g, h, i, j, k) d.add(l, m) diff --git a/spec/cards/card_wall_spec.rb b/spec/cards/card_wall_spec.rb index d8f4fea..3e11305 100644 --- a/spec/cards/card_wall_spec.rb +++ b/spec/cards/card_wall_spec.rb @@ -1,6 +1,5 @@ require File.dirname(__FILE__) + '/../spec_helper' -require 'cards/card_wall' include Cards describe CardWall, "row, col" do diff --git a/spec/cards/writers/dot_writer_spec.rb b/spec/cards/dot_writer_spec.rb similarity index 96% rename from spec/cards/writers/dot_writer_spec.rb rename to spec/cards/dot_writer_spec.rb index 7fef950..d3720a4 100644 --- a/spec/cards/writers/dot_writer_spec.rb +++ b/spec/cards/dot_writer_spec.rb @@ -1,5 +1,5 @@ -require File.dirname(__FILE__) + '/../../spec_helper' -require 'cards/writers/dot_writer' +require File.dirname(__FILE__) + '/../spec_helper' +require 'cards/dot_writer' require 'stringio' include Cards diff --git a/spec/cards/numbers_parser_spec.rb b/spec/cards/numbers_parser_spec.rb index 76dda7f..4fe61a6 100644 --- a/spec/cards/numbers_parser_spec.rb +++ b/spec/cards/numbers_parser_spec.rb @@ -1,5 +1,5 @@ require File.dirname(__FILE__) + '/../spec_helper' -require 'cards' +require 'cards/numbers_parser' # not the best test, but it will do describe Cards::NumbersParser do diff --git a/spec/cards/writers/text_writer_spec.rb b/spec/cards/text_writer_spec.rb similarity index 90% rename from spec/cards/writers/text_writer_spec.rb rename to spec/cards/text_writer_spec.rb index fbe0499..d981db5 100644 --- a/spec/cards/writers/text_writer_spec.rb +++ b/spec/cards/text_writer_spec.rb @@ -1,4 +1,4 @@ -require File.dirname(__FILE__) + '/../../spec_helper' +require File.dirname(__FILE__) + '/../spec_helper' include Cards describe TextWriter do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6f3ea16..09fc82f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,12 +1,9 @@ -$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + "/../lib") +require File.dirname(__FILE__) + "/../lib/cards" -require "rubygems" gem "rspec" -gem "mocha" gem "file_sandbox" -require 'cards/extensions' -require 'cards/writers/text_writer' +require 'cards/text_writer' Spec::Runner.configure do |config| #config.mock_with :mocha