feature: build groups

See docs and changelog for more details on how these work.
This commit is contained in:
Andy Meneely
2016-03-13 00:38:13 -05:00
parent aeadcd16ed
commit 61a3d3446b
12 changed files with 189 additions and 0 deletions
+47
View File
@@ -0,0 +1,47 @@
require 'set'
module Squib
# An idea for later...
# def enable_group_env group
# ENV['SQUIB_BUILD'] ||= ''
# ENV['SQUIB_BUILD'] += ','
# ENV['SQUIB_BUILD'] += group
# end
# module_function :enable_group_env
class Deck
# See official API docs
def group grp = :all, &block
raise 'Please provide a block' unless block_given?
block.yield if groups.include? grp
end
# See official API docs
def enable_group grp
groups # make sure it's initialized
@build_groups << grp
end
# See official API docs
def disable_group grp
groups # make sure it's initialized
@build_groups.delete grp
end
# See official API docs
def groups
@build_groups ||= Set.new.add(:all)
end
# See official API docs
def enable_groups_from_env!
return if ENV['SQUIB_BUILD'].nil?
ENV['SQUIB_BUILD'].split(',').each do |grp|
enable_group grp.strip.to_sym
end
end
end
end
+2
View File
@@ -69,6 +69,7 @@ module Squib
@height = Args::UnitConversion.parse height, dpi
cards.times{ |i| @cards << Squib::Card.new(self, @width, @height, i) }
@layout = LayoutParser.load_layout(layout)
enable_groups_from_env!
if block_given?
instance_eval(&block) # here we go. wheeeee!
end
@@ -102,6 +103,7 @@ module Squib
##################
require_relative 'api/background'
require_relative 'api/data'
require_relative 'api/groups'
require_relative 'api/image'
require_relative 'api/save'
require_relative 'api/settings'