Browse Source

converted the rest!

dev
Andy Meneely 6 years ago
parent
commit
9ef4afc2e6
  1. 5
      docs/args/draw.rst
  2. 20
      docs/dsl/cut_zone.rst
  3. 14
      docs/dsl/line.rst
  4. 18
      docs/dsl/rect.rst
  5. 19
      docs/dsl/safe_zone.rst
  6. 110
      lib/squib/api/shapes.rb
  7. 2
      lib/squib/args/coords.rb
  8. 12
      lib/squib/deck.rb
  9. 39
      lib/squib/dsl/circle.rb
  10. 35
      lib/squib/dsl/curve.rb
  11. 47
      lib/squib/dsl/cut_zone.rb
  12. 37
      lib/squib/dsl/ellipse.rb
  13. 2
      lib/squib/dsl/grid.rb
  14. 35
      lib/squib/dsl/line.rb
  15. 36
      lib/squib/dsl/polygon.rb
  16. 37
      lib/squib/dsl/rect.rb
  17. 48
      lib/squib/dsl/safe_zone.rb
  18. 37
      lib/squib/dsl/star.rb
  19. 35
      lib/squib/dsl/triangle.rb
  20. 2
      samples/ranges/_ranges.rb
  21. 2
      samples/saves/_save_pdf.rb
  22. 2
      samples/saves/_saves.rb
  23. 4
      spec/docs/docs_helper_spec.rb

5
docs/args/draw.rst

@ -34,3 +34,8 @@ cap
default: ``:butt``
Define how the end of the stroke is drawn. Options are ``:square``, ``:butt``, and ``:round`` (or string equivalents of those).
join
default: ``:mitre``
Specifies how to render the junction of two lines when stroking. Options are ``:mitre``, ``:round``, and ``:bevel``.

20
docs/dsl/cut_zone.rst

@ -50,6 +50,11 @@ stroke_strategy
Must be either ``:fill_first`` or ``:stroke_first`` (or their string equivalents).
join
default: ``:mitre``
Specifies how to render the junction of two lines when stroking. Options are ``:mitre``, ``:round``, and ``:bevel``.
dash
default: ``'3 3'`` (no dash pattern set)
@ -78,6 +83,21 @@ angle
the angle at which to rotate the rectangle about it's upper-left corner
x_radius
default: ``0.125in``
The x radius of the rounded corners. Supports :doc:`/units`.
y_radius
default: ``0.125in``
The y radius of the rounded corners. Supports :doc:`/units`.
radius
default: ``nil``
The x and y radius of the rounded corners. If specified, overrides x_radius and y_radius. Supports :doc:`/units`.
Examples
^^^^^^^^

14
docs/dsl/line.rst

@ -30,20 +30,6 @@ y2
the y-coordinate to place. Supports :doc:`/units/`
x3
default: ``0``
the x-coordinate to place. Supports :doc:`/units/`
y3
default: ``50``
the y-coordinate to place. Supports :doc:`/units/`
.. include:: /args/draw.rst
.. include:: /args/range.rst
.. include:: /args/layout.rst

18
docs/dsl/rect.rst

@ -9,12 +9,28 @@ Options
.. include:: /args/xy.rst
.. include:: /args/wh.rst
x_radius
default: ``0``
The x radius of the rounded corners. Supports :doc:`/units`.
y_radius
default: ``0``
The y radius of the rounded corners. Supports :doc:`/units`.
radius
default: ``nil``
The x and y radius of the rounded corners. If specified, overrides x_radius and y_radius. Supports :doc:`/units`.
.. include:: /args/draw.rst
.. include:: /args/range.rst
.. include:: /args/layout.rst
angle
default: 0
default: ``0``
the angle at which to rotate the rectangle about it's upper-left corner

19
docs/dsl/safe_zone.rst

@ -42,6 +42,20 @@ stroke_width
the width of the outside stroke. Supports :doc:`/units`.
x_radius
default: ``0.125in``
The x radius of the rounded corners. Supports :doc:`/units`.
y_radius
default: ``0.125in``
The y radius of the rounded corners. Supports :doc:`/units`.
radius
default: ``nil``
The x and y radius of the rounded corners. If specified, overrides x_radius and y_radius. Supports :doc:`/units`.
stroke_strategy
default: ``:fill_first``
@ -50,6 +64,11 @@ stroke_strategy
Must be either ``:fill_first`` or ``:stroke_first`` (or their string equivalents).
join
default: ``:mitre``
Specifies how to render the junction of two lines when stroking. Options are ``:mitre``, ``:round``, and ``:bevel``.
dash
default: ``'3 3'`` (no dash pattern set)

110
lib/squib/api/shapes.rb

@ -7,117 +7,9 @@ require_relative '../args/coords'
module Squib
class Deck
# DSL method. See http://squib.readthedocs.io
def rect(opts = {})
range = Args::CardRange.new(opts[:range], deck_size: size)
box = Args::Box.new(self).load!(opts, expand_by: size, layout: layout, dpi: dpi)
draw = Args::Draw.new(custom_colors).load!(opts, expand_by: size, layout: layout, dpi: dpi)
trans = Args::Transform.new.load!(opts, expand_by: size, layout: layout, dpi: dpi)
range.each { |i| @cards[i].rect(box[i], draw[i], trans[i]) }
end
# DSL method. See http://squib.readthedocs.io
def circle(opts = {})
range = Args::CardRange.new(opts[:range], deck_size: size)
coords = Args::Coords.new.load!(opts, expand_by: size, layout: layout, dpi: dpi)
draw = Args::Draw.new(custom_colors).load!(opts, expand_by: size, layout: layout, dpi: dpi)
range.each { |i| @cards[i].circle(coords[i], draw[i]) }
end
# DSL method. See http://squib.readthedocs.io
def ellipse(opts = {})
range = Args::CardRange.new(opts[:range], deck_size: size)
draw = Args::Draw.new(custom_colors).load!(opts, expand_by: size, layout: layout, dpi: dpi)
box = Args::Box.new(self, { width: '0.25in', height: '0.25in' }).load!(opts, expand_by: size, layout: layout, dpi: dpi)
trans = Args::Transform.new.load!(opts, expand_by: size, layout: layout, dpi: dpi)
range.each { |i| @cards[i].ellipse(box[i], draw[i], trans[i]) }
end
# DSL method. See http://squib.readthedocs.io
# def grid(opts = {})
# range = Args::CardRange.new(opts[:range], deck_size: size)
# draw = Args::Draw.new(custom_colors).load!(opts, expand_by: size, layout: layout, dpi: dpi)
# box = Args::Box.new(self).load!(opts, expand_by: size, layout: layout, dpi: dpi)
# range.each { |i| @cards[i].grid(box[i], draw[i]) }
# end
# DSL method. See http://squib.readthedocs.io
def triangle(opts = {})
range = Args::CardRange.new(opts[:range], deck_size: size)
draw = Args::Draw.new(custom_colors).load!(opts, expand_by: size, layout: layout, dpi: dpi)
coords = Args::Coords.new.load!(opts, expand_by: size, layout: layout, dpi: dpi)
range.each { |i| @cards[i].triangle(coords[i], draw[i]) }
end
# DSL method. See http://squib.readthedocs.io
def line(opts = {})
range = Args::CardRange.new(opts[:range], deck_size: size)
draw = Args::Draw.new(custom_colors).load!(opts, expand_by: size, layout: layout, dpi: dpi)
coords = Args::Coords.new.load!(opts, expand_by: size, layout: layout, dpi: dpi)
range.each { |i| @cards[i].line(coords[i], draw[i]) }
end
# DSL method. See http://squib.readthedocs.io
def curve(opts = {})
range = Args::CardRange.new(opts[:range], deck_size: size)
draw = Args::Draw.new(custom_colors).load!(opts, expand_by: size, layout: layout, dpi: dpi)
coords = Args::Coords.new.load!(opts, expand_by: size, layout: layout, dpi: dpi)
range.each { |i| @cards[i].curve(coords[i], draw[i]) }
end
# DSL method. See http://squib.readthedocs.io
def star(opts = {})
range = Args::CardRange.new(opts[:range], deck_size: size)
draw = Args::Draw.new(custom_colors).load!(opts, expand_by: size, layout: layout, dpi: dpi)
coords = Args::Coords.new.load!(opts, expand_by: size, layout: layout, dpi: dpi)
trans = Args::Transform.new.load!(opts, expand_by: size, layout: layout, dpi: dpi)
range.each { |i| @cards[i].star(coords[i], trans[i], draw[i]) }
end
# DSL method. See http://squib.readthedocs.io
def polygon(opts = {})
range = Args::CardRange.new(opts[:range], deck_size: size)
draw = Args::Draw.new(custom_colors).load!(opts, expand_by: size, layout: layout, dpi: dpi)
coords = Args::Coords.new.load!(opts, expand_by: size, layout: layout, dpi: dpi)
trans = Args::Transform.new.load!(opts, expand_by: size, layout: layout, dpi: dpi)
range.each { |i| @cards[i].polygon(coords[i], trans[i], draw[i]) }
end
# DSL method. See http://squib.readthedocs.io
def safe_zone(opts = {})
safe_defaults = {
margin: '0.25in',
radius: '0.125in',
stroke_color: :blue,
fill_color: '#0000',
stroke_width: 1.0,
dash: '3 3',
}
new_opts = safe_defaults.merge(opts)
margin = Args::UnitConversion.parse new_opts[:margin]
new_opts[:x] = margin
new_opts[:y] = margin
new_opts[:width] = width - (2 * margin)
new_opts[:height] = height - (2 * margin)
rect new_opts
end
# DSL method. See http://squib.readthedocs.io
def cut_zone(opts = {})
safe_defaults = {
margin: '0.125in',
radius: '0.125in',
stroke_color: :red,
fill_color: '#0000',
stroke_width: 2.0,
}
new_opts = safe_defaults.merge(opts)
margin = Args::UnitConversion.parse new_opts[:margin]
new_opts[:x] = margin
new_opts[:y] = margin
new_opts[:width] = width - (2 * margin)
new_opts[:height] = height - (2 * margin)
rect new_opts
end
end

2
lib/squib/args/coords.rb

@ -1,7 +1,7 @@
require_relative 'arg_loader'
module Squib::Args
module_function def extract_coord(opts, deck)
module_function def extract_coords(opts, deck)
Coords.new.extract!(opts, deck)
end

12
lib/squib/deck.rb

@ -102,11 +102,9 @@ module Squib
##################
### PUBLIC API ###
##################
require_relative 'dsl/background'
require_relative 'api/data'
require_relative 'api/groups'
require_relative 'api/settings'
require_relative 'api/shapes'
require_relative 'api/text'
require_relative 'api/units'
@ -114,15 +112,25 @@ module Squib
### DSL METHODS ###
###################
require_relative 'dsl/background'
require_relative 'dsl/circle'
require_relative 'dsl/curve'
require_relative 'dsl/cut_zone'
require_relative 'dsl/ellipse'
require_relative 'dsl/grid'
require_relative 'dsl/hand'
require_relative 'dsl/line'
require_relative 'dsl/png'
require_relative 'dsl/polygon'
require_relative 'dsl/rect'
require_relative 'dsl/safe_zone'
require_relative 'dsl/save_pdf'
require_relative 'dsl/save_png'
require_relative 'dsl/save_sheet'
require_relative 'dsl/save'
require_relative 'dsl/showcase'
require_relative 'dsl/star'
require_relative 'dsl/svg'
require_relative 'dsl/triangle'
end
end

39
lib/squib/dsl/circle.rb

@ -0,0 +1,39 @@
require_relative '../errors_warnings/warn_unexpected_params'
require_relative '../args/card_range'
require_relative '../args/coords'
require_relative '../args/draw'
module Squib
class Deck
def circle(opts = {})
DSL::Circle.new(self, __callee__).run(opts)
end
end
module DSL
class Circle
include WarnUnexpectedParams
attr_reader :dsl_method, :deck
def initialize(deck, dsl_method)
@deck = deck
@dsl_method = dsl_method
end
def self.accepted_params
%i(x y
radius arc_start arc_end arc_direction arc_close
fill_color stroke_color stroke_width stroke_strategy join dash cap
range layout)
end
def run(opts)
warn_if_unexpected opts
range = Args.extract_range opts, deck
coords = Args.extract_coords opts, deck
draw = Args.extract_draw opts, deck
range.each { |i| deck.cards[i].circle(coords[i], draw[i]) }
end
end
end
end

35
lib/squib/dsl/curve.rb

@ -0,0 +1,35 @@
require_relative '../errors_warnings/warn_unexpected_params'
module Squib
class Deck
def curve(opts = {})
DSL::Curve.new(self, __callee__).run(opts)
end
end
module DSL
class Curve
include WarnUnexpectedParams
attr_reader :dsl_method, :deck
def initialize(deck, dsl_method)
@deck = deck
@dsl_method = dsl_method
end
def self.accepted_params
%i(x1 y1 x2 y2 cx1 cy1 cx2 cy2
fill_color stroke_color stroke_width stroke_strategy join dash cap
range layout)
end
def run(opts)
warn_if_unexpected opts
range = Args.extract_range opts, deck
draw = Args.extract_draw opts, deck
coords = Args.extract_coords opts, deck
range.each { |i| deck.cards[i].curve(coords[i], draw[i]) }
end
end
end
end

47
lib/squib/dsl/cut_zone.rb

@ -0,0 +1,47 @@
require_relative '../errors_warnings/warn_unexpected_params'
module Squib
class Deck
def cut_zone(opts = {})
DSL::CutZone.new(self, __callee__).run(opts)
end
end
module DSL
class CutZone
include WarnUnexpectedParams
attr_reader :dsl_method, :deck
def initialize(deck, dsl_method)
@deck = deck
@dsl_method = dsl_method
end
def self.accepted_params
%i(x y width height margin angle
x_radius y_radius radius
fill_color stroke_color stroke_width stroke_strategy join dash cap
range layout)
end
def run(opts)
warn_if_unexpected opts
cut_defaults = {
margin: '0.125in',
radius: '0.125in',
stroke_color: :red,
fill_color: '#0000',
stroke_width: 2.0,
}
new_opts = cut_defaults.merge(opts)
margin = Args::UnitConversion.parse new_opts[:margin]
new_opts[:x] = margin
new_opts[:y] = margin
new_opts[:width] = deck.width - (2 * margin)
new_opts[:height] = deck.height - (2 * margin)
new_opts.delete :margin
deck.rect new_opts
end
end
end
end

37
lib/squib/dsl/ellipse.rb

@ -0,0 +1,37 @@
require_relative '../errors_warnings/warn_unexpected_params'
module Squib
class Deck
def ellipse(opts = {})
DSL::Ellipse.new(self, __callee__).run(opts)
end
end
module DSL
class Ellipse
include WarnUnexpectedParams
attr_reader :dsl_method, :deck
def initialize(deck, dsl_method)
@deck = deck
@dsl_method = dsl_method
end
def self.accepted_params
%i(x y width height
fill_color stroke_color stroke_width stroke_strategy join dash cap
angle
range layout)
end
def run(opts)
warn_if_unexpected opts
range = Args.extract_range opts, deck
draw = Args.extract_draw opts, deck
box = Args.extract_box opts, deck
trans = Args.extract_transform opts, deck
range.each { |i| deck.cards[i].ellipse(box[i], draw[i], trans[i]) }
end
end
end
end

2
lib/squib/dsl/grid.rb

@ -19,7 +19,7 @@ module Squib
def self.accepted_params
%i(x y width height
fill_color stroke_color stroke_width stroke_strategy dash cap
fill_color stroke_color stroke_width stroke_strategy join dash cap
range layout)
end

35
lib/squib/dsl/line.rb

@ -0,0 +1,35 @@
require_relative '../errors_warnings/warn_unexpected_params'
module Squib
class Deck
def line(opts = {})
DSL::Line.new(self, __callee__).run(opts)
end
end
module DSL
class Line
include WarnUnexpectedParams
attr_reader :dsl_method, :deck
def initialize(deck, dsl_method)
@deck = deck
@dsl_method = dsl_method
end
def self.accepted_params
%i(x1 y1 x2 y2
fill_color stroke_color stroke_width stroke_strategy join dash cap
range layout)
end
def run(opts)
warn_if_unexpected opts
range = Args.extract_range opts, deck
draw = Args.extract_draw opts, deck
coords = Args.extract_coords opts, deck
range.each { |i| deck.cards[i].line(coords[i], draw[i]) }
end
end
end
end

36
lib/squib/dsl/polygon.rb

@ -0,0 +1,36 @@
require_relative '../errors_warnings/warn_unexpected_params'
module Squib
class Deck
def polygon(opts = {})
DSL::Polygon.new(self, __callee__).run(opts)
end
end
module DSL
class Polygon
include WarnUnexpectedParams
attr_reader :dsl_method, :deck
def initialize(deck, dsl_method)
@deck = deck
@dsl_method = dsl_method
end
def self.accepted_params
%i(n x y radius angle
fill_color stroke_color stroke_width stroke_strategy join dash cap
range layout)
end
def run(opts)
warn_if_unexpected opts
range = Args.extract_range opts, deck
draw = Args.extract_draw opts, deck
coords = Args.extract_coords opts, deck
trans = Args.extract_transform opts, deck
range.each { |i| deck.cards[i].polygon(coords[i], trans[i], draw[i]) }
end
end
end
end

37
lib/squib/dsl/rect.rb

@ -0,0 +1,37 @@
require_relative '../errors_warnings/warn_unexpected_params'
module Squib
class Deck
def rect(opts = {})
DSL::Rect.new(self, __callee__).run(opts)
end
end
module DSL
class Rect
include WarnUnexpectedParams
attr_reader :dsl_method, :deck
def initialize(deck, dsl_method)
@deck = deck
@dsl_method = dsl_method
end
def self.accepted_params
%i(x y width height angle
x_radius y_radius radius
fill_color stroke_color stroke_width stroke_strategy join dash cap
range layout)
end
def run(opts)
warn_if_unexpected opts
range = Args.extract_range opts, deck
draw = Args.extract_draw opts, deck
box = Args.extract_box opts, deck
trans = Args.extract_transform opts, deck
range.each { |i| deck.cards[i].rect(box[i], draw[i], trans[i]) }
end
end
end
end

48
lib/squib/dsl/safe_zone.rb

@ -0,0 +1,48 @@
require_relative '../errors_warnings/warn_unexpected_params'
module Squib
class Deck
def safe_zone(opts = {})
DSL::SafeZone.new(self, __callee__).run(opts)
end
end
module DSL
class SafeZone
include WarnUnexpectedParams
attr_reader :dsl_method, :deck
def initialize(deck, dsl_method)
@deck = deck
@dsl_method = dsl_method
end
def self.accepted_params
%i(x y width height margin angle
x_radius y_radius radius
fill_color stroke_color stroke_width stroke_strategy join dash cap
range layout)
end
def run(opts)
warn_if_unexpected opts
safe_defaults = {
margin: '0.25in',
radius: '0.125in',
stroke_color: :blue,
fill_color: '#0000',
stroke_width: 1.0,
dash: '3 3',
}
new_opts = safe_defaults.merge(opts)
margin = Args::UnitConversion.parse new_opts[:margin]
new_opts[:x] = margin
new_opts[:y] = margin
new_opts[:width] = deck.width - (2 * margin)
new_opts[:height] = deck.height - (2 * margin)
new_opts.delete :margin
deck.rect(new_opts)
end
end
end
end

37
lib/squib/dsl/star.rb

@ -0,0 +1,37 @@
require_relative '../errors_warnings/warn_unexpected_params'
module Squib
class Deck
def star(opts = {})
DSL::Star.new(self, __callee__).run(opts)
end
end
module DSL
class Star
include WarnUnexpectedParams
attr_reader :dsl_method, :deck
def initialize(deck, dsl_method)
@deck = deck
@dsl_method = dsl_method
end
def self.accepted_params
%i(n x y
inner_radius outer_radius angle
fill_color stroke_color stroke_width stroke_strategy join dash cap
range layout)
end
def run(opts)
warn_if_unexpected opts
range = Args.extract_range opts, deck
draw = Args.extract_draw opts, deck
coords = Args.extract_coords opts, deck
trans = Args.extract_transform opts, deck
range.each { |i| deck.cards[i].star(coords[i], trans[i], draw[i]) }
end
end
end
end

35
lib/squib/dsl/triangle.rb

@ -0,0 +1,35 @@
require_relative '../errors_warnings/warn_unexpected_params'
module Squib
class Deck
def triangle(opts = {})
DSL::Triangle.new(self, __callee__).run(opts)
end
end
module DSL
class Triangle
include WarnUnexpectedParams
attr_reader :dsl_method, :deck
def initialize(deck, dsl_method)
@deck = deck
@dsl_method = dsl_method
end
def self.accepted_params
%i(x1 y1 x2 y2 x3 y3
fill_color stroke_color stroke_width stroke_strategy join dash cap
range layout)
end
def run(opts)
warn_if_unexpected opts
range = Args.extract_range opts, deck
draw = Args.extract_draw opts, deck
coords = Args.extract_coords opts, deck
range.each { |i| deck.cards[i].triangle(coords[i], draw[i]) }
end
end
end
end

2
samples/ranges/_ranges.rb

@ -59,6 +59,6 @@ Squib::Deck.new(width: 825, height: 1125, cards: 3) do
end
end
rect color: 'black' # just a border
rect stroke_color: 'black' # just a border
save_sheet prefix: 'ranges_', columns: 3
end

2
samples/saves/_save_pdf.rb

@ -3,7 +3,7 @@ require 'squib'
Squib::Deck.new(cards: 8) do
background color: :gray
rect x: 37.5, y: 37.5, width: 750, height: 1050,
x_radius: 37.5, y_radius: 37.5, stroke: 3.0, dash: '4 4'
x_radius: 37.5, y_radius: 37.5, stroke_width: 2.0, dash: '4 4'
# Tests for crop marks
save_pdf file: 'crops-default.pdf', crop_marks: true

2
samples/saves/_saves.rb

@ -5,7 +5,7 @@ require 'squib'
Squib::Deck.new(width: 825, height: 1125, cards: 16) do
background color: :gray
rect x: 38, y: 38, width: 750, height: 1050,
x_radius: 38, y_radius: 38, stroke: 3.0, dash: '4 4'
x_radius: 38, y_radius: 38, stroke_width: 2.0, dash: '4 4'
text str: (1..16).to_a, x: 220, y: 78, font: 'Arial 18'

4
spec/docs/docs_helper_spec.rb

@ -8,9 +8,9 @@ describe 'docs spec helper' do
expect(options.sort).to eq(%i(color range))
end
it 'gets all documented options for grid' do
it 'gets all documented options for grid.rst' do
expected = %i(x y width height fill_color stroke_color stroke_width
stroke_strategy dash cap range layout)
stroke_strategy join dash cap range layout)
options = documented_options(:Grid)
expect(options.sort).to eq(expected.sort)
end

Loading…
Cancel
Save