Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(overrides): cleanup override.lua #348

Merged
merged 1 commit into from
Jul 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 22 additions & 29 deletions lua/github-theme/override.lua
Original file line number Diff line number Diff line change
@@ -1,46 +1,39 @@
local collect = require('github-theme.lib.collect')
local M = {}

local store = {
palettes = {},
specs = {},
groups = {},
has_override = false,
}

local function reset()
store.palettes = {}
store.specs = {}
store.groups = {}
store.has_override = false
function M.reset()
getmetatable(M).__index =
{ palettes = {}, specs = {}, groups = {}, has_override = false }
return M
end

local function hash()
local hash = require('github-theme.lib.hash')(store)
return hash and hash or 0
function M.hash()
return require('github-theme.lib.hash')(getmetatable(M).__index) or 0
end

local function check_link(tbl)
for _, style in pairs(tbl) do
for _, opts in pairs(style) do
for _, theme in pairs(tbl) do
for _, opts in pairs(theme) do
opts.link = opts.link or ''
end
end
end

return setmetatable({ reset = reset, hash = hash }, {
__index = function(_, value)
if store[value] then
return store[value]
end
end,

__newindex = function(_, key, value)
if store[key] then
if key == 'groups' then
check_link(value or {})
setmetatable(M, {
__newindex = function(self, k, v)
local store = getmetatable(self).__index
if type(store[k]) == 'table' then
if not v then
store[k] = {}
return
end
if k == 'groups' then
check_link(v)
end
store[key] = collect.deep_extend(store[key], value or {})
store[k] = collect.deep_extend(store[k], v)
store.has_override = true
end
end,
})

return M.reset()
Loading