Rubocop: Using single-quotes properly
parent
37fd4e7733
commit
e115135d51
|
|
@ -4,12 +4,12 @@ require 'mercenary'
|
||||||
|
|
||||||
Mercenary.program(:squib) do |p|
|
Mercenary.program(:squib) do |p|
|
||||||
p.version Squib::VERSION
|
p.version Squib::VERSION
|
||||||
p.description "A Ruby DSL for prototyping card games"
|
p.description 'A Ruby DSL for prototyping card games'
|
||||||
p.syntax "squib <subcommand> [options]"
|
p.syntax 'squib <subcommand> [options]'
|
||||||
|
|
||||||
p.command(:new) do |c|
|
p.command(:new) do |c|
|
||||||
c.syntax "new PATH"
|
c.syntax 'new PATH'
|
||||||
c.description "Creates a new Squib project scaffolding in PATH. Must be a new directory or already empty."
|
c.description 'Creates a new Squib project scaffolding in PATH. Must be a new directory or already empty.'
|
||||||
|
|
||||||
c.action do |args, options|
|
c.action do |args, options|
|
||||||
Squib::Commands::New.new.process(args)
|
Squib::Commands::New.new.process(args)
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ module Squib
|
||||||
(s.first_row+1).upto(s.last_row) do |row|
|
(s.first_row+1).upto(s.last_row) do |row|
|
||||||
cell = s.cell(row,col)
|
cell = s.cell(row,col)
|
||||||
# Roo hack for avoiding unnecessary .0's on whole integers
|
# Roo hack for avoiding unnecessary .0's on whole integers
|
||||||
cell = s.excelx_value(row,col) if s.excelx_type(row,col) == [:numeric_or_formula, "General"]
|
cell = s.excelx_value(row,col) if s.excelx_type(row,col) == [:numeric_or_formula, 'General']
|
||||||
data[header] << cell
|
data[header] << cell
|
||||||
end#row
|
end#row
|
||||||
end#col
|
end#col
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ module Squib
|
||||||
def png(opts = {})
|
def png(opts = {})
|
||||||
opts = needs(opts, [:range, :files, :x, :y, :alpha, :layout, :blend])
|
opts = needs(opts, [:range, :files, :x, :y, :alpha, :layout, :blend])
|
||||||
Dir.chdir(@img_dir) do
|
Dir.chdir(@img_dir) do
|
||||||
@progress_bar.start("Loading PNG(s)", opts[:range].size) do |bar|
|
@progress_bar.start('Loading PNG(s)', opts[:range].size) do |bar|
|
||||||
opts[:range].each do |i|
|
opts[:range].each do |i|
|
||||||
@cards[i].png(opts[:file][i], opts[:x][i], opts[:y][i], opts[:alpha][i], opts[:blend][i])
|
@cards[i].png(opts[:file][i], opts[:x][i], opts[:y][i], opts[:alpha][i], opts[:blend][i])
|
||||||
bar.increment
|
bar.increment
|
||||||
|
|
@ -51,7 +51,7 @@ module Squib
|
||||||
def svg(opts = {})
|
def svg(opts = {})
|
||||||
p = needs(opts,[:range, :files, :svgid, :force_svgid, :x, :y, :width, :height, :layout, :alpha, :blend])
|
p = needs(opts,[:range, :files, :svgid, :force_svgid, :x, :y, :width, :height, :layout, :alpha, :blend])
|
||||||
Dir.chdir(@img_dir) do
|
Dir.chdir(@img_dir) do
|
||||||
@progress_bar.start("Loading SVG(s)", p[:range].size) do |bar|
|
@progress_bar.start('Loading SVG(s)', p[:range].size) do |bar|
|
||||||
p[:range].each do |i|
|
p[:range].each do |i|
|
||||||
unless p[:force_id][i] && p[:id][i].to_s.empty?
|
unless p[:force_id][i] && p[:id][i].to_s.empty?
|
||||||
@cards[i].svg(p[:file][i], p[:id][i], p[:x][i], p[:y][i],
|
@cards[i].svg(p[:file][i], p[:id][i], p[:x][i], p[:y][i],
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ module Squib
|
||||||
# @example
|
# @example
|
||||||
# inches(2.5) # 750 (for default Deck::dpi of 300)
|
# inches(2.5) # 750 (for default Deck::dpi of 300)
|
||||||
#
|
#
|
||||||
# @param [Decimal] n, the number of inches
|
# @param n [Decimal], the number of inches
|
||||||
# @return [Decimal] the number of pixels, according to the deck's DPI
|
# @return [Decimal] the number of pixels, according to the deck's DPI
|
||||||
# @api public
|
# @api public
|
||||||
def inches(n)
|
def inches(n)
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ module Squib
|
||||||
def process(args)
|
def process(args)
|
||||||
raise ArgumentError.new('Please specify a path.') if args.empty?
|
raise ArgumentError.new('Please specify a path.') if args.empty?
|
||||||
|
|
||||||
new_project_path = File.expand_path(args.join(" "), Dir.pwd)
|
new_project_path = File.expand_path(args.join(' '), Dir.pwd)
|
||||||
template_path = File.expand_path('../project_template', File.dirname(__FILE__))
|
template_path = File.expand_path('../project_template', File.dirname(__FILE__))
|
||||||
|
|
||||||
FileUtils.mkdir_p new_project_path
|
FileUtils.mkdir_p new_project_path
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ module Squib
|
||||||
:blend => :none,
|
:blend => :none,
|
||||||
:color => :black,
|
:color => :black,
|
||||||
:default_font => 'Arial 36',
|
:default_font => 'Arial 36',
|
||||||
:dir => "_output",
|
:dir => '_output',
|
||||||
:ellipsize => :end,
|
:ellipsize => :end,
|
||||||
:fill_color => '#0000',
|
:fill_color => '#0000',
|
||||||
:force_id => false,
|
:force_id => false,
|
||||||
|
|
@ -23,7 +23,7 @@ module Squib
|
||||||
:justify => false,
|
:justify => false,
|
||||||
:margin => 75,
|
:margin => 75,
|
||||||
:markup => false,
|
:markup => false,
|
||||||
:prefix => "card_",
|
:prefix => 'card_',
|
||||||
:progress_bar => false,
|
:progress_bar => false,
|
||||||
:range => :all,
|
:range => :all,
|
||||||
:rotate => false,
|
:rotate => false,
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ module Squib
|
||||||
# @example
|
# @example
|
||||||
# require 'squib'
|
# require 'squib'
|
||||||
# Squib::Deck.new do
|
# Squib::Deck.new do
|
||||||
# text str: 'Hello, World!'
|
# text str: 'Hello, World!"
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
# @param width [Integer] the width of each card in pixels
|
# @param width [Integer] the width of each card in pixels
|
||||||
|
|
@ -126,9 +126,9 @@ module Squib
|
||||||
parent_keys.each do |parent_key|
|
parent_keys.each do |parent_key|
|
||||||
from_extends = yml[key].merge(recurse_extends(yml, parent_key, visited)) do |key, child_val, parent_val|
|
from_extends = yml[key].merge(recurse_extends(yml, parent_key, visited)) do |key, child_val, parent_val|
|
||||||
if child_val.to_s.strip.start_with?('+=')
|
if child_val.to_s.strip.start_with?('+=')
|
||||||
parent_val + child_val.sub("+=",'').strip.to_f
|
parent_val + child_val.sub('+=','').strip.to_f
|
||||||
elsif child_val.to_s.strip.start_with?('-=')
|
elsif child_val.to_s.strip.start_with?('-=')
|
||||||
parent_val - child_val.sub("-=",'').strip.to_f
|
parent_val - child_val.sub('-=','').strip.to_f
|
||||||
else
|
else
|
||||||
child_val #child overrides parent when merging, no +=
|
child_val #child overrides parent when merging, no +=
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ module Squib
|
||||||
@enabled = enabled
|
@enabled = enabled
|
||||||
end
|
end
|
||||||
|
|
||||||
def start(title="", total=100, &block)
|
def start(title='', total=100, &block)
|
||||||
if @enabled
|
if @enabled
|
||||||
@bar = ProgressBar.create(title: title, total: total, format: '%t <%B> %p%% %a')
|
@bar = ProgressBar.create(title: title, total: total, format: '%t <%B> %p%% %a')
|
||||||
yield(@bar)
|
yield(@bar)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
require 'squib'
|
require 'squib'
|
||||||
|
|
||||||
Squib::Deck.new(cards: 3, layout: 'layout.yml') do
|
Squib::Deck.new(cards: 3, layout: 'layout.yml') do
|
||||||
text str: "Hello, World!"
|
text str: 'Hello, World!'
|
||||||
save format: :png
|
save format: :png
|
||||||
end
|
end
|
||||||
|
|
@ -6,5 +6,5 @@ module Squib
|
||||||
# Most of the time this is in the alpha of the next release.
|
# Most of the time this is in the alpha of the next release.
|
||||||
# e.g. v0.0.5a is on its way to becoming v0.0.5
|
# e.g. v0.0.5a is on its way to becoming v0.0.5
|
||||||
#
|
#
|
||||||
VERSION = "0.0.5a"
|
VERSION = '0.0.5a'
|
||||||
end
|
end
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -12,5 +12,5 @@ Squib::Deck.new(width: 825, height: 1125, cards: 1) do
|
||||||
text color: '#ffff000000009999', str: '12-hex (alpha)', x: 50, y: y+=50
|
text color: '#ffff000000009999', str: '12-hex (alpha)', x: 50, y: y+=50
|
||||||
text color: :burnt_orange, str: 'Symbols of constants too', x: 50, y: y+=50
|
text color: :burnt_orange, str: 'Symbols of constants too', x: 50, y: y+=50
|
||||||
|
|
||||||
save_png prefix: "colors_"
|
save_png prefix: 'colors_'
|
||||||
end
|
end
|
||||||
|
|
@ -6,7 +6,7 @@ Squib::Deck.new(config: 'custom-config.yml') do
|
||||||
background color: :foo
|
background color: :foo
|
||||||
|
|
||||||
# Hints are turned on in the config file
|
# Hints are turned on in the config file
|
||||||
text str: "The Title", x: 0, y: 78, width: 825,
|
text str: 'The Title', x: 0, y: 78, width: 825,
|
||||||
font: 'Arial 72', align: :center
|
font: 'Arial 72', align: :center
|
||||||
|
|
||||||
# Progress bars are shown for these commands
|
# Progress bars are shown for these commands
|
||||||
|
|
@ -14,6 +14,6 @@ Squib::Deck.new(config: 'custom-config.yml') do
|
||||||
png file: 'shiny-purse2.png', x: 620, y: 75
|
png file: 'shiny-purse2.png', x: 620, y: 75
|
||||||
svg file: 'spanner2.svg', x: 620, y: 218
|
svg file: 'spanner2.svg', x: 620, y: 218
|
||||||
save_png prefix: 'custom-config_'
|
save_png prefix: 'custom-config_'
|
||||||
save_pdf file: "custom-config-out.pdf"
|
save_pdf file: 'custom-config-out.pdf'
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
@ -8,16 +8,16 @@ require 'squib'
|
||||||
Squib::Deck.new(width: 825, height: 1125) do
|
Squib::Deck.new(width: 825, height: 1125) do
|
||||||
background color: '#aaa'
|
background color: '#aaa'
|
||||||
|
|
||||||
text str: "This is portrait"
|
text str: 'This is portrait'
|
||||||
|
|
||||||
save_png prefix: "portrait_"
|
save_png prefix: 'portrait_'
|
||||||
end
|
end
|
||||||
|
|
||||||
# Money cards are landscape
|
# Money cards are landscape
|
||||||
Squib::Deck.new(width: 1125, height: 825) do
|
Squib::Deck.new(width: 1125, height: 825) do
|
||||||
background color: '#aaa'
|
background color: '#aaa'
|
||||||
|
|
||||||
text str: "This is landscape"
|
text str: 'This is landscape'
|
||||||
|
|
||||||
save_png prefix: "landscape_", rotate: true
|
save_png prefix: 'landscape_', rotate: true
|
||||||
end
|
end
|
||||||
|
|
@ -17,17 +17,17 @@ Squib::Deck.new(width: 825, height: 1125, cards: 3) do
|
||||||
width: 100, align: :center
|
width: 100, align: :center
|
||||||
|
|
||||||
# Ranges are inclusive, zero-based
|
# Ranges are inclusive, zero-based
|
||||||
text range: 0..1, str: "Thief and Grifter only!!", x: 25, y:200
|
text range: 0..1, str: 'Thief and Grifter only!!', x: 25, y:200
|
||||||
|
|
||||||
# Integers are also allowed
|
# Integers are also allowed
|
||||||
text range: 0, str: "Thief only!", x: 25, y: 250
|
text range: 0, str: 'Thief only!', x: 25, y: 250
|
||||||
|
|
||||||
# Negatives go from the back of the deck
|
# Negatives go from the back of the deck
|
||||||
text range: -1, str: "Mastermind only!", x: 25, y: 250
|
text range: -1, str: 'Mastermind only!', x: 25, y: 250
|
||||||
text range: -2..-1, str: "Grifter and Mastermind only!", x: 25, y: 650
|
text range: -2..-1, str: 'Grifter and Mastermind only!', x: 25, y: 650
|
||||||
|
|
||||||
# We can use Arrays too!
|
# We can use Arrays too!
|
||||||
text range: [0,2], str: "Thief and Mastermind only!!", x: 25, y:300
|
text range: [0,2], str: 'Thief and Mastermind only!!', x: 25, y:300
|
||||||
|
|
||||||
# Just about everything in Squib can be given an array that
|
# Just about everything in Squib can be given an array that
|
||||||
# corresponds to the deck's cards. This allows for each card to be styled differently
|
# corresponds to the deck's cards. This allows for each card to be styled differently
|
||||||
|
|
@ -41,13 +41,13 @@ Squib::Deck.new(width: 825, height: 1125, cards: 3) do
|
||||||
# then use a range. No need to memorize IDs, and you can add cards easily
|
# then use a range. No need to memorize IDs, and you can add cards easily
|
||||||
id = {} ; data['name'].each_with_index{ |name,i| id[name] = i}
|
id = {} ; data['name'].each_with_index{ |name,i| id[name] = i}
|
||||||
text range: id['Thief']..id['Grifter'],
|
text range: id['Thief']..id['Grifter'],
|
||||||
str: "Thief through Grifter with id lookup!!",
|
str: 'Thief through Grifter with id lookup!!',
|
||||||
x:25, y: 400
|
x:25, y: 400
|
||||||
|
|
||||||
# Useful idiom: generate arrays from a column called 'type'
|
# Useful idiom: generate arrays from a column called 'type'
|
||||||
type = {}; data['type'].each_with_index{ |t,i| (type[t] ||= []) << i}
|
type = {}; data['type'].each_with_index{ |t,i| (type[t] ||= []) << i}
|
||||||
text range: type['Thinker'],
|
text range: type['Thinker'],
|
||||||
str: "Only for Thinkers!",
|
str: 'Only for Thinkers!',
|
||||||
x:25, y: 500
|
x:25, y: 500
|
||||||
|
|
||||||
save prefix: 'ranges_', format: :png
|
save prefix: 'ranges_', format: :png
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,8 @@ Squib::Deck.new(width: 825, height: 1125, cards: 16) do
|
||||||
|
|
||||||
text str: (1..16).to_a, x: 220, y: 78, font: 'Arial 54'
|
text str: (1..16).to_a, x: 220, y: 78, font: 'Arial 54'
|
||||||
|
|
||||||
save_pdf file: "sample-save-pdf.pdf", margin: 75, gap: 5, trim: 37
|
save_pdf file: 'sample-save-pdf.pdf', margin: 75, gap: 5, trim: 37
|
||||||
|
|
||||||
#Note that our PNGs still are not trimmed even though the pdf ones are
|
#Note that our PNGs still are not trimmed even though the pdf ones are
|
||||||
save_png range: 1, prefix: "save_pdf_"
|
save_png range: 1, prefix: 'save_pdf_'
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -16,38 +16,38 @@ Squib::Deck.new(width: 825, height: 1125, cards: 3) do
|
||||||
|
|
||||||
text str: "UTF-8 \u2663", x: 565, y: 150, font: 'Arial weight=900 36'
|
text str: "UTF-8 \u2663", x: 565, y: 150, font: 'Arial weight=900 36'
|
||||||
|
|
||||||
text str: "Font strings are expressive!", x:65, y: 200,
|
text str: 'Font strings are expressive!', x:65, y: 200,
|
||||||
font: 'Impact bold italic 36'
|
font: 'Impact bold italic 36'
|
||||||
|
|
||||||
text str: "Font strings are expressive!", x:65, y: 300,
|
text str: 'Font strings are expressive!', x:65, y: 300,
|
||||||
font: 'Arial,Verdana weight=900 style=oblique 36'
|
font: 'Arial,Verdana weight=900 style=oblique 36'
|
||||||
|
|
||||||
text str: "Font string sizes can be overridden per card.", x: 65, y: 350,
|
text str: 'Font string sizes can be overridden per card.', x: 65, y: 350,
|
||||||
font: 'Impact 36', font_size: [16, 20, 24]
|
font: 'Impact 36', font_size: [16, 20, 24]
|
||||||
|
|
||||||
text str: "This text has fixed width, fixed height, center-aligned, middle-valigned, and has a red hint",
|
text str: 'This text has fixed width, fixed height, center-aligned, middle-valigned, and has a red hint',
|
||||||
hint: :red,
|
hint: :red,
|
||||||
x: 65, y: 400,
|
x: 65, y: 400,
|
||||||
width: 300, height: 200,
|
width: 300, height: 200,
|
||||||
align: :center, valign: :middle,
|
align: :center, valign: :middle,
|
||||||
font: 'Arial 18'
|
font: 'Arial 18'
|
||||||
|
|
||||||
text str: "Ellipsization!\nThe ultimate question of life, the universe, and everything to life and everything is 42",
|
text str: 'Ellipsization!\nThe ultimate question of life, the universe, and everything to life and everything is 42',
|
||||||
hint: :green, font: 'Arial 22',
|
hint: :green, font: 'Arial 22',
|
||||||
x: 450, y: 400,
|
x: 450, y: 400,
|
||||||
width: 280, height: 180,
|
width: 280, height: 180,
|
||||||
ellipsize: true
|
ellipsize: true
|
||||||
|
|
||||||
hint text: :cyan
|
hint text: :cyan
|
||||||
text str: "Text hints are also globally togglable!",
|
text str: 'Text hints are also globally togglable!',
|
||||||
x: 65, y: 625,
|
x: 65, y: 625,
|
||||||
font: 'Arial 22'
|
font: 'Arial 22'
|
||||||
hint text: :off
|
hint text: :off
|
||||||
text str: "See? No hint here.",
|
text str: 'See? No hint here.',
|
||||||
x: 565, y: 625,
|
x: 565, y: 625,
|
||||||
font: 'Arial 22'
|
font: 'Arial 22'
|
||||||
|
|
||||||
text str: "Rotated",
|
text str: 'Rotated',
|
||||||
x: 565, y: 675, angle: 0.1,
|
x: 565, y: 675, angle: 0.1,
|
||||||
font: 'Arial 18'
|
font: 'Arial 18'
|
||||||
|
|
||||||
|
|
@ -56,7 +56,7 @@ Squib::Deck.new(width: 825, height: 1125, cards: 3) do
|
||||||
width: inches(2.25), height: inches(1),
|
width: inches(2.25), height: inches(1),
|
||||||
justify: true
|
justify: true
|
||||||
|
|
||||||
text str: "<b>Markup</b> is also <i>quite</i> <s>easy</s> awesome",
|
text str: '<b>Markup</b> is also <i>quite</i> <s>easy</s> awesome',
|
||||||
markup: true,
|
markup: true,
|
||||||
x: 50, y: 1000,
|
x: 50, y: 1000,
|
||||||
width: 750, height: 100,
|
width: 750, height: 100,
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ require 'squib'
|
||||||
|
|
||||||
describe Squib::Deck, '#text' do
|
describe Squib::Deck, '#text' do
|
||||||
|
|
||||||
context "fonts" do
|
context 'fonts' do
|
||||||
it "should use the default font when #text and #set_font don't specify" do
|
it "should use the default font when #text and #set_font don't specify" do
|
||||||
card = instance_double(Squib::Card)
|
card = instance_double(Squib::Card)
|
||||||
expect(card).to receive(:text).with('a', 'Arial 36',
|
expect(card).to receive(:text).with('a', 'Arial 36',
|
||||||
|
|
@ -27,7 +27,7 @@ describe Squib::Deck, '#text' do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should use the specified font no matter what" do
|
it 'should use the specified font no matter what' do
|
||||||
card = instance_double(Squib::Card)
|
card = instance_double(Squib::Card)
|
||||||
expect(card).to receive(:text).with('a', 'Arial 18',
|
expect(card).to receive(:text).with('a', 'Arial 18',
|
||||||
anything, anything, anything, anything,anything,anything,anything, anything, anything,anything, anything, anything, anything, anything, anything
|
anything, anything, anything, anything,anything,anything,anything, anything, anything,anything, anything, anything, anything, anything, anything
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ require 'squib'
|
||||||
|
|
||||||
describe Squib::Commands::New do
|
describe Squib::Commands::New do
|
||||||
|
|
||||||
describe "#process" do
|
describe '#process' do
|
||||||
before(:all) do
|
before(:all) do
|
||||||
@old_stderr = $stderr
|
@old_stderr = $stderr
|
||||||
$stderr = StringIO.new
|
$stderr = StringIO.new
|
||||||
|
|
@ -16,27 +16,27 @@ describe Squib::Commands::New do
|
||||||
@cmd = Squib::Commands::New.new
|
@cmd = Squib::Commands::New.new
|
||||||
end
|
end
|
||||||
|
|
||||||
it "raises an error if no directory was specified" do
|
it 'raises an error if no directory was specified' do
|
||||||
expect{@cmd.process([])}.to raise_error(ArgumentError, 'Please specify a path.')
|
expect{@cmd.process([])}.to raise_error(ArgumentError, 'Please specify a path.')
|
||||||
end
|
end
|
||||||
|
|
||||||
it "creates a new template on an fresh directory" do
|
it 'creates a new template on an fresh directory' do
|
||||||
@cmd.process(['foo'])
|
@cmd.process(['foo'])
|
||||||
expect(File.exists?('foo/deck.rb')).to be true
|
expect(File.exists?('foo/deck.rb')).to be true
|
||||||
end
|
end
|
||||||
|
|
||||||
it "creates a new template on an empty directory" do
|
it 'creates a new template on an empty directory' do
|
||||||
Dir.mkdir('foo')
|
Dir.mkdir('foo')
|
||||||
@cmd.process(['foo'])
|
@cmd.process(['foo'])
|
||||||
expect(File.exists?('foo/deck.rb')).to be true
|
expect(File.exists?('foo/deck.rb')).to be true
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not create a new template on an empty " do
|
it 'does not create a new template on an empty ' do
|
||||||
Dir.mkdir('foo')
|
Dir.mkdir('foo')
|
||||||
File.new('foo/somefile.txt', 'w+')
|
File.new('foo/somefile.txt', 'w+')
|
||||||
@cmd.process(['foo'])
|
@cmd.process(['foo'])
|
||||||
$stderr.rewind
|
$stderr.rewind
|
||||||
expect($stderr.string.chomp).to end_with " exists and is not empty. Doing nothing and quitting."
|
expect($stderr.string.chomp).to end_with ' exists and is not empty. Doing nothing and quitting.'
|
||||||
end
|
end
|
||||||
|
|
||||||
after(:all) do
|
after(:all) do
|
||||||
|
|
|
||||||
|
|
@ -3,15 +3,15 @@ require 'squib/deck'
|
||||||
|
|
||||||
describe Squib::Deck do
|
describe Squib::Deck do
|
||||||
|
|
||||||
it "initializes with default parameters" do
|
it 'initializes with default parameters' do
|
||||||
d = Squib::Deck.new
|
d = Squib::Deck.new
|
||||||
expect(d.width).to eq(825)
|
expect(d.width).to eq(825)
|
||||||
expect(d.height).to eq(1125)
|
expect(d.height).to eq(1125)
|
||||||
expect(d.cards.size).to eq(1)
|
expect(d.cards.size).to eq(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
context "in dealing with ranges" do
|
context 'in dealing with ranges' do
|
||||||
it "calls text on all cards by default" do
|
it 'calls text on all cards by default' do
|
||||||
card1 = instance_double(Squib::Card)
|
card1 = instance_double(Squib::Card)
|
||||||
card2 = instance_double(Squib::Card)
|
card2 = instance_double(Squib::Card)
|
||||||
expect(card1).to receive(:text).once
|
expect(card1).to receive(:text).once
|
||||||
|
|
@ -22,7 +22,7 @@ describe Squib::Deck do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "calls text on some cards with an integer" do
|
it 'calls text on some cards with an integer' do
|
||||||
card1 = instance_double(Squib::Card)
|
card1 = instance_double(Squib::Card)
|
||||||
card2 = instance_double(Squib::Card)
|
card2 = instance_double(Squib::Card)
|
||||||
expect(card2).to receive(:text).once
|
expect(card2).to receive(:text).once
|
||||||
|
|
@ -32,7 +32,7 @@ describe Squib::Deck do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "calls text with ranges" do
|
it 'calls text with ranges' do
|
||||||
card1 = instance_double(Squib::Card)
|
card1 = instance_double(Squib::Card)
|
||||||
card2 = instance_double(Squib::Card)
|
card2 = instance_double(Squib::Card)
|
||||||
card3 = instance_double(Squib::Card)
|
card3 = instance_double(Squib::Card)
|
||||||
|
|
@ -45,22 +45,22 @@ describe Squib::Deck do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "#load_layout" do
|
context '#load_layout' do
|
||||||
|
|
||||||
it "loads a normal layout with no extends" do
|
it 'loads a normal layout with no extends' do
|
||||||
d = Squib::Deck.new(layout: test_file('no-extends.yml'))
|
d = Squib::Deck.new(layout: test_file('no-extends.yml'))
|
||||||
expect(d.layout).to \
|
expect(d.layout).to \
|
||||||
eq({'frame' => {
|
eq({'frame' => {
|
||||||
'x' => 38,
|
'x' => 38,
|
||||||
'valign' => :middle,
|
'valign' => :middle,
|
||||||
'str' => "blah",
|
'str' => 'blah',
|
||||||
'font' => "Mr. Font",
|
'font' => 'Mr. Font',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "loads with a single extends" do
|
it 'loads with a single extends' do
|
||||||
d = Squib::Deck.new(layout: test_file('single-extends.yml'))
|
d = Squib::Deck.new(layout: test_file('single-extends.yml'))
|
||||||
expect(d.layout).to \
|
expect(d.layout).to \
|
||||||
eq({'frame' => {
|
eq({'frame' => {
|
||||||
|
|
@ -77,7 +77,7 @@ describe Squib::Deck do
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "applies the extends regardless of order" do
|
it 'applies the extends regardless of order' do
|
||||||
d = Squib::Deck.new(layout: test_file('pre-extends.yml'))
|
d = Squib::Deck.new(layout: test_file('pre-extends.yml'))
|
||||||
expect(d.layout).to \
|
expect(d.layout).to \
|
||||||
eq({'frame' => {
|
eq({'frame' => {
|
||||||
|
|
@ -94,7 +94,7 @@ describe Squib::Deck do
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "applies the single-level extends multiple times" do
|
it 'applies the single-level extends multiple times' do
|
||||||
d = Squib::Deck.new(layout: test_file('single-level-multi-extends.yml'))
|
d = Squib::Deck.new(layout: test_file('single-level-multi-extends.yml'))
|
||||||
expect(d.layout).to \
|
expect(d.layout).to \
|
||||||
eq({'frame' => {
|
eq({'frame' => {
|
||||||
|
|
@ -117,7 +117,7 @@ describe Squib::Deck do
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "applies multiple extends in a single rule" do
|
it 'applies multiple extends in a single rule' do
|
||||||
d = Squib::Deck.new(layout: test_file('multi-extends-single-entry.yml'))
|
d = Squib::Deck.new(layout: test_file('multi-extends-single-entry.yml'))
|
||||||
expect(d.layout).to \
|
expect(d.layout).to \
|
||||||
eq({'aunt' => {
|
eq({'aunt' => {
|
||||||
|
|
@ -142,7 +142,7 @@ describe Squib::Deck do
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "applies multi-level extends" do
|
it 'applies multi-level extends' do
|
||||||
d = Squib::Deck.new(layout: test_file('multi-level-extends.yml'))
|
d = Squib::Deck.new(layout: test_file('multi-level-extends.yml'))
|
||||||
expect(d.layout).to \
|
expect(d.layout).to \
|
||||||
eq({'frame' => {
|
eq({'frame' => {
|
||||||
|
|
@ -165,22 +165,22 @@ describe Squib::Deck do
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "fails on a self-circular extends" do
|
it 'fails on a self-circular extends' do
|
||||||
file = test_file('self-circular-extends.yml')
|
file = test_file('self-circular-extends.yml')
|
||||||
expect { Squib::Deck.new(layout: file) }.to \
|
expect { Squib::Deck.new(layout: file) }.to \
|
||||||
raise_error(RuntimeError, "Invalid layout: circular extends with 'a'")
|
raise_error(RuntimeError, 'Invalid layout: circular extends with \'a\'')
|
||||||
end
|
end
|
||||||
|
|
||||||
it "fails on a easy-circular extends" do
|
it 'fails on a easy-circular extends' do
|
||||||
file = test_file('easy-circular-extends.yml')
|
file = test_file('easy-circular-extends.yml')
|
||||||
expect { Squib::Deck.new(layout: file) }.to \
|
expect { Squib::Deck.new(layout: file) }.to \
|
||||||
raise_error(RuntimeError, "Invalid layout: circular extends with 'a'")
|
raise_error(RuntimeError, 'Invalid layout: circular extends with \'a\'')
|
||||||
end
|
end
|
||||||
|
|
||||||
it "hard on a easy-circular extends" do
|
it 'hard on a easy-circular extends' do
|
||||||
file = test_file('hard-circular-extends.yml')
|
file = test_file('hard-circular-extends.yml')
|
||||||
expect { Squib::Deck.new(layout: file) }.to \
|
expect { Squib::Deck.new(layout: file) }.to \
|
||||||
raise_error(RuntimeError, "Invalid layout: circular extends with 'a'")
|
raise_error(RuntimeError, 'Invalid layout: circular extends with \'a\'')
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ describe Squib::InputHelpers do
|
||||||
end
|
end
|
||||||
|
|
||||||
context '#layoutify' do
|
context '#layoutify' do
|
||||||
it "warns on the logger when the layout doesn't exist" do
|
it 'warns on the logger when the layout does not exist' do
|
||||||
@old_logger = Squib.logger
|
@old_logger = Squib.logger
|
||||||
Squib.logger = instance_double(Logger)
|
Squib.logger = instance_double(Logger)
|
||||||
expect(Squib.logger).to receive(:warn).with("Layout entry 'foo' does not exist.").twice
|
expect(Squib.logger).to receive(:warn).with("Layout entry 'foo' does not exist.").twice
|
||||||
|
|
@ -37,23 +37,23 @@ describe Squib::InputHelpers do
|
||||||
Squib.logger = @old_logger
|
Squib.logger = @old_logger
|
||||||
end
|
end
|
||||||
|
|
||||||
it "applies the layout in a normal situation" do
|
it 'applies the layout in a normal situation' do
|
||||||
expect(@deck.send(:layoutify, {layout: :blah})).to \
|
expect(@deck.send(:layoutify, {layout: :blah})).to \
|
||||||
eq({layout: [:blah, :blah], x: [25, 25]})
|
eq({layout: [:blah, :blah], x: [25, 25]})
|
||||||
end
|
end
|
||||||
|
|
||||||
it "applies two different layouts for two different situations" do
|
it 'applies two different layouts for two different situations' do
|
||||||
expect(@deck.send(:layoutify, {layout: ['blah', 'apples']})).to \
|
expect(@deck.send(:layoutify, {layout: ['blah', 'apples']})).to \
|
||||||
eq({layout: ['blah','apples'], x: [25, 35]})
|
eq({layout: ['blah','apples'], x: [25, 35]})
|
||||||
end
|
end
|
||||||
|
|
||||||
it "still has nils when not applied two different layouts differ in structure" do
|
it 'still has nils when not applied two different layouts differ in structure' do
|
||||||
expect(@deck.send(:layoutify, {layout: ['apples', 'oranges']})).to \
|
expect(@deck.send(:layoutify, {layout: ['apples', 'oranges']})).to \
|
||||||
eq({layout: ['apples','oranges'], x: [35], y: [nil, 45]})
|
eq({layout: ['apples','oranges'], x: [35], y: [nil, 45]})
|
||||||
#...this might behavior that is hard to debug for users. Trying to come up with a warning or something...
|
#...this might behavior that is hard to debug for users. Trying to come up with a warning or something...
|
||||||
end
|
end
|
||||||
|
|
||||||
it "also looks up based on strings" do
|
it 'also looks up based on strings' do
|
||||||
expect(@deck.send(:layoutify, {layout: 'blah'})).to \
|
expect(@deck.send(:layoutify, {layout: 'blah'})).to \
|
||||||
eq({layout: ['blah','blah'], x: [25, 25]})
|
eq({layout: ['blah','blah'], x: [25, 25]})
|
||||||
end
|
end
|
||||||
|
|
@ -61,54 +61,54 @@ describe Squib::InputHelpers do
|
||||||
end
|
end
|
||||||
|
|
||||||
context '#rangeify' do
|
context '#rangeify' do
|
||||||
it "must be within the card size range" do
|
it 'must be within the card size range' do
|
||||||
expect{@deck.send(:rangeify, {range: 2..3})}.to \
|
expect{@deck.send(:rangeify, {range: 2..3})}.to \
|
||||||
raise_error(ArgumentError, '2..3 is outside of deck range of 0..1')
|
raise_error(ArgumentError, '2..3 is outside of deck range of 0..1')
|
||||||
end
|
end
|
||||||
|
|
||||||
it "cannot be nil" do
|
it 'cannot be nil' do
|
||||||
expect{@deck.send(:rangeify, {range: nil})}.to \
|
expect{@deck.send(:rangeify, {range: nil})}.to \
|
||||||
raise_error(RuntimeError, 'Range cannot be nil')
|
raise_error(RuntimeError, 'Range cannot be nil')
|
||||||
end
|
end
|
||||||
|
|
||||||
it "defaults to a range of all cards if :all" do
|
it 'defaults to a range of all cards if :all' do
|
||||||
expect(@deck.send(:rangeify, {range: :all})).to eq({range: 0..1})
|
expect(@deck.send(:rangeify, {range: :all})).to eq({range: 0..1})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "#fileify" do
|
context '#fileify' do
|
||||||
it "should throw an error if the file doesn't exist" do
|
it 'should throw an error if the file does not exist' do
|
||||||
expect{@deck.send(:fileify, {file: 'nonexist.txt'}, true)}.to \
|
expect{@deck.send(:fileify, {file: 'nonexist.txt'}, true)}.to \
|
||||||
raise_error(RuntimeError,"File #{File.expand_path('nonexist.txt')} does not exist!")
|
raise_error(RuntimeError,"File #{File.expand_path('nonexist.txt')} does not exist!")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "#dir" do
|
context '#dir' do
|
||||||
it "should raise an error if the directory does not exist" do
|
it 'should raise an error if the directory does not exist' do
|
||||||
expect{@deck.send(:dirify, {dir: 'nonexist'}, :dir, false)}.to \
|
expect{@deck.send(:dirify, {dir: 'nonexist'}, :dir, false)}.to \
|
||||||
raise_error(RuntimeError,"'nonexist' does not exist!")
|
raise_error(RuntimeError,"'nonexist' does not exist!")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "#colorify" do
|
context '#colorify' do
|
||||||
it "should parse if nillable" do
|
it 'should parse if nillable' do
|
||||||
color = @deck.send(:colorify, {color: ['#fff']}, true)[:color]
|
color = @deck.send(:colorify, {color: ['#fff']}, true)[:color]
|
||||||
expect(color.to_a[0].to_a).to eq([1.0, 1.0, 1.0, 1.0])
|
expect(color.to_a[0].to_a).to eq([1.0, 1.0, 1.0, 1.0])
|
||||||
end
|
end
|
||||||
|
|
||||||
it "raises and error if the color doesn't exist" do
|
it 'raises and error if the color does not exist' do
|
||||||
expect{ @deck.send(:colorify, {color: [:nonexist]}, false) }.to \
|
expect{ @deck.send(:colorify, {color: [:nonexist]}, false) }.to \
|
||||||
raise_error(ArgumentError, "unknown color name: nonexist")
|
raise_error(ArgumentError, 'unknown color name: nonexist')
|
||||||
end
|
end
|
||||||
|
|
||||||
it "pulls from config's custom colors" do
|
it 'pulls from custom colors in the config' do
|
||||||
@deck.custom_colors['foo'] = "#abc"
|
@deck.custom_colors['foo'] = '#abc'
|
||||||
expect(@deck.send(:colorify, {color: [:foo]}, false)[:color][0].to_s).to \
|
expect(@deck.send(:colorify, {color: [:foo]}, false)[:color][0].to_s).to \
|
||||||
eq('#AABBCCFF')
|
eq('#AABBCCFF')
|
||||||
end
|
end
|
||||||
|
|
||||||
it "pulls from config's custom colors even when a string" do
|
it 'pulls custom colors even when a string' do
|
||||||
@deck.custom_colors['foo'] = "#abc"
|
@deck.custom_colors['foo'] = '#abc'
|
||||||
expect(@deck.send(:colorify, {color: ['foo']}, false)[:color][0].to_s).to \
|
expect(@deck.send(:colorify, {color: ['foo']}, false)[:color][0].to_s).to \
|
||||||
eq('#AABBCCFF')
|
eq('#AABBCCFF')
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,9 @@ require 'pp'
|
||||||
|
|
||||||
describe Squib do
|
describe Squib do
|
||||||
|
|
||||||
context "all samples run without error" do
|
context 'all samples run without error' do
|
||||||
it "should execute with no errors" do
|
it 'should execute with no errors' do
|
||||||
p = double("ProgressBar")
|
p = double('ProgressBar')
|
||||||
allow(ProgressBar).to receive(:create).and_return(Squib::DoNothing.new)
|
allow(ProgressBar).to receive(:create).and_return(Squib::DoNothing.new)
|
||||||
samples = File.expand_path('../samples', File.dirname(__FILE__))
|
samples = File.expand_path('../samples', File.dirname(__FILE__))
|
||||||
Dir["#{samples}/**/*.rb"].each do |sample|
|
Dir["#{samples}/**/*.rb"].each do |sample|
|
||||||
|
|
|
||||||
|
|
@ -5,27 +5,27 @@ require 'squib/version'
|
||||||
|
|
||||||
Gem::Specification.new do |spec|
|
Gem::Specification.new do |spec|
|
||||||
spec.specification_version = 2 if spec.respond_to? :specification_version=
|
spec.specification_version = 2 if spec.respond_to? :specification_version=
|
||||||
spec.required_rubygems_version = Gem::Requirement.new(">= 0") if spec.respond_to? :required_rubygems_version=
|
spec.required_rubygems_version = Gem::Requirement.new('>= 0') if spec.respond_to? :required_rubygems_version=
|
||||||
spec.rubygems_version = '2.2.2'
|
spec.rubygems_version = '2.2.2'
|
||||||
spec.required_ruby_version = '>= 2.0.0'
|
spec.required_ruby_version = '>= 2.0.0'
|
||||||
|
|
||||||
spec.name = "squib"
|
spec.name = 'squib'
|
||||||
spec.version = Squib::VERSION
|
spec.version = Squib::VERSION
|
||||||
spec.license = "MIT"
|
spec.license = 'MIT'
|
||||||
|
|
||||||
spec.summary = %q{A Ruby DSL for prototyping card games}
|
spec.summary = %q{A Ruby DSL for prototyping card games}
|
||||||
spec.description = %q{Squib is a Ruby DSL for prototyping card games}
|
spec.description = %q{Squib is a Ruby DSL for prototyping card games}
|
||||||
spec.authors = ["Andy Meneely"]
|
spec.authors = ['Andy Meneely']
|
||||||
spec.email = ["playconfidencegames@gmail.com"]
|
spec.email = ['playconfidencegames@gmail.com']
|
||||||
spec.homepage = "https://github.com/andymeneely/squib"
|
spec.homepage = 'https://github.com/andymeneely/squib'
|
||||||
|
|
||||||
spec.rdoc_options = ["--charset=UTF-8"]
|
spec.rdoc_options = ['--charset=UTF-8']
|
||||||
spec.extra_rdoc_files = %w[README.md LICENSE.txt]
|
spec.extra_rdoc_files = %w(README.md LICENSE.txt)
|
||||||
|
|
||||||
spec.files = `git ls-files -z`.split("\x0")
|
spec.files = `git ls-files -z`.split("\x0")
|
||||||
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
||||||
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
||||||
spec.require_paths = ["lib"]
|
spec.require_paths = ['lib']
|
||||||
|
|
||||||
spec.add_runtime_dependency 'cairo', '~> 1.12.9'
|
spec.add_runtime_dependency 'cairo', '~> 1.12.9'
|
||||||
spec.add_runtime_dependency 'pango', '~> 2.2.0'
|
spec.add_runtime_dependency 'pango', '~> 2.2.0'
|
||||||
|
|
@ -34,13 +34,13 @@ Gem::Specification.new do |spec|
|
||||||
spec.add_runtime_dependency 'mercenary', '~> 0.3.4'
|
spec.add_runtime_dependency 'mercenary', '~> 0.3.4'
|
||||||
spec.add_runtime_dependency 'ruby-progressbar', '~> 1.6'
|
spec.add_runtime_dependency 'ruby-progressbar', '~> 1.6'
|
||||||
|
|
||||||
spec.add_development_dependency "bundler", "~> 1.6"
|
spec.add_development_dependency 'bundler', '~> 1.6'
|
||||||
spec.add_development_dependency "rake"
|
spec.add_development_dependency 'rake'
|
||||||
spec.add_development_dependency "rspec", "~> 3.0"
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
||||||
spec.add_development_dependency "rspec-mocks", "~> 3.0"
|
spec.add_development_dependency 'rspec-mocks', '~> 3.0'
|
||||||
spec.add_development_dependency "redcarpet", '~> 3.1.2'
|
spec.add_development_dependency 'redcarpet', '~> 3.1.2'
|
||||||
spec.add_development_dependency "github-markup", '~> 1.3'
|
spec.add_development_dependency 'github-markup', '~> 1.3'
|
||||||
spec.add_development_dependency "yard"
|
spec.add_development_dependency 'yard'
|
||||||
spec.add_development_dependency "coveralls"
|
spec.add_development_dependency 'coveralls'
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue