commit 99e59adc722d03536d392c3dd37606a532181cbf
parent 73ba21f62047849e3f857df8c7b25a0a0da0ef91
Author: Hugo Soucy <hs0ucy@h50ucy.local>
Date: Mon, 1 Jul 2019 22:07:11 -0400
Replace by shorter module names in requires
Diffstat:
10 files changed, 113 insertions(+), 108 deletions(-)
diff --git a/ferron/content.lua b/ferron/content.lua
@@ -13,8 +13,8 @@ local contentmeta = {
local site = require 'ferron.site'
local fileutils = require 'ferron.utilities.file-utils'
local slugify = require 'ferron.utilities.lua-slugify.slugify'
-local tableutils = require 'ferron.utilities.table-utils'
-local templateutils = require 'ferron.utilities.template-utils'
+local tb = require 'ferron.utilities.table-utils'
+local tp = require 'ferron.utilities.template-utils'
function content.getarchetypes(dir)
local archetypes = {}
@@ -49,7 +49,7 @@ function content.setcontent()
io.flush()
whicharchetype=io.read()
- until (tableutils.haskey(archetypes, tonumber(whicharchetype))) == true
+ until (tb.haskey(archetypes, tonumber(whicharchetype))) == true
repeat
io.write('Please write the title of your new content... \n')
@@ -65,7 +65,7 @@ function content.makecontent(contenttype, contenttitle)
local archetypetype = contenttype or arg[1]
local title = contenttitle or arg[2]
- if tableutils.hasvalue(content.getarchetypes(), archetypetype) and type(title) == 'string' then
+ if tb.hasvalue(content.getarchetypes(), archetypetype) and type(title) == 'string' then
local archetype = {}
local contentpath = site.content .. '/' .. archetypetype .. '/' .. os.date('%Y') ..'/'..os.date('%m') .. '/'
local archetypepath = site.archetypes .. '/'
@@ -83,7 +83,7 @@ function content.makecontent(contenttype, contenttitle)
-- Build the markdown file
fileutils.pushfilecontent(
contentpath .. archetype.filename .. '.md',
- templateutils.rendermustache(
+ tp.rendermustache(
fileutils.pullfilecontent(archetypepath .. archetypetype .. '.md' ),
site.templates .. '/partials',
archetype
@@ -93,7 +93,7 @@ function content.makecontent(contenttype, contenttitle)
-- Build the JSON file
fileutils.pushfilecontent(
contentpath .. archetype.filename .. '.json',
- templateutils.rendermustache(
+ tp.rendermustache(
fileutils.pullfilecontent(archetypepath .. archetypetype .. '.json'),
site.templates .. '/partials',
archetype
diff --git a/ferron/feed.lua b/ferron/feed.lua
@@ -7,22 +7,21 @@ local feedmeta = {
}
local site = require 'ferron.site'
-local fileutils = require 'ferron.utilities.file-utils'
-local tableutils = require 'ferron.utilities.table-utils'
-local templateutils = require 'ferron.utilities.template-utils'
+local fl = require 'ferron.utilities.file-utils'
+local tp = require 'ferron.utilities.template-utils'
function feed.makefeed(entries, destination)
local feedtypes = site.config.feedtypes
- local feedpartials = fileutils.isDirectory(site.templates .. '/partials')
+ local feedpartials = fl.isDirectory(site.templates .. '/partials')
for k, v in pairs(feedtypes) do
local feedtemplate = site.templates .. '/feed/' .. k .. '.mustache'
- if fileutils.isFile(feedtemplate) then
- fileutils.pushfilecontent(
+ if fl.isFile(feedtemplate) then
+ fl.pushfilecontent(
destination .. '/' .. v.name .. v.extension,
- templateutils.rendermustache(
- fileutils.pullfilecontent(feedtemplate),
+ tp.rendermustache(
+ fl.pullfilecontent(feedtemplate),
feedpartials,
entries
)
diff --git a/ferron/init.lua b/ferron/init.lua
@@ -16,7 +16,7 @@ local page = require 'ferron.page'
local link = require 'ferron.link'
local static = require 'ferron.static'
local plugin = require 'ferron.plugin'
-local tableutils = require 'ferron.utilities.table-utils'
+local tb = require 'ferron.utilities.table-utils'
-- App's Globals
-- Init the main namespace
@@ -34,9 +34,15 @@ Ferron = {
if arg[1] == 'build' then
do
- local sitename = arg[3]
+ local sitename
- return tableutils.build{
+ if arg[2] ~= '--dev' then
+ sitename = arg[2]
+ else
+ sitename = arg[3]
+ end
+
+ return tb.build{
site.setsite(sitename),
site.setnavigation(),
page.makepages(),
diff --git a/ferron/link.lua b/ferron/link.lua
@@ -8,9 +8,8 @@ local linkmeta = {
local json = require 'dkjson'
local site = require 'ferron.site'
-local fileutils = require 'ferron.utilities.file-utils'
-local tableutils = require 'ferron.utilities.table-utils'
-local templateutils = require 'ferron.utilities.template-utils'
+local fl = require 'ferron.utilities.file-utils'
+local tb = require 'ferron.utilities.table-utils'
function link.makeshorts()
local links = {}
@@ -18,32 +17,32 @@ function link.makeshorts()
local links_db = site.data .. '/shortlinks.json'
-- If `links_db` dosen't exists create it
- if fileutils.isFile(links_db) == false then
+ if fl.isFile(links_db) == false then
local counter = 0
- fileutils.pushfilecontent(links_db, '')
+ fl.pushfilecontent(links_db, '')
- for k, v in tableutils.sortdescendingpairs(Ferron.site.pagestable) do
+ for k, v in tb.sortdescendingpairs(Ferron.site.pagestable) do
if v.rellink ~= '' then
counter = counter + 1
table.insert(links_keyorder, v.rellink)
- links[v.rellink] = fileutils.shorturlencode(counter)
+ links[v.rellink] = fl.shorturlencode(counter)
- fileutils.pushfilecontent(links_db, json.encode(links, {indent = true, keyorder = links_keyorder}))
+ fl.pushfilecontent(links_db, json.encode(links, {indent = true, keyorder = links_keyorder}))
end
end
else
- links = json.decode(fileutils.pullfilecontent(links_db))
+ links = json.decode(fl.pullfilecontent(links_db))
- for k, v in tableutils.sortdescendingpairs(Ferron.site.pagestable) do
+ for k, v in tb.sortdescendingpairs(Ferron.site.pagestable) do
if v.rellink ~= '' and links[v.rellink] == nil then
table.insert(links_keyorder, v.rellink)
- links[v.rellink] = fileutils.shorturlencode(tableutils.length(links) + 1)
+ links[v.rellink] = fl.shorturlencode(tb.length(links) + 1)
- fileutils.pushfilecontent(links_db, json.encode(links, {indent = true, keyorder = links_keyorder}))
+ fl.pushfilecontent(links_db, json.encode(links, {indent = true, keyorder = links_keyorder}))
end
end
end
@@ -53,12 +52,12 @@ function link.makerewritemap()
local links_db = site.data .. '/shortlinks.json'
local links_map = site.html .. '/shortlinksmap.txt'
- if fileutils.isFile(links_db) then
- links = json.decode(fileutils.pullfilecontent(links_db))
+ if fl.isFile(links_db) then
+ links = json.decode(fl.pullfilecontent(links_db))
if links then
-- Create an empty map file
- fileutils.pushfilecontent(links_map, '')
+ fl.pushfilecontent(links_map, '')
-- Open it
map, map_err = io.open(links_map, 'a')
diff --git a/ferron/page.lua b/ferron/page.lua
@@ -9,9 +9,9 @@ local pagemeta = {
local json = require 'dkjson'
local markdown = require 'discount'
local site = require 'ferron.site'
-local fileutils = require 'ferron.utilities.file-utils'
-local tableutils = require 'ferron.utilities.table-utils'
-local templateutils = require 'ferron.utilities.template-utils'
+local fl = require 'ferron.utilities.file-utils'
+local tb = require 'ferron.utilities.table-utils'
+local tp = require 'ferron.utilities.template-utils'
local feed = require 'ferron.feed'
local function sortentries(entries_tb, list_mt)
@@ -19,7 +19,7 @@ local function sortentries(entries_tb, list_mt)
local entries_count = list_length and 0 or nil
if entries_count then
- for k, v in tableutils.sortdescendingpairs(entries_tb) do
+ for k, v in tb.sortdescendingpairs(entries_tb) do
if entries_count < list_length then
table.insert(list_mt['entries'], v)
@@ -27,7 +27,7 @@ local function sortentries(entries_tb, list_mt)
end
end
else
- for k, v in tableutils.sortdescendingpairs(entries_tb) do
+ for k, v in tb.sortdescendingpairs(entries_tb) do
table.insert(list_mt['entries'], v)
end
end
@@ -38,14 +38,14 @@ end
local function setentries(directory, list_mt)
local entries_tb = {}
- tableutils.each(
+ tb.each(
function(entry)
- local entry_metadatas = fileutils.getpageconf(entry)
- local entry_key = entry_metadatas.date .. 'T' .. entry_metadatas.datetime .. ':' .. fileutils.getrelpath(fileutils.removeextension(entry))
+ local entry_metadatas = fl.getpageconf(entry)
+ local entry_key = entry_metadatas.date .. 'T' .. entry_metadatas.datetime .. ':' .. fl.getrelpath(fl.removeextension(entry))
entries_tb[entry_key] = Ferron.site.pagestable[entry_key]
end,
- tableutils.filter(fileutils.isNotIndex, tableutils.from(fileutils.getdirtree(directory)))
+ tb.filter(fl.isNotIndex, tb.from(fl.getdirtree(directory)))
)
sortentries(entries_tb, list_mt)
@@ -63,65 +63,65 @@ end
local function setmetaprops(pagesource, relpath)
return {
- content = markdown(fileutils.pullfilecontent(pagesource)),
+ content = markdown(fl.pullfilecontent(pagesource)),
navigation = Ferron.site.navigation,
- permalink = site.config.baseurl .. (fileutils.getplainname(pagesource) ~= 'index' and relpath .. '.html' or ''),
- rellink = (fileutils.getplainname(pagesource) ~= 'index' and relpath .. '.html' or ''),
+ permalink = site.config.baseurl .. (fl.getplainname(pagesource) ~= 'index' and relpath .. '.html' or ''),
+ rellink = (fl.getplainname(pagesource) ~= 'index' and relpath .. '.html' or ''),
site = site.config,
updated = os.date('%Y-%m-%dT%H:%M:%S', lfs.attributes(pagesource).modification),
- id = 'tag:' .. site.config.domainname .. ',' .. fileutils.getpageconf(pagesource).date .. ':' .. relpath,
+ id = 'tag:' .. site.config.domainname .. ',' .. fl.getpageconf(pagesource).date .. ':' .. relpath,
entries = {},
}
end
function page.render(pagesource)
local page = pagesource
- local pathRel = fileutils.getrelpath(fileutils.removeextension(page))
- local pathToHtml = fileutils.sethtmlpath(fileutils.getrelpath(fileutils.getdirname(page)))
+ local pathRel = fl.getrelpath(fl.removeextension(page))
+ local pathToHtml = fl.sethtmlpath(fl.getrelpath(fl.getdirname(page)))
local metaTable = setmetatable(
- setmetaprops(page, pathRel), {__index = fileutils.getpageconf(page)}
+ setmetaprops(page, pathRel), {__index = fl.getpageconf(page)}
)
- local shortlinks_db = fileutils.isFile(site.data .. '/shortlinks.json')
- local shortlinks_tb = (shortlinks_db ~= false and json.decode(fileutils.pullfilecontent(shortlinks_db)) or nil)
+ local shortlinks_db = fl.isFile(site.data .. '/shortlinks.json')
+ local shortlinks_tb = (shortlinks_db ~= false and json.decode(fl.pullfilecontent(shortlinks_db)) or nil)
-- Populate Ferron.site.pagestable{}
- if fileutils.isNotIndex(page) then
+ if fl.isNotIndex(page) then
setpagetable(metaTable, pathRel)
end
-- If exists set the shortlink
- if fileutils.isNotIndex(page) then
+ if fl.isNotIndex(page) then
if shortlinks_tb and shortlinks_db then
metaTable.shortlink = (shortlinks_tb[metaTable.rellink] and shortlinks_tb[metaTable.rellink] or nil)
end
end
-- For index page set and get entries
- if fileutils.isIndex(page) then
- setentries(fileutils.getdirname(page), metaTable)
+ if fl.isIndex(page) then
+ setentries(fl.getdirname(page), metaTable)
end
-- If the ancestors of the page dosen't exists make it
- if not fileutils.isDirectory(pathToHtml) then
- fileutils.mkdir(pathToHtml)
+ if not fl.isDirectory(pathToHtml) then
+ fl.mkdir(pathToHtml)
end
-- For each index page create syndication feeds
- if fileutils.isIndex(page) and metaTable.feed ~= false then
+ if fl.isIndex(page) and metaTable.feed ~= false then
feed.makefeed(metaTable, pathToHtml)
end
-- Build and push the HTML page
- fileutils.pushfilecontent(
+ fl.pushfilecontent(
-- Create that page
- pathToHtml .. '/' .. fileutils.getplainname(page) .. '.html',
+ pathToHtml .. '/' .. fl.getplainname(page) .. '.html',
-- With that mustache template
- templateutils.rendertemplate(
- templateutils.selecttemplate(false, metaTable.template),
+ tp.rendertemplate(
+ tp.selecttemplate(false, metaTable.template),
metaTable,
- assert(fileutils.isDirectory(site.templates)) .. '/partials'
+ assert(fl.isDirectory(site.templates)) .. '/partials'
)
)
@@ -129,18 +129,18 @@ function page.render(pagesource)
end
function page.makepages()
- local contentpath = tableutils.from(fileutils.getdirtree(fileutils.isDirectory(site.content)))
- local singlepages = tableutils.filter(fileutils.isNotIndex, contentpath)
- local indexpages = tableutils.filter(fileutils.isIndex, contentpath)
+ local contentpath = tb.from(fl.getdirtree(fl.isDirectory(site.content)))
+ local singlepages = tb.filter(fl.isNotIndex, contentpath)
+ local indexpages = tb.filter(fl.isIndex, contentpath)
-- Render single pages
- tableutils.each(page.render, singlepages)
+ tb.each(page.render, singlepages)
-- Render index pages
- tableutils.each(page.render, indexpages)
+ tb.each(page.render, indexpages)
print('==========')
- print('§ ' .. tableutils.length(Ferron.site.pagestable) .. ' HTML pages have been created.')
+ print('§ ' .. tb.length(Ferron.site.pagestable) .. ' HTML pages have been created.')
print('==========')
return
diff --git a/ferron/plugin.lua b/ferron/plugin.lua
@@ -6,10 +6,10 @@ local pluginmeta = {
end
}
-local fileutils = require 'ferron.utilities.file-utils'
+local fl = require 'ferron.utilities.file-utils'
function plugin.run(site, plugname)
- local plugin = require(site.config.sites .. fileutils.getbasename(site.path) .. site.config.paths.plugins .. '/' .. plugname)
+ local plugin = require(site.config.sites .. fl.getbasename(site.path) .. site.config.paths.plugins .. '/' .. plugname)
return plugin.init(site)
end
diff --git a/ferron/site.lua b/ferron/site.lua
@@ -8,28 +8,28 @@ local sitemeta = {
local lfs = require 'lfs'
local config = require 'ferron.config'
-local tableutils = require 'ferron.utilities.table-utils'
-local fileutils = require 'ferron.utilities.file-utils'
+local tb = require 'ferron.utilities.table-utils'
+local fl = require 'ferron.utilities.file-utils'
-- Create a simple array with the directory name of the sites
function site.getsitelist(siteslocation)
local location = siteslocation or Ferron.site.location
- return tableutils.map(
+ return tb.map(
function(site, i)
- if fileutils.isDirectory(location .. site)
+ if fl.isDirectory(location .. site)
and site ~= '.'
and site ~= '..'
then
return site
end
end,
- tableutils.from(lfs.dir(location))
+ tb.from(lfs.dir(location))
)
end
function site.isSite(sitename)
- if tableutils.hasvalue(site.getsitelist(), sitename) then
+ if tb.hasvalue(site.getsitelist(), sitename) then
return sitename
end
@@ -45,7 +45,7 @@ end
function site.setsiteconfig(sitename)
local thatsite = assert(site.isSite(sitename), "That is not a valid site")
- site.config = tableutils.extend({}, config, site.getsiteconfig(thatsite))
+ site.config = tb.extend({}, config, site.getsiteconfig(thatsite))
Ferron.site.config = site.config
@@ -86,7 +86,7 @@ function site.choosesite(siteslist)
io.flush()
whichsite=io.read()
- until (tableutils.haskey(siteslist, tonumber(whichsite))) == true
+ until (tb.haskey(siteslist, tonumber(whichsite))) == true
elseif #siteslist == 1 then
whichsite = 1
else
@@ -99,12 +99,13 @@ end
function site.setsite(sitename)
local thatsite = sitename and sitename or site.choosesite(site.getsitelist())
- -- Assign values to site.path and site.config
- site.setsitepath(thatsite)
- site.setsiteconfig(thatsite)
-
- -- Create absolute path properties for the chosen site's folders
- site.makepaths(site.setsitepath(thatsite), site.setsiteconfig(thatsite))
+ tb.build{
+ -- Assign values to site.path and site.config
+ site.setsitepath(thatsite),
+ site.setsiteconfig(thatsite),
+ -- Create absolute path properties for the chosen site's folders
+ site.makepaths(site.setsitepath(thatsite), site.setsiteconfig(thatsite)),
+ }
-- Have different values if devmode is at true or not
site.config.baseurl = (Ferron.devmode == true and site.config.urldev or site.config.url)
@@ -113,26 +114,26 @@ function site.setsite(sitename)
end
function site.setnavigation(contentlocation)
- local location = assert(fileutils.isDirectory(contentlocation or site.content))
- local navigation = tableutils.map(
+ local location = assert(fl.isDirectory(contentlocation or site.content))
+ local navigation = tb.map(
function(f, i)
- local meta = fileutils.getpageconf(f)
+ local meta = fl.getpageconf(f)
if meta.navigation then
local label = meta.navigation.label and meta.navigation.label or meta.title
- local location = site.config.baseurl .. fileutils.removeextension(fileutils.getrelpath(f)) .. '.html'
+ local location = site.config.baseurl .. fl.removeextension(fl.getrelpath(f)) .. '.html'
local attributes = meta.navigation.attributes
local order = meta.navigation.order
- if fileutils.getbasename(location) == 'index.html' then
- location = fileutils.getdirname(location)
+ if fl.getbasename(location) == 'index.html' then
+ location = fl.getdirname(location)
end
return {label = label, location = location, attributes = attributes, order = order}
end
end,
-- The data table
- tableutils.filter(fileutils.isMarkdown, tableutils.from(fileutils.getdirtree(location)))
+ tb.filter(fl.isMarkdown, tb.from(fl.getdirtree(location)))
)
-- It's a dumb way to sort but it works for now.
@@ -157,7 +158,7 @@ function site.setnavigation(contentlocation)
return _tbl
end
- return tableutils.extend(Ferron.site.navigation, sortnavigation(navigation))
+ return tb.extend(Ferron.site.navigation, sortnavigation(navigation))
end
function site.startsite(samplelocation)
@@ -177,11 +178,11 @@ function site.startsite(samplelocation)
newsite.name = io.read()
newsite.location = Ferron.site.location .. newsite.name
- fileutils.mkdir(newsite.location)
+ fl.mkdir(newsite.location)
os.execute('cp -Rp ' .. location .. '/*' .. ' ' .. newsite.location)
- if fileutils.isDirectory(newsite.location) then
+ if fl.isDirectory(newsite.location) then
return print('Your new website is ready to be cutomize here "' .. newsite.location .. '"!')
else
return print('!! Error, something went wrong !')
@@ -194,7 +195,7 @@ function site.sitereset(htmllocation)
local function removefiles(dir)
local ok, errormsg
- tableutils.each(
+ tb.each(
function(file)
if file ~= '.'
and file ~= '..'
@@ -213,7 +214,7 @@ function site.sitereset(htmllocation)
end
end
end,
- tableutils.from(lfs.dir(dir))
+ tb.from(lfs.dir(dir))
)
-- remove directory
diff --git a/ferron/static.lua b/ferron/static.lua
@@ -8,8 +8,8 @@ local staticmeta = {
-- Required Packages
local site = require 'ferron.site'
-local fileutils = require 'ferron.utilities.file-utils'
-local tableutils = require 'ferron.utilities.table-utils'
+local fl = require 'ferron.utilities.file-utils'
+local tb = require 'ferron.utilities.table-utils'
local function dispatchnontextual(file)
return os.execute('cp -p ' .. file .. ' ' .. site.html)
@@ -20,12 +20,12 @@ local function movestaticfolder()
end
function static.init()
- local contentpath = assert(fileutils.isDirectory(site.content))
+ local contentpath = assert(fl.isDirectory(site.content))
print('¤¤ Your site is ready at `' .. site.html .. '` ¤¤')
return movestaticfolder(),
- tableutils.each(dispatchnontextual, tableutils.filter(fileutils.isNonTextual, tableutils.from(fileutils.getdirtree(contentpath))))
+ tb.each(dispatchnontextual, tb.filter(fl.isNonTextual, tb.from(fl.getdirtree(contentpath))))
end
return setmetatable(static, staticmeta)
diff --git a/ferron/utilities/file-utils.lua b/ferron/utilities/file-utils.lua
@@ -10,7 +10,7 @@ local json = require 'dkjson'
local lfs = require 'lfs'
local mimetypes = require 'mimetypes'
local config = require 'ferron.config'
-local tableutils = require 'ferron.utilities.table-utils'
+local tb = require 'ferron.utilities.table-utils'
function fileutils.getbasename(filepath)
return string.gsub(filepath, '(.*/)(.*)', '%2')
@@ -68,7 +68,7 @@ function fileutils.isNotIndex(filepath)
end
function fileutils.isNonTextual(filepath)
- return (tableutils.hasvalue(config.mimetypes, mimetypes.guess(filepath)) and true or false)
+ return (tb.hasvalue(config.mimetypes, mimetypes.guess(filepath)) and true or false)
end
-- getdirtree
diff --git a/ferron/utilities/template-utils.lua b/ferron/utilities/template-utils.lua
@@ -8,7 +8,7 @@ local templateutilsmeta = {
local lustache = require 'lustache'
local etlua = require 'etlua'
-local fileutils = require 'ferron.utilities.file-utils'
+local fl = require 'ferron.utilities.file-utils'
-- set template
@@ -27,7 +27,7 @@ function templateutils.selecttemplate(index, templatename)
end
-- etlua or mustache
-- etlua templates will outrank the mustache ones
- return assert(fileutils.isFile(template .. '.etlua') and template .. '.etlua' or template .. '.mustache',
+ return assert(fl.isFile(template .. '.etlua') and template .. '.etlua' or template .. '.mustache',
'You need to add some templates to your site.')
end
@@ -37,7 +37,7 @@ function templateutils.rendermustache(tpl, partialspath, data)
for i,v in ipairs(lustache:parse(tpl)) do
if v.type == '>' then
- partials[v.value] = fileutils.pullfilecontent(partialspath .. '/' .. v.value .. '.mustache')
+ partials[v.value] = fl.pullfilecontent(partialspath .. '/' .. v.value .. '.mustache')
end
end
@@ -53,13 +53,13 @@ end
-- process template
function templateutils.rendertemplate(template, data, partials)
- local extension = fileutils.getextension(template)
+ local extension = fl.getextension(template)
local render = nil
if extension == '.etlua' then
- render = templateutils.renderetlua(fileutils.pullfilecontent(template), data)
+ render = templateutils.renderetlua(fl.pullfilecontent(template), data)
elseif extension == '.mustache' then
- render = templateutils.rendermustache(fileutils.pullfilecontent(template), partials, data)
+ render = templateutils.rendermustache(fl.pullfilecontent(template), partials, data)
end
return render