Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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(':')
- $
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement