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.
 
 
 

62 lines
1.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.model import Config
  9. from hyde.site import Site
  10. from fswrap import File, Folder
  11. import yaml
  12. TEST_SITE = File(__file__).parent.parent.child_folder('_test')
  13. class TestUrlCleaner(object):
  14. def setUp(self):
  15. TEST_SITE.make()
  16. TEST_SITE.parent.child_folder(
  17. 'sites/test_jinja').copy_contents_to(TEST_SITE)
  18. def tearDown(self):
  19. TEST_SITE.delete()
  20. def test_url_cleaner(self):
  21. s = Site(TEST_SITE)
  22. cfg = """
  23. plugins:
  24. - hyde.ext.plugins.urls.UrlCleanerPlugin
  25. urlcleaner:
  26. index_file_names:
  27. - about.html
  28. strip_extensions:
  29. - html
  30. append_slash: true
  31. """
  32. s.config = Config(TEST_SITE, config_dict=yaml.load(cfg))
  33. text = """
  34. {% extends "base.html" %}
  35. {% block main %}
  36. <a id="index" href="{{ content_url('about.html') }}"></a>
  37. <a id="blog" href=
  38. "{{ content_url('blog/2010/december/merry-christmas.html') }}"></a>
  39. {% endblock %}
  40. """
  41. about2 = File(TEST_SITE.child('content/test.html'))
  42. about2.write(text)
  43. gen = Generator(s)
  44. gen.generate_all()
  45. from pyquery import PyQuery
  46. target = File(Folder(s.config.deploy_root_path).child('test.html'))
  47. text = target.read_all()
  48. q = PyQuery(text)
  49. assert q('a#index').attr("href") == '/'
  50. assert q('a#blog').attr(
  51. "href") == '/blog/2010/december/merry-christmas'