ferron

Ferron is a fast and simple static website generator made with Lua.
Log | Files | Refs | Submodules | README | LICENSE

commit 2ad639dac5e5765324f84d8c9614fd2f8b79fb8f
parent 82257f9dbd38e3f67ef15168c2cc61330e1eedf0
Author: Hugo Soucy <hsoucy@kronostechnologies.com>
Date:   Wed, 24 Oct 2018 13:41:04 -0400

Rename some function + test etlua template engine

Diffstat:
Mferron.lua | 2++
Mferron/content.lua | 4++--
Mferron/feed.lua | 2+-
Mferron/list.lua | 2+-
Mferron/page.lua | 13+++++++++----
Mferron/tag.lua | 2+-
Mferron/utilities/template-utils.lua | 23+++++++++++++++++++----
7 files changed, 35 insertions(+), 13 deletions(-)

diff --git a/ferron.lua b/ferron.lua @@ -8,6 +8,8 @@ Ferron = { site = {} } -- Set if the build need to be in devmode Ferron.devmode = (arg[1] == "--dev" and true or false) +etlua = require "etlua" + if Ferron.devmode == true then inspect = require "inspect" end diff --git a/ferron/content.lua b/ferron/content.lua @@ -79,7 +79,7 @@ function content.makecontent(contenttype, contenttitle) -- Build the markdown file fileutils.pushfilecontent( contentpath .. archetype.filename .. ".md", - templateutils.processmustache( + templateutils.rendermustache( fileutils.pullfilecontent(archetypepath .. archetypetype .. ".md" ), Ferron.site.path .. Ferron.site.config.paths.templates .. "/partials", archetype @@ -89,7 +89,7 @@ function content.makecontent(contenttype, contenttitle) -- Build the JSON file fileutils.pushfilecontent( contentpath .. archetype.filename .. ".json", - templateutils.processmustache( + templateutils.rendermustache( fileutils.pullfilecontent(archetypepath .. archetypetype .. ".json"), Ferron.site.path .. Ferron.site.config.paths.templates .. "/partials", archetype diff --git a/ferron/feed.lua b/ferron/feed.lua @@ -15,7 +15,7 @@ function feed.makefeed(entries, destination) if path.isfile(feedtemplate) then fileutils.pushfilecontent( destination .. "/" .. v.name .. v.extension, - templateutils.processmustache( + templateutils.rendermustache( fileutils.pullfilecontent(feedtemplate), feedpartials, entries diff --git a/ferron/list.lua b/ferron/list.lua @@ -105,7 +105,7 @@ function list.makelist() -- Build and push the HTML page fileutils.pushfilecontent( list_htmlpath .. "/" .. fileutils.getplainname(list) .. ".html", - templateutils.processmustache( + templateutils.rendermustache( fileutils.pullfilecontent(templateutils.selecttemplate(true, list_conf.template)), templatespath .. "/partials", list_conf_mt diff --git a/ferron/page.lua b/ferron/page.lua @@ -55,13 +55,16 @@ function page.makepage() json.encode(page_conf, {indent = true, keyorder = Ferron.site.config.metaskeyorder}) ) + + print(page) + -- Build and push the HTML page fileutils.pushfilecontent( page_htmlpath .. "/" .. fileutils.getplainname(page) .. ".html", - templateutils.processmustache( - fileutils.pullfilecontent(templateutils.selecttemplate(false, page_conf.template)), - templatespath .. "/partials", - page_conf_mt + templateutils.rendertemplate( + templateutils.selecttemplate(false, page_conf.template), + page_conf_mt, + templatespath .. "/partials" ) ) end @@ -73,6 +76,8 @@ function page.makepage() } ) + os.exit('1') + print("ยง " .. tableutils.length(Ferron.site.pagestable) .. " HTML pages have been created.") print("==========") end diff --git a/ferron/tag.lua b/ferron/tag.lua @@ -50,7 +50,7 @@ function tag.maketagpage() -- Build the HTML file fileutils.pushfilecontent( htmlpath .. "/tag/" .. tag .. ".html", - templateutils.processmustache( + templateutils.rendermustache( fileutils.pullfilecontent(Ferron.site.path .. Ferron.site.config.paths.templates .. "/tag.mustache"), Ferron.site.path .. Ferron.site.config.paths.templates .. "/partials", tag_tb diff --git a/ferron/utilities/template-utils.lua b/ferron/utilities/template-utils.lua @@ -27,7 +27,7 @@ function templateutils.selecttemplate(index, templatename) end -- process mustache -function templateutils.processmustache(tpl, partialspath, data) +function templateutils.rendermustache(tpl, partialspath, data) local partials = {} for i,v in ipairs(lustache:parse(tpl)) do @@ -39,15 +39,30 @@ function templateutils.processmustache(tpl, partialspath, data) return lustache:render(tpl, data, partials) end -function templateutils.processetlua(template, data) +-- +function templateutils.renderetlua(template, data) local tpl = etlua.compile(template) + print(tpl(data)) + return tpl(data) end -- process template -function templateutils.processtemplate(template, data) - print(template, data) +function templateutils.rendertemplate(template, data, partials) + local extension = path.extension(template) + local render = nil + + + if extension == ".etlua" then + print(extension) + render = templateutils.renderetlua(fileutils.pullfilecontent(template), data) + elseif extension == ".mustache" then + print(extension) + render = templateutils.rendermustache(fileutils.pullfilecontent(template), partials, data) + end + + return render end return templateutils