A fork of hyde, the static site generation. Some patches will be pushed upstream.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

119 lines
2.6 KiB

  1. # -*- coding: utf-8 -*-
  2. """
  3. Use nose
  4. `$ pip install nose`
  5. `$ nosetests`
  6. """
  7. from hyde.generator import Generator
  8. from hyde.site import Site
  9. from fswrap import File
  10. from pyquery import PyQuery
  11. TEST_SITE = File(__file__).parent.parent.child_folder('_test')
  12. def assert_valid_conversion(html):
  13. assert html
  14. q = PyQuery(html)
  15. assert "is_processable" not in html
  16. assert q("h1")
  17. assert "This is a" in q("h1").text()
  18. assert "heading" in q("h1").text()
  19. assert q(".amp").length == 1
  20. assert "mark" not in html
  21. assert "reference" not in html
  22. assert '.' not in q.text()
  23. assert '/' not in q.text()
  24. class TestMarkings(object):
  25. def setUp(self):
  26. TEST_SITE.make()
  27. TEST_SITE.parent.child_folder(
  28. 'sites/test_jinja').copy_contents_to(TEST_SITE)
  29. def tearDown(self):
  30. TEST_SITE.delete()
  31. def test_mark(self):
  32. text = u"""
  33. ===
  34. is_processable: False
  35. ===
  36. {% filter markdown|typogrify %}
  37. §§ heading
  38. This is a heading
  39. =================
  40. §§ /heading
  41. §§ content
  42. Hyde & Jinja
  43. §§ /
  44. {% endfilter %}
  45. """
  46. text2 = """
  47. {% refer to "inc.md" as inc %}
  48. {% filter markdown|typogrify %}
  49. {{ inc.heading }}
  50. {{ inc.content }}
  51. {% endfilter %}
  52. """
  53. site = Site(TEST_SITE)
  54. site.config.plugins = [
  55. 'hyde.ext.plugins.meta.MetaPlugin',
  56. 'hyde.ext.plugins.text.MarkingsPlugin']
  57. inc = File(TEST_SITE.child('content/inc.md'))
  58. inc.write(text)
  59. site.load()
  60. gen = Generator(site)
  61. gen.load_template_if_needed()
  62. template = gen.template
  63. html = template.render(text2, {}).strip()
  64. assert_valid_conversion(html)
  65. def test_reference(self):
  66. text = u"""
  67. ===
  68. is_processable: False
  69. ===
  70. {% filter markdown|typogrify %}
  71. §§ heading
  72. This is a heading
  73. =================
  74. §§ /heading
  75. §§ content
  76. Hyde & Jinja
  77. §§ /
  78. {% endfilter %}
  79. """
  80. text2 = u"""
  81. ※ inc.md as inc
  82. {% filter markdown|typogrify %}
  83. {{ inc.heading }}
  84. {{ inc.content }}
  85. {% endfilter %}
  86. """
  87. site = Site(TEST_SITE)
  88. site.config.plugins = [
  89. 'hyde.ext.plugins.meta.MetaPlugin',
  90. 'hyde.ext.plugins.text.MarkingsPlugin',
  91. 'hyde.ext.plugins.text.ReferencePlugin']
  92. inc = File(site.content.source_folder.child('inc.md'))
  93. inc.write(text.strip())
  94. src = File(site.content.source_folder.child('src.html'))
  95. src.write(text2.strip())
  96. gen = Generator(site)
  97. gen.generate_all()
  98. f = File(site.config.deploy_root_path.child(src.name))
  99. assert f.exists
  100. html = f.read_all()
  101. assert_valid_conversion(html)