diff --git a/Rakefile b/Rakefile index 02927a9..614d4be 100644 --- a/Rakefile +++ b/Rakefile @@ -3,7 +3,7 @@ require 'rspec/core/rake_task' require 'yard' RSpec::Core::RakeTask.new(:spec) -task :default => [:install, :spec] +task default: [:install, :spec] YARD::Rake::YardocTask.new(:doc) do |t| t.files = ['lib/**/*.rb', 'samples/**/*.rb'] # optional diff --git a/bin/squib b/bin/squib index 370c637..b558298 100755 --- a/bin/squib +++ b/bin/squib @@ -9,11 +9,11 @@ Mercenary.program(:squib) do |p| p.command(:new) do |c| 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| Squib::Commands::New.new.process(args) end end - + end \ No newline at end of file diff --git a/lib/squib.rb b/lib/squib.rb index e2aa614..1bc04d3 100644 --- a/lib/squib.rb +++ b/lib/squib.rb @@ -8,15 +8,15 @@ require 'squib/deck' require 'squib/card' module Squib - + # Access the internal logger that Squib uses. By default, Squib configure the logger to the WARN level - # Use this to suppress or increase output levels. + # Use this to suppress or increase output levels. # @example # Squib.logger.level = Logger::DEBUG #show waaaay more information than you probably need, unless you're a dev # Squib.logger.level = Logger::ERROR #basically turns it off - # + # # @return [Logger] the ruby logger - # @api public + # @api public def logger if @logger.nil? @logger = Logger.new(STDOUT); @@ -28,5 +28,5 @@ module Squib @logger end module_function :logger - + end \ No newline at end of file diff --git a/lib/squib/api/background.rb b/lib/squib/api/background.rb index 024088e..ca343bb 100644 --- a/lib/squib/api/background.rb +++ b/lib/squib/api/background.rb @@ -1,6 +1,6 @@ module Squib class Deck - # Fills the background with the given color + # Fills the background with the given color # @example # background color: :white # @@ -14,6 +14,6 @@ module Squib opts = needs(opts,[:range, :color]) opts[:range].each { |i| @cards[i].background(opts[:color][i]) } end - + end end \ No newline at end of file diff --git a/lib/squib/api/data.rb b/lib/squib/api/data.rb index 5221554..c1a446a 100644 --- a/lib/squib/api/data.rb +++ b/lib/squib/api/data.rb @@ -4,13 +4,13 @@ module Squib # Pulls Excel data from `.xlsx` files into a column-based hash # - # Pulls the data into a Hash of arrays based on the columns. First row is assumed to be the header row. + # Pulls the data into a Hash of arrays based on the columns. First row is assumed to be the header row. # See the example `samples/excel.rb` in the [source repository](https://github.com/andymeneely/squib/tree/master/samples) # # @example # # Excel file looks like this: # # | h1 | h2 | - # # ------------ + # # ------------ # # | 1 | 2 | # # | 3 | 4 | # data = xlsx file: 'data.xlsx', sheet: 0 @@ -41,11 +41,11 @@ module Squib module_function :xlsx class Deck - + # Convenience call for Squib.xlsx def xlsx(opts = {}) Squib.xlsx(opts) - end + end end end diff --git a/lib/squib/api/image.rb b/lib/squib/api/image.rb index fd786b1..942fb26 100644 --- a/lib/squib/api/image.rb +++ b/lib/squib/api/image.rb @@ -21,8 +21,8 @@ module Squib opts = needs(opts, [:range, :files, :x, :y, :alpha, :layout, :blend]) Dir.chdir(@img_dir) do @progress_bar.start("Loading PNG(s)", opts[:range].size) do |bar| - opts[:range].each do |i| - @cards[i].png(opts[:file][i], opts[:x][i], opts[:y][i], opts[:alpha][i], opts[:blend][i]) + opts[:range].each do |i| + @cards[i].png(opts[:file][i], opts[:x][i], opts[:y][i], opts[:alpha][i], opts[:blend][i]) bar.increment end end @@ -32,7 +32,7 @@ module Squib # Renders an entire svg file at the given location. Uses the SVG-specified units and DPI to determine the pixel width and height. # # See {file:samples/load-images.rb samples/load-images.rb} and {file:samples/tgc-overlay.rb samples/tgc-overlay.rb} as examples. - # @example + # @example # svg 1..2, 'icon.svg', '#stone', x: 50, y:50 # # @option opts range [Enumerable, :all] (:all) the range of cards over which this will be rendered. See {file:README.md#Specifying_Ranges Specifying Ranges} @@ -54,8 +54,8 @@ module Squib @progress_bar.start("Loading SVG(s)", p[:range].size) do |bar| p[:range].each do |i| 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], - p[:width][i], p[:height][i], p[:alpha][i], p[:blend][i]) + @cards[i].svg(p[:file][i], p[:id][i], p[:x][i], p[:y][i], + p[:width][i], p[:height][i], p[:alpha][i], p[:blend][i]) end bar.increment end diff --git a/lib/squib/api/save.rb b/lib/squib/api/save.rb index 5c61992..b8ef25b 100644 --- a/lib/squib/api/save.rb +++ b/lib/squib/api/save.rb @@ -1,6 +1,6 @@ module Squib class Deck - + # Saves the given range of cards to either PNG or PDF # # @option opts [Enumerable] range (:all) the range of cards over which this will be rendered. See {file:README.md#Specifying_Ranges Specifying Ranges} @@ -16,8 +16,8 @@ module Squib save_pdf(opts) if opts[:format].include? :pdf self end - - # Saves the given range of cards to a PNG + + # Saves the given range of cards to a PNG # # @example # save range: 1..8, dir: '_pnp', prefix: 'bw_' @@ -31,7 +31,7 @@ module Squib def save_png(opts = {}) opts = needs(opts,[:range, :creatable_dir, :prefix, :rotate]) @progress_bar.start("Saving PNGs to #{opts[:dir]}/#{opts[:prefix]}*", @cards.size) do |bar| - opts[:range].each do |i| + opts[:range].each do |i| @cards[i].save_png(i, opts[:dir], opts[:prefix], opts[:rotate], opts[:angle]) bar.increment end diff --git a/lib/squib/api/settings.rb b/lib/squib/api/settings.rb index 69cd25c..3a9eb2c 100644 --- a/lib/squib/api/settings.rb +++ b/lib/squib/api/settings.rb @@ -1,7 +1,7 @@ module Squib class Deck - # Toggle hints globally. + # Toggle hints globally. # # Text hints are rectangles around where the text will be laid out. They are intended to be temporary. # Setting a hint to nil or to :off will disable hints. @see samples/text.rb @@ -9,7 +9,7 @@ module Squib # hint text: :cyan # hint text: :cyan # - # @param [String] text the color of the text hint. To turn off use :off. @see README.md + # @param [String] text the color of the text hint. To turn off use :off. @see README.md # @return [nil] Returns nothing # @api public def hint(text: :off) @@ -17,7 +17,7 @@ module Squib end # Sets various defaults for this deck. Defaults can be overriden by the commands themselves when that command supports it. - # @example + # @example # set font: 'Arial 26' # text 'blah' # in Arial 26 # text 'blah24', font: 'Arial 24' # in Arial 24 @@ -31,7 +31,7 @@ module Squib opts = needs(opts, [:font, :img_dir]) @font = opts[:font][0] #was expanded - just need the first @img_dir = opts[:img_dir] - end + end end end diff --git a/lib/squib/api/shapes.rb b/lib/squib/api/shapes.rb index 2e998f8..9c9af3d 100644 --- a/lib/squib/api/shapes.rb +++ b/lib/squib/api/shapes.rb @@ -1,11 +1,11 @@ module Squib class Deck - + # Draw a rounded rectangle - # - # @example + # + # @example # rect x: 0, y: 0, width: 825, height: 1125, radius: 25 - # + # # Options support Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion} # # @option opts range [Enumerable, :all] (:all) the range of cards over which this will be rendered. See {file:README.md#Specifying_Ranges Specifying Ranges} @@ -26,16 +26,16 @@ module Squib opts = needs(opts, [:range, :x, :y, :width, :height, :rect_radius, :x_radius, :y_radius, :fill_color, :stroke_color, :stroke_width, :layout]) opts[:range].each do |i| - @cards[i].rect(opts[:x][i], opts[:y][i], opts[:width][i], opts[:height][i], - opts[:x_radius][i], opts[:y_radius][i], - opts[:fill_color][i], opts[:stroke_color][i], + @cards[i].rect(opts[:x][i], opts[:y][i], opts[:width][i], opts[:height][i], + opts[:x_radius][i], opts[:y_radius][i], + opts[:fill_color][i], opts[:stroke_color][i], opts[:stroke_width][i]) end end # Draw a circle centered at the given coordinates - # - # @example + # + # @example # circle x: 0, y: 0, radius: 100 # # Options support Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion} @@ -54,14 +54,14 @@ module Squib opts = needs(opts, [:range, :x, :y, :circle_radius, :layout, :fill_color, :stroke_color, :stroke_width]) opts[:range].each do |i| - @cards[i].circle(opts[:x][i], opts[:y][i], opts[:radius][i], + @cards[i].circle(opts[:x][i], opts[:y][i], opts[:radius][i], opts[:fill_color][i], opts[:stroke_color][i], opts[:stroke_width][i]) end end # Draw a triangle using the given coordinates - # - # @example + # + # @example # triangle :x1 => 0, :y1 => 0, :x2 => 50, :y2 => 50, :x3 => 0, :y3 => 50 # # Options support Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion} @@ -82,17 +82,17 @@ module Squib opts = needs(opts, [:range, :x1, :y1, :x2, :y2, :x3, :y3, :layout, :fill_color, :stroke_color, :stroke_width]) opts[:range].each do |i| - @cards[i].triangle(opts[:x1][i], opts[:y1][i], - opts[:x2][i], opts[:y2][i], - opts[:x3][i], opts[:y3][i], - opts[:fill_color][i], opts[:stroke_color][i], + @cards[i].triangle(opts[:x1][i], opts[:y1][i], + opts[:x2][i], opts[:y2][i], + opts[:x3][i], opts[:y3][i], + opts[:fill_color][i], opts[:stroke_color][i], opts[:stroke_width][i]) end end # Draw a line using the given coordinates - # - # @example + # + # @example # triangle :x1 => 0, :y1 => 0, :x2 => 50, :y2 => 50 # # @option opts range [Enumerable, :all] (:all) the range of cards over which this will be rendered. See {file:README.md#Specifying_Ranges Specifying Ranges} @@ -112,6 +112,6 @@ module Squib opts[:stroke_color][i], opts[:stroke_width][i]) end end - + end end \ No newline at end of file diff --git a/lib/squib/api/text.rb b/lib/squib/api/text.rb index 8f69c58..af57fff 100644 --- a/lib/squib/api/text.rb +++ b/lib/squib/api/text.rb @@ -3,20 +3,20 @@ module Squib # Renders a string at a given location, width, alignment, font, etc. # - # Unix-like newlines are interpreted even on Windows. + # Unix-like newlines are interpreted even on Windows. # See the {file:samples/text-options.rb samples/text.rb} for a lengthy example. # - # @example + # @example # text str: 'hello' # text str: 'hello', x: 50, y:50, align: center - # + # # Options support Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion} # # @option opts range [Enumerable, :all] (:all) the range of cards over which this will be rendered. See {file:README.md#Specifying_Ranges Specifying Ranges} # @option opts str [String, Array] ('') the string to be rendered. Must support `#to_s`. If the card responds to `#each`, it's mapped out one at a time across the cards. # @option opts font [String] (Arial 36 or whatever was set with `set`) the Font description string, including family, styles, and size. # (e.g. `'Arial bold italic 12'`) - # For the official documentation, see the [Pango docs](http://ruby-gnome2.sourceforge.jp/hiki.cgi?Pango%3A%3AFontDescription#style). + # For the official documentation, see the [Pango docs](http://ruby-gnome2.sourceforge.jp/hiki.cgi?Pango%3A%3AFontDescription#style). # This [description](http://www.pygtk.org/pygtk2reference/class-pangofontdescription.html) is also quite good. # See the {file:samples/text-options.rb samples/text.rb} as well. # @option opts font_size [Integer] (nil) an override of font string description, for scaling the font according to the size of the string @@ -27,15 +27,15 @@ module Squib # @option opts width [Integer, :native] (:native) the width of the box the string will be placed in. Stretches to the content by default. # @option opts height [Integer, :native] the height of the box the string will be placed in. Stretches to the content by default. # @option opts layout [String, Symbol] (nil) entry in the layout to use as defaults for this command. See {file:README.md#Custom_Layouts Custom Layouts} - # @option opts wrap [:none, :word, :char, :word_char, true, false] (:word_char) When height is set, determines the behavior of how the string wraps. The `:word_char` option will break at words, but then fall back to characters when the word cannot fit. # + # @option opts wrap [:none, :word, :char, :word_char, true, false] (:word_char) When height is set, determines the behavior of how the string wraps. The `:word_char` option will break at words, but then fall back to characters when the word cannot fit. # # Options are `:none, :word, :char, :word_char`. Also: `true` is the same as `:word_char`, `false` is the same as `:none`. Default `:word_char` # @option opts spacing [Integer] (0) Adjust the spacing when the text is multiple lines. No effect when the text does not wrap. # @option opts align [:left, right, :center] (:left) The alignment of the text - # @option opts justify [Boolean] (false) toggles whether or not the text is justified or not. + # @option opts justify [Boolean] (false) toggles whether or not the text is justified or not. # @option opts valign [:top, :middle, :bottom] (:top) When width and height are set, align text vertically according to the ink extents of the text. # @option opts ellipsize [:none, :start, :middle, :end, true, false] (:end) When width and height are set, determines the behavior of overflowing text. Also: `true` maps to `:end` and `false` maps to `:none`. Default `:end` - # @option opts angle [FixNum] (0) Rotation of the text in radians. - # @option opts hint [String] (:nil) draw a rectangle around the text with the given color. Overrides global hints (see {Deck#hint}). + # @option opts angle [FixNum] (0) Rotation of the text in radians. + # @option opts hint [String] (:nil) draw a rectangle around the text with the given color. Overrides global hints (see {Deck#hint}). # @return [nil] Returns nothing # @api public def text(opts = {}) @@ -44,8 +44,8 @@ module Squib opts[:range].each do |i| @cards[i].text(opts[:str][i], opts[:font][i], opts[:font_size][i], opts[:color][i], opts[:x][i], opts[:y][i], opts[:width][i], opts[:height][i], - opts[:markup][i], opts[:justify][i], opts[:wrap][i], - opts[:ellipsize][i], opts[:spacing][i], opts[:align][i], + opts[:markup][i], opts[:justify][i], opts[:wrap][i], + opts[:ellipsize][i], opts[:spacing][i], opts[:align][i], opts[:valign][i], opts[:hint][i], opts[:angle][i]) end end diff --git a/lib/squib/api/units.rb b/lib/squib/api/units.rb index 7dfcbed..ee608b3 100644 --- a/lib/squib/api/units.rb +++ b/lib/squib/api/units.rb @@ -2,8 +2,8 @@ module Squib class Deck # Given inches, returns the number of pixels according to the deck's DPI. - # - # @example + # + # @example # inches(2.5) # 750 (for default Deck::dpi of 300) # # @param [Decimal] n, the number of inches diff --git a/lib/squib/card.rb b/lib/squib/card.rb index ae818b7..294e014 100644 --- a/lib/squib/card.rb +++ b/lib/squib/card.rb @@ -7,15 +7,15 @@ module Squib include Squib::InputHelpers # :nodoc: - # @api private + # @api private attr_reader :width, :height # :nodoc: - # @api private + # @api private attr_accessor :cairo_surface, :cairo_context # :nodoc: - # @api private + # @api private def initialize(deck, width, height) @deck=deck; @width=width; @height=height @cairo_surface = Cairo::ImageSurface.new(width,height) @@ -37,6 +37,6 @@ module Squib require 'squib/graphics/save_images' require 'squib/graphics/shapes' require 'squib/graphics/text' - + end end \ No newline at end of file diff --git a/lib/squib/commands/new.rb b/lib/squib/commands/new.rb index 8db42f5..f1907f3 100644 --- a/lib/squib/commands/new.rb +++ b/lib/squib/commands/new.rb @@ -6,9 +6,9 @@ module Squib # Generate a new Squib project into a fresh directory. # - # Provides conventions for using Git (you are using version control, right??). + # Provides conventions for using Git (you are using version control, right??). # Also provides some basic layout and config files to start from, along with templates for instructions and other notes you don't want to forget. - # + # # # @example # squib new foo-blasters @@ -22,7 +22,7 @@ module Squib class New # :nodoc: - # @api private + # @api private def process(args) raise ArgumentError.new('Please specify a path.') if args.empty? diff --git a/lib/squib/constants.rb b/lib/squib/constants.rb index 7d0abfb..36dee2b 100644 --- a/lib/squib/constants.rb +++ b/lib/squib/constants.rb @@ -1,8 +1,8 @@ module Squib # Squib's defaults for when arguments are not specified in the command nor layouts. - # + # # @api public - SYSTEM_DEFAULTS = { + SYSTEM_DEFAULTS = { :align => :left, :alpha => 1.0, :angle => 0, @@ -40,7 +40,7 @@ module Squib :x1 => 100, :x2 => 150, :x3 => 100, - :x_radius => 0, + :x_radius => 0, :y => 0, :y1 => 100, :y2 => 150, @@ -49,9 +49,9 @@ module Squib } # Squib's configuration defaults - # + # # @api public - CONFIG_DEFAULTS = { + CONFIG_DEFAULTS = { 'custom_colors' => {}, 'dpi' => 300, 'hint' => :none, @@ -59,8 +59,8 @@ module Squib 'img_dir' => '.', } - # These are parameters that are intended to be "expanded" across - # range if they are singletons. + # These are parameters that are intended to be "expanded" across + # range if they are singletons. # # For example, using a different font for each card, using one `text` # diff --git a/lib/squib/deck.rb b/lib/squib/deck.rb index 9a43e2c..1b94ee3 100644 --- a/lib/squib/deck.rb +++ b/lib/squib/deck.rb @@ -19,37 +19,37 @@ module Squib include Squib::InputHelpers # :nodoc: - # @api private + # @api private attr_reader :width, :height - + # :nodoc: - # @api private + # @api private attr_reader :cards - + # :nodoc: - # @api private + # @api private attr_reader :text_hint # :nodoc: - # @api private + # @api private attr_reader :layout, :config # Squib's constructor that sets the immutable properties. # - # This is the starting point for Squib. In providing a block to the constructor, you have access to all of Deck's instance methods. - # The documented methods in Deck are the ones intended for use by most users. + # This is the starting point for Squib. In providing a block to the constructor, you have access to all of Deck's instance methods. + # The documented methods in Deck are the ones intended for use by most users. # If your game requires multiple different sizes or orientations, I recommend using multiple `Squib::Deck`s in your `deck.rb`. You can modify the internals of `Squib::Deck` (e.g. `@cards`), but that's not recommended. - # @example + # @example # require 'squib' # Squib::Deck.new do # text str: 'Hello, World!' # end - # - # @param width: [Integer] the width of each card in pixels - # @param height: [Integer] the height of each card in pixels - # @param cards: [Integer] the number of cards in the deck - # @param dpi: [Integer] the pixels per inch when rendering out to PDF or calculating using inches. - # @param config: [String] the file used for global settings of this deck + # + # @param width [Integer] the width of each card in pixels + # @param height [Integer] the height of each card in pixels + # @param cards [Integer] the number of cards in the deck + # @param dpi [Integer] the pixels per inch when rendering out to PDF or calculating using inches. + # @param config [String] the file used for global settings of this deck # @param block [Block] the main body of the script. # @api public def initialize(width: 825, height: 1125, cards: 1, dpi: 300, config: 'config.yml', layout: nil, &block) @@ -77,7 +77,7 @@ module Squib end # Iterates over each card in the deck - # + # # @api private def each(&block) @cards.each { |card| block.call(card) } @@ -129,10 +129,10 @@ module Squib parent_val + child_val.sub("+=",'').strip.to_f elsif child_val.to_s.strip.start_with?('-=') parent_val - child_val.sub("-=",'').strip.to_f - else + else child_val #child overrides parent when merging, no += end - end + end h = h.merge(from_extends) do |key, older_sibling, younger_sibling| younger_sibling #when two siblings have the same entry, the "younger" (lower one) overrides end diff --git a/lib/squib/graphics/background.rb b/lib/squib/graphics/background.rb index 19d816d..a8cbeb6 100644 --- a/lib/squib/graphics/background.rb +++ b/lib/squib/graphics/background.rb @@ -2,13 +2,13 @@ module Squib class Card # :nodoc: - # @api private + # @api private def background(color) use_cairo do |cc| cc.set_source_color(color) cc.paint end end - + end end \ No newline at end of file diff --git a/lib/squib/graphics/image.rb b/lib/squib/graphics/image.rb index 07d267b..ef96aae 100644 --- a/lib/squib/graphics/image.rb +++ b/lib/squib/graphics/image.rb @@ -1,7 +1,7 @@ module Squib # Cache all pngs we've already loaded - # + # # :nodoc: # @api private def cache_load_image(file) @@ -13,7 +13,7 @@ module Squib class Card # :nodoc: - # @api private + # @api private def png(file, x, y, alpha, blend) return if file.nil? or file.eql? '' png = Squib.cache_load_image(file) @@ -25,7 +25,7 @@ module Squib end # :nodoc: - # @api private + # @api private def svg(file, id, x, y, width, height, alpha, blend) Squib.logger.debug {"Rendering: #{file}, #{id} #{x}, #{y}, #{width}, #{height}, #{alpha}, #{blend}"} return if file.nil? or file.eql? '' diff --git a/lib/squib/graphics/save_doc.rb b/lib/squib/graphics/save_doc.rb index 50ac5f1..f99ae76 100644 --- a/lib/squib/graphics/save_doc.rb +++ b/lib/squib/graphics/save_doc.rb @@ -9,7 +9,7 @@ module Squib # @option opts file [String] the name of the PDF file to save. See {file:README.md#Specifying_Files Specifying Files} # @option opts dir [String] (_output) the directory to save to. Created if it doesn't exist. # @option opts margin [Integer] (75) the margin around the outside of the page - # @option opts gap [Integer] (0) the space in pixels between the cards + # @option opts gap [Integer] (0) the space in pixels between the cards # @option opts trim [Integer] (0) the space around the edge of each card to trim (e.g. to cut off the bleed margin for print-and-play) # @return [nil] # @api public @@ -39,7 +39,7 @@ module Squib end # :nodoc: - # @api private + # @api private def trim(surface, trim, width, height) if trim > 0 tmp = Cairo::ImageSurface.new(width-2*trim, height-2*trim) diff --git a/lib/squib/graphics/save_images.rb b/lib/squib/graphics/save_images.rb index 55c26c4..936a389 100644 --- a/lib/squib/graphics/save_images.rb +++ b/lib/squib/graphics/save_images.rb @@ -2,7 +2,7 @@ module Squib class Card # :nodoc: - # @api private + # @api private def save_png(i, dir, prefix, do_rotate, angle) if [true, :clockwise, :counterclockwise].include?(do_rotate) surface = rotated_image(angle) @@ -24,7 +24,7 @@ module Squib rotated_cc.target end # :nodoc: - # @api private + # @api private def write_png(surface, i, dir, prefix) surface.write_to_png("#{dir}/#{prefix}#{i}.png") end diff --git a/lib/squib/graphics/shapes.rb b/lib/squib/graphics/shapes.rb index 1c42591..3cd3ae9 100644 --- a/lib/squib/graphics/shapes.rb +++ b/lib/squib/graphics/shapes.rb @@ -1,8 +1,8 @@ module Squib class Card - + # :nodoc: - # @api private + # @api private def rect(x, y, width, height, x_radius, y_radius, fill_color, stroke_color, stroke_width) width=@width if width==:native; height=@height if height==:native use_cairo do |cc| @@ -17,7 +17,7 @@ module Squib end # :nodoc: - # @api private + # @api private def circle(x, y, radius, fill_color, stroke_color, stroke_width) use_cairo do |cc| cc.circle(x, y, radius) @@ -31,7 +31,7 @@ module Squib end # :nodoc: - # @api private + # @api private def triangle(x1, y1, x2, y2, x3, y3, fill_color, stroke_color, stroke_width) use_cairo do |cc| cc.triangle(x1, y1, x2, y2, x3, y3) @@ -45,7 +45,7 @@ module Squib end # :nodoc: - # @api private + # @api private def line(x1, y1, x2, y2, stroke_color, stroke_width) use_cairo do |cc| cc.move_to(x1, y1) @@ -55,6 +55,6 @@ module Squib cc.stroke end end - + end end \ No newline at end of file diff --git a/lib/squib/graphics/text.rb b/lib/squib/graphics/text.rb index c38b1fe..21cd405 100644 --- a/lib/squib/graphics/text.rb +++ b/lib/squib/graphics/text.rb @@ -4,7 +4,7 @@ module Squib class Card # :nodoc: - # @api private + # @api private def draw_text_hint(cc,x,y,layout, color,angle) color = @deck.text_hint if color.to_s.eql? 'off' and not @deck.text_hint.to_s.eql? 'off' return if color.to_s.eql? 'off' or color.nil? @@ -22,7 +22,7 @@ module Squib end # :nodoc: - # @api private + # @api private def ellipsize(layout, ellipsize) unless ellipsize.nil? h = { :none => Pango::Layout::ELLIPSIZE_NONE, @@ -38,7 +38,7 @@ module Squib end # :nodoc: - # @api private + # @api private def wrap(layout, wrap) unless wrap.nil? h = { :word => Pango::Layout::WRAP_WORD, @@ -54,7 +54,7 @@ module Squib end # :nodoc: - # @api private + # @api private def align(layout, align) unless align.nil? h = { :left => Pango::ALIGN_LEFT, @@ -67,9 +67,9 @@ module Squib end # :nodoc: - # @api private + # @api private def valign(cc, layout, x, y, valign) - if layout.height > 0 + if layout.height > 0 ink_extents = layout.extents[1] case valign when :middle @@ -81,7 +81,7 @@ module Squib end # :nodoc: - # @api private + # @api private def setwh(layout, width, height) layout.width = width * Pango::SCALE unless width.nil? || width == :native layout.height = height * Pango::SCALE unless height.nil? || height == :native @@ -89,17 +89,17 @@ module Squib end # :nodoc: - # @api private - def text(str, font, font_size, color, + # @api private + def text(str, font, font_size, color, x, y, width, height, - markup, justify, wrap, ellipsize, + markup, justify, wrap, ellipsize, spacing, align, valign, hint, angle) Squib.logger.debug {"Placing '#{str}'' with font '#{font}' @ #{x}, #{y}, color: #{color}, angle: #{angle} etc."} use_cairo do |cc| cc.set_source_color(color) cc.move_to(x,y) cc.rotate(angle) - + layout = cc.create_pango_layout font_desc = Pango::FontDescription.new(font) font_desc.size = font_size * Pango::SCALE unless font_size.nil? @@ -111,8 +111,8 @@ module Squib layout = ellipsize(layout, ellipsize) layout = align(layout, align) layout.justify = justify unless justify.nil? - layout.spacing = spacing * Pango::SCALE unless spacing.nil? - cc.update_pango_layout(layout) + layout.spacing = spacing * Pango::SCALE unless spacing.nil? + cc.update_pango_layout(layout) valign(cc, layout, x,y, valign) cc.update_pango_layout(layout) ; cc.show_pango_layout(layout) draw_text_hint(cc,x,y,layout,hint,angle) diff --git a/lib/squib/input_helpers.rb b/lib/squib/input_helpers.rb index b42fe8a..0e8ea84 100644 --- a/lib/squib/input_helpers.rb +++ b/lib/squib/input_helpers.rb @@ -12,7 +12,7 @@ module Squib opts = layoutify(opts) if params.include? :layout opts = Squib::SYSTEM_DEFAULTS.merge(opts) opts = expand_singletons(opts, params) - opts = rangeify(opts) if params.include? :range + opts = rangeify(opts) if params.include? :range opts = fileify(opts) if params.include? :file opts = fileify(opts, false) if params.include? :file_to_save opts = colorify(opts, true) if params.include? :nillable_color @@ -37,7 +37,7 @@ module Squib Squib::EXPANDING_PARAMS.each_pair do |param_name, api_param| if needed_params.include? param_name unless opts[api_param].respond_to?(:each) - opts[api_param] = [opts[api_param]] * @cards.size + opts[api_param] = [opts[api_param]] * @cards.size end end end @@ -50,8 +50,8 @@ module Squib # :nodoc: # @api private def layoutify(opts) - unless opts[:layout].respond_to?(:each) - opts[:layout] = [opts[:layout]] * @cards.size + unless opts[:layout].respond_to?(:each) + opts[:layout] = [opts[:layout]] * @cards.size end opts[:layout].each_with_index do |layout, i| unless layout.nil? @@ -61,7 +61,7 @@ module Squib opts[key.to_sym] = [] if opts[key.to_sym].nil? opts[key.to_sym][i] ||= entry[key] #don't override if it's already there end - else + else Squib.logger.warn ("Layout entry '#{layout}' does not exist." ) end end @@ -99,7 +99,7 @@ module Squib # @api private def fileify(opts, file_must_exist=true) [opts[:file]].flatten.each do |file| - if file_must_exist and !File.exists?(file) + if file_must_exist and !File.exists?(file) raise "File #{File.expand_path(file)} does not exist!" end end @@ -114,7 +114,7 @@ module Squib if allow_create Squib.logger.warn {"Dir #{opts[key]} does not exist, creating it."} Dir.mkdir opts[key] - return opts + return opts else raise "'#{opts[key]}' does not exist!" end @@ -145,14 +145,14 @@ module Squib opts[:font][i] = Squib::SYSTEM_DEFAULTS[:default_font] if font == :default end Squib.logger.debug {"After fontify: #{opts}"} - opts + opts end - module_function :fontify + module_function :fontify # :nodoc: # @api private def radiusify(opts) - opts[:radius].each_with_index do |radius, i| + opts[:radius].each_with_index do |radius, i| unless radius.nil? opts[:x_radius][i] = radius opts[:y_radius][i] = radius diff --git a/lib/squib/progress.rb b/lib/squib/progress.rb index 664d594..504672b 100644 --- a/lib/squib/progress.rb +++ b/lib/squib/progress.rb @@ -25,10 +25,10 @@ module Squib def start(title="", total=100, &block) 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) @bar.finish - else + else yield(Squib::DoNothing.new) end end diff --git a/lib/squib/project_template/deck.rb b/lib/squib/project_template/deck.rb index 8bdd792..dfec7bc 100644 --- a/lib/squib/project_template/deck.rb +++ b/lib/squib/project_template/deck.rb @@ -1,6 +1,6 @@ require 'squib' -Squib::Deck.new(cards: 3, layout: 'layout.yml') do +Squib::Deck.new(cards: 3, layout: 'layout.yml') do text str: "Hello, World!" save format: :png end \ No newline at end of file diff --git a/lib/squib/version.rb b/lib/squib/version.rb index 301fc99..6c18c96 100644 --- a/lib/squib/version.rb +++ b/lib/squib/version.rb @@ -3,8 +3,8 @@ module Squib # The next version to be released. # Uses semantic versioning: http://semver.org/ # - # 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 - # + # VERSION = "0.0.5a" end diff --git a/samples/autoscale_font.rb b/samples/autoscale_font.rb index 3186c46..0e5202f 100644 --- a/samples/autoscale_font.rb +++ b/samples/autoscale_font.rb @@ -1,7 +1,7 @@ require 'squib' -# Here's an exmaple of being able to scale a font -# based on the length of individual string. +# Here's an exmaple of being able to scale a font +# based on the length of individual string. # Handy for making minor font scales to fill text boxes. def autoscale(str_array) str_array.inject([]) do | memo, str | @@ -21,7 +21,7 @@ Squib::Deck.new(cards: 3) do title = %w(ShortBig Medium_Length_Name Super_Duper_Long_Name) text str: title, x: 65, y: 400, align: :center, width: 700, - font: 'Arial', font_size: autoscale(title), hint: :red + font: 'Arial', font_size: autoscale(title), hint: :red save prefix: 'autoscale_', format: :png end \ No newline at end of file diff --git a/samples/basic.rb b/samples/basic.rb index 1e90272..e7b28b2 100644 --- a/samples/basic.rb +++ b/samples/basic.rb @@ -1,7 +1,7 @@ #!/usr/bin/env ruby require 'squib' -data = {'name' => ['Thief', 'Grifter', 'Mastermind'], +data = {'name' => ['Thief', 'Grifter', 'Mastermind'], 'level' => [1,2,3]} Squib::Deck.new(width: 825, height: 1125, cards: 3) do @@ -10,7 +10,7 @@ Squib::Deck.new(width: 825, height: 1125, cards: 3) do rect x: 75, y: 75, width: 128, height: 128, radius: 25 text str: data['name'], x: 220, y: 78, font: 'Arial 54' - text str: data['level'], x: 75, y: 85, width: 128, + text str: data['level'], x: 75, y: 85, width: 128, font: 'Arial 72', align: :center png range: [0,2], file: 'shiny-purse.png', x: 620, y: 75 diff --git a/samples/custom-layout.yml b/samples/custom-layout.yml index 6145920..1fc849f 100644 --- a/samples/custom-layout.yml +++ b/samples/custom-layout.yml @@ -1,4 +1,4 @@ -frame: +frame: x: 38 y: 38 width: 750 @@ -10,7 +10,7 @@ title: width: 625 height: 100 align: !ruby/symbol center #see http://www.yaml.org/YAML_for_ruby.html#symbols - valign: !ruby/symbol middle + valign: !ruby/symbol middle subtitle: x: 150 y: 150 @@ -37,15 +37,15 @@ icon_right: # Called "extends" # Any layout can extend another layout, so long as it's not a circle # Order doesn't matter since it's done after YAML procesing -# And, if the entry overrides +# And, if the entry overrides bonus: #becomes our bonus rectangle x: 250 y: 600 width: 300 height: 200 radius: 32 -bonus_inner: - extends: bonus +bonus_inner: + extends: bonus x: += 10 # i.e. 260 y: += 10 # i.e. 610 width: -= 20 # i.e. 180 diff --git a/samples/custom_config.rb b/samples/custom_config.rb index 5637381..54c1265 100644 --- a/samples/custom_config.rb +++ b/samples/custom_config.rb @@ -3,7 +3,7 @@ require 'squib' Squib::Deck.new(config: 'custom-config.yml') do # Custom color defined in our config - background color: :foo + background color: :foo # Hints are turned on in the config file text str: "The Title", x: 0, y: 78, width: 825, diff --git a/samples/draw_shapes.rb b/samples/draw_shapes.rb index 2fdfa3e..f3260f9 100644 --- a/samples/draw_shapes.rb +++ b/samples/draw_shapes.rb @@ -1,19 +1,19 @@ require 'squib' -Squib::Deck.new do - rect x: 300, y: 300, width: 400, height: 400, +Squib::Deck.new do + rect x: 300, y: 300, width: 400, height: 400, fill_color: :blue, stroke_color: :red, stroke_width: 50.0 circle x: 600, y: 600, radius: 75, - fill_color: :gray, stroke_color: :green, stroke_width: 8.0 + fill_color: :gray, stroke_color: :green, stroke_width: 8.0 - triangle x1: 50, y1: 50, - x2: 150, y2: 150, + triangle x1: 50, y1: 50, + x2: 150, y2: 150, x3: 75, y3: 250 - line x1: 50, y1: 550, + line x1: 50, y1: 550, x2: 150, y2: 650, - stroke_width: 25.0 + stroke_width: 25.0 save_png prefix: 'shape_' end \ No newline at end of file diff --git a/samples/hello_world.rb b/samples/hello_world.rb index 2de558d..df90e1a 100644 --- a/samples/hello_world.rb +++ b/samples/hello_world.rb @@ -2,6 +2,6 @@ require 'squib' Squib::Deck.new do - text str: 'Hello, World!' + text str: 'Hello, World!' save_png end \ No newline at end of file diff --git a/samples/load_images.rb b/samples/load_images.rb index 7f87a59..12add04 100644 --- a/samples/load_images.rb +++ b/samples/load_images.rb @@ -19,7 +19,7 @@ Squib::Deck.new(width: 825, height: 1125, cards: 1) do # relative to the SVG page. See this example in an SVG editor svg file: 'offset.svg', id: 'thing', x: 0, y: 0, width: 600, height: 600 - # Over 15 different blending operators are supported. + # Over 15 different blending operators are supported. # See http://cairographics.org/operators # Alpha transparency too png file: 'ball.png', x: 50, y: 700 diff --git a/samples/portrait-landscape.rb b/samples/portrait-landscape.rb index 837b7b8..933caba 100644 --- a/samples/portrait-landscape.rb +++ b/samples/portrait-landscape.rb @@ -1,11 +1,11 @@ require 'squib' # For decks with both landscape and portrait orientations, -# we recommend using two separate decks. +# we recommend using two separate decks. # For print-on-demand, we can rotate all of the images in the final step. # Normal cards -Squib::Deck.new(width: 825, height: 1125) do +Squib::Deck.new(width: 825, height: 1125) do background color: '#aaa' text str: "This is portrait" diff --git a/samples/ranges.rb b/samples/ranges.rb index 42d53e6..92934bc 100644 --- a/samples/ranges.rb +++ b/samples/ranges.rb @@ -1,7 +1,7 @@ #!/usr/bin/env ruby require 'squib' -data = {'name' => ['Thief', 'Grifter', 'Mastermind'], +data = {'name' => ['Thief', 'Grifter', 'Mastermind'], 'type' => ['Thug', 'Thinker', 'Thinker'], 'level' => [1,2,3]} @@ -12,8 +12,8 @@ Squib::Deck.new(width: 825, height: 1125, cards: 3) do text str: data['level'], x: 65, y: 40, font: 'Arial 72' # Could be explicit about using :all, too - text range: :all, - str: data['type'], x: 40, y: 128, font: 'Arial 18', + text range: :all, + str: data['type'], x: 40, y: 128, font: 'Arial 18', width: 100, align: :center # Ranges are inclusive, zero-based @@ -40,16 +40,16 @@ Squib::Deck.new(width: 825, height: 1125, cards: 3) do # Useful idiom: construct a hash from card names back to its index (ID), # 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} - text range: id['Thief']..id['Grifter'], - str: "Thief through Grifter with id lookup!!", + text range: id['Thief']..id['Grifter'], + str: "Thief through Grifter with id lookup!!", x:25, y: 400 # Useful idiom: generate arrays from a column called 'type' type = {}; data['type'].each_with_index{ |t,i| (type[t] ||= []) << i} - text range: type['Thinker'], - str: "Only for Thinkers!", + text range: type['Thinker'], + str: "Only for Thinkers!", x:25, y: 500 - + save prefix: 'ranges_', format: :png end diff --git a/samples/text_options.rb b/samples/text_options.rb index 2c8cee5..5390055 100644 --- a/samples/text_options.rb +++ b/samples/text_options.rb @@ -1,7 +1,7 @@ #!/usr/bin/env ruby require 'squib' -data = {'name' => ['Thief', 'Grifter', 'Mastermind'], +data = {'name' => ['Thief', 'Grifter', 'Mastermind'], 'level' => [1,2,3]} longtext = "This is left-justified text.\nWhat do you know about tweetle beetles? well... \nWhen tweetle beetles fight, it's called a tweetle beetle battle. And when they battle in a puddle, it's a tweetle beetle puddle battle. AND when tweetle beetles battle with paddles in a puddle, they call it a tweetle beetle puddle paddle battle. AND... When beetles battle beetles in a puddle paddle battle and the beetle battle puddle is a puddle in a bottle... ..they call this a tweetle beetle bottle puddle paddle battle muddle. AND... When beetles fight these battles in a bottle with their paddles and the bottle's on a poodle and the poodle's eating noodles... ...they call this a muddle puddle tweetle poodle beetle noodle bottle paddle battle." @@ -25,7 +25,7 @@ Squib::Deck.new(width: 825, height: 1125, cards: 3) do text str: "Font string sizes can be overridden per card.", x: 65, y: 350, 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, x: 65, y: 400, width: 300, height: 200, @@ -52,16 +52,16 @@ Squib::Deck.new(width: 825, height: 1125, cards: 3) do font: 'Arial 18' text str: longtext, font: 'Arial 16', - x: 65, y: 700, - width: inches(2.25), height: inches(1), + x: 65, y: 700, + width: inches(2.25), height: inches(1), justify: true - text str: "Markup is also quite easy awesome", + text str: "Markup is also quite easy awesome", markup: true, x: 50, y: 1000, - width: 750, height: 100, + width: 750, height: 100, valign: :bottom, font: 'Arial 32', hint: :cyan - + save prefix: 'text_', format: :png end diff --git a/samples/tgc_proofs.rb b/samples/tgc_proofs.rb index 7c799ce..fcdfb4e 100644 --- a/samples/tgc_proofs.rb +++ b/samples/tgc_proofs.rb @@ -2,7 +2,7 @@ require 'squib' # This sample uses a proof overlay from TheGameCrafter.com to check bleed -Squib::Deck.new(width: 825, height: 1125, cards: 1) do +Squib::Deck.new(width: 825, height: 1125, cards: 1) do background color: :white rect x: 38, y: 38, width: 750, height: 1050, x_radius: 38, y_radius: 38 rect x: 75, y: 75, width: 128, height: 128, x_radius: 25, y_radius: 25 @@ -15,6 +15,6 @@ Squib::Deck.new(width: 825, height: 1125, cards: 1) do # TGC proof overlay png file: 'pokercard.png', x:0, y:0, alpha: 0.5 - + save_png prefix: 'tgc_sample_' end \ No newline at end of file diff --git a/samples/use_layout.rb b/samples/use_layout.rb index b00554b..913a4e0 100644 --- a/samples/use_layout.rb +++ b/samples/use_layout.rb @@ -1,6 +1,6 @@ require 'squib' -Squib::Deck.new(layout: 'custom-layout.yml') do +Squib::Deck.new(layout: 'custom-layout.yml') do background color: :white hint text: :cyan @@ -29,6 +29,6 @@ Squib::Deck.new(layout: 'custom-layout.yml') do # For debugging purposes, you can always print out the loaded layout #require 'pp' #pp @layout - + save_png prefix: 'layout_' end \ No newline at end of file diff --git a/spec/api/api_text_spec.rb b/spec/api/api_text_spec.rb index 3b06d36..00b1fbf 100644 --- a/spec/api/api_text_spec.rb +++ b/spec/api/api_text_spec.rb @@ -6,22 +6,22 @@ describe Squib::Deck, '#text' do context "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', 'Arial 36', + expect(card).to receive(:text).with('a', 'Arial 36', anything, anything, anything,anything,anything,anything, anything, anything, anything,anything, anything, anything, anything, anything, anything ).once - Squib::Deck.new do - @cards = [card] + 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', + expect(card).to receive(:text).with('a', 'Times New Roman 16', anything, anything, anything, anything,anything,anything, anything, anything, anything,anything, anything, anything, anything, anything, anything ).once - Squib::Deck.new do - @cards = [card] + Squib::Deck.new do + @cards = [card] set font: 'Times New Roman 16' text str: 'a' end @@ -29,11 +29,11 @@ describe Squib::Deck, '#text' do it "should use the specified font no matter what" do 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 ).once - Squib::Deck.new do - @cards = [card] + Squib::Deck.new do + @cards = [card] set font: 'Times New Roman 16' text str: 'a', font: 'Arial 18' end diff --git a/spec/commands/new_spec.rb b/spec/commands/new_spec.rb index 3a5819c..1c87677 100644 --- a/spec/commands/new_spec.rb +++ b/spec/commands/new_spec.rb @@ -1,9 +1,9 @@ require 'spec_helper' require 'squib' -describe Squib::Commands::New do +describe Squib::Commands::New do - describe "#process" do + describe "#process" do before(:all) do @old_stderr = $stderr $stderr = StringIO.new @@ -44,5 +44,5 @@ describe Squib::Commands::New do Dir.chdir(@oldpwd) end end - + end \ No newline at end of file diff --git a/spec/data/easy-circular-extends.yml b/spec/data/easy-circular-extends.yml index ccfc559..43ca217 100644 --- a/spec/data/easy-circular-extends.yml +++ b/spec/data/easy-circular-extends.yml @@ -1,4 +1,4 @@ -a: +a: extends: b x: 50 b: diff --git a/spec/data/hard-circular-extends.yml b/spec/data/hard-circular-extends.yml index 6ef16fc..1c3f5a2 100644 --- a/spec/data/hard-circular-extends.yml +++ b/spec/data/hard-circular-extends.yml @@ -1,9 +1,9 @@ -a: +a: extends: c x: 50 b: extends: a x: 150 -c: +c: extends: b y: 250 \ No newline at end of file diff --git a/spec/data/multi-extends-single-entry.yml b/spec/data/multi-extends-single-entry.yml index 805c98b..0dfdd14 100644 --- a/spec/data/multi-extends-single-entry.yml +++ b/spec/data/multi-extends-single-entry.yml @@ -1,13 +1,13 @@ -aunt: +aunt: a: 101 b: 102 c: 103 -uncle: +uncle: x: 104 y: 105 b: 106 child: - extends: + extends: - uncle - aunt a: 107 diff --git a/spec/data/multi-level-extends.yml b/spec/data/multi-level-extends.yml index 9f8867e..78dd517 100644 --- a/spec/data/multi-level-extends.yml +++ b/spec/data/multi-level-extends.yml @@ -1,4 +1,4 @@ -frame: +frame: x: 38 y: 38 title: diff --git a/spec/data/no-extends.yml b/spec/data/no-extends.yml index 3881f3e..776a0fa 100644 --- a/spec/data/no-extends.yml +++ b/spec/data/no-extends.yml @@ -1,5 +1,5 @@ -frame: +frame: x: 38 - valign: !ruby/symbol middle + valign: !ruby/symbol middle str: "blah" font: Mr. Font diff --git a/spec/data/pre-extends.yml b/spec/data/pre-extends.yml index 753cd5a..ab4ded3 100644 --- a/spec/data/pre-extends.yml +++ b/spec/data/pre-extends.yml @@ -2,6 +2,6 @@ title: extends: frame y: 50 width: 100 -frame: +frame: x: 38 y: 38 diff --git a/spec/data/self-circular-extends.yml b/spec/data/self-circular-extends.yml index f988d3b..8ac1806 100644 --- a/spec/data/self-circular-extends.yml +++ b/spec/data/self-circular-extends.yml @@ -1,3 +1,3 @@ -a: +a: extends: a x: 50 diff --git a/spec/data/single-extends.yml b/spec/data/single-extends.yml index 2788822..dea30a8 100644 --- a/spec/data/single-extends.yml +++ b/spec/data/single-extends.yml @@ -1,4 +1,4 @@ -frame: +frame: x: 38 y: 38 title: diff --git a/spec/data/single-level-multi-extends.yml b/spec/data/single-level-multi-extends.yml index 6cbd349..64169e8 100644 --- a/spec/data/single-level-multi-extends.yml +++ b/spec/data/single-level-multi-extends.yml @@ -1,4 +1,4 @@ -frame: +frame: x: 38 y: 38 title: diff --git a/spec/deck_spec.rb b/spec/deck_spec.rb index 43d7719..99b83f7 100644 --- a/spec/deck_spec.rb +++ b/spec/deck_spec.rb @@ -1,10 +1,10 @@ require 'spec_helper' require 'squib/deck' -describe Squib::Deck do +describe Squib::Deck do it "initializes with default parameters" do - d = Squib::Deck.new + d = Squib::Deck.new expect(d.width).to eq(825) expect(d.height).to eq(1125) expect(d.cards.size).to eq(1) @@ -13,11 +13,11 @@ describe Squib::Deck do context "in dealing with ranges" do it "calls text on all cards by default" do card1 = instance_double(Squib::Card) - card2 = instance_double(Squib::Card) + card2 = instance_double(Squib::Card) expect(card1).to receive(:text).once expect(card2).to receive(:text).once - Squib::Deck.new do - @cards = [card1, card2] + Squib::Deck.new do + @cards = [card1, card2] text str: 'blah' end end @@ -26,11 +26,11 @@ describe Squib::Deck do card1 = instance_double(Squib::Card) card2 = instance_double(Squib::Card) expect(card2).to receive(:text).once - Squib::Deck.new do - @cards = [card1, card2] + Squib::Deck.new do + @cards = [card1, card2] text range: 1, str: 'blah' end - end + end it "calls text with ranges" do card1 = instance_double(Squib::Card) @@ -38,8 +38,8 @@ describe Squib::Deck do card3 = instance_double(Squib::Card) expect(card1).to receive(:text).once expect(card2).to receive(:text).once - Squib::Deck.new do - @cards = [card1, card2, card3] + Squib::Deck.new do + @cards = [card1, card2, card3] text range: 0..1, str: 'blah' end end @@ -48,10 +48,10 @@ describe Squib::Deck do context "#load_layout" 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 \ eq({'frame' => { - 'x' => 38, + 'x' => 38, 'valign' => :middle, 'str' => "blah", 'font' => "Mr. Font", @@ -61,16 +61,16 @@ describe Squib::Deck do end 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 \ eq({'frame' => { - 'x' => 38, - 'y' => 38, + 'x' => 38, + 'y' => 38, }, 'title' => { 'extends' => 'frame', - 'x' => 38, - 'y' => 50, + 'x' => 38, + 'y' => 50, 'width' => 100, } } @@ -78,16 +78,16 @@ describe Squib::Deck do end 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 \ eq({'frame' => { - 'x' => 38, - 'y' => 38, + 'x' => 38, + 'y' => 38, }, 'title' => { 'extends' => 'frame', - 'x' => 38, - 'y' => 50, + 'x' => 38, + 'y' => 50, 'width' => 100, } } @@ -95,22 +95,22 @@ describe Squib::Deck do end 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 \ eq({'frame' => { - 'x' => 38, - 'y' => 38, + 'x' => 38, + 'y' => 38, }, 'title' => { 'extends' => 'frame', - 'x' => 38, - 'y' => 50, + 'x' => 38, + 'y' => 50, 'width' => 100, }, 'title2' => { 'extends' => 'frame', - 'x' => 75, - 'y' => 150, + 'x' => 75, + 'y' => 150, 'width' => 150, }, } @@ -118,17 +118,17 @@ describe Squib::Deck do end 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 \ eq({'aunt' => { - 'a' => 101, - 'b' => 102, - 'c' => 103, + 'a' => 101, + 'b' => 102, + 'c' => 103, }, 'uncle' => { - 'x' => 104, - 'y' => 105, - 'b' => 106, + 'x' => 104, + 'y' => 105, + 'b' => 106, }, 'child' => { 'extends' => ['uncle','aunt'], @@ -143,22 +143,22 @@ describe Squib::Deck do end 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 \ eq({'frame' => { - 'x' => 38, - 'y' => 38, + 'x' => 38, + 'y' => 38, }, 'title' => { 'extends' => 'frame', - 'x' => 38, - 'y' => 50, + 'x' => 38, + 'y' => 50, 'width' => 100, }, 'subtitle' => { 'extends' => 'title', 'x' => 38, - 'y' => 150, + 'y' => 150, 'width' => 100, }, } diff --git a/spec/input_helpers_spec.rb b/spec/input_helpers_spec.rb index c475724..b4549b5 100644 --- a/spec/input_helpers_spec.rb +++ b/spec/input_helpers_spec.rb @@ -19,7 +19,7 @@ describe Squib::InputHelpers do before(:each) do @deck = DummyDeck.new @deck.layout = { - 'blah' => {x: 25}, + 'blah' => {x: 25}, 'apples' => {x: 35}, 'oranges' => {y: 45}, } @@ -33,29 +33,29 @@ describe Squib::InputHelpers do Squib.logger = instance_double(Logger) expect(Squib.logger).to receive(:warn).with("Layout entry 'foo' does not exist.").twice expect(Squib.logger).to receive(:debug) - expect(@deck.send(:layoutify, {layout: :foo})).to eq({layout: [:foo,:foo]}) + expect(@deck.send(:layoutify, {layout: :foo})).to eq({layout: [:foo,:foo]}) Squib.logger = @old_logger end it "applies the layout in a normal situation" do expect(@deck.send(:layoutify, {layout: :blah})).to \ - eq({layout: [:blah, :blah], x: [25, 25]}) + eq({layout: [:blah, :blah], x: [25, 25]}) end it "applies two different layouts for two different situations" do expect(@deck.send(:layoutify, {layout: ['blah', 'apples']})).to \ - eq({layout: ['blah','apples'], x: [25, 35]}) + eq({layout: ['blah','apples'], x: [25, 35]}) end it "still has nils when not applied two different layouts differ in structure" do 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... end it "also looks up based on strings" do expect(@deck.send(:layoutify, {layout: 'blah'})).to \ - eq({layout: ['blah','blah'], x: [25, 25]}) + eq({layout: ['blah','blah'], x: [25, 25]}) end end diff --git a/spec/samples_run_spec.rb b/spec/samples_run_spec.rb index ba1ca12..ee274ad 100644 --- a/spec/samples_run_spec.rb +++ b/spec/samples_run_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' require 'squib' require 'pp' -describe Squib do +describe Squib do context "all samples run without error" do it "should execute with no errors" do @@ -15,6 +15,6 @@ describe Squib do end end end - end + end end \ No newline at end of file