Browse Source

More work on the conversion

dev
Andy Meneely 12 years ago
parent
commit
093b2cf15b
  1. 16
      lib/squib/api/save.rb
  2. 2
      lib/squib/api/settings.rb
  3. 15
      lib/squib/api/shapes.rb
  4. 14
      lib/squib/api/text.rb
  5. 15
      lib/squib/constants.rb
  6. 2
      lib/squib/deck.rb
  7. 2
      lib/squib/graphics/shapes.rb
  8. 9
      lib/squib/input_helpers.rb

16
lib/squib/api/save.rb

@ -7,10 +7,10 @@ module Squib
# @param dir: the directory for the output to be sent to. Will be created if it doesn't exist
# @param format: the format that this will be rendered too. Options `:pdf, :png`. Array of both is allowed: `[:pdf, :png]`
# @param prefix: the prefix of the file name to be printed
def save(range: :all, dir: "_output", format: :png, prefix: "card_")
format = [format].flatten
save_png(range: range, dir: dir, prefix: prefix) if format.include? :png
save_pdf if format.include? :pdf
def save(opts = {})
opts = needs(opts, [:range, :creatable_dir, :formats, :prefix])
save_png(opts) if opts[:format].include? :png
save_pdf(opts) if opts[:format].include? :pdf
end
# Saves the range of cards to PNG
@ -18,9 +18,11 @@ module Squib
# @param range: the range of cards over which this will be rendered. See {file:API.md#label-Specifying+Ranges Specifying Ranges}
# @param dir: the directory for the output to be sent to. Will be created if it doesn't exist
# @param prefix: the prefix of the file name to be printed
def save_png(range: :all, dir: "_output", prefix: 'card_')
range = rangeify(range); dir = dirify(dir, allow_create: true)
range.each { |i| @cards[i].save_png(i, dir, prefix) }
def save_png(opts = {})
opts = needs(opts,[:range, :creatable_dir, :prefix])
opts[:range].each do |i|
@cards[i].save_png(i, opts[:dir], opts[:prefix])
end
end
end

2
lib/squib/api/settings.rb

@ -10,7 +10,7 @@ module Squib
# @api public
def hint(text: nil)
text = nil if text == :off
@text_hint = colorify(text, nillable: true)
@text_hint = text
end
end

15
lib/squib/api/shapes.rb

@ -14,14 +14,13 @@ module Squib
# @param stroke_color: the color with which to stroke the outside of the rectangle
# @param stroke_width: the width of the outside stroke
# @api public
def rect(range: :all, x: 0, y: 0, width: 825, height: 1125, \
radius: nil, x_radius: 0, y_radius: 0, \
fill_color: '#0000', stroke_color: :black, stroke_width: 2.0)
range = rangeify(range)
color = colorify(color)
x_radius,y_radius = radiusify(radius, x_radius, y_radius)
range.each do |i|
@cards[i].draw_rectangle(x, y, width, height, x_radius, y_radius, fill_color, stroke_color, stroke_width)
def rect(opts = {})
opts = needs(opts, [:range, :x, :y, :width, :height, :radius,
:fill_color, :stroke_color, :stroke_width])
opts[:range].each do |i|
@cards[i].rect(opts[:x], opts[:y], opts[:width], opts[:height],
opts[:x_radius], opts[:y_radius],
opts[:fill_color], opts[:stroke_color], opts[:stroke_width])
end
end

14
lib/squib/api/text.rb

@ -40,14 +40,12 @@ module Squib
# @option hint: show a text hint with the given color. Overrides global hints (see {Deck#hint}).
# @return [nil] Returns nothing
# @api public
def text(range: :all, str: '', font: :use_set, x: 0, y: 0, **options)
range = rangeify(range)
str = [str] * @cards.size unless str.respond_to? :each
font = fontify(font)
color = colorify(options[:color], nillable: false)
options[:hint] = colorify(options[:hint]) unless options[:hint].nil?
range.each do |i|
cards[i].text(str[i], font, x, y, color, options)
def text(opts = {})
opts = needs(opts, [:range, :str, :font, :x, :y, :width, :height, :color, :wrap,
:fitxy, :align, :justify, :valign, :ellipsize, :hint])
str = [opts[:str]] * @cards.size unless str.respond_to? :each
opts[:range].each do |i|
@cards[i].text(str[i], opts[:font], opts[:x], opts[:y], opts[:color], opts) #TODO split this out
end
end

15
lib/squib/constants.rb

@ -4,11 +4,24 @@ module Squib
SYSTEM_DEFAULTS = {
:range => :all,
:color => :white,
:str => '',
:fill_color => '#0000',
:stroke_color => :black,
:font => 'Arial, Sans 36',
:sheet => 0,
:x => 0,
:y => 0,
:alpha => 1.0
:fitxy => false,
:align => :left,
:valign => :top,
:justify => false,
:ellipsize => :end,
:width => :native,
:height => :native,
:alpha => 1.0,
:format => :png,
:dir => "_output",
:prefix => "card_"
}
end

2
lib/squib/deck.rb

@ -3,7 +3,6 @@ require 'squib/card'
require 'squib/input_helpers'
require 'squib/constants'
# The project module
#
# @api public
@ -15,7 +14,6 @@ module Squib
class Deck
include Enumerable
include Squib::InputHelpers
include Squib::Constants
attr_reader :width, :height
attr_reader :cards
attr_reader :text_hint

2
lib/squib/graphics/shapes.rb

@ -1,7 +1,7 @@
module Squib
class Card
def draw_rectangle(x, y, width, height, x_radius, y_radius, fill_color, stroke_color, stroke_width)
def rect(x, y, width, height, x_radius, y_radius, fill_color, stroke_color, stroke_width)
cc = cairo_context
cc.rounded_rectangle(x, y, width, height, x_radius, y_radius)
cc.set_source_color(stroke_color)

9
lib/squib/input_helpers.rb

@ -15,9 +15,16 @@ module Squib
opts = fontify(opts) if params.include? :font
opts = radiusify(opts) if params.include? :radius
opts = svgidify(opts) if params.include? :svgid
opts = formatify(opts) if params.include? :formats
end
module_function :needs
def formatify(opts)
opts[:format] = [opts[:format]].flatten
opts
end
module_function :formatify
def rangeify (opts)
range = opts[:range]
raise 'Range cannot be nil' if range.nil?
@ -88,7 +95,7 @@ module Squib
end
opts
end
module_function :idify
module_function :svgidify
def xyify
#TODO: Allow negative numbers that subtract from the card width & height.

Loading…
Cancel
Save