Skip to content

Commit

Permalink
making cards play nice w/ activesupport
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremylightsmith committed Mar 30, 2009
1 parent 109e706 commit eaf6b76
Show file tree
Hide file tree
Showing 19 changed files with 91 additions and 109 deletions.
13 changes: 5 additions & 8 deletions Manifest.txt
Expand Up @@ -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
Expand All @@ -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
18 changes: 11 additions & 7 deletions 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
9 changes: 0 additions & 9 deletions lib/cards/builder.rb

This file was deleted.

2 changes: 1 addition & 1 deletion lib/cards/card.rb
Expand Up @@ -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
10 changes: 4 additions & 6 deletions 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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
File renamed without changes.
14 changes: 0 additions & 14 deletions 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
Expand All @@ -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
Expand All @@ -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
Expand Down
@@ -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")
Expand Down
48 changes: 25 additions & 23 deletions 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
18 changes: 10 additions & 8 deletions 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
32 changes: 17 additions & 15 deletions 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
3 changes: 3 additions & 0 deletions 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
Expand Down
File renamed without changes.
13 changes: 5 additions & 8 deletions 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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand Down
1 change: 0 additions & 1 deletion 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
Expand Down
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion 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
Expand Down
@@ -1,4 +1,4 @@
require File.dirname(__FILE__) + '/../../spec_helper'
require File.dirname(__FILE__) + '/../spec_helper'
include Cards

describe TextWriter do
Expand Down
7 changes: 2 additions & 5 deletions 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
Expand Down

0 comments on commit eaf6b76

Please sign in to comment.