Module: Squib

Defined in:
lib/squib/deck.rb,
lib/squib.rb,
lib/squib/card.rb,
lib/squib/conf.rb,
lib/squib/dsl/csv.rb,
lib/squib/dsl/png.rb,
lib/squib/dsl/svg.rb,
lib/squib/version.rb,
lib/squib/dsl/grid.rb,
lib/squib/dsl/hand.rb,
lib/squib/dsl/line.rb,
lib/squib/dsl/rect.rb,
lib/squib/dsl/save.rb,
lib/squib/dsl/star.rb,
lib/squib/dsl/text.rb,
lib/squib/dsl/xlsx.rb,
lib/squib/dsl/yaml.rb,
lib/squib/progress.rb,
lib/squib/constants.rb,
lib/squib/dsl/curve.rb,
lib/squib/dsl/units.rb,
lib/squib/dsl/circle.rb,
lib/squib/dsl/groups.rb,
lib/squib/dsl/ellipse.rb,
lib/squib/dsl/polygon.rb,
lib/squib/api/settings.rb,
lib/squib/commands/cli.rb,
lib/squib/commands/new.rb,
lib/squib/dsl/cut_zone.rb,
lib/squib/dsl/save_pdf.rb,
lib/squib/dsl/save_png.rb,
lib/squib/dsl/showcase.rb,
lib/squib/dsl/triangle.rb,
lib/squib/sprues/sprue.rb,
lib/squib/system_fonts.rb,
lib/squib/dsl/safe_zone.rb,
lib/squib/graphics/hand.rb,
lib/squib/graphics/text.rb,
lib/squib/layout_parser.rb,
lib/squib/dsl/background.rb,
lib/squib/dsl/save_sheet.rb,
lib/squib/dsl/text_embed.rb,
lib/squib/graphics/image.rb,
lib/squib/sample_helpers.rb,
lib/squib/graphics/shapes.rb,
lib/squib/sprues/crop_line.rb,
lib/squib/graphics/save_doc.rb,
lib/squib/graphics/save_pdf.rb,
lib/squib/graphics/showcase.rb,
lib/squib/import/data_frame.rb,
lib/squib/commands/make_sprue.rb,
lib/squib/graphics/background.rb,
lib/squib/graphics/save_sprue.rb,
lib/squib/sprues/sprue_schema.rb,
lib/squib/args/unit_conversion.rb,
lib/squib/args/xywh_shorthands.rb,
lib/squib/graphics/save_images.rb,
lib/squib/sprues/crop_line_dash.rb,
lib/squib/graphics/gradient_regex.rb,
lib/squib/graphics/embedding_utils.rb,
lib/squib/import/quantity_exploder.rb,
lib/squib/commands/data/template_option.rb,
lib/squib/graphics/cairo_context_wrapper.rb,
lib/squib/sprues/invalid_sprue_definition.rb

Overview

The project module

Defined Under Namespace

Modules: Args, Commands, DSL, Graphics, Import, Sprues, WarnUnexpectedParams Classes: CLI, Card, Conf, DataFrame, Deck, DoNothing, EmbeddingUtils, Gap, LayoutParser, Margin, Progress, Sprue, TemplateOption, TextEmbed

Constant Summary collapse

USER_CONFIG =
{}
VERSION =

The next version to be released. Uses semantic versioning: semver.org/

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

'0.19.0'
DEFAULT_FONT =

System-wide default font :nodoc:

'Arial 12'
INCHES_IN_CM =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Used for inch-cm conversion :nodoc:

0.393700787
POINTS_PER_IN =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Used for points-inch conversion :nodoc:

72.0
PNG_MAGIC =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Open a PNG file, checking magic bytes if it’s a real PNG Magic bytes taken from: en.wikipedia.org/wiki/List_of_file_signatures :nodoc:

[0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A]

Class Method Summary collapse

Class Method Details

.cache_load_image(file) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Cache all pngs we’ve already loaded

:nodoc:



7
8
9
10
# File 'lib/squib/graphics/image.rb', line 7

def cache_load_image(file)
  @img_cache ||= {}
  @img_cache[file] ||= open_png file
end

.configure(opts) ⇒ Object



8
9
10
11
# File 'lib/squib/conf.rb', line 8

def configure(opts)
  str_hash = opts.inject({}) { |h, (k, v)| h[k.to_s] = v; h }
  USER_CONFIG.merge! str_hash
end

.csv(opts = {}, &block) ⇒ Object

DSL method. See squib.readthedocs.io



8
9
10
# File 'lib/squib/dsl/csv.rb', line 8

def csv(opts = {}, &block)
  DSL::Csv.new(__callee__).run(opts, &block)
end

.disable_build_globally(group) ⇒ Object

DSL method. See squib.readthedocs.io



13
14
15
16
17
# File 'lib/squib/dsl/groups.rb', line 13

def disable_build_globally group
  groups = (ENV['SQUIB_BUILD'] ||= '').split(',')
  groups.delete(group.to_s)
  ENV['SQUIB_BUILD'] = groups.uniq.join(',')
end

.enable_build_globally(group) ⇒ Object

DSL method. See squib.readthedocs.io



6
7
8
9
# File 'lib/squib/dsl/groups.rb', line 6

def enable_build_globally group
  groups = (ENV['SQUIB_BUILD'] ||= '').split(',')
  ENV['SQUIB_BUILD'] = (groups << group).uniq.join(',')
end

.loggerLogger

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.

Examples:

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

Returns:

  • (Logger)

    the ruby logger



23
24
25
26
27
28
29
30
31
32
# File 'lib/squib.rb', line 23

def logger
  if @logger.nil?
    @logger = Logger.new($stdout)
    @logger.level = Logger::WARN
    @logger.formatter = proc do |severity, datetime, m_progname, msg|
      "[#{datetime.strftime('%F %H:%M:%S')} #{severity.red}] #{msg}\n"
    end
  end
  @logger
end

.open_png(file) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/squib/graphics/image.rb', line 19

def open_png(file)
  if PNG_MAGIC == File.read(file, 8).bytes
    return Cairo::ImageSurface.from_png(file)
  else
    raise ArgumentError.new("ERROR: #{file} is not a PNG file")
  end
end

Prints out the system fonts in sorted order



13
14
15
16
# File 'lib/squib/system_fonts.rb', line 13

module_function def print_system_fonts
  puts "== DEBUG: Squib knows about these fonts =="
  puts system_fonts.sort
end

.system_fontsObject

List all system fonts that Cairo/Pango can see Wow this call was convoluted… Returns array of strings with the names of fonts



7
8
9
10
# File 'lib/squib/system_fonts.rb', line 7

module_function def system_fonts
  cc = Cairo::Context.new(Cairo::ImageSurface.new(0,0)) # empty image
  cc.create_pango_layout.context.families.map {|f| f.name }
end

.xlsx(opts = {}, &block) ⇒ Object

DSL method. See squib.readthedocs.io



7
8
9
# File 'lib/squib/dsl/xlsx.rb', line 7

def xlsx(opts = {}, &block)
  DSL::Xlsx.new(__callee__).run(opts, &block)
end

.yaml(opts = {}, &block) ⇒ Object

DSL method. See squib.readthedocs.io



7
8
9
# File 'lib/squib/dsl/yaml.rb', line 7

def yaml(opts = {}, &block)
  DSL::Yaml.new(__callee__).run(opts, &block)
end