Browse Source

👮 spaces around operators

dev
Andy Meneely 10 years ago
parent
commit
310030eee4
  1. 2
      lib/squib/api/settings.rb
  2. 4
      lib/squib/api/text_embed.rb
  3. 2
      lib/squib/args/card_range.rb
  4. 4
      lib/squib/conf.rb
  5. 2
      lib/squib/graphics/cairo_context_wrapper.rb
  6. 2
      lib/squib/graphics/hand.rb
  7. 8
      lib/squib/graphics/save_doc.rb
  8. 2
      lib/squib/graphics/save_images.rb
  9. 26
      lib/squib/graphics/shapes.rb
  10. 6
      lib/squib/graphics/showcase.rb
  11. 22
      samples/colors.rb
  12. 2
      samples/ranges.rb
  13. 2
      samples/showcase.rb
  14. 2
      samples/text_options.rb
  15. 6
      spec/api/api_data_spec.rb
  16. 2
      spec/layout_parser_spec.rb
  17. 2
      spec/spec_helper.rb

2
lib/squib/api/settings.rb

@ -9,7 +9,7 @@ module Squib
# DSL method. See http://squib.readthedocs.org
def set(opts = {})
raise 'DEPRECATED: As of v0.7 img_dir is no longer supported in "set". Use config.yml instead.' if opts.key? :img_dir
@font = (opts[:font] == :default) ? Squib::DEFAULT_FONT: opts[:font]
@font = (opts[:font] == :default) ? Squib::DEFAULT_FONT : opts[:font]
end
# DSL method. See http://squib.readthedocs.org

4
lib/squib/api/text_embed.rb

@ -43,7 +43,7 @@ module Squib
range = Args::CardRange.new(opts[:range], deck_size: @deck_size)
paint = Args::Paint.new(@custom_colors).load!(opts, expand_by: @deck_size, layout: @layout)
box = Args::Box.new(self, { width: :native, height: :native }).load!(opts, expand_by: @deck_size, layout: @layout, dpi: @dpi)
adjust= Args::EmbedAdjust.new.load!(opts, expand_by: @deck_size, layout: @layout, dpi: @dpi)
adjust = Args::EmbedAdjust.new.load!(opts, expand_by: @deck_size, layout: @layout, dpi: @dpi)
trans = Args::Transform.new.load!(opts, expand_by: @deck_size, layout: @layout, dpi: @dpi)
ifile = Args::InputFile.new.load!(opts, expand_by: @deck_size, layout: @layout, dpi: @dpi)
svg_args = Args::SvgSpecial.new.load!(opts, expand_by: @deck_size, layout: @layout, dpi: @dpi)
@ -77,7 +77,7 @@ module Squib
range = Args::CardRange.new(opts[:range], deck_size: @deck_size)
paint = Args::Paint.new(@custom_colors).load!(opts, expand_by: @deck_size, layout: @layout)
box = Args::Box.new(self, { width: :native, height: :native }).load!(opts, expand_by: @deck_size, layout: @layout, dpi: @dpi)
adjust= Args::EmbedAdjust.new.load!(opts, expand_by: @deck_size, layout: @layout, dpi: @dpi)
adjust = Args::EmbedAdjust.new.load!(opts, expand_by: @deck_size, layout: @layout, dpi: @dpi)
trans = Args::Transform.new.load!(opts, expand_by: @deck_size, layout: @layout, dpi: @dpi)
ifile = Args::InputFile.new.load!(opts, expand_by: @deck_size, layout: @layout, dpi: @dpi)
rule = { type: :png, file: ifile, box: box, paint: paint, trans: trans, adjust: adjust }

2
lib/squib/args/card_range.rb

@ -23,7 +23,7 @@ module Squib
input = 0..(deck_size - 1) if input == :all
input = (input.to_i)..(input.to_i) if input.respond_to? :to_i
raise ArgumentError.new("#{input} must be Enumerable (i.e. respond_to :each).") unless input.respond_to? :each
raise ArgumentError.new("#{input} is outside of deck range of 0..#{deck_size-1}") if (!input.max.nil?) && (input.max > (deck_size - 1))
raise ArgumentError.new("#{input} is outside of deck range of 0..#{deck_size - 1}") if (!input.max.nil?) && (input.max > (deck_size - 1))
input
end

4
lib/squib/conf.rb

@ -24,8 +24,8 @@ module Squib
'ellipsis' => "\u2026",
'smart_quotes' => true,
'text_hint' => 'off',
'warn_ellipsize'=> true,
'warn_png_scale'=> true,
'warn_ellipsize' => true,
'warn_png_scale' => true,
}
#Translate the hints to the methods.

2
lib/squib/graphics/cairo_context_wrapper.rb

@ -105,7 +105,7 @@ module Squib
v = vertical ? -1.0 : 1.0
h = horizontal ? -1.0 : 1.0
transform Cairo::Matrix.new(v, 0.0, 0.0,
h, x*(1-v), y*(1-h))
h, x * (1 - v), y * (1 - h))
end
end

2
lib/squib/graphics/hand.rb

@ -30,7 +30,7 @@ module Squib
end
end
x, y, w, h = cxt.target.ink_extents # I love Ruby assignment ;)
png_cxt = Squib::Graphics::CairoContextWrapper.new(Cairo::Context.new(Cairo::ImageSurface.new(w + 2*sheet.margin, h + 2*sheet.margin)))
png_cxt = Squib::Graphics::CairoContextWrapper.new(Cairo::Context.new(Cairo::ImageSurface.new(w + 2 * sheet.margin, h + 2 * sheet.margin)))
png_cxt.set_source_squibcolor(sheet.fill_color)
png_cxt.paint
png_cxt.translate(-x + sheet.margin, -y + sheet.margin)

8
lib/squib/graphics/save_doc.rb

@ -32,10 +32,10 @@ module Squib
bar.increment
cc.reset_clip
cc.translate(-x, -y)
x += card.width + sheet.gap - 2*sheet.trim
x += card.width + sheet.gap - 2 * sheet.trim
if x > (sheet.width - card_width - sheet.margin)
x = sheet.margin
y += card.height + sheet.gap - 2*sheet.trim
y += card.height + sheet.gap - 2 * sheet.trim
if y > (sheet.height - card_height - sheet.margin)
cc.show_page # next page
x, y = sheet.margin, sheet.margin
@ -90,9 +90,9 @@ module Squib
# @api private
def trim(surface, trim, width, height)
if trim > 0
tmp = Cairo::ImageSurface.new(width-2*trim, height-2*trim)
tmp = Cairo::ImageSurface.new(width - 2 * trim, height - 2 * trim)
cc = Cairo::Context.new(tmp)
cc.set_source(surface, -1*trim, -1*trim)
cc.set_source(surface, -1 * trim, -1 * trim)
cc.paint
surface = tmp
end

2
lib/squib/graphics/save_images.rb

@ -19,7 +19,7 @@ module Squib
end
def preprocessed_save(angle, trim, trim_radius)
new_width, new_height = @width - 2*trim, @height - 2*trim
new_width, new_height = @width - 2 * trim, @height - 2 * trim
new_cc = Cairo::Context.new(Cairo::ImageSurface.new(new_width, new_height))
new_cc.translate(new_width * 0.5, new_height * 0.5)
new_cc.rotate(angle)

26
lib/squib/graphics/shapes.rb

@ -30,19 +30,19 @@ module Squib
def ellipse(box, draw)
x, y, w, h = box.x, box.y, box.width, box.height
use_cairo do |cc|
cc.move_to(x, y + 0.5*h) # start west
cc.curve_to(x, y + 0.25*h, # west to north
x + 0.25*w, y,
x + 0.5*w, y)
cc.curve_to(x + 0.75*w, y, # north to east
x + w, y + 0.25*h,
x + w, y + 0.5*h)
cc.curve_to(x + w, y + 0.75*h, # east to south
x + 0.75*w, y + h,
x + 0.5*w, y + h)
cc.curve_to(x + 0.25*w, y + h, # south to west
x, y + 0.75*h,
x, y + 0.5*h)
cc.move_to(x, y + 0.5 * h) # start west
cc.curve_to(x, y + 0.25 * h, # west to north
x + 0.25 * w, y,
x + 0.5 * w, y)
cc.curve_to(x + 0.75 * w, y, # north to east
x + w, y + 0.25 * h,
x + w, y + 0.5 * h)
cc.curve_to(x + w, y + 0.75 * h, # east to south
x + 0.75 * w, y + h,
x + 0.5 * w, y + h)
cc.curve_to(x + 0.25 * w, y + h, # south to west
x, y + 0.75 * h,
x, y + 0.5 * h)
cc.fill_n_stroke(draw)
end
end

6
lib/squib/graphics/showcase.rb

@ -12,8 +12,8 @@ module Squib
# :nodoc:
# @api private
def render_showcase(range, sheet, showcase)
out_width = range.size * ((@width - 2*sheet.trim) * showcase.scale * showcase.offset) + 2*sheet.margin
out_height = showcase.reflect_offset + (1.0 + showcase.reflect_percent) * (@height - 2*sheet.trim) + 2*sheet.margin
out_width = range.size * ((@width - 2 * sheet.trim) * showcase.scale * showcase.offset) + 2 * sheet.margin
out_height = showcase.reflect_offset + (1.0 + showcase.reflect_percent) * (@height - 2 * sheet.trim) + 2 * sheet.margin
out_cc = Cairo::Context.new(Cairo::ImageSurface.new(out_width, out_height))
wrapper = Squib::Graphics::CairoContextWrapper.new(out_cc)
wrapper.set_source_squibcolor(sheet.fill_color)
@ -33,7 +33,7 @@ module Squib
# :nodoc:
# @api private
def trim_rounded(src, trim, radius)
trim_cc = Cairo::Context.new(Cairo::ImageSurface.new(src.width-2.0*trim, src.height-2.0*trim))
trim_cc = Cairo::Context.new(Cairo::ImageSurface.new(src.width - 2.0 * trim, src.height - 2.0 * trim))
trim_cc.rounded_rectangle(0, 0, trim_cc.target.width, trim_cc.target.height, radius, radius)
trim_cc.set_source(src, -1 * trim, -1 * trim)
trim_cc.clip

22
samples/colors.rb

@ -4,15 +4,15 @@ Squib::Deck.new(width: 825, height: 1125, cards: 1) do
background color: :white
y = 0
text color: '#f00', str: '3-hex', x: 50, y: y+=50
text color: '#f00', str: '3-hex (alpha)', x: 50, y: y+=50
text color: '#ff0000', str: '6-hex', x: 50, y: y+=50
text color: '#ff000099', str: '8-hex(alpha)', x: 50, y: y+=50
text color: '#ffff00000000', str: '12-hex', 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: '(0,0)(400,0) blue@0.0 red@1.0', str: 'Linear gradients!', x: 50, y: y+=50
text color: '(200,500,10)(200,500,100) blue@0.0 red@1.0', str: 'Radial gradients!', x: 50, y: y+=50
text color: '#f00', str: '3-hex', x: 50, y: y += 50
text color: '#f00', str: '3-hex (alpha)', x: 50, y: y += 50
text color: '#ff0000', str: '6-hex', x: 50, y: y += 50
text color: '#ff000099', str: '8-hex(alpha)', x: 50, y: y += 50
text color: '#ffff00000000', str: '12-hex', 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: '(0,0)(400,0) blue@0.0 red@1.0', str: 'Linear gradients!', x: 50, y: y += 50
text color: '(200,500,10)(200,500,100) blue@0.0 red@1.0', str: 'Radial gradients!', x: 50, y: y += 50
# see gradients.rb sample for more on gradients
save_png prefix: 'colors_'
@ -25,8 +25,8 @@ Squib::Deck.new(width: 3000, height: 1500) do
x, y, w, h = 0, 0, 300, 50
colors.each_with_index do |color, i|
rect x: x, y: y, width: w, height: h, fill_color: color
text str: color.to_s, x: x + 5, y: y+13, font: 'Sans Bold 16',
color: (Cairo::Color.parse(color).to_hsv.v > 0.9) ? '#000': '#fff'
text str: color.to_s, x: x + 5, y: y + 13, font: 'Sans Bold 16',
color: (Cairo::Color.parse(color).to_hsv.v > 0.9) ? '#000' : '#fff'
y += h
if y > @height
x += w

2
samples/ranges.rb

@ -55,7 +55,7 @@ Squib::Deck.new(width: 825, height: 1125, cards: 3) do
range = hearts.each_index.select { |i| hearts[i] == n}
n.times do |i|
svg file: 'glass-heart.svg', range: range,
x: 150, y: 55 + i*42, width: 40, height: 40
x: 150, y: 55 + i * 42, width: 40, height: 40
end
end

2
samples/showcase.rb

@ -9,7 +9,7 @@ Squib::Deck.new(cards: 4) do
text str: %w(Grifter Thief Thug Kingpin),
font: 'Helvetica,Sans weight=800 120',
x: 78, y: 78, width: '2.25in', align: :center
svg file: 'spanner.svg', x: (825-500)/2, y: 500, width: 500, height: 500
svg file: 'spanner.svg', x: (825 - 500) / 2, y: 500, width: 500, height: 500
# Defaults are pretty sensible.
showcase file: 'showcase.png'

2
samples/text_options.rb

@ -37,7 +37,7 @@ Squib::Deck.new(width: 825, height: 1125, cards: 3) do
# Extents come back as an array of hashes, which can get split out like this
ws = extents.inject([]) { |arr, ext| arr << ext[:width] + 10; arr }
hs = extents.inject([]) { |arr, ext| arr << ext[:height] + 10; arr }
rect x: 65 - margin/2, y: 550 - margin/2,
rect x: 65 - margin / 2, y: 550 - margin / 2,
width: ws, height: hs,
radius: 10, stroke_color: :black

6
spec/api/api_data_spec.rb

@ -38,14 +38,14 @@ describe Squib::Deck do
it 'explodes quantities' do
expect(Squib.csv(file: csv_file('qty.csv'))).to eq({
'Name' => %w(Ha Ha Ha Ho),
'Name' => %w(Ha Ha Ha Ho),
'Qty' => [3, 3, 3, 1],
})
end
it 'explodes quantities on specified header' do
expect(Squib.csv(explode: 'Quantity', file: csv_file('qty_named.csv'))).to eq({
'Name' => %w(Ha Ha Ha Ho),
'Name' => %w(Ha Ha Ha Ho),
'Quantity' => [3, 3, 3, 1],
})
end
@ -65,7 +65,7 @@ describe Squib::Deck do
expect(Squib.xlsx(file: xlsx_file('basic.xlsx'))).to eq({
'Name' => %w(Larry Curly Mo),
'General Number' => %w(1 2 3), #general types always get loaded as strings with no conversion
'Actual Number' => [4.0, 5.0, 6.0], #numbers get auto-converted to integers
'Actual Number' => [4.0, 5.0, 6.0], #numbers get auto-converted to integers
})
end

2
spec/layout_parser_spec.rb

@ -179,7 +179,7 @@ describe Squib::LayoutParser do
.with("Processing layout: 'verbal' attempts to extend a missing 'kaisersoze'")
layout = Squib::LayoutParser.load_layout(layout_file('extends-nonexists.yml'))
expect(layout).to eq({
'verbal' => {
'verbal' => {
'font_size' => 25,
'extends' => 'kaisersoze'
}

2
spec/spec_helper.rb

@ -98,7 +98,7 @@ def mock_cairo(strio)
allow(pango).to receive(:height).and_return(25)
allow(pango).to receive(:width).and_return(25)
allow(pango).to receive(:index_to_pos).and_return(Pango::Rectangle.new(0, 0, 0, 0))
allow(pango).to receive(:extents).and_return([Pango::Rectangle.new(0, 0, 0, 0)]*2)
allow(pango).to receive(:extents).and_return([Pango::Rectangle.new(0, 0, 0, 0)] * 2)
allow(pango).to receive(:iter).and_return(iter)
allow(pango).to receive(:alignment).and_return(Pango::Layout::Alignment::LEFT)
allow(pango).to receive(:text).and_return("foo")

Loading…
Cancel
Save