summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenny Shields <mail@kennyshields.net>2016-07-10 19:28:52 -0400
committerKenny Shields <mail@kennyshields.net>2016-07-16 14:00:27 -0400
commitf64032da41be2be9cb0139b24bf276b7ab901b3b (patch)
tree4ddb78b39e06aa52d8c2c77063abbc7d2511c131
parentfc7f09b8137525e37b3d270f2ad7b7301722360a (diff)
downloadstp-f64032da41be2be9cb0139b24bf276b7ab901b3b.tar.gz
stp-f64032da41be2be9cb0139b24bf276b7ab901b3b.zip
Allow subject text to be specified in configuration table
-rw-r--r--init.lua53
1 files changed, 35 insertions, 18 deletions
diff --git a/init.lua b/init.lua
index 6c79ccc..2c6bda6 100644
--- a/init.lua
+++ b/init.lua
@@ -159,29 +159,46 @@ function lib.init(config)
token_current = false
collected = {}
+ local path
+ local temp = false
if config.path then
- if config.comment_patterns then
- if config.replace_comment_patterns then
- comment_patterns = config.comment_patterns
- else
- for k, v in pairs(config.comment_patterns.multiline) do
- comment_patterns.multiline[k] = v
- end
- for k, v in ipairs(config.comment_patterns.single) do
- table.insert(comment_patterns.single, v)
- end
+ path = config.path
+ elseif config.text then
+ temp = true
+ path = os.tmpname()
+ file = io.open(path, "w")
+ file:write(config.text)
+ file:close()
+ else
+ return false
+ end
+
+ if config.comment_patterns then
+ if config.replace_comment_patterns then
+ comment_patterns = config.comment_patterns
+ else
+ for k, v in pairs(config.comment_patterns.multiline) do
+ comment_patterns.multiline[k] = v
+ end
+ for k, v in ipairs(config.comment_patterns.single) do
+ table.insert(comment_patterns.single, v)
end
end
- if config.token_pattern then
- token_pattern = config.token_pattern
- end
- for line in io.lines(config.path) do
- parseLine(trim(line))
- end
- return collected
end
- return false
+ if config.token_pattern then
+ token_pattern = config.token_pattern
+ end
+
+ for line in io.lines(path) do
+ parseLine(trim(line))
+ end
+
+ if temp then
+ os.remove(path)
+ end
+
+ return collected
end