mirror of https://github.com/Malphaet/vkyweb.git
Progress made on the generator, still a lot to do to get a BARELY BEARABLE export
This commit is contained in:
parent
56d22b5aca
commit
fcfe2a434f
|
|
@ -30,7 +30,7 @@ class WebPage(object):
|
|||
|
||||
def get_reserved(self,var):
|
||||
"Get a reserved variable"
|
||||
getattr(self,self.reserved_prefix+var)
|
||||
return getattr(self,self.reserved_prefix+var)
|
||||
|
||||
def add_content(self,text,lang):
|
||||
"Add a line of content, with the appropriates langues"
|
||||
|
|
@ -69,15 +69,16 @@ class WebPage(object):
|
|||
|
||||
def get_variable(self,varname,filter_lang="*"):
|
||||
"Get a variable, if * or nothing is used a filter the program will attempt to give a global variable, or will yield one at random"
|
||||
if varname in self.reserved:
|
||||
return getattr(self,varname)
|
||||
if varname in self.variable:
|
||||
if filter_lang in self.variable[varname]:
|
||||
return self.variable[varname][filter_lang]
|
||||
#print "Getting",varname,filter_lang,"in",self.variables
|
||||
#if varname in self.reserved:
|
||||
# return getattr(self,varname)
|
||||
if varname in self.variables:
|
||||
if filter_lang in self.variables[varname]:
|
||||
return self.variables[varname][filter_lang]
|
||||
else:
|
||||
if filter_lang=="*":
|
||||
return self.variable[varname].items()[0]
|
||||
raise KeyError("The variable "+varname+" doens't exist in te language "+filter_lang)
|
||||
return self.variables[varname].values()[0]
|
||||
raise KeyError("The variable "+varname+" doens't exist in the language "+filter_lang)
|
||||
|
||||
def export(self):
|
||||
"Export the Webobject in every language"
|
||||
|
|
|
|||
|
|
@ -1,52 +1,75 @@
|
|||
# Copyleft (c) 2016 Cocobug All Rights Reserved.
|
||||
# coding=utf-8
|
||||
from tree_parser import *
|
||||
import re,traceback
|
||||
|
||||
|
||||
re_vars=re.compile(".*\#_(?P<variable>.*)_\#|.*\#\#(?P<section>.*)\#\#")
|
||||
|
||||
class HTMLPage(object):
|
||||
"Basic HTML object"
|
||||
def __init__(self,name,variables={}):
|
||||
def __init__(self,name,node):
|
||||
self.html=""
|
||||
self.name=name
|
||||
self.variables=variables
|
||||
self.node=node
|
||||
self.path=""
|
||||
|
||||
def load(self,path):
|
||||
self.path=path
|
||||
try:
|
||||
with open(path) as a:
|
||||
self.html=a.read()
|
||||
self.model=a.read()
|
||||
except:
|
||||
print "Error loading model"
|
||||
|
||||
def replace(self,lang,variables=None):
|
||||
if variables==None:
|
||||
variables=self.variables
|
||||
for var,langs in variables.iteritems():
|
||||
self.html.replace("%_"+var+"_%",langs[lang])
|
||||
def replace(self,lang):
|
||||
self.html=""
|
||||
for line in self.model.splitlines():
|
||||
#print line
|
||||
try:
|
||||
|
||||
variable,section=re_vars.match(line).groups()
|
||||
if variable!=None:
|
||||
#print line,re_vars.match(line),variable
|
||||
#print self.node.config_file
|
||||
#print self.node.get_variable(variable,lang),variable
|
||||
line=line.replace("#_"+variable+"_#",self.node.get_variable(variable,lang))
|
||||
#print line
|
||||
elif section!=None:
|
||||
pass
|
||||
except AttributeError:
|
||||
pass#print " > No match"
|
||||
except:
|
||||
print traceback.print_exc()
|
||||
self.html+=line
|
||||
self.html+=os.linesep
|
||||
#print self.html
|
||||
|
||||
def export(self):
|
||||
"Generate the HTML code and output it"
|
||||
return self.html
|
||||
|
||||
class Container(object):
|
||||
class Container(HTMLPage):
|
||||
"Side menus and title, acess to all special pages"
|
||||
def __init__(self,name,variables,menus):
|
||||
HTMLPage.__init__(self,name,variables)
|
||||
self.menus=menus
|
||||
def __init__(self,name,node):
|
||||
super(Container,self).__init__(name,node)
|
||||
|
||||
def generate(self):
|
||||
self.html=""
|
||||
|
||||
class Data(object):
|
||||
class Data(HTMLPage):
|
||||
"Webpage itself"
|
||||
def __init__(self):
|
||||
HTMLPage.__init__(self)
|
||||
def __init__(self,name,node):
|
||||
super(Data,self).__init__(name,node)
|
||||
|
||||
class DualContainer(Container):
|
||||
"Dual view"
|
||||
pass
|
||||
def __init__(self,name,node):
|
||||
super(DualContainer,self).__init__(name,node)
|
||||
|
||||
|
||||
class DualData(Data):
|
||||
"Dual view"
|
||||
pass
|
||||
|
||||
|
||||
def DataType(ext):
|
||||
"Return some kind of general types depending on the extention"
|
||||
data={"image":[".jpg",".png",".svg",".tiff",".jpeg"],
|
||||
|
|
@ -58,8 +81,24 @@ def DataType(ext):
|
|||
return typename
|
||||
return None
|
||||
|
||||
def makeContainer(tree):
|
||||
|
||||
def makeContainer(node):
|
||||
c=DualContainer(node.name,node)
|
||||
#print node.variables
|
||||
#print node.config_file
|
||||
c.load("generator/model/dual_menu.html")
|
||||
c.replace("fr")
|
||||
return c
|
||||
|
||||
def makeMakeContent(node):
|
||||
c=DualData(node.name,node)
|
||||
c.load("generator/model/dual_page.html")
|
||||
c.replace("fr")
|
||||
return c
|
||||
|
||||
def makePage(node,cont,data):
|
||||
c=DualData(node.name,node)
|
||||
c.replace("fr")
|
||||
cont.export()
|
||||
|
||||
if __name__ == '__main__':
|
||||
pass
|
||||
makeContainer(makeWebsite("sites/example_website"))
|
||||
|
|
|
|||
|
|
@ -0,0 +1,64 @@
|
|||
<!DOCTYPE html>
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>#_title_#</title>
|
||||
<!-- BOOTSTRAP STYLES-->
|
||||
<link href="assets/css/bootstrap.css" rel="stylesheet" />
|
||||
<!-- FONTAWESOME STYLES-->
|
||||
<link href="assets/css/font-awesome.css" rel="stylesheet" />
|
||||
<!-- CUSTOM STYLES-->
|
||||
<link href="assets/css/custom.css" rel="stylesheet" />
|
||||
<!-- GOOGLE FONTS-->
|
||||
<link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css' />
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<div id="wrapper">
|
||||
<div class="navbar navbar-inverse navbar-fixed-top">
|
||||
<div class="adjust-nav">
|
||||
<div class="navbar-header">
|
||||
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".sidebar-collapse">
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</button>
|
||||
<a class="navbar-brand" href="#"><i class="fa fa-square-o "></i> #_websitename_#</a>
|
||||
</div>
|
||||
<!-- <div class="navbar-collapse collapse">
|
||||
<ul class="nav navbar-nav navbar-right">
|
||||
<li><a href="#">Login</a></li>
|
||||
</ul>
|
||||
</div> -->
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<!-- /. NAV TOP -->
|
||||
<nav class="navbar-default navbar-side" role="navigation">
|
||||
<div class="sidebar-collapse">
|
||||
<ul class="nav" id="main-menu">
|
||||
##MENU##
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
<!-- /. NAV SIDE -->
|
||||
<div id="page-wrapper" >
|
||||
##PAGE##
|
||||
</div>
|
||||
<!-- /. PAGE WRAPPER -->
|
||||
</div>
|
||||
<!-- /. WRAPPER -->
|
||||
<!-- SCRIPTS -AT THE BOTOM TO REDUCE THE LOAD TIME-->
|
||||
<!-- JQUERY SCRIPTS -->
|
||||
<script src="assets/js/jquery-1.10.2.js"></script>
|
||||
<!-- BOOTSTRAP SCRIPTS -->
|
||||
<script src="assets/js/bootstrap.min.js"></script>
|
||||
<!-- METISMENU SCRIPTS -->
|
||||
<script src="assets/js/jquery.metisMenu.js"></script>
|
||||
<!-- CUSTOM SCRIPTS -->
|
||||
<script src="assets/js/custom.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
<li class="text-center user-image-back">
|
||||
<img src="assets/img/logo.png" class="img-responsive" />
|
||||
</li>
|
||||
<li><a href="index.html"><i class="fa fa-arrow-left "></i>#_previous_#</a></li>
|
||||
<li class="active">
|
||||
<a href="#"><i class="fa fa-folder"></i>#_articles_#<span class="fa arrow"></span></a>
|
||||
<ul class="nav nav-second-level">
|
||||
<li><a href="index.html"><i class="fa fa-music "></i>Une petite musique</a></li>
|
||||
<li> <a href="index.html"><i class="fa fa-film "></i>Un petit film</a> </li>
|
||||
<li><a href="index.html"><i class="fa fa-file "></i>Un petit article</a></li>
|
||||
<li><a href="index.html"><i class="fa fa-picture-o "></i>Une petite image</a></li>
|
||||
<li>
|
||||
<a href="#"><i class="fa fa-folder"></i>Dossier 1<span class="fa arrow"></span></a>
|
||||
<ul class="nav nav-third-level">
|
||||
<li><a href="index.html"><i class="fa fa-music "></i>Une petite musique</a></li>
|
||||
<li> <a href="index.html"><i class="fa fa-film "></i>Un petit film</a> </li>
|
||||
<li><a href="index.html"><i class="fa fa-file "></i>Un petit article</a></li>
|
||||
<li><a href="index.html"><i class="fa fa-picture-o "></i>Une petite image</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
<li><a href="index.html"><i class="fa fa-gear "></i>#_preferences_#</a></li>
|
||||
<li><a href="#"><i class="fa fa-edit "></i>#_about_#</a></li>
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
<div id="page-inner">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<h2>#_name_#</h2>
|
||||
|
||||
#_content_#
|
||||
</div>
|
||||
</div>
|
||||
<!-- /. ROW -->
|
||||
<hr />
|
||||
|
||||
<!-- /. ROW -->
|
||||
</div>
|
||||
<!-- /. PAGE INNER -->
|
||||
|
|
@ -25,7 +25,7 @@ class WebTree(object):
|
|||
|
||||
def get_variable(self,varname,filter_lang="*"):
|
||||
"Get the corresponding variable"
|
||||
self.config_file.get_variable(varname,filter_lang)
|
||||
return self.config_file.get_variable(varname,filter_lang)
|
||||
|
||||
def convert_local(self,files):
|
||||
pass
|
||||
|
|
@ -56,9 +56,9 @@ class WebSubTree(WebTree):
|
|||
def get_variable(self,varname,filter_lang):
|
||||
"Get the variable, either in it's config or one of the above"
|
||||
try:
|
||||
self.config_file.get_variable(varname,filter_lang)
|
||||
return self.config_file.get_variable(varname,filter_lang)
|
||||
except:
|
||||
self.parent_node.get_variable(varname,filter_lang)
|
||||
return self.parent_node.get_variable(varname,filter_lang)
|
||||
|
||||
def get_config(self):
|
||||
"Try to init a config, if not just use an empty variable set"
|
||||
|
|
@ -131,12 +131,12 @@ class WebNode(WebSubTree):
|
|||
def get_variable(self,varname,filter_lang):
|
||||
"Get the corresponding variable, first in the Webnode, then the config and repeating up until the Root"
|
||||
try:
|
||||
self.file.get_variable(varname,filter_lang)
|
||||
return self.config_file.get_variable(varname,filter_lang)
|
||||
except:
|
||||
try:
|
||||
self.config_file.get_variable(varname,filter_lang)
|
||||
return self.config_file.get_variable(varname,filter_lang)
|
||||
except:
|
||||
self.parent_node.get_variable(varname,filter_lang)
|
||||
return self.parent_node.get_variable(varname,filter_lang)
|
||||
|
||||
def open_node(self):
|
||||
"Open the file in the node, for now the parse is left linked, but later versions will ditch it asap"
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>%_title_%</title>
|
||||
<title>#_title_#</title>
|
||||
<!-- BOOTSTRAP STYLES-->
|
||||
<link href="assets/css/bootstrap.css" rel="stylesheet" />
|
||||
<!-- FONTAWESOME STYLES-->
|
||||
|
|
@ -26,7 +26,7 @@
|
|||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</button>
|
||||
<a class="navbar-brand" href="#"><i class="fa fa-square-o "></i> %_websitename_%</a>
|
||||
<a class="navbar-brand" href="#"><i class="fa fa-square-o "></i> #_websitename_#</a>
|
||||
</div>
|
||||
<!-- <div class="navbar-collapse collapse">
|
||||
<ul class="nav navbar-nav navbar-right">
|
||||
|
|
@ -43,9 +43,9 @@
|
|||
<li class="text-center user-image-back">
|
||||
<img src="assets/img/logo.png" class="img-responsive" />
|
||||
</li>
|
||||
<li><a href="index.html"><i class="fa fa-arrow-left "></i>%_previous_%</a></li>
|
||||
<li><a href="index.html"><i class="fa fa-arrow-left "></i>#_previous_#</a></li>
|
||||
<li class="active">
|
||||
<a href="#"><i class="fa fa-folder"></i>%_articles_%<span class="fa arrow"></span></a>
|
||||
<a href="#"><i class="fa fa-folder"></i>#_articles_#<span class="fa arrow"></span></a>
|
||||
<ul class="nav nav-second-level">
|
||||
<li><a href="index.html"><i class="fa fa-music "></i>Une petite musique</a></li>
|
||||
<li> <a href="index.html"><i class="fa fa-film "></i>Un petit film</a> </li>
|
||||
|
|
@ -61,8 +61,8 @@
|
|||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
<li><a href="index.html"><i class="fa fa-gear "></i>%_preferences_%</a></li>
|
||||
<li><a href="#"><i class="fa fa-edit "></i>%_about_%</a></li>
|
||||
<li><a href="index.html"><i class="fa fa-gear "></i>#_preferences_#</a></li>
|
||||
<li><a href="#"><i class="fa fa-edit "></i>#_about_#</a></li>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
|
|
@ -73,9 +73,9 @@
|
|||
<div id="page-inner">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<h2>%_name_%</h2>
|
||||
<h2>#_name_#</h2>
|
||||
|
||||
%_content_%
|
||||
#_content_#
|
||||
</div>
|
||||
</div>
|
||||
<!-- /. ROW -->
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@ articles_en: Articles
|
|||
articles_fr: Articles
|
||||
previous_en: Previous articles
|
||||
previous_fr: Articles précédents
|
||||
preferences_en: Preferences
|
||||
preferences_fr: Préférences
|
||||
about_en: About me
|
||||
about_fr: A propos
|
||||
----
|
||||
|
|
|
|||
Loading…
Reference in New Issue