diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..e0a7662 --- /dev/null +++ b/Gemfile @@ -0,0 +1 @@ +gemspec diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..f1d91e7 --- /dev/null +++ b/Gemfile.lock @@ -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 diff --git a/Rakefile b/Rakefile index 6d4dbec..7fffda5 100644 --- a/Rakefile +++ b/Rakefile @@ -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 @@ -20,7 +20,7 @@ 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" @@ -28,7 +28,6 @@ Rake::RDocTask.new do |rdoc| end spec = Gem::Specification.load("crawdad.gemspec") -Rake::GemPackageTask.new(spec) do |pkg| +Gem::PackageTask.new(spec) do |pkg| pkg.need_tar = true end - diff --git a/crawdad.gemspec b/crawdad.gemspec index b18892d..3aaa80b 100644 --- a/crawdad.gemspec +++ b/crawdad.gemspec @@ -1,3 +1,5 @@ +require 'rake' + Gem::Specification.new do |spec| spec.name = 'crawdad' spec.version = '0.1.0' @@ -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 diff --git a/examples/gettysburg.rb b/examples/gettysburg.rb index 8afbcf7..635cdba 100644 --- a/examples/gettysburg.rb +++ b/examples/gettysburg.rb @@ -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' @@ -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 @@ -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 diff --git a/examples/gettysburg_shaped.rb b/examples/gettysburg_shaped.rb index 6213eb4..623719a 100644 --- a/examples/gettysburg_shaped.rb +++ b/examples/gettysburg_shaped.rb @@ -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 diff --git a/lib/crawdad/prawn_tokenizer.rb b/lib/crawdad/prawn_tokenizer.rb index 32ad76c..47b6cdf 100644 --- a/lib/crawdad/prawn_tokenizer.rb +++ b/lib/crawdad/prawn_tokenizer.rb @@ -191,4 +191,3 @@ def word_segment(word, hyphenator) end end - diff --git a/spec/item_spec.rb b/spec/item_spec.rb index cd9aa6e..20dba34 100644 --- a/spec/item_spec.rb +++ b/spec/item_spec.rb @@ -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 @@ -62,4 +62,3 @@ end end - diff --git a/spec/paragraph_spec.rb b/spec/paragraph_spec.rb index 1504371..09aeada 100644 --- a/spec/paragraph_spec.rb +++ b/spec/paragraph_spec.rb @@ -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 @@ -84,4 +84,3 @@ end end - diff --git a/spec/prawn_tokenizer_spec.rb b/spec/prawn_tokenizer_spec.rb index 94d392a..3e8749e 100644 --- a/spec/prawn_tokenizer_spec.rb +++ b/spec/prawn_tokenizer_spec.rb @@ -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 @@ -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) @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2e22d7a..bfb3265 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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" @@ -30,4 +29,3 @@ def width_of(text, options={}) @width_cache[[text, options]] ||= super end end).new -