Commit ef50f63d authored by Denis Salem's avatar Denis Salem
Browse files

done with IncludeHTML

parent d96841c9
......@@ -6,5 +6,7 @@ style: features
---
## V __en__ C is super easy to use and learn!
Here's a random number .:GetRandomNumber::0::100::0:.
.:DoesntExists:.
.:IncludeHTML::Lolilool:.
.:IncludeHTML:: ../../../../../../../etc/shadow :.
......@@ -106,7 +106,7 @@
DONE | Add random number generator.
WIP | Massive refactorisation, code cleaning and optimisation.
WIP | Change nomenclature: Most of the usual patterns are changed. Fix doc.
WIP | Add function Include. (Add a directory force included ressources)
DONE | Add function Include. (Add a directory force included ressources)
TODO | Fix vertical scroll bar in code snippet.
TODO | Add relevant templates for themes.
TODO | Add categories tree in entry.
......
......@@ -18,17 +18,8 @@
# along with VenC. If not, see <http://www.gnu.org/licenses/>.
import sys
import importlib
from venc2.commands.export import export_blog
from venc2.commands.export import edit_and_export
from venc2.commands.export import export_and_remote_copy
from venc2.commands.install import install_theme
from venc2.commands.new import new_blog
from venc2.commands.new import new_entry
from venc2.commands.print import print_version
from venc2.commands.print import print_themes
from venc2.commands.print import print_help
from venc2.commands.remote import remote_copy
from venc2.helpers import notify
from venc2.l10n import messages;
from venc2.l10n import locale_err;
......@@ -36,35 +27,33 @@ from venc2.l10n import locale_err;
if locale_err:
notify(messages.cannot_get_current_locale, color="YELLOW")
command_index = {"-v": [print_version, 0],
"-nb": [new_blog, -1],
"-ne": [new_entry, 2],
"-xb": [export_blog, 1],
"-ex": [edit_and_export, 1],
"-xftp": [export_and_remote_copy, 1],
"-rc": [remote_copy, 0],
"-it": [install_theme, 1],
"-h": [print_help, 0],
"-t": [print_themes, 0],
"--themes": [print_themes, 0],
"--help": [print_help, 0],
"--remote-copy": [remote_copy, 0],
"--export-via-ftp": [export_and_remote_copy, 1],
"--edit-and-export": [edit_and_export, 1],
"--install-theme": [install_theme, 1],
"--export-blog": [export_blog, 1],
"--new-entry": [new_entry, 2],
"--new-blog": [new_blog, -1],
"--version": [print_version, 0]}
command_index = {"-v": [".print", "print_version", 0],
"-nb": [".new", "new_blog", -1],
"-ne": [".new", "new_entry", 2],
"-xb": [".export", "export_blog", 1],
"-ex": [".export", "edit_and_export", 1],
"-xftp": [".export", "export_and_remote_copy", 1],
"-rc": [".remote", "remote_copy", 0],
"-it": [".install", "install_theme", 1],
"-h": [".print", "print_help", 0],
"-t": [".print", "print_themes", 0],
"--themes": [".print", "print_themes", 0],
"--help": [".print", "print_help", 0],
"--install-theme": [".install", "install_theme", 1],
"--remote-copy": [".remote", "remote_copy", 0],
"--export-via-ftp": [".export", "export_and_remote_copy", 1],
"--edit-and-export": [".export", "edit_and_export", 1],
"--export-blog": [".export", "export_blog", 1],
"--new-entry": [".new", "new_entry", 2],
"--new-blog": [".new", "new_blog", -1],
"--version": [".print", "print_version", 0]}
def argv_handler(argv=None):
argv = argv if argv != None else sys.argv[1:]
if argv != []:
if argv[0] in command_index:
if command_index[argv[0]][1] != -1:
arguments = argv[1:command_index[argv[0]][1]+1]
if command_index[argv[0]][2] != -1:
arguments = argv[1:command_index[argv[0]][2]+1]
else:
arguments = list()
......@@ -75,7 +64,9 @@ def argv_handler(argv=None):
else:
break
command_index[argv[0]][0](arguments)
module = importlib.import_module(command_index[argv[0]][0], "venc2.commands")
command = getattr(module, command_index[argv[0]][1])
command(arguments)
argv_handler(argv[len(arguments)+1:])
else:
......
......@@ -81,3 +81,4 @@ class Messages:
variable_error_in_filename="Variable error in main configuration file where paths and filenames are defined: {0} doesn't exists."
wrong_pattern_argument="Argument '{0}' = '{1}' from pattern '{2}' is wrong."
pattern_argument_must_be_integer="It must be a positive integer."
wrong_permissions = "{0} : You don't have the right permissions on this file."
......@@ -21,9 +21,9 @@ class Messages:
blog_created = "Votre blog a été crée!"
theme_installed = "Le thème à bien été installé!"
entry_written = "La publication a bien été ajouté!"
file_not_found = "{0}: Ce fichier ou ce dossier n'existe pas."
file_already_exists = "{0}: {1}: Le fichier existe déjà."
invalid_entry_filename = "{0}: Nom de fichier invalide pour une publication"
file_not_found = "{0} : Ce fichier ou ce dossier n'existe pas."
file_already_exists = "{0} : {1}: Le fichier existe déjà."
invalid_entry_filename = "{0} : Nom de fichier invalide pour une publication"
blog_name = "Nom du blog"
your_name = "Votre nom"
blog_description = "Courte description du blog"
......@@ -33,10 +33,10 @@ class Messages:
blog_url = "L'url du blog"
blog_language = "La langue du blog"
your_email = "Votre adresse email"
missing_params = "{0}: Paramètres manquants."
cannot_read_in = "{0}: Impossible de lire dans {1}."
missing_params = "{0} : Paramètres manquants."
cannot_read_in = "{0} : Impossible de lire dans {1}."
nothing_to_do = "Rien à faire."
unknown_command = "{0}: Commande inconnue."
unknown_command = "{0} : Commande inconnue."
no_blog_configuration = "Le fichier de configuration du blog n'existe pas ou vous n'avez pas les bonnes permissions."
missing_mandatory_field_in_blog_conf = "Attention, le champ \"{0}\" est manquant dans le fichier de configuration principal du blog."
username="Nom d'utilisateur: "
......@@ -68,15 +68,16 @@ class Messages:
theme_description_dummy = "Le thème vide. Il donne une bonne base pour concevoir le votre."
theme_description_gentle = "Thème mono colonne, très clair, aéré et élégant. Idéal pour un blog."
theme_description_tessellation = "Thème comportant trois colonnes, très clair, aéré et élégant. Idéal pour une galerie."
theme_doesnt_exists = "{0}: Ce thème n'existe pas."
unknown_text_editor = "{0}: Éditeur de texte inconnu."
theme_doesnt_exists = "{0} : Ce thème n'existe pas."
unknown_text_editor = "{0} : Éditeur de texte inconnu."
theme_name = "Nom du thème"
entry_is_empty = "{0}: Le contenu de la publication est vide."
entry_is_empty = "{0} : Le contenu de la publication est vide."
missing_entry_content_inclusion="Thème invalide. Il manque l'inclusion du contenu de la publication dans entry.html et/ou rssEntry.html"
unknown_language="Pygments: {0}: Langage inconnu."
unknown_language="Pygments: {0} : Langage inconnu."
pre_process="Pré-traitement du théme et des publications..."
directory_not_copied="Le dossier ne peut être copié. Erreur: %s"
variable_error_in_filename="Erreur de variable dans le fichier de configuration principal où les chemins et noms de fichier sont définis: {0} n'existe pas."
wrong_pattern_argument="L'argument '{0}' = '{1}' du motif '{2}' n'est pas correct."
pattern_argument_must_be_integer="L'argument doit être un entier positif."
wrong_permissions = "{0} : Vous n'avez pas les bonnes permissions d'accès sur ce fichier."
......@@ -19,22 +19,26 @@
from venc2 import venc_version
from venc2.l10n import messages
import venc2.helpers.PatternInvalidArgument
from venc2.helpers import PatternInvalidArgument
def get_venc_version(argv):
return venc_version
def include_html(argv):
try:
include_string = open("includes/"+argv[0], 'r').read()
filename = argv[0]
include_string = open("includes/"+filename, 'r').read()
return include_string
except PermissionError:
raise PatternInvalidArgument("path", argv[0], )
raise PatternInvalidArgument("path", filename, messages.wrong_permissions.format(argv[0]))
except FileNotFoundError:
raise PatternInvalidArgument("path", argv[0], )
raise PatternInvalidArgument("path", filename, messages.file_not_found.format(filename))
non_contextual_pattern_name = {
"GetVenCVersion" : get_venc_version
"Include" : include
non_contextual_pattern_names = {
"GetVenCVersion" : get_venc_version,
"IncludeHTML" : include_html
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment