Browse Source

Putting together a global `set` method for defaults

dev
Andy Meneely 12 years ago
parent
commit
10890be8a1
  1. 18
      lib/squib/api/settings.rb
  2. 10
      lib/squib/api/text.rb
  3. 2
      lib/squib/constants.rb
  4. 2
      lib/squib/deck.rb
  5. 2
      samples/basic.rb
  6. 37
      spec/api/api_text_spec.rb

18
lib/squib/api/settings.rb

@ -6,12 +6,28 @@ module Squib
# Setting a hint to nil or to :off will disable hints. @see samples/text.rb
#
# @param [Color] text the color of the text hint. To turn off use nil or :off. @see API.md
# @return nil
# @return [nil] Returns nothing
# @api public
def hint(text: nil)
text = nil if text == :off
@text_hint = text
end
# Sets various defaults for this deck. Defaults can be overriden by the commands themselves
# @example
# set font: 'Arial 26'
# text 'blah' # in Arial 26
# text 'blah24', font: 'Arial 24' # in Arial 24
# set font: :default # Back to Squib-wide default
#
# @param opts: the hash of options.
# @option font: the font string to set as default. Can also be set to `:default` to use the Squib-wide default.
# @return [nil] Returns nothing
# @api public
def set(opts = {})
opts = needs(opts, [:font])
@font = opts[:font]
end
end
end

10
lib/squib/api/text.rb

@ -1,16 +1,6 @@
module Squib
class Deck
# @api private todo
def font(type: 'Arial', size: 12, **options)
raise 'Not implemented!'
end
# @api private todo
def set_font(type: 'Arial', size: 12, **options)
raise 'Not implemented!'
end
# Renders a string at a given location, width, alignment, font, etc.
# Unix-like newlines are interpreted even on Windows.
#

2
lib/squib/constants.rb

@ -8,7 +8,7 @@ module Squib
:fill_color => '#0000',
:stroke_color => :black,
:stroke_width => 2.0,
:font => 'Arial, Sans 36',
:font => :use_set,
:sheet => 0,
:x => 0,
:y => 0,

2
lib/squib/deck.rb

@ -24,7 +24,7 @@ module Squib
def initialize(width: 825, height: 1125, cards: 1, dpi: 300, config: 'config.yml', &block)
@width=width; @height=height
@dpi = dpi
@font = 'Sans 36'
@font = Squib::SYSTEM_DEFAULTS[:font]
@cards = []
cards.times{ @cards << Squib::Card.new(self, width, height) }
load_config(config)

2
samples/basic.rb

@ -5,7 +5,7 @@ data = {'name' => ['Thief', 'Grifter', 'Mastermind'],
'level' => [1,2,3]}
Squib::Deck.new(width: 825, height: 1125, cards: 3) do
puts background color: :white
background color: :white
rect x: 38, y: 38, width: 750, height: 1050, radius: 38
rect x: 75, y: 75, width: 128, height: 128, radius: 25

37
spec/api/api_text_spec.rb

@ -0,0 +1,37 @@
require 'spec_helper'
require 'squib'
describe Squib::Deck, '#text' do
context "when working with fonts" do
it"should use the default font when #text and #set_font don't specify" do
card = instance_double(Squib::Card)
expect(card).to receive(:text).with('a', Squib::SYSTEM_DEFAULTS[:font], anything, anything, anything, anything).once
Squib::Deck.new do
@cards = [card]
text str: 'a'
end
end
it "should use the #set_font when #text doesn't specify" do
card = instance_double(Squib::Card)
expect(card).to receive(:text).with('a', 'Times New Roman 16', anything, anything, anything, anything).once
Squib::Deck.new do
@cards = [card]
set font: 'Times New Roman 16'
text str: 'a'
end
end
it "should use the specified font no matter what" do
card = instance_double(Squib::Card)
expect(card).to receive(:text).with('a', 'Arial 18', anything, anything, anything, anything).once
Squib::Deck.new do
@cards = [card]
set font: 'Times New Roman 16'
text str: 'a', font: 'Arial 18'
end
end
end
end
Loading…
Cancel
Save