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.
 
 
 

149 lines
4.3 KiB

  1. # -*- coding: utf-8 -*-
  2. """
  3. Tests the simple copy feature.
  4. In order to mark some files to simply be copied to the
  5. destination without any processing what so ever add this
  6. to the config (site.yaml for example):
  7. simple_copy:
  8. - media/css/*.css
  9. - media/js/*.js
  10. - **/*.js
  11. Matching is done with `fnmatch` module. So any `glob` that fnmatch
  12. can process is a valid pattern.
  13. Use nose
  14. `$ pip install nose`
  15. `$ nosetests`
  16. """
  17. import yaml
  18. from hyde.model import Config
  19. from hyde.site import Site
  20. from hyde.generator import Generator
  21. from fswrap import File
  22. from nose.tools import nottest
  23. TEST_SITE_ROOT = File(__file__).parent.child_folder('sites/test_jinja')
  24. class TestSimpleCopy(object):
  25. @classmethod
  26. def setup_class(cls):
  27. cls.SITE_PATH = File(__file__).parent.child_folder(
  28. 'sites/test_jinja_with_config')
  29. cls.SITE_PATH.make()
  30. TEST_SITE_ROOT.copy_contents_to(cls.SITE_PATH)
  31. @classmethod
  32. def teardown_class(cls):
  33. cls.SITE_PATH.delete()
  34. @nottest
  35. def setup_config(self, passthru):
  36. self.config_file = File(self.SITE_PATH.child('site.yaml'))
  37. with open(self.config_file.path) as config:
  38. conf = yaml.load(config)
  39. conf['simple_copy'] = passthru
  40. self.config = Config(sitepath=self.SITE_PATH, config_dict=conf)
  41. def test_simple_copy_basic(self):
  42. self.setup_config([
  43. 'about.html'
  44. ])
  45. s = Site(self.SITE_PATH, config=self.config)
  46. s.load()
  47. res = s.content.resource_from_relative_path('about.html')
  48. assert res
  49. assert res.simple_copy
  50. def test_simple_copy_directory(self):
  51. self.setup_config([
  52. '**/*.html'
  53. ])
  54. s = Site(self.SITE_PATH, config=self.config)
  55. s.load()
  56. res = s.content.resource_from_relative_path('about.html')
  57. assert res
  58. assert not res.simple_copy
  59. res = s.content.resource_from_relative_path(
  60. 'blog/2010/december/merry-christmas.html')
  61. assert res
  62. assert res.simple_copy
  63. def test_simple_copy_multiple(self):
  64. self.setup_config([
  65. '**/*.html',
  66. 'media/css/*.css'
  67. ])
  68. s = Site(self.SITE_PATH, config=self.config)
  69. s.load()
  70. res = s.content.resource_from_relative_path('about.html')
  71. assert res
  72. assert not res.simple_copy
  73. res = s.content.resource_from_relative_path(
  74. 'blog/2010/december/merry-christmas.html')
  75. assert res
  76. assert res.simple_copy
  77. res = s.content.resource_from_relative_path('media/css/site.css')
  78. assert res
  79. assert res.simple_copy
  80. def test_generator(self):
  81. self.setup_config([
  82. '**/*.html',
  83. 'media/css/*.css'
  84. ])
  85. s = Site(self.SITE_PATH, self.config)
  86. g = Generator(s)
  87. g.generate_all()
  88. source = s.content.resource_from_relative_path(
  89. 'blog/2010/december/merry-christmas.html')
  90. target = File(
  91. s.config.deploy_root_path.child(source.relative_deploy_path))
  92. left = source.source_file.read_all()
  93. right = target.read_all()
  94. assert left == right
  95. def test_plugins(self):
  96. text = """
  97. ---
  98. title: Hey
  99. author: Me
  100. twitter: @me
  101. ---
  102. {%% extends "base.html" %%}
  103. {%% block main %%}
  104. Hi!
  105. I am a test template to make sure jinja2 generation works well with hyde.
  106. <span class="title">{{resource.meta.title}}</span>
  107. <span class="author">{{resource.meta.author}}</span>
  108. <span class="twitter">{{resource.meta.twitter}}</span>
  109. {%% endblock %%}
  110. """
  111. index = File(self.SITE_PATH.child('content/blog/index.html'))
  112. index.write(text)
  113. self.setup_config([
  114. '**/*.html',
  115. 'media/css/*.css'
  116. ])
  117. conf = {'plugins': ['hyde.ext.plugins.meta.MetaPlugin']}
  118. conf.update(self.config.to_dict())
  119. s = Site(self.SITE_PATH, Config(
  120. sitepath=self.SITE_PATH, config_dict=conf))
  121. g = Generator(s)
  122. g.generate_all()
  123. source = s.content.resource_from_relative_path('blog/index.html')
  124. target = File(
  125. s.config.deploy_root_path.child(source.relative_deploy_path))
  126. left = source.source_file.read_all()
  127. right = target.read_all()
  128. assert left == right