Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dependencies and improved compatibility for Ruby 2.0 #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gemspec
46 changes: 46 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
PATH
remote: .
specs:
crawdad (0.1.0)
ffi (~> 1.9.3)
prawn (~> 0.12.0)
text-hyphen (~> 1.4.1)

GEM
specs:
Ascii85 (1.0.2)
afm (0.2.0)
diff-lcs (1.1.3)
ffi (1.9.3)
hashery (2.1.1)
metaclass (0.0.1)
mocha (0.10.5)
metaclass (~> 0.0.1)
pdf-reader (1.3.3)
Ascii85 (~> 1.0.0)
afm (~> 0.2.0)
hashery (~> 2.0)
ruby-rc4
ttfunk
prawn (0.12.0)
pdf-reader (>= 0.9.0)
ttfunk (~> 1.0.2)
rspec (2.12.0)
rspec-core (~> 2.12.0)
rspec-expectations (~> 2.12.0)
rspec-mocks (~> 2.12.0)
rspec-core (2.12.2)
rspec-expectations (2.12.1)
diff-lcs (~> 1.1.3)
rspec-mocks (2.12.2)
ruby-rc4 (0.1.5)
text-hyphen (1.4.1)
ttfunk (1.0.3)

PLATFORMS
ruby

DEPENDENCIES
crawdad!
mocha
rspec
9 changes: 4 additions & 5 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require 'rubygems'
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
require 'rake/gempackagetask'
require 'rdoc/task'
require 'rubygems/package_task'

# Build must be the default task, to fake out using a Makefile to build a
# non-Ruby extension with Rubygems. There's probably an easier way, but I can't
Expand All @@ -20,15 +20,14 @@ Rake::TestTask.new do |test|
end

desc "Generate documentation"
Rake::RDocTask.new do |rdoc|
RDoc::Task.new do |rdoc|
rdoc.rdoc_files.include("README", "lib/")
rdoc.main = "README"
rdoc.rdoc_dir = "doc/html"
rdoc.title = "Crawdad Documentation"
end

spec = Gem::Specification.load("crawdad.gemspec")
Rake::GemPackageTask.new(spec) do |pkg|
Gem::PackageTask.new(spec) do |pkg|
pkg.need_tar = true
end

10 changes: 9 additions & 1 deletion crawdad.gemspec
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'rake'

Gem::Specification.new do |spec|
spec.name = 'crawdad'
spec.version = '0.1.0'
Expand All @@ -20,5 +22,11 @@ Gem::Specification.new do |spec|
Crawdad is an implementation of Knuth-Plass linebreaking (justification)
for Ruby.
END_DESC
end

spec.add_runtime_dependency "ffi", "~> 1.9.3"
spec.add_runtime_dependency "prawn", "~> 0.12.0"
spec.add_runtime_dependency "text-hyphen", "~> 1.4.1"

spec.add_development_dependency "mocha"
spec.add_development_dependency "rspec"
end
13 changes: 9 additions & 4 deletions examples/gettysburg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@
# This is free software. Please see the LICENSE and COPYING files for details.

$:.unshift 'lib'
require 'prawn'
require 'crawdad'

require 'crawdad/ffi'
require 'crawdad/ffi/tokens'
require 'crawdad/native'
require 'text/hyphen'
$:.unshift 'vendor/prawn/lib'
require 'prawn'

Expand All @@ -32,15 +37,15 @@

para.lines.each do |tokens, breakpoint|
# skip over glue and penalties at the beginning of each line
tokens.shift until Crawdad::Box === tokens.first
tokens.shift until Crawdad::Tokens::Box === tokens.first

x = 0
tokens.each do |token|
case token
when Crawdad::Box
when Crawdad::Tokens::Box
pdf.draw_text!(token.content, :at => [x, pdf.cursor])
x += token.width
when Crawdad::Glue
when Crawdad::Tokens::Glue
r = breakpoint.ratio
w = case
when r > 0
Expand All @@ -50,7 +55,7 @@
else token.width
end
x += w
when Crawdad::Penalty
when Crawdad::Tokens::Penalty
# TODO: add a hyphen when we break at a flagged penalty
end
end
Expand Down
4 changes: 4 additions & 0 deletions examples/gettysburg_shaped.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
$:.unshift 'vendor/prawn/lib'
require 'prawn'

require 'crawdad/ffi'
require 'crawdad/ffi/tokens'
require 'crawdad/native'

Prawn::Document.generate("gettysburg_shaped.pdf") do |pdf|
line_spacing = pdf.font.height

Expand Down
1 change: 0 additions & 1 deletion lib/crawdad/prawn_tokenizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,3 @@ def word_segment(word, hyphenator)
end

end

7 changes: 3 additions & 4 deletions spec/item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@
p = penalty(5, 10, true)
penalty_penalty(p).should == 5
token_width(p).should == 10
assert penalty_flagged?(p)
penalty_flagged?(p).should be
end

it "should default its width to zero and flagged to false" do
p = penalty(10)
penalty_penalty(p).should == 10
token_width(p).should.be.zero
assert !penalty_flagged?(p)
token_width(p).should be 0
(!penalty_flagged?(p)).should be
end

it "should allow infinite penalties (positive or negative)" do
Expand All @@ -62,4 +62,3 @@
end

end

3 changes: 1 addition & 2 deletions spec/paragraph_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
it "should be zero for a perfect fit (no adjustment needed)" do
@para.width = @tw
@para.optimum_breakpoints
@para.adjustment_ratio(@start, 6).should.be.zero
@para.adjustment_ratio(@start, 6).should be(0)
end

it "should be positive when stretching, proportional to available stretch" do
Expand All @@ -84,4 +84,3 @@
end

end

21 changes: 11 additions & 10 deletions spec/prawn_tokenizer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# This is free software. Please see the LICENSE and COPYING files for details.

require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
require 'crawdad/prawn_tokenizer'

describe "Prawn tokenizer" do

Expand Down Expand Up @@ -78,10 +79,10 @@
%w[cul- de- sac]

# check penalties
token_width(stream[1]).should.be.zero
assert penalty_flagged?(stream[1])
token_width(stream[3]).should.be.zero
assert penalty_flagged?(stream[3])
token_width(stream[1]).should be(0)
penalty_flagged?(stream[1]).should be
token_width(stream[3]).should be(0)
penalty_flagged?(stream[3]).should be
end

# (5)
Expand All @@ -96,13 +97,13 @@
penalty_penalty(disallowed_break).should == Infinity

token_type(finishing_glue).should == :glue
token_width(finishing_glue).should.be.zero
token_width(finishing_glue).should be(0)
glue_stretch(finishing_glue).should == Infinity

token_type(forced_break).should == :penalty
penalty_penalty(forced_break).should == -Infinity
# check this, because we will break here for sure
token_width(forced_break).should.be.zero
token_width(forced_break).should be(0)
end

it "should insert extra space after sentence-ending periods" do
Expand All @@ -114,7 +115,7 @@
sentence_glue = stream[i+1]

token_type(sentence_glue).should == :glue
token_width(sentence_glue).should.be > token_width(normal_glue)
token_width(sentence_glue).should be > token_width(normal_glue)
end

describe "with hyphenation" do
Expand All @@ -127,7 +128,7 @@

box_content(stream[0]).should == "test"
token_width(stream[1]).should == @pdf.width_of('-')
assert penalty_flagged?(stream[1])
penalty_flagged?(stream[1]).should be
box_content(stream[2]).should == "ing"
end

Expand All @@ -137,8 +138,8 @@

stream.map { |t| token_type(t) }.should == [:box, :penalty, :box]
box_content(stream[0]).should == 'play-'
token_width(stream[1]).should.be.zero
assert penalty_flagged?(stream[1])
token_width(stream[1]).should be(0)
penalty_flagged?(stream[1]).should be
box_content(stream[2]).should == "thing"
end

Expand Down
4 changes: 1 addition & 3 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
puts "Running on Ruby version: #{RUBY_VERSION}"

require "rubygems"
require "test/spec"
require "mocha"
require "mocha/api"
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
require "crawdad"

Expand All @@ -30,4 +29,3 @@ def width_of(text, options={})
@width_cache[[text, options]] ||= super
end
end).new