Created
July 16, 2015 21:34
-
-
Save Inviz/ed68b86c2389df674b73 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
expectations = ($, result, block, page) -> | |
return unless result | |
for property, value of result | |
if property == 'textual' | |
if block.text | |
$.expect(block).to.have.a('text') | |
else | |
$.expect(block).to.have.a('description') | |
else if property == 'type' | |
if value == 'text' | |
value = 'textual' | |
$.expect(block).to.be.subtypeOf value | |
else if property.indexOf('.') > -1# || property == 'subtitle' | |
if value | |
$.expect(block).to.have.a(property).defined | |
else | |
$.expect(block).to.not.have.a(property).defined | |
else | |
if property != 'condition' | |
if value | |
expectation = $.expect(block).with.a(property) | |
if property is "cover" | |
expectation.with.src | |
expectation.with.width | |
expectation.with.height | |
else | |
unless page.relaxed | |
expectation = $.expect(block).not.with.a(property) | |
else | |
expectation = undefined | |
if typeof value == 'function' | |
value.call(expectation, $, block) | |
module.exports = (rules, page, recursive, result) -> | |
consume = rules.consume | |
consume ?= rules.extends?.consume | |
return consume if typeof consume is "function" | |
result = rules.consumers || (rules.extends?.consumers) || (rules.extends?.extends?.consumers) || {} | |
return ($) -> | |
if page.ordered | |
type = 'block' | |
else | |
type = 'item' | |
$.inlet type, (item, attempt) -> | |
if values = (rules.consume or rules.extends?.consume)?[type]?($, item) | |
return values | |
if result.required | |
blocks = [item.id] | |
else | |
blocks = [] | |
if result.blocks | |
for config in result.blocks | |
$.inlet 'block', item, attempt, (block) -> | |
expectations($, config, block, page) | |
blocks.push(block.id) | |
return block | |
expectations($, result.required, item.block || item, page) | |
return blocks.join(':') | |
$ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment