Skip to content

Commit

Permalink
Update module for 0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
TiagoDanin committed Mar 3, 2016
1 parent 2558e28 commit c6cbe72
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 36 deletions.
90 changes: 64 additions & 26 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,82 @@ LUA = /5.2
BETA = /5.3

LUA_DIR = $(PREFIX)
LUA_SHAREDIR = $(LUA_DIR)/share/lua
LUA_LIBDIR = $(LUA_DIR)/lib/lua
LUA_SHAREDIR = $(LUA_DIR)/share/lua

msg_install = 'Requires permission of "root" to create the system directory'
msg_unistall = 'Requires permission of "root" to remove the system directory'
msg_end = "Files can be located in:'\n '$(LUA_LIBDIR)/*Version' and '$(LUA_SHAREDIR)/*Version'\nTo remove use '$ make unistall'"

install: all
unistall: all


installall: all
all:
@echo 'Module for Lua'
@echo $(msg_install)
@sudo mkdir -p $(LUA_LIBDIR)$(LAST)
@sudo cp -f $(SOURCES) $(LUA_LIBDIR)$(LAST)
@sudo mkdir -p $(LUA_LIBDIR)$(LUA)
@sudo cp -f $(SOURCES) $(LUA_LIBDIR)$(LUA)
@sudo mkdir -p $(LUA_LIBDIR)$(BETA)
@sudo cp -f $(SOURCES) $(LUA_LIBDIR)$(BETA)
@sudo mkdir -p $(LUA_SHAREDIR)$(LAST)
@sudo cp -f $(SOURCES) $(LUA_SHAREDIR)$(LAST)
@sudo mkdir -p $(LUA_SHAREDIR)$(LUA)
@sudo cp -f $(SOURCES) $(LUA_SHAREDIR)$(LUA)
@sudo mkdir -p $(LUA_SHAREDIR)$(BETA)
@sudo cp -f $(SOURCES) $(LUA_SHAREDIR)$(BETA)
@echo $(msg_end)

install: 5.2

5.1:
@echo 'Libs for Lua5.1'
@echo 'Requirement permission "root" to create directory in the system'
@echo 'Module for Lua5.1'
@echo $(msg_install)
@sudo mkdir -p $(LUA_LIBDIR)$(LAST)
@sudo cp -f $(SOURCES) $(LUA_LIBDIR)$(LAST)
@sudo mkdir -p $(LUA_SHAREDIR)$(LAST)
@cp -f $(SOURCES) $(LUA_LIBDIR)$(LAST)
@cp -f $(SOURCES) $(LUA_SHAREDIR)$(LAST)
@echo 'Files can be located in:'
@echo "'$(LUA_LIBDIR)' and '@(LUA_SHAREDIR)'"
@echo "To remove use '$ make unistall'"
@sudo cp -f $(SOURCES) $(LUA_SHAREDIR)$(LAST)
@echo $(msg_end)

5.2:
@echo 'Libs for Lua5.2'
@echo 'Requirement permission "root" to create directory in the system'
@echo 'Module for Lua5.2'
@echo $(msg_install)
@sudo mkdir -p $(LUA_LIBDIR)$(LUA)
@sudo cp -f $(SOURCES) $(LUA_LIBDIR)$(LUA)
@sudo mkdir -p $(LUA_SHAREDIR)$(LUA)
@cp -f $(SOURCES) $(LUA_LIBDIR)$(LUA)
@cp -f $(SOURCES) $(LUA_SHAREDIR)$(LUA)
@echo 'Files can be located in:'
@echo "'$(LUA_LIBDIR)' and '@(LUA_SHAREDIR)'"
@echo "To remove use '$ make unistall'"
@sudo cp -f $(SOURCES) $(LUA_SHAREDIR)$(LUA)
@echo $(msg_end)

5.3:
@echo 'Libs for Lua5.3'
@echo 'Requirement permission "root" to create directory in the system'
@echo 'Module for Lua5.3'
@echo $(msg_install)
@sudo mkdir -p $(LUA_LIBDIR)$(BETA)
@sudo cp -f $(SOURCES) $(LUA_LIBDIR)$(BETA)
@sudo mkdir -p $(LUA_SHAREDIR)$(BETA)
@cp -f $(SOURCES) $(LUA_LIBDIR)$(BETA)
@cp -f $(SOURCES) $(LUA_SHAREDIR)$(BETA)
@echo 'Files can be located in:'
@echo "'$(LUA_LIBDIR)' and '@(LUA_SHAREDIR)'"
@echo "To remove use '$ make unistall'"
@sudo cp -f $(SOURCES) $(LUA_SHAREDIR)$(BETA)
@echo $(msg_end)

unistall5.1:
@echo $(msg_install)
@sudo rm -f $(LUA_LIBDIR)$(LAST)/htmlEntities.lua
@sudo rm -f $(LUA_LIBDIR)$(LAST)/htmlEntities.lua

unistall5.2:
@echo $(msg_install)
@sudo rm -f $(LUA_LIBDIR)$(LUA)/htmlEntities.lua
@sudo rm -f $(LUA_SHAREDIR)$(LUA)/htmlEntities.lua

unistall5.3:
@echo $(msg_install)
@sudo rm -f $(LUA_LIBDIR)$(BETA)/htmlEntities.lua
@sudo rm -f $(LUA_SHAREDIR)$(BETA)/htmlEntities.lua

unistall:
unistallall:
@echo $(msg_install)
@sudo rm -f $(LUA_LIBDIR)$(LAST)/htmlEntities.lua
@sudo rm -f $(LUA_LIBDIR)$(LUA)/htmlEntities.lua
@sudo rm -f $(LUA_SHAREDIR)$(LUA)/htmlEntities.lua
@sudo rm -f $(LUA_LIBDIR)$(BETA)/htmlEntities.lua
@sudo rm -f $(LUA_SHAREDIR)$(LAST)/htmlEntities.lua
@sudo rm -f $(LUA_SHAREDIR)$(LUA)/htmlEntities.lua
@sudo rm -f $(LUA_SHAREDIR)$(BETA)/htmlEntities.lua
12 changes: 9 additions & 3 deletions example.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ function test_module()
local text = [[&XAMPLE text
⁢≡≡≡≡≡≡≡≡≡≡>]]

for k,v in pairs(htmlEntities) do
if v and type(v) == 'string' then
print(k .. ': ' .. v)
end
end

local dec = htmlEntities.decode(text)
print('Version'..htmlEntities.version)
print('Input: ' .. text .. '\n\nOutput: ' .. dec)
print('\nInput: ' .. text .. '\n\nOutput: ' .. dec)

repeat
io.write('\nYou want to do a test (y/n) ')
Expand All @@ -20,7 +25,8 @@ function test_module()
io.write('> ')
io.flush()
local input = io.read()
print('\nInput: ' .. input .. '\n\nOutput: ' .. htmlEntities.decode(input))
--print('\nInput: ' .. input .. '\n\nOutput: ' .. htmlEntities.encode(input)) --Encode
print('\nInput: ' .. input .. '\n\nOutput: ' .. htmlEntities.decode(input)) --Decode
test()
end
if res == 'y' then test() end
Expand Down
35 changes: 28 additions & 7 deletions src/htmlEntities.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
-- Module options:
local debug_htmlEntities = false
local ASCII_htmlEntities = true
local utf8_htmlEntities = true
local register_global_module_htmlEntities = false
local global_module_name_htmlEntities = 'htmlEntities'

Expand Down Expand Up @@ -29,9 +30,11 @@ Copyright (c) 2016 Tiago Danin
]==]--

local htmlEntities = {
version = "htmlEntities 0.2",
name = "htmlEntities",
author = "Tiago Danin - 2016"
version = '0.3',
name = 'htmlEntities-for-lua',
author = 'Tiago Danin - 2016',
license = 'The MIT License (MIT)',
page = 'github.com/TiagoDanin/htmlEntities-for-lua'
}

if register_global_module_htmlEntities then
Expand Down Expand Up @@ -309,16 +312,24 @@ local htmlEntities_table = {
}

function htmlEntities.ASCII_dec (input)
if not input then print('htmlEntities >> ERRO: input is value nil') return end
if math.abs(input) < 256 then
local output = input:char()
return output
if _VERSION == 'Lua 5.3' then
return utf8.char(input)
else
local output = string.char(input)
if utf8_htmlEntities and not output:match('([%z\1-\127\194-\244][\128-\191]*)')then
return input
end
return output
end
else
return input
end
end

function htmlEntities.decode (input)
if not input then print('htmlEntities >> ERRO: input is value nil') end
if not input then print('htmlEntities >> ERRO: input is value nil') return end
local output = string.gsub(input, '&.-;', htmlEntities_table)
if ASCII_htmlEntities then
output = string.gsub(output, '&#([1234567890]*);', htmlEntities.ASCII_dec)
Expand All @@ -328,4 +339,14 @@ function htmlEntities.decode (input)
return output
end

return htmlEntities
function htmlEntities.encode (input)
if not input then print('htmlEntities >> ERRO: input is value nil') return end
input = htmlEntities.decode(input)
local output = ''
for k = 1, string.len(input) do
output = output .. '&#'.. string.sub(input,k,k):byte() ..';'
end
return output
end

return htmlEntities

0 comments on commit c6cbe72

Please sign in to comment.