Browse Source

Extending a non-existent parent yells at you now

Fixes #24
dev
Andy Meneely 11 years ago
parent
commit
73d6eb992b
  1. 2
      CHANGELOG.md
  2. 14
      README.md
  3. 14
      lib/squib/layout_parser.rb
  4. 3
      spec/data/layouts/extends-nonexists.yml
  5. 13
      spec/layout_parser_spec.rb

2
CHANGELOG.md

@ -2,7 +2,7 @@
* Added `showcase` feature to create a fancy-looking 3D reflection to showcase your cards. Documented, tested, and added a sample for it.
* Added a basic Rakefile, documented in README.
* Some internal refactoring and better testing around layouts
* Some internal refactoring, better testing, and more documentation with layouts
## v0.1.0
* Added `save_sheet` command that saves a range into PNG sheets, complete with trim, gap, margin, columns, and sometimes automagically computed rows. See samples/saves.rb.

14
README.md

@ -209,6 +209,20 @@ yang:
x: += 50
```
Furthermore, if you want to extend multiple parents, it looks like this:
```yaml
socrates:
x: 100
aristotle:
y: 200
aristotle:
extends:
- socrates
- plato
x: += 50
```
### Multiple layout files
Squib also supports the combination of multiple layout files. As shown in the above example, if you provide an `Array` of files then Squib will merge them sequentially. Colliding keys will be completely re-defined by the later file. Extends is processed after _each file_. YAML merge keys are NOT supported across multiple files - use extends instead. Here's a demonstrative example:

14
lib/squib/layout_parser.rb

@ -34,6 +34,7 @@ module Squib
def self.recurse_extends(yml, key, visited )
assert_not_visited(key, visited)
return yml[key] unless has_extends?(yml, key)
return yml[key] unless parents_exist?(yml, key)
visited[key] = key
parent_keys = [yml[key]['extends']].flatten
h = {}
@ -62,6 +63,19 @@ module Squib
!!yml[key] && yml[key].key?('extends')
end
# Checks if we have any absentee parents
# @api private
def self.parents_exist?(yml, key)
exists = true
Array(yml[key]['extends']).each do |parent|
unless yml.key?(parent)
exists = false unless
Squib.logger.error "Processing layout: '#{key}' attempts to extend a missing '#{yml[key]['extends']}'"
end
end
return exists
end
# Safeguard against malformed circular extends
# :nodoc:
# @api private

3
spec/data/layouts/extends-nonexists.yml

@ -0,0 +1,3 @@
verbal:
extends: kaisersoze
font_size: 25

13
spec/layout_parser_spec.rb

@ -173,4 +173,17 @@ describe Squib::LayoutParser do
Squib::LayoutParser.load_layout('yeti')
end
it 'freaks out if you extend something doesn\'t exist' do
expect(Squib.logger)
.to receive(:error)
.with("Processing layout: 'verbal' attempts to extend a missing 'kaisersoze'")
layout = Squib::LayoutParser.load_layout(layout_file('extends-nonexists.yml'))
expect(layout).to eq({
'verbal' => {
'font_size' => 25,
'extends' => 'kaisersoze'
}
})
end
end
Loading…
Cancel
Save