Adding a basic custom config file
* Also adding in a logger * Added a sample for custom config * Saving a png now creates _outputdev
parent
3daea1b452
commit
0bcac1a76d
10
lib/squib.rb
10
lib/squib.rb
|
|
@ -1,4 +1,14 @@
|
|||
require 'logger'
|
||||
require 'squib/version'
|
||||
require 'squib/commands/new'
|
||||
require 'squib/deck'
|
||||
require 'squib/card'
|
||||
|
||||
module Squib
|
||||
|
||||
def logger
|
||||
@logger ||= Logger.new(STDOUT)
|
||||
end
|
||||
module_function :logger
|
||||
|
||||
end
|
||||
|
|
@ -8,7 +8,7 @@ module Squib
|
|||
end
|
||||
|
||||
def save_png(range: :all, dir: "_output", prefix: 'card_')
|
||||
range = rangeify(range)
|
||||
range = rangeify(range); dir = dirify(dir, allow_create: true)
|
||||
range.each { |i| @cards[i].save_png(i, dir, prefix) }
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
require 'yaml'
|
||||
require 'squib/card'
|
||||
require 'squib/input_helpers'
|
||||
require 'squib/constants'
|
||||
|
|
@ -11,26 +12,41 @@ module Squib
|
|||
attr_reader :cards
|
||||
attr_reader :text_hint
|
||||
|
||||
def initialize(width: 825, height: 1125, cards: 1, &block)
|
||||
def initialize(width: 825, height: 1125, cards: 1, config: 'config.yml', &block)
|
||||
@width=width; @height=height
|
||||
@dpi = 300
|
||||
@font = 'Sans 36'
|
||||
@cards = []
|
||||
cards.times{ @cards << Squib::Card.new(self, width, height) }
|
||||
load_config(config)
|
||||
if block_given?
|
||||
instance_eval(&block)
|
||||
end
|
||||
end
|
||||
|
||||
# API: Accesses the array of cards in the deck
|
||||
# @api public
|
||||
def [](key)
|
||||
@cards[key]
|
||||
end
|
||||
|
||||
#For Enumerable
|
||||
# Public: Accesses each card of the array in the deck
|
||||
# @api
|
||||
def each(&block)
|
||||
@cards.each { |card| block.call(card) }
|
||||
end
|
||||
|
||||
# Internal: Load the configuration file, if exists,
|
||||
# overriding hardcoded defaults
|
||||
# @api private
|
||||
def load_config(file)
|
||||
if File.exists? file
|
||||
if config = YAML.load_file(file)
|
||||
@dpi = config['dpi'].to_i
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
##################
|
||||
### PUBLIC API ###
|
||||
##################
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
#!/usr/bin/env ruby
|
||||
require 'squib'
|
||||
|
||||
Squib::Deck.new(config: 'custom-config.yml') do
|
||||
|
||||
end
|
||||
|
|
@ -0,0 +1 @@
|
|||
dpi: 300
|
||||
Loading…
Reference in New Issue