From b2b6a070d1e8b208ca885bb6a4209e24bf2c0c22 Mon Sep 17 00:00:00 2001 From: LongHairedHacker Date: Thu, 26 Feb 2015 20:26:39 +0100 Subject: [PATCH] Just playing around a bit. --- .gitignore | 1 + requirements.txt | 2 + test_input/rendered_root/index.html | 7 ++++ test_input/rendered_root/page2.html | 7 ++++ test_input/rendered_root/subdir/page3.html | 7 ++++ test_input/templates/base.html | 7 ++++ test_input/testblog.py | 28 +++++++++++++ verdandi/__init__.py | 0 verdandi/__init__.pyc | Bin 0 -> 110 bytes verdandi/mixins/__init__.py | 0 verdandi/mixins/__init__.pyc | Bin 0 -> 117 bytes verdandi/mixins/menuitemmixin.py | 18 +++++++++ verdandi/mixins/menuitemmixin.pyc | Bin 0 -> 767 bytes verdandi/mixins/messagemixin.py | 6 +++ verdandi/mixins/messagemixin.pyc | Bin 0 -> 480 bytes verdandi/mixins/rendermixin.py | 6 +++ verdandi/mixins/templatemixin.py | 22 +++++++++++ verdandi/mixins/templatemixin.pyc | Bin 0 -> 1098 bytes verdandi/module.pyc | Bin 0 -> 621 bytes verdandi/modules/__init__.py | 0 verdandi/modules/__init__.pyc | Bin 0 -> 118 bytes verdandi/modules/page.py | 17 ++++++++ verdandi/modules/page.pyc | Bin 0 -> 706 bytes verdandi/verdandi.py | 44 +++++++++++++++++++++ verdandi/verdandi.pyc | Bin 0 -> 1631 bytes 25 files changed, 172 insertions(+) create mode 100644 .gitignore create mode 100644 requirements.txt create mode 100644 test_input/rendered_root/index.html create mode 100644 test_input/rendered_root/page2.html create mode 100644 test_input/rendered_root/subdir/page3.html create mode 100644 test_input/templates/base.html create mode 100644 test_input/testblog.py create mode 100644 verdandi/__init__.py create mode 100644 verdandi/__init__.pyc create mode 100644 verdandi/mixins/__init__.py create mode 100644 verdandi/mixins/__init__.pyc create mode 100644 verdandi/mixins/menuitemmixin.py create mode 100644 verdandi/mixins/menuitemmixin.pyc create mode 100644 verdandi/mixins/messagemixin.py create mode 100644 verdandi/mixins/messagemixin.pyc create mode 100644 verdandi/mixins/rendermixin.py create mode 100644 verdandi/mixins/templatemixin.py create mode 100644 verdandi/mixins/templatemixin.pyc create mode 100644 verdandi/module.pyc create mode 100644 verdandi/modules/__init__.py create mode 100644 verdandi/modules/__init__.pyc create mode 100644 verdandi/modules/page.py create mode 100644 verdandi/modules/page.pyc create mode 100644 verdandi/verdandi.py create mode 100644 verdandi/verdandi.pyc diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8aa978b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +virtenv diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..5a9d4d5 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +Jinja2==2.7.3 +MarkupSafe==0.23 diff --git a/test_input/rendered_root/index.html b/test_input/rendered_root/index.html new file mode 100644 index 0000000..43bd345 --- /dev/null +++ b/test_input/rendered_root/index.html @@ -0,0 +1,7 @@ + + + A cool new Page + + + + \ No newline at end of file diff --git a/test_input/rendered_root/page2.html b/test_input/rendered_root/page2.html new file mode 100644 index 0000000..f0fa0bb --- /dev/null +++ b/test_input/rendered_root/page2.html @@ -0,0 +1,7 @@ + + + An other cool Page + + + + \ No newline at end of file diff --git a/test_input/rendered_root/subdir/page3.html b/test_input/rendered_root/subdir/page3.html new file mode 100644 index 0000000..da0660a --- /dev/null +++ b/test_input/rendered_root/subdir/page3.html @@ -0,0 +1,7 @@ + + + Yet an other cool Page + + + + \ No newline at end of file diff --git a/test_input/templates/base.html b/test_input/templates/base.html new file mode 100644 index 0000000..4cde369 --- /dev/null +++ b/test_input/templates/base.html @@ -0,0 +1,7 @@ + + + {{page_title}} + + + + diff --git a/test_input/testblog.py b/test_input/testblog.py new file mode 100644 index 0000000..acffdf1 --- /dev/null +++ b/test_input/testblog.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python2 + +import sys +sys.path.append('../') + +from verdandi.verdandi import Verdandi +from verdandi.modules.page import Page + +class TestPage1(Page): + title = "A cool new Page" + +class TestPage2(Page): + title = "An other cool Page" + url = "page2.html" + +class TestPage3(Page): + title = "Yet an other cool Page" + url = "subdir/page3.html" + + +class TestBlog(Verdandi): + modules = [TestPage1(), + TestPage2(), + TestPage3()] + + +testblog = TestBlog() +testblog.run() diff --git a/verdandi/__init__.py b/verdandi/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/verdandi/__init__.pyc b/verdandi/__init__.pyc new file mode 100644 index 0000000000000000000000000000000000000000..2c349ab7e187d6623ff6c450bdd935878731f07f GIT binary patch literal 110 zcmZSn%*z$H@O4Ns0~9a3 literal 0 HcmV?d00001 diff --git a/verdandi/mixins/__init__.py b/verdandi/mixins/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/verdandi/mixins/__init__.pyc b/verdandi/mixins/__init__.pyc new file mode 100644 index 0000000000000000000000000000000000000000..063bbed915ab6aff371bea69ae86a2abf620a877 GIT binary patch literal 117 zcmZSn%*z$G{B=k&0~9aEGd|zSNV~8d)M2{Y6k3NXriSB3E_%x09oI8Mw zO|`mprX1(%yxL+sWJXx_3<3t1L4DEz%{ro8rp`jffj#R{GL1T1(uXkh#O1Cqvdt@P z*71`oi_Axs7aO?7vNw>8;9q>IN0bW~)ZvEc8Hu2Y(7V$_0qJfN!AVHNxkuAEVW=KZ z6Pc<+f0b&ja*XEKmU~+o*X4j+xe(DZtxe_RWsyFZ!m+1ST|{z>izbW8IG#s%P37M2 zwk_YLg^@5g;sK?rHN~T2Tcxo!otp?DiP%#_aXff6wN5LY4@$lOJK#=iTDI}>%^l&~ zvR-5WsFuPl?IDD`eXrj>hyEnm!7In2RF#%SDKW29xzMWu+k|ro`$?FQ?6R=qg#QZS v>rejcFhQwYr(AXDhn_sJBR>P<7Z1-Sb8_&HFVTOS$W#~29G84gmb?A{m|dCc literal 0 HcmV?d00001 diff --git a/verdandi/mixins/messagemixin.py b/verdandi/mixins/messagemixin.py new file mode 100644 index 0000000..f63f402 --- /dev/null +++ b/verdandi/mixins/messagemixin.py @@ -0,0 +1,6 @@ +#!/usr/bin/env python2 + +class MessageMixin(object): + + def process_message(self, message): + return [] diff --git a/verdandi/mixins/messagemixin.pyc b/verdandi/mixins/messagemixin.pyc new file mode 100644 index 0000000000000000000000000000000000000000..06f9e360bf3892d48882dba91c1dcd388980284c GIT binary patch literal 480 zcmbVIF;2rk5F9%YPy|A>lvJ+l4s4spy!!vq%k= zc5df(c4yC%ujASG$LDQ>@tg3xV#pc60uERuunFFQH{fnbl46mm&L0uxPNaTt^Y*3f zf2SlYTr=d9z!BO79kEPNEix@PDM3TY4MX+_RK;=`L|*U8p?8@o0~5Di`2(^p8fQ!q zK+c)vdGYMFw(f0Pbh?uiqcE_1^XgA1+iZu1{bsD~^GehLNqpHMQ)BwNbH?~tAl+b} s)})p0v~&H7b;VBTp9@~ow2aT1@@BYybd3*!|IPNg@ literal 0 HcmV?d00001 diff --git a/verdandi/mixins/rendermixin.py b/verdandi/mixins/rendermixin.py new file mode 100644 index 0000000..09329c8 --- /dev/null +++ b/verdandi/mixins/rendermixin.py @@ -0,0 +1,6 @@ +#!/usr/bin/env python2 + +class RenderMixin(object): + + def render(self, output_directory, jinja_env): + return None diff --git a/verdandi/mixins/templatemixin.py b/verdandi/mixins/templatemixin.py new file mode 100644 index 0000000..ce597cd --- /dev/null +++ b/verdandi/mixins/templatemixin.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python2 + +import os + +class TemplateMixin(object): + template = "base.html" + url = "index.html" + context = {} + + def get_context(self): + return self.context + + def render(self, output_directory, jinja_env): + template = jinja_env.get_template(self.template) + html = template.render(self.get_context()) + out_path = os.path.join(output_directory, self.url) + out_dir = os.path.dirname(out_path) + if not os.path.isdir(out_dir): + os.mkdir(out_dir) + out_file = open(out_path, "wb") + out_file.write(html) + out_file.close() diff --git a/verdandi/mixins/templatemixin.pyc b/verdandi/mixins/templatemixin.pyc new file mode 100644 index 0000000000000000000000000000000000000000..8642b8d04702b10942be7c1acc06a293df848131 GIT binary patch literal 1098 zcmbVL&5qMR4E7}b*_IYom5{h2p&U?q;EE7p&-9Sp3%x{XGG!;^r^>kdBV|wJHFyKw zj3W;K{@ixC0&T}*dpw^%d))Bnbo}P~kE@K1pHTMqvivI%x%>>3L@QAOvW7N>@{qm~ z?TJ3E0vumPJqdNcGXwT%U5M_7B08digdGl+DjDvqsoCD~!2#yp zmYYa+QsG~UHlHtUY@4Tb?iLlQ@C!Z`rRIEl&rc-ov*qN72Sz>+K_&}Dp2@)0`-JwC!9Uv9u<8m2Gkin8qz+XhyKZbMqOVc2Pe;nx&b`it7m*P zO-&>mC0d>c5JT#QR7|MrA=<#0BCU~ExQxJj$&k0}=&5Wx5rO(ng)=I8GzMa{R$icu zQKjB&ypSi_rhKhR(YTs%x@${qeeT*itt|J&=e$^|RbQatX0x@mx^7#?hp?<{yp51L z201=Q*p9b5PUM!&xM}Yhvr)LZNE2J%#Gs~dm=t9#7ZPQK_lJRmz=XbWrHw@Yx95)m zg<1{z@NbO#0JamA z38|I*YCG@Q?;QM`EHA&lpGug10sY@l*b4#;fBAf|Kp@YmeLfLzu O_`4b%UGq^aZ}FMd0r52?m=A~rn l=jNxB=A;(u$H!;pWtPOp>lIX%Z~)cVKqTxyCKUrQ0|2u57O(&S literal 0 HcmV?d00001 diff --git a/verdandi/modules/page.py b/verdandi/modules/page.py new file mode 100644 index 0000000..41c3b8a --- /dev/null +++ b/verdandi/modules/page.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python2 + +from verdandi.mixins.templatemixin import TemplateMixin +from verdandi.mixins.menuitemmixin import MenuItemMixin + + +class Page(TemplateMixin, MenuItemMixin): + title = 'Page Title' + + def get_context(self): + context = super(Page,self).get_context() + context['page_title'] = self.title + return context + + + + diff --git a/verdandi/modules/page.pyc b/verdandi/modules/page.pyc new file mode 100644 index 0000000000000000000000000000000000000000..b5b4a517503fe7c3962d985a5538979ccd719386 GIT binary patch literal 706 zcmb7>u};G<5Qfi5TToG@E{FjkF`-Q93lxN4VkoN8E_AV?#;sDtX;fcPk;()Q#CtLF z0Pvqv=)wS&eepT}-F^0jAD#B_?R`9@-3al$#&VZ18K$Cw$SRsBQsM_x1Y|>+gz!T$ zicCnefU*X?61@;TOd6CmX%w}PA^*gP6n5N!85>&_DVssQ$;!v;}KGi$I8< zy}Jl$i^Pih_|*CCSrS%As96$5g2qkBw64r5k=%R)GdHZK%aYB8{qI`se@lon#f%TI z*=Ztd$s2cyT^#ow%_>XFEbrN6wl0k8Nzu4^N~D-TIC)J{$Eu@hibJ?sm#H;cdrYnC zSgjM$`pA8uzf}`r;dDaXQmx=V5&%Af`9_SbG|$E8m+z%_69|5nS@brCww6gp{ImU& SjODuh`hr)|PEXiX-S7(-YmX`b literal 0 HcmV?d00001 diff --git a/verdandi/verdandi.py b/verdandi/verdandi.py new file mode 100644 index 0000000..633a96f --- /dev/null +++ b/verdandi/verdandi.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python2 + +import os +from jinja2 import Environment, FileSystemLoader + +class Verdandi(object): + + template_dir = "templates" + output_directory = "rendered_root" + modules = [] + + + def __init__(self): + self.jinja_env = Environment(loader=FileSystemLoader(self.template_dir)) + + + def send_message(self, message): + results = [] + + for module in self.modules: + results += module.process_message(message) + + return results + + + def pass_messages(self): + messages = self.send_message(None) + + while len(messages) > 0: + message = messages.pop() + print message + messages = messages + self.send_message(message) + + + def render(self): + if not os.path.exists(self.output_directory): + os.mkdir(self.output_directory) + for module in self.modules: + module.render(self.output_directory, self.jinja_env) + + + def run(self): + self.pass_messages() + self.render() diff --git a/verdandi/verdandi.pyc b/verdandi/verdandi.pyc new file mode 100644 index 0000000000000000000000000000000000000000..cdceb3f0bca6825d697a9c255fb90da39cf8f760 GIT binary patch literal 1631 zcmb7EU27Ce5Urls-Iy3n{D`?%1s@a~e2D0aAR^-D1usEnMR7rzb*I%?=VLS78xlyK z;xF=V`REVOb85!KCyldP)zvlKU3E^?bo}kq((udImlNrp7~=zozXz4!Z=?_zwRR+h zkus7|BxNk4SWFg+>&bf~Sx-KT9EiLb^|@)7^l?D`9nWSG!3-y%o>bd;Q&**{LRiK8 zXER<*XP7=ff$?8do6?m)WMS!-SD3J;)=7zXBDMm0)B~ zWE#nV0c-=?#!PFdXg9+ED+>jcaCZuklxKxysxGL_@UO> zyb{x%a7=LI%cCqmW1QifA;b)#RkI#xnPSW-3iAaFR!7?wX!ecl+?4=`3J!hqsVB{I zPNy-u7HEO=*?(}f`!K`4b!^-^E3dP|y5=}pT9kwz$n0iaxxm;3`kLdco+TVpC4#D> z$EO5yOx!HwY<$G6zX*q4f)cY5t(j%hHwyh{l^^l_D=2g*3W?q%7T`1D6Lt2EJf;%a zxvuj*df+lSA{~Qn3AZlDK_q7Dc1Hj^b2Cv)3|V_cKO2XST2!}_d(@ZTbv+NWd0=z9 zNvNCMz{{Zggn7#Rb$R=xrEC-ZWR$G*G^db1H+@Pvu0pzASTpC$YD)+cr6?i)z-ViF z052_mu(-Nd(-soZr01!4raCp7<0YacZ|2nv?DgyiF-s;C6Zpk^e6|les>L|#KB`dYcPlg2ETZ*x5#H9(SU1sqx9>AbNiQT diLdK-Qxr_k`HQ%E{oHGT-H#ccEG(M~(GR%pA%6e> literal 0 HcmV?d00001