def test_can_uglify(self): s = Site(TEST_SITE) s.config.plugins = ['hyde.ext.plugins.uglify.UglifyPlugin'] s.config.mode = "production" source = TEST_SITE.child('content/media/js/jquery.js') target = File(Folder(s.config.deploy_root_path).child('media/js/jquery.js')) gen = Generator(s) gen.generate_resource_at_path(source) assert target.exists expected = File(UGLIFY_SOURCE.child('expected-jquery.js')) # TODO: Very fragile. Better comparison needed. assert target.read_all() == expected.read_all()
def test_can_uglify(self): s = Site(TEST_SITE) s.config.plugins = ['hyde.ext.plugins.uglify.UglifyPlugin'] s.config.mode = "production" source = TEST_SITE.child('content/media/js/jquery.js') target = File( Folder(s.config.deploy_root_path).child('media/js/jquery.js')) gen = Generator(s) gen.generate_resource_at_path(source) assert target.exists expected = File(UGLIFY_SOURCE.child('expected-jquery.js')) # TODO: Very fragile. Better comparison needed. assert target.read_all() == expected.read_all()
def test_plugins(self): text = """ --- title: Hey author: Me twitter: @me --- {%% extends "base.html" %%} {%% block main %%} Hi! I am a test template to make sure jinja2 generation works well with hyde. <span class="title">{{resource.meta.title}}</span> <span class="author">{{resource.meta.author}}</span> <span class="twitter">{{resource.meta.twitter}}</span> {%% endblock %%} """ index = File(self.SITE_PATH.child('content/blog/index.html')) index.write(text) self.setup_config(['**/*.html', 'media/css/*.css']) conf = {'plugins': ['hyde.ext.plugins.meta.MetaPlugin']} conf.update(self.config.to_dict()) s = Site(self.SITE_PATH, Config(sitepath=self.SITE_PATH, config_dict=conf)) g = Generator(s) g.generate_all() source = s.content.resource_from_relative_path('blog/index.html') target = File( s.config.deploy_root_path.child(source.relative_deploy_path)) left = source.source_file.read_all() right = target.read_all() assert left == right
def test_url_cleaner(self): s = Site(TEST_SITE) cfg = """ plugins: - hyde.ext.plugins.urls.UrlCleanerPlugin urlcleaner: index_file_names: - about.html strip_extensions: - html append_slash: true """ s.config = Config(TEST_SITE, config_dict=yaml.load(cfg)) text = """ {% extends "base.html" %} {% block main %} <a id="index" href="{{ content_url('about.html') }}"></a> <a id="blog" href="{{ content_url('blog/2010/december/merry-christmas.html') }}"></a> {% endblock %} """ about2 = File(TEST_SITE.child('content/test.html')) about2.write(text) gen = Generator(s) gen.generate_all() from pyquery import PyQuery target = File(Folder(s.config.deploy_root_path).child('test.html')) text = target.read_all() q = PyQuery(text) assert q('a#index').attr("href") == '/' assert q('a#blog').attr("href") == '/blog/2010/december/merry-christmas'
def test_can_compress_with_stylus(self): s = Site(TEST_SITE) s.config.mode = "production" s.config.plugins = ['hyde.ext.plugins.stylus.StylusPlugin'] paths = [ '/usr/local/share/npm/bin/stylus', '~/local/bin/stylus', '~/bin/stylus' ] stylus = [path for path in paths if File(path).exists] if not stylus: assert False, "Cannot find the stylus executable" stylus = stylus[0] s.config.stylus = Expando(dict(app=stylus)) source = TEST_SITE.child('content/media/css/site.styl') target = File( Folder(s.config.deploy_root_path).child('media/css/site.css')) gen = Generator(s) gen.generate_resource_at_path(source) assert target.exists text = target.read_all() expected_text = File( STYLUS_SOURCE.child('expected-site-compressed.css')).read_all() assert text.strip() == expected_text.strip()
def test_ignores_pattern_in_content(self): text = """ {% markdown %} Heading 1 === Heading 2 === {% endmarkdown %} """ about2 = File(TEST_SITE.child("content/about2.html")) about2.write(text) s = Site(TEST_SITE) s.load() res = s.content.resource_from_path(about2.path) assert res.is_processable s.config.plugins = ["hyde.ext.plugins.meta.MetaPlugin"] gen = Generator(s) gen.generate_all() target = File(Folder(s.config.deploy_root_path).child("about2.html")) text = target.read_all() q = PyQuery(text) assert q("h1").length == 2 assert q("h1:eq(0)").text().strip() == "Heading 1" assert q("h1:eq(1)").text().strip() == "Heading 2"
def test_plugins(self): text = """ --- title: Hey author: Me twitter: @me --- {%% extends "base.html" %%} {%% block main %%} Hi! I am a test template to make sure jinja2 generation works well with hyde. <span class="title">{{resource.meta.title}}</span> <span class="author">{{resource.meta.author}}</span> <span class="twitter">{{resource.meta.twitter}}</span> {%% endblock %%} """ index = File(self.SITE_PATH.child("content/blog/index.html")) index.write(text) self.setup_config(["**/*.html", "media/css/*.css"]) conf = {"plugins": ["hyde.ext.plugins.meta.MetaPlugin"]} conf.update(self.config.to_dict()) s = Site(self.SITE_PATH, Config(sitepath=self.SITE_PATH, config_dict=conf)) g = Generator(s) g.generate_all() source = s.content.resource_from_relative_path("blog/index.html") target = File(s.config.deploy_root_path.child(source.relative_deploy_path)) left = source.source_file.read_all() right = target.read_all() assert left == right
def test_context(self): site = Site(TEST_SITE, Config(TEST_SITE, config_dict={ "context": { "data": { "abc": "def" } } })) text = """ {% extends "base.html" %} {% block main %} abc = {{ abc }} Hi! I am a test template to make sure jinja2 generation works well with hyde. {{resource.name}} {% endblock %} """ site.load() resource = site.content.resource_from_path(TEST_SITE.child('content/about.html')) gen = Generator(site) resource.source_file.write(text) gen.generate_all() target = File(site.config.deploy_root_path.child(resource.name)) assert "abc = def" in target.read_all()
def test_context(self): site = Site( TEST_SITE, Config(TEST_SITE, config_dict={"context": { "data": { "abc": "def" } }})) text = """ {% extends "base.html" %} {% block main %} abc = {{ abc }} Hi! I am a test template to make sure jinja2 generation works well with hyde. {{resource.name}} {% endblock %} """ site.load() resource = site.content.resource_from_path( TEST_SITE.child('content/about.html')) gen = Generator(site) resource.source_file.write(text) gen.generate_all() target = File(site.config.deploy_root_path.child(resource.name)) assert "abc = def" in target.read_all()
def test_textlinks(self): d = { 'objects': 'template/variables', 'plugins': 'plugins/metadata', 'sorter': 'plugins/sorter' } text = u""" {%% markdown %%} [[!!img/hyde-logo.png]] * [Rich object model][hyde objects] and [overridable hierarchical metadata]([[ %(plugins)s ]]) thats available for use in templates. * Configurable [sorting][], filtering and grouping support. [hyde objects]: [[ %(objects)s ]] [sorting]: [[%(sorter)s]] {%% endmarkdown %%} """ site = Site(TEST_SITE) site.config.plugins = ['hyde.ext.plugins.textlinks.TextlinksPlugin'] site.config.base_url = 'http://example.com/' site.config.media_url = '/media' tlink = File(site.content.source_folder.child('tlink.html')) tlink.write(text % d) gen = Generator(site) gen.generate_all() f = File(site.config.deploy_root_path.child(tlink.name)) assert f.exists html = f.read_all() assert html for name, path in d.items(): assert quote(site.config.base_url + path) in html assert '/media/img/hyde-logo.png' in html
def test_ignores_pattern_in_content(self): text = """ {% markdown %} Heading 1 === Heading 2 === {% endmarkdown %} """ about2 = File(TEST_SITE.child('content/about2.html')) about2.write(text) s = Site(TEST_SITE) s.load() res = s.content.resource_from_path(about2.path) assert res.is_processable s.config.plugins = ['hyde.ext.plugins.meta.MetaPlugin'] gen = Generator(s) gen.generate_all() target = File(Folder(s.config.deploy_root_path).child('about2.html')) text = target.read_all() q = PyQuery(text) assert q("h1").length == 2 assert q("h1:eq(0)").text().strip() == "Heading 1" assert q("h1:eq(1)").text().strip() == "Heading 2"
def test_multiple_levels(self): page_d = {'title': 'An even nicer title'} blog_d = {'author': 'Laks'} content_d = {'title': 'A nice title', 'author': 'Lakshmi Vyas'} site_d = {'author': 'Lakshmi', 'twitter': 'lakshmivyas', 'nodemeta': 'meta.yaml'} text = """ --- title: %(title)s --- {%% extends "base.html" %%} {%% block main %%} Hi! I am a test template to make sure jinja2 generation works well with hyde. <span class="title">{{resource.meta.title}}</span> <span class="author">{{resource.meta.author}}</span> <span class="twitter">{{resource.meta.twitter}}</span> {%% endblock %%} """ about2 = File(TEST_SITE.child('content/blog/about2.html')) about2.write(text % page_d) content_meta = File(TEST_SITE.child('content/nodemeta.yaml')) content_meta.write(yaml.dump(content_d)) content_meta = File(TEST_SITE.child('content/blog/meta.yaml')) content_meta.write(yaml.dump(blog_d)) s = Site(TEST_SITE) s.config.plugins = ['hyde.ext.plugins.meta.MetaPlugin'] s.config.meta = site_d gen = Generator(s) gen.generate_all() expected = {} expected.update(site_d) expected.update(content_d) expected.update(blog_d) expected.update(page_d) res = s.content.resource_from_path(about2.path) assert hasattr(res, 'meta') for k, v in expected.items(): assert hasattr(res.meta, k) assert getattr(res.meta, k) == v target = File(Folder(s.config.deploy_root_path).child('blog/about2.html')) text = target.read_all() q = PyQuery(text) for k, v in expected.items(): if k != 'nodemeta': assert v in q("span." + k).text()
def test_generator(self): self.setup_config(["**/*.html", "media/css/*.css"]) s = Site(self.SITE_PATH, self.config) g = Generator(s) g.generate_all() source = s.content.resource_from_relative_path("blog/2010/december/merry-christmas.html") target = File(s.config.deploy_root_path.child(source.relative_deploy_path)) left = source.source_file.read_all() right = target.read_all() assert left == right
def test_generate_resource_from_path(self): site = Site(TEST_SITE) site.load() gen = Generator(site) gen.generate_resource_at_path(TEST_SITE.child('content/about.html')) about = File(Folder(site.config.deploy_root_path).child('about.html')) assert about.exists text = about.read_all() q = PyQuery(text) assert about.name in q("div#main").text()
def test_plugin_chaining(self): self.site.config.plugins = [ 'hyde.tests.test_plugin.ConstantReturnPlugin', 'hyde.tests.test_plugin.NoReturnPlugin' ] path = self.site.content.source_folder.child('about.html') gen = Generator(self.site) gen.generate_resource_at_path(path) about = File(Folder( self.site.config.deploy_root_path).child('about.html')) assert about.read_all() == "Jam"
def test_can_uglify(self): s = Site(TEST_SITE) s.config.plugins = ['hyde.ext.plugins.uglify.UglifyPlugin'] s.config.mode = "production" paths = ['/usr/local/share/npm/bin/uglifyjs', '~/local/bin/uglifyjs'] uglify = [path for path in paths if File(path).exists] if not uglify: assert False, "Cannot find the uglify executable" uglify = uglify[0] s.config.uglify = Expando(dict(app=uglify)) source = TEST_SITE.child('content/media/js/jquery.js') target = File(Folder(s.config.deploy_root_path).child('media/js/jquery.js')) gen = Generator(s) gen.generate_resource_at_path(source) assert target.exists expected = File(UGLIFY_SOURCE.child('expected-jquery.js')) # TODO: Very fragile. Better comparison needed. assert target.read_all() == expected.read_all()
def test_plugin_chaining(self): self.site.config.plugins = [ 'hyde.tests.test_plugin.ConstantReturnPlugin', 'hyde.tests.test_plugin.NoReturnPlugin' ] path = self.site.content.source_folder.child('about.html') gen = Generator(self.site) gen.generate_resource_at_path(path) about = File( Folder(self.site.config.deploy_root_path).child('about.html')) assert about.read_all() == "Jam"
def test_can_uglify(self): s = Site(TEST_SITE) s.config.plugins = ['hyde.ext.plugins.uglify.UglifyPlugin'] s.config.mode = "production" paths = ['/usr/local/share/npm/bin/uglifyjs', '~/local/bin/uglifyjs', '/usr/bin/uglifyjs', '~/bin/uglifyjs'] uglify = [path for path in paths if File(path).exists] if not uglify: assert False, "Cannot find the uglify executable" uglify = uglify[0] s.config.uglify = Expando(dict(app=uglify)) source = TEST_SITE.child('content/media/js/jquery.js') target = File(Folder(s.config.deploy_root_path).child('media/js/jquery.js')) gen = Generator(s) gen.generate_resource_at_path(source) assert target.exists expected = File(UGLIFY_SOURCE.child('expected-jquery.js')) # TODO: Very fragile. Better comparison needed. assert target.read_all() == expected.read_all()
def _generic_test_image(self, text): self.site.config.mode = "production" self.site.config.plugins = ['hyde.ext.plugins.images.ImageSizerPlugin'] tlink = File(self.site.content.source_folder.child('timg.html')) tlink.write(text) gen = Generator(self.site) gen.generate_all() f = File(self.site.config.deploy_root_path.child(tlink.name)) assert f.exists html = f.read_all() assert html return html
def test_generator(self): self.setup_config(['**/*.html', 'media/css/*.css']) s = Site(self.SITE_PATH, self.config) g = Generator(s) g.generate_all() source = s.content.resource_from_relative_path( 'blog/2010/december/merry-christmas.html') target = File( s.config.deploy_root_path.child(source.relative_deploy_path)) left = source.source_file.read_all() right = target.read_all() assert left == right
def test_generate_resource_from_path_with_uses_template_false(self): site = Site(TEST_SITE) site.load() resource = site.content.resource_from_path(TEST_SITE.child('content/about.html')) resource.uses_template = False gen = Generator(site) gen.generate_resource_at_path(TEST_SITE.child('content/about.html')) about = File(Folder(site.config.deploy_root_path).child('about.html')) assert about.exists text = about.read_all() expected = resource.source_file.read_all() assert text == expected
def test_generate_resource_from_path_with_uses_template_false(self): site = Site(TEST_SITE) site.load() resource = site.content.resource_from_path( TEST_SITE.child('content/about.html')) resource.uses_template = False gen = Generator(site) gen.generate_resource_at_path(TEST_SITE.child('content/about.html')) about = File(Folder(site.config.deploy_root_path).child('about.html')) assert about.exists text = about.read_all() expected = resource.source_file.read_all() assert text == expected
def assert_extended(self, s, txt, templ): content = (templ.strip() % txt).strip() bd = File(TEST_SITE.child('content/auto_extend.html')) bd.write(content) gen = Generator(s) gen.generate_resource_at_path(bd.path) res = s.content.resource_from_path(bd.path) target = File(s.config.deploy_root_path.child( res.relative_deploy_path)) assert target.exists text = target.read_all() q = PyQuery(text) assert q('title').text().strip() == txt.strip()
def test_can_execute_rjs(self): s = Site(TEST_SITE) s.config.plugins = ['hyde.ext.plugins.requirejs.RequireJSPlugin'] source = TEST_SITE.child('content/media/js/rjs.conf') target = File(Folder(s.config.deploy_root_path).child('media/js/app.js')) gen = Generator(s) gen.generate_resource_at_path(source) assert target.exists text = target.read_all() expected_text = File(RJS_SOURCE.child('app.js')).read_all() assert text == expected_text return
def test_can_execute_less(self): s = Site(TEST_SITE) s.config.plugins = ['hyde.ext.plugins.less.LessCSSPlugin'] source = TEST_SITE.child('content/media/css/site.less') target = File(Folder(s.config.deploy_root_path).child('media/css/site.css')) gen = Generator(s) gen.generate_resource_at_path(source) assert target.exists text = target.read_all() expected_text = File(LESS_SOURCE.child('expected-site.css')).read_all() assert text == expected_text return
def test_uglify_with_extra_options(self): s = Site(TEST_SITE) s.config.plugins = ['hyde.ext.plugins.uglify.UglifyPlugin'] s.config.mode = "production" s.config.uglify = Expando(dict(args={"nc":""})) source = TEST_SITE.child('content/media/js/jquery.js') target = File(Folder(s.config.deploy_root_path).child('media/js/jquery.js')) gen = Generator(s) gen.generate_resource_at_path(source) assert target.exists expected = File(UGLIFY_SOURCE.child('expected-jquery-nc.js')) # TODO: Very fragile. Better comparison needed. text = target.read_all() assert text.startswith("(function(")
def test_can_execute_less(self): s = Site(TEST_SITE) s.config.plugins = ['hyde.ext.plugins.less.LessCSSPlugin'] source = TEST_SITE.child('content/media/css/site.less') target = File( Folder(s.config.deploy_root_path).child('media/css/site.css')) gen = Generator(s) gen.generate_resource_at_path(source) assert target.exists text = target.read_all() expected_text = File(LESS_SOURCE.child('expected-site.css')).read_all() assert text == expected_text return
def _test_combine(self, content): s = Site(TEST_SITE) s.config.plugins = [ 'hyde.ext.plugins.meta.MetaPlugin', 'hyde.ext.plugins.combine.CombinePlugin'] source = TEST_SITE.child('content/media/js/script.js') target = File(Folder(s.config.deploy_root_path).child('media/js/script.js')) File(source).write(content) gen = Generator(s) gen.generate_resource_at_path(source) assert target.exists text = target.read_all() return text, s
def load(sitepath, ctx): """ Load context from config data and providers. """ context = {} try: context.update(ctx.data.__dict__) for provider_name, resource_name in ctx.providers.__dict__.items(): res = File(Folder(sitepath).child(resource_name)) if res.exists: context[provider_name] = yaml.load(res.read_all()) except AttributeError: # No context data found pass return context
def test_context_providers(self): site = Site( TEST_SITE, Config(TEST_SITE, config_dict={ "context": { "data": { "abc": "def" }, "providers": { "nav": "nav.yaml" } } })) nav = """ main: - home - articles - projects """ text = """ {% extends "base.html" %} {% block main %} {{nav}} {% for item in nav.main %} {{item}} {% endfor %} abc = {{ abc }} Hi! I am a test template to make sure jinja2 generation works well with hyde. {{resource.name}} {% endblock %} """ File(TEST_SITE.child('nav.yaml')).write(nav) site.load() resource = site.content.resource_from_path( TEST_SITE.child('content/about.html')) gen = Generator(site) resource.source_file.write(text) gen.generate_all() target = File(site.config.deploy_root_path.child(resource.name)) out = target.read_all() assert "abc = def" in out assert "home" in out assert "articles" in out assert "projects" in out
def test_can_execute_stylus(self): s = Site(TEST_SITE) s.config.plugins = ['hyde.ext.plugins.stylus.StylusPlugin'] paths = ['/usr/local/share/npm/bin/stylus'] for path in paths: if File(path).exists: s.config.stylus = Expando(dict(app=path)) source = TEST_SITE.child('content/media/css/site.styl') target = File(Folder(s.config.deploy_root_path).child('media/css/site.css')) gen = Generator(s) gen.generate_resource_at_path(source) assert target.exists text = target.read_all() expected_text = File(STYLUS_SOURCE.child('expected-site.css')).read_all() assert text.strip() == expected_text.strip()
def test_uglify_with_extra_options(self): s = Site(TEST_SITE) s.config.plugins = ['hyde.ext.plugins.uglify.UglifyPlugin'] s.config.mode = "production" s.config.uglify = Expando(dict(args={"nc": ""})) source = TEST_SITE.child('content/media/js/jquery.js') target = File( Folder(s.config.deploy_root_path).child('media/js/jquery.js')) gen = Generator(s) gen.generate_resource_at_path(source) assert target.exists expected = File(UGLIFY_SOURCE.child('expected-jquery-nc.js')) # TODO: Very fragile. Better comparison needed. text = target.read_all() assert text.startswith("(function(")
def _test_combine(self, content): s = Site(TEST_SITE) s.config.plugins = [ 'hyde.ext.plugins.meta.MetaPlugin', 'hyde.ext.plugins.combine.CombinePlugin' ] source = TEST_SITE.child('content/media/js/script.js') target = File( Folder(s.config.deploy_root_path).child('media/js/script.js')) File(source).write(content) gen = Generator(s) gen.generate_resource_at_path(source) assert target.exists text = target.read_all() return text, s
def test_can_load_from_site_meta(self): d = {'title': 'A nice title', 'author': 'Lakshmi Vyas'} text = """ --- title: Even nicer title --- {%% extends "base.html" %%} {%% block main %%} Hi! I am a test template to make sure jinja2 generation works well with hyde. <span class="title">{{resource.meta.title}}</span> <span class="author">{{resource.meta.author}}</span> <span class="twitter">{{resource.meta.twitter}}</span> {%% endblock %%} """ about2 = File(TEST_SITE.child('content/about2.html')) about2.write(text % d) meta = File(TEST_SITE.child('content/nodemeta.yaml')) meta.write(yaml.dump(d)) s = Site(TEST_SITE) s.config.plugins = ['hyde.ext.plugins.meta.MetaPlugin'] s.config.meta = { 'author': 'Lakshmi', 'twitter': 'lakshmivyas' } gen = Generator(s) gen.generate_all() res = s.content.resource_from_path(about2.path) assert hasattr(res, 'meta') assert hasattr(res.meta, 'title') assert hasattr(res.meta, 'author') assert hasattr(res.meta, 'twitter') assert res.meta.title == "Even nicer title" assert res.meta.author == "Lakshmi Vyas" assert res.meta.twitter == "lakshmivyas" target = File(Folder(s.config.deploy_root_path).child('about2.html')) text = target.read_all() q = PyQuery(text) for k, v in d.items(): if not k == 'title': assert v in q("span." + k).text() assert q("span.title").text() == "Even nicer title"
def test_has_resource_changed(self): site = Site(TEST_SITE) site.load() resource = site.content.resource_from_path(TEST_SITE.child('content/about.html')) gen = Generator(site) gen.generate_all() assert not gen.has_resource_changed(resource) import time time.sleep(1) text = resource.source_file.read_all() resource.source_file.write(text) assert gen.has_resource_changed(resource) gen.generate_all() assert not gen.has_resource_changed(resource) time.sleep(1) l = File(TEST_SITE.child('layout/root.html')) l.write(l.read_all()) assert gen.has_resource_changed(resource)
def test_context_providers(self): site = Site(TEST_SITE, Config(TEST_SITE, config_dict={ "context": { "data": { "abc": "def" }, "providers": { "nav": "nav.yaml" } } })) nav = """ main: - home - articles - projects """ text = """ {% extends "base.html" %} {% block main %} {{nav}} {% for item in nav.main %} {{item}} {% endfor %} abc = {{ abc }} Hi! I am a test template to make sure jinja2 generation works well with hyde. {{resource.name}} {% endblock %} """ File(TEST_SITE.child('nav.yaml')).write(nav) site.load() resource = site.content.resource_from_path(TEST_SITE.child('content/about.html')) gen = Generator(site) resource.source_file.write(text) gen.generate_all() target = File(site.config.deploy_root_path.child(resource.name)) out = target.read_all() assert "abc = def" in out assert "home" in out assert "articles" in out assert "projects" in out
class Dependents(IterableUserDict): """ Represents the dependency graph for hyde. """ def __init__(self, sitepath, depends_file_name='.hyde_deps'): self.sitepath = Folder(sitepath) self.deps_file = File(self.sitepath.child(depends_file_name)) self.data = {} if self.deps_file.exists: self.data = yaml.load(self.deps_file.read_all()) import atexit atexit.register(self.save) def save(self): """ Saves the dependency graph (just a dict for now). """ if self.deps_file.parent.exists: self.deps_file.write(yaml.dump(self.data))
def test_has_resource_changed(self): site = Site(TEST_SITE) site.load() resource = site.content.resource_from_path( TEST_SITE.child('content/about.html')) gen = Generator(site) gen.generate_all() assert not gen.has_resource_changed(resource) import time time.sleep(1) text = resource.source_file.read_all() resource.source_file.write(text) assert gen.has_resource_changed(resource) gen.generate_all() assert not gen.has_resource_changed(resource) time.sleep(1) l = File(TEST_SITE.child('layout/root.html')) l.write(l.read_all()) assert gen.has_resource_changed(resource)
def test_can_execute_less(self): s = Site(TEST_SITE) s.config.plugins = ['hyde.ext.plugins.less.LessCSSPlugin'] paths = ['/usr/local/share/npm/bin/lessc', '~/local/bin/lessc'] less = [path for path in paths if File(path).exists] if not less: assert False, "Cannot find the lessc executable" less = less[0] s.config.less = Expando(dict(app=less)) source = TEST_SITE.child('content/media/css/site.less') target = File(Folder(s.config.deploy_root_path).child('media/css/site.css')) gen = Generator(s) gen.generate_resource_at_path(source) assert target.exists text = target.read_all() expected_text = File(LESS_SOURCE.child('expected-site.css')).read_all() assert text == expected_text return
def do_404(self): """ Sends a 'not found' response. """ site = self.server.site if self.path != site.config.not_found: self.redirect(site.config.not_found) else: res = site.content.resource_from_relative_deploy_path( site.config.not_found) message = "Requested resource not found" if not res: logger.error("Cannot find the 404 template [%s]." % site.config.not_found) else: f404 = File(self.translate_path(site.config.not_found)) if f404.exists: message = f404.read_all() self.send_response(200, message)
def test_can_compress_with_stylus(self): s = Site(TEST_SITE) s.config.mode = "production" s.config.plugins = ['hyde.ext.plugins.stylus.StylusPlugin'] paths = ['/usr/local/share/npm/bin/stylus', '~/local/bin/stylus'] stylus = [path for path in paths if File(path).exists] if not stylus: assert False, "Cannot find the stylus executable" stylus = stylus[0] s.config.stylus = Expando(dict(app=stylus)) source = TEST_SITE.child('content/media/css/site.styl') target = File(Folder(s.config.deploy_root_path).child('media/css/site.css')) gen = Generator(s) gen.generate_resource_at_path(source) assert target.exists text = target.read_all() expected_text = File(STYLUS_SOURCE.child('expected-site-compressed.css')).read_all() assert text.strip() == expected_text.strip()
def test_can_parse_blockdown(self): s = Site(TEST_SITE) s.config.plugins = ['hyde.ext.plugins.blockdown.BlockdownPlugin'] txt ="This template tests to make sure blocks can be replaced with markdownish syntax." templ = """ {%% extends "base.html" %%} =====title======== %s ====/title========""" content = (templ.strip() % txt).strip() bd = File(TEST_SITE.child('content/blockdown.html')) bd.write(content) gen = Generator(s) gen.generate_resource_at_path(bd.path) res = s.content.resource_from_path(bd.path) target = File(s.config.deploy_root_path.child(res.relative_deploy_path)) assert target.exists text = target.read_all() q = PyQuery(text) assert q('title').text().strip() == txt.strip()
def do_404(self): """ Sends a 'not found' response. """ site = self.server.site if self.path != site.config.not_found: self.redirect(site.config.not_found) else: res = site.content.resource_from_relative_deploy_path( site.config.not_found) message = "Requested resource not found" if not res: logger.error( "Cannot find the 404 template [%s]." % site.config.not_found) else: f404 = File(self.translate_path(site.config.not_found)) if f404.exists: message = f404.read_all() self.send_response(200, message)
def test_reference(self): text = u""" === is_processable: False === {% filter markdown|typogrify %} §§ heading This is a heading ================= §§ /heading §§ content Hyde & Jinja §§ / {% endfilter %} """ text2 = u""" ※ inc.md as inc {% filter markdown|typogrify %} {{ inc.heading }} {{ inc.content }} {% endfilter %} """ site = Site(TEST_SITE) site.config.plugins = [ 'hyde.ext.plugins.meta.MetaPlugin', 'hyde.ext.plugins.markings.MarkingsPlugin', 'hyde.ext.plugins.markings.ReferencePlugin'] inc = File(site.content.source_folder.child('inc.md')) inc.write(text.strip()) src = File(site.content.source_folder.child('src.html')) src.write(text2.strip()) gen = Generator(site) gen.generate_all() f = File(site.config.deploy_root_path.child(src.name)) assert f.exists html = f.read_all() assert_valid_conversion(html)
def test_walk_resources_sorted_using_generator(self): s = Site(TEST_SITE) cfg = """ meta: time: !!timestamp 2010-10-23 title: NahNahNah plugins: - hyde.ext.plugins.meta.MetaPlugin - hyde.ext.plugins.sorter.SorterPlugin sorter: time: attr: meta.time filters: source_file.kind: html """ s.config = Config(TEST_SITE, config_dict=yaml.load(cfg)) text = """ --- time: !!timestamp 2010-12-31 title: YayYayYay --- {% extends "base.html" %} {% block main %} {% set latest = site.content.walk_resources_sorted_by_time()|reverse|first %} <span class="latest">{{ latest.meta.title }}</span> {% endblock %} """ about2 = File(TEST_SITE.child('content/about2.html')) about2.write(text) gen = Generator(s) gen.generate_all() from pyquery import PyQuery target = File(Folder(s.config.deploy_root_path).child('about2.html')) text = target.read_all() q = PyQuery(text) assert q('span.latest').text() == 'YayYayYay'
def test_walk_resources_sorted_using_generator(self): s = Site(TEST_SITE) cfg = """ meta: time: !!timestamp 2010-10-23 title: NahNahNah plugins: - hyde.ext.plugins.meta.MetaPlugin - hyde.ext.plugins.sorter.SorterPlugin sorter: time: attr: meta.time filters: source_file.kind: html """ s.config = Config(TEST_SITE, config_dict=yaml.load(cfg)) text = """ --- time: !!timestamp 2010-12-31 title: YayYayYay --- {% extends "base.html" %} {% block main %} {% set latest = site.sorter.time(site.content)|reverse|first %} <span class="latest">{{ latest.meta.title }}</span> {% endblock %} """ about2 = File(TEST_SITE.child('content/about2.html')) about2.write(text) gen = Generator(s) gen.generate_all() from pyquery import PyQuery target = File(Folder(s.config.deploy_root_path).child('about2.html')) text = target.read_all() q = PyQuery(text) assert q('span.latest').text() == 'YayYayYay'
def test_syntext(self): text = u""" ~~~~~~~~css~~~~~~~ .body{ background-color: white; } ~~~~~~~~~~~~~~~~~~ """ site = Site(TEST_SITE) site.config.plugins = [ 'hyde.ext.plugins.meta.MetaPlugin', 'hyde.ext.plugins.syntext.SyntextPlugin'] syn = File(site.content.source_folder.child('syn.html')) syn.write(text) gen = Generator(site) gen.generate_all() f = File(site.config.deploy_root_path.child(syn.name)) assert f.exists html = f.read_all() assert html q = PyQuery(html) assert q('figure.code').length == 1
def test_syntext(self): text = u""" ~~~~~~~~css~~~~~~~ .body{ background-color: white; } ~~~~~~~~~~~~~~~~~~ """ site = Site(TEST_SITE) site.config.plugins = [ 'hyde.ext.plugins.meta.MetaPlugin', 'hyde.ext.plugins.syntext.SyntextPlugin' ] syn = File(site.content.source_folder.child('syn.html')) syn.write(text) gen = Generator(site) gen.generate_all() f = File(site.config.deploy_root_path.child(syn.name)) assert f.exists html = f.read_all() assert html q = PyQuery(html) assert q('figure.code').length == 1