Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merged in Ruby 1.9 fixes from clbustos

  • Loading branch information...
commit c21ac6e3304d820dbec4cbaef670812d9e948dc7 2 parents 1b23540 + 8801d64
Chris O'Sullivan authored
9 Rakefile
View
@@ -3,10 +3,11 @@ require 'rake'
begin
require 'jeweler'
Jeweler::Tasks.new do |s|
- s.name = "rtf"
+ s.rubyforge_project = "ruby-statsample"
+ s.name = "clbustos-rtf"
s.summary = 'Ruby library to create rich text format documents.'
- s.email = "paw220470@yahoo.ie"
- s.homepage = "http://github.com/thechrisoshow/ruby-rtf"
+ s.email = "clbustos@gmail.com"
+ s.homepage = "http://github.com/clbustos/rtf"
s.description = 'Ruby RTF is a library that can be used to create '\
'rich text format (RTF) documents. RTF is a text '\
'based standard for laying out document content.'
@@ -14,7 +15,7 @@ begin
s.files = FileList["[A-Z]*", "{examples,lib,test}/**/*"]
end
rescue LoadError
- puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
+ puts "Jeweler not available. Install it with: sudo gem install jeweler"
end
require 'rake/rdoctask'
5 VERSION.yml
View
@@ -1,4 +1,5 @@
---
-:minor: 2
-:patch: 0
:major: 0
+:minor: 2
+:patch: 2
+:build:
7 lib/rtf/CVS/Entries
View
@@ -1,7 +0,0 @@
-/colour.rb/1.1.1.1/Fri Nov 18 21:25:33 2005//
-/font.rb/1.1.1.1/Fri Nov 18 21:25:33 2005//
-/information.rb/1.1.1.1/Fri Nov 18 21:25:33 2005//
-/node.rb/1.2/Mon Apr 3 12:22:19 2006//
-/paper.rb/1.1.1.1/Fri Nov 18 21:25:35 2005//
-/style.rb/1.1.1.1/Fri Nov 18 21:25:36 2005//
-D
1  lib/rtf/CVS/Repository
View
@@ -1 +0,0 @@
-rtf/lib/rtf
1  lib/rtf/CVS/Root
View
@@ -1 +0,0 @@
-:pserver:anonymous@rubyforge.org:/var/cvs/ruby-rtf
5 lib/rtf/information.rb
View
@@ -1,8 +1,7 @@
#!/usr/bin/env ruby
require 'stringio'
-require 'parsedate'
-
+require 'date'
module RTF
# This class represents an information group for a RTF document.
class Information
@@ -56,7 +55,7 @@ def created=(setting)
if setting.instance_of?(Time)
@created = setting
else
- datetime = ParseDate::parsedate(setting.to_s)
+ datetime = Date._parse(setting.to_s).values_at(:year, :mon, :mday, :hour, :min, :sec, :zone, :wday)
if datetime == nil
RTFError.fire("Invalid document creation date/time information "\
"specified.")
66 lib/rtf/node.rb
View
@@ -63,11 +63,8 @@ def root
# This class represents a specialisation of the Node class to refer to a Node
# that simply contains text.
class TextNode < Node
- # Attribute accessor.
- attr_reader :text
-
- # Attribute mutator.
- attr_writer :text
+ # Actual text
+ attr_accessor :text
# This is the constructor for the TextNode class.
#
@@ -131,11 +128,8 @@ def to_rtf
class ContainerNode < Node
include Enumerable
- # Attribute accessor.
- attr_reader :children
-
- # Attribute mutator.
- attr_writer :children
+ # Children elements of the node
+ attr_accessor :children
# This is the constructor for the ContainerNode class.
#
@@ -208,11 +202,14 @@ def to_rtf
# is concrete enough to be used on its own but will also be used as the
# base class for some specific command node types.
class CommandNode < ContainerNode
- # Attribute accessor.
- attr_reader :prefix, :suffix, :split
-
- # Attribute mutator.
- attr_writer :prefix, :suffix, :split
+ # String containing the prefix text for the command
+ attr_accessor :prefix
+ # String containing the suffix text for the command
+ attr_accessor :suffix
+ # A boolean to indicate whether the prefix and suffix should
+ # be written to separate lines whether the node is converted
+ # to RTF. Defaults to true
+ attr_accessor :split
# This is the constructor for the CommandNode class.
#
@@ -522,12 +519,9 @@ def table(rows, columns, *widths)
# specialised container nodes that contain only TableRowNodes and have their
# size specified when they are created an cannot be resized after that.
class TableNode < ContainerNode
- # Attribute accessor.
- attr_reader :cell_margin
-
- # Attribute mutator.
- attr_writer :cell_margin
-
+ # Cell margin. Default to 100
+ attr_accessor :cell_margin
+
# This is a constructor for the TableNode class.
#
# ==== Parameters
@@ -536,12 +530,22 @@ class TableNode < ContainerNode
# columns:: The number of columns in the table.
# *widths:: One or more integers specifying the widths of the table
# columns.
- def initialize(parent, rows, columns, *widths)
+ def initialize(parent, *args, &block)
+ if args.size>=2
+ rows=args.shift
+ columns=args.shift
+ widths=args
super(parent) do
entries = []
rows.times {entries.push(TableRowNode.new(self, columns, *widths))}
entries
end
+
+ elsif block
+ block.arity<1 ? self.instance_eval(&block) : block.call(self)
+ else
+ raise "You should use 0 or >2 args"
+ end
@cell_margin = 100
end
@@ -669,7 +673,7 @@ def initialize(table, cells, *widths)
end
end
- # Attrobute accessors
+ # Attribute accessors
def length
entries.size
end
@@ -745,13 +749,11 @@ def to_rtf
class TableCellNode < CommandNode
# A definition for the default width for the cell.
DEFAULT_WIDTH = 300
-
+ # Width of cell
+ attr_accessor :width
# Attribute accessor.
- attr_reader :width, :shading_colour, :style
-
- # Attribute mutator.
- attr_writer :width, :style
-
+ attr_reader :shading_colour, :style
+
# This is the constructor for the TableCellNode class.
#
# ==== Parameters
@@ -1158,6 +1160,7 @@ def get_file_type(file)
# Check if the file is a JPEG.
read_source(2)
+
if @read[0,2] == [255, 216]
type = JPEG
else
@@ -1251,7 +1254,7 @@ def read_source(size=nil)
done = false
while done == false && @source.eof? == false
- @read << @source.getc
+ @read << @source.getbyte
done = yield @read[-1]
end
else
@@ -1259,7 +1262,8 @@ def read_source(size=nil)
if size > 0
total = 0
while @source.eof? == false && total < size
- @read << @source.getc
+
+ @read << @source.getbyte
total += 1
end
end
5 test/image_node_test.rb
View
@@ -1,3 +1,5 @@
+$:.unshift(File.dirname(__FILE__)+"/../lib")
+
require 'test_helper'
# Colour class unit test class.
@@ -5,7 +7,6 @@ class ImageNodeTest < Test::Unit::TestCase
def setup
@document = Document.new(Font.new(Font::ROMAN, 'Arial'))
end
-
def test_basics
image = ImageNode.new(@document, fixture_file_path("bitmap1.bmp"), 1)
@@ -121,4 +122,4 @@ def test_exceptions
rescue
end
end
-end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.