Skip to content

Commit

Permalink
feat: formatters overridable in config
Browse files Browse the repository at this point in the history
also fix #19.
  • Loading branch information
gorillamoe committed Jul 1, 2024
1 parent ebeb7cb commit 35b011f
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/_coverpage.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# kulala.nvim <small>1.2.2</small>
# kulala.nvim <small>1.3.0</small>

> A minimal 🤏 HTTP-client 🐼 interface 🖥️ for Neovim ❤️.
Expand Down
6 changes: 6 additions & 0 deletions lua/kulala/config/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ KULALA_CONFIG = KULALA_CONFIG or {
default_env = "dev",
-- enable/disable debug mode
debug = false,
-- formatters
formatters = {
json = { "jq", "." },
xml = { "xmllint", "--format", "-" },
html = { "xmllint", "--format", "--html", "-" },
}
}

local M = {}
Expand Down
8 changes: 5 additions & 3 deletions lua/kulala/formatter/init.lua
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
local CONFIG = require("kulala.config")
local FS = require("kulala.utils.fs")
local CFG = CONFIG.get_config()
local M = {}

M.format = function(ft, contents)
local cmd = {}
local cmd_exists = false
if ft == "json" then
cmd = { "jq", "." }
cmd = CFG.formatters.json
cmd_exists = FS.command_exists("jq")
elseif ft == "xml" then
cmd = { "xmllint", "--format", "-" }
cmd = CFG.formatters.xml
cmd_exists = FS.command_exists("xmllint")
elseif ft == "html" then
cmd = { "xmllint", "--format", "--html", "-" }
cmd = CFG.formatters.html
cmd_exists = FS.command_exists("xmllint")
end
if not cmd_exists then
Expand Down
2 changes: 1 addition & 1 deletion lua/kulala/globals/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ local FS = require("kulala.utils.fs")

local M = {}

M.VERSION = "1.2.2"
M.VERSION = "1.3.0"
M.UI_ID = "kulala://ui"
M.HEADERS_FILE = FS.get_plugin_tmp_dir() .. "/headers.txt"
M.BODY_FILE = FS.get_plugin_tmp_dir() .. "/body.txt"
Expand Down
4 changes: 3 additions & 1 deletion lua/kulala/parser/env.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ M.get_env = function()
local dotenv_env = vim.fn.readfile(dotenv)
for _, line in ipairs(dotenv_env) do
local key, value = line:match('([^=]+)=(.*)')
env[key] = value
if key and value then
env[key] = value
end
end
end
return env
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kulala.nvim",
"version": "1.2.2",
"version": "1.3.0",
"scripts": {
"docs": "docsify serve docs"
},
Expand Down

0 comments on commit 35b011f

Please sign in to comment.