Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2015
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. expectations = ($, result, block, page) ->
  2. return unless result
  3. for property, value of result
  4. if property == 'textual'
  5. if block.text
  6. $.expect(block).to.have.a('text')
  7. else
  8. $.expect(block).to.have.a('description')
  9.  
  10. else if property == 'type'
  11. if value == 'text'
  12. value = 'textual'
  13. $.expect(block).to.be.subtypeOf value
  14. else if property.indexOf('.') > -1# || property == 'subtitle'
  15. if value
  16. $.expect(block).to.have.a(property).defined
  17. else
  18. $.expect(block).to.not.have.a(property).defined
  19. else
  20. if property != 'condition'
  21. if value
  22. expectation = $.expect(block).with.a(property)
  23. if property is "cover"
  24. expectation.with.src
  25. expectation.with.width
  26. expectation.with.height
  27. else
  28. unless page.relaxed
  29. expectation = $.expect(block).not.with.a(property)
  30. else
  31. expectation = undefined
  32. if typeof value == 'function'
  33. value.call(expectation, $, block)
  34.  
  35.  
  36. module.exports = (rules, page, recursive, result) ->
  37. consume = rules.consume
  38. consume ?= rules.extends?.consume
  39. return consume if typeof consume is "function"
  40.  
  41. result = rules.consumers || (rules.extends?.consumers) || (rules.extends?.extends?.consumers) || {}
  42.  
  43. return ($) ->
  44. if page.ordered
  45. type = 'block'
  46. else
  47. type = 'item'
  48.  
  49. $.inlet type, (item, attempt) ->
  50. if values = (rules.consume or rules.extends?.consume)?[type]?($, item)
  51. return values
  52.  
  53. if result.required
  54. blocks = [item.id]
  55. else
  56. blocks = []
  57.  
  58. if result.blocks
  59. for config in result.blocks
  60. $.inlet 'block', item, attempt, (block) ->
  61. expectations($, config, block, page)
  62. blocks.push(block.id)
  63. return block
  64.  
  65. expectations($, result.required, item.block || item, page)
  66. return blocks.join(':')
  67. $
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement