diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..62889a2 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +Lajavel \ No newline at end of file diff --git a/src/main/java/lajavel/View.java b/src/main/java/lajavel/View.java index 7abdd73..f8ac5b5 100644 --- a/src/main/java/lajavel/View.java +++ b/src/main/java/lajavel/View.java @@ -35,6 +35,8 @@ public static String make(String viewName, Map.Entry... entries) return viewContent; } + viewContent = importCss(viewContent); + Matcher m = Pattern.compile("\\{\\{([^{{}}]*)\\}\\}").matcher(viewContent); // Creating the target string buffer @@ -81,10 +83,63 @@ public static String getValueOf(String propertyName, Object object) { } } + public static String importCss(String viewContent) { + // get CSS by import + final String cssRegex = "\\{% import (\\S*) %\\}"; // Dans le html on a {% import nomdufichiercss %} + + // Ici on effectue le include avant de s'attaquer au CSS (returnIncluded) + final Matcher cssMatcher = Pattern.compile(cssRegex, Pattern.DOTALL).matcher(returnIncluded(viewContent)); + StringBuffer sbImport = new StringBuffer(); + + while (cssMatcher.find()) { + String css_url = ""; + cssMatcher.appendReplacement(sbImport, css_url); + } + cssMatcher.appendTail(sbImport); + + viewContent = sbImport.toString(); + + return viewContent; + } + + public static String returnIncluded(String viewContent) { + StringBuffer sbImport = new StringBuffer(); + + final String includeRegex = "\\{% include (\\S*) %\\}"; + + final Matcher includeMatcher = Pattern.compile(includeRegex, Pattern.DOTALL).matcher(viewContent); + + while (includeMatcher.find()) { + final String blockRegex = "\\{% block (\\S*) %\\}(.*)\\{% endblock %\\}"; + final Matcher blockMatcher = Pattern.compile(blockRegex, Pattern.DOTALL).matcher(View.getViewContent(includeMatcher.group(1))); + while (blockMatcher.find()){ + includeMatcher.appendReplacement(sbImport, blockMatcher.group(2)); + } + } + includeMatcher.appendTail(sbImport); + + viewContent = sbImport.toString(); + + return viewContent; + } + public static String getViewContent(String viewName) { + // Dans le HTML on a {% include Component:nomdufichierhtml %} + String[] viewNameCategorized = viewName.split("\\:"); + String viewNameCategory = viewNameCategorized[0]; + + if (viewNameCategorized.length > 1) { + viewName = viewNameCategorized[1]; + } + + if (viewNameCategory.equals("Component")) { + viewNameCategory = "components/"; + } else { + viewNameCategory = "views/"; + } // Get the file url, not working in JAR file. - URL resource = View.class.getClassLoader().getResource("views/" + viewName + ".view"); + URL resource = View.class.getClassLoader().getResource(viewNameCategory + viewName + ".view"); if (resource == null) { throw new IllegalArgumentException("file not found!"); diff --git a/src/main/resources/components/header.view b/src/main/resources/components/header.view new file mode 100644 index 0000000..8ddc487 --- /dev/null +++ b/src/main/resources/components/header.view @@ -0,0 +1,6 @@ +{% block header %} + {% import header %} +
+

Welcome In Lajavel

+
+{% endblock %} \ No newline at end of file diff --git a/src/main/resources/public/css/header.css b/src/main/resources/public/css/header.css new file mode 100644 index 0000000..f4ee234 --- /dev/null +++ b/src/main/resources/public/css/header.css @@ -0,0 +1,6 @@ +header h1{ + text-align: center; + font-size: 1.5rem; + color: red; + text-decoration: underline; +} \ No newline at end of file diff --git a/src/main/resources/views/index.view b/src/main/resources/views/index.view index f055960..83871f0 100644 --- a/src/main/resources/views/index.view +++ b/src/main/resources/views/index.view @@ -4,6 +4,8 @@ +{% include Component:header %} +

Bonjour,