replace util interpolation with shipwright

This commit is contained in:
Michael Chris Lopez
2021-11-06 13:06:54 +08:00
parent 981c2bc0b2
commit c623e9ff93
2 changed files with 8 additions and 15 deletions

View File

@@ -1,20 +1,18 @@
local util = require "zenbones.util"
local key_template = [[ local key_template = [[
<key>${k} Color</key> <key>$k Color</key>
]] ]]
local color_template = [[ local color_template = [[
<dict> <dict>
<key>Alpha Component</key> <key>Alpha Component</key>
<real>1</real> <real>1</real>
<key>Blue Component</key> <key>Blue Component</key>
<real>${b}</real> <real>$b</real>
<key>Color Space</key> <key>Color Space</key>
<string>sRGB</string> <string>sRGB</string>
<key>Green Component</key> <key>Green Component</key>
<real>${g}</real> <real>$g</real>
<key>Red Component</key> <key>Red Component</key>
<real>${r}</real> <real>$r</real>
</dict>]] </dict>]]
local start_template = [[<?xml version="1.0" encoding="UTF-8"?> local start_template = [[<?xml version="1.0" encoding="UTF-8"?>
@@ -27,6 +25,8 @@ local end_template = [[
</dict> </dict>
</plist>]] </plist>]]
local helpers = require "shipwright.transform.helpers"
local function hex_to_rgb(hex) local function hex_to_rgb(hex)
local _, r, g, b = hex:match "(.)(..)(..)(..)" local _, r, g, b = hex:match "(.)(..)(..)(..)"
r, g, b = r, g, b =
@@ -37,9 +37,9 @@ local function hex_to_rgb(hex)
end end
local function key_to_xml(key, color) local function key_to_xml(key, color)
local xml = util.interp(key_template, { k = key }) local xml = helpers.apply_template(key_template, { k = key })
local rgb = hex_to_rgb(color.hex) local rgb = hex_to_rgb(color.hex)
xml = xml .. util.interp(color_template, rgb) xml = xml .. helpers.apply_template(color_template, rgb)
return xml return xml
end end

View File

@@ -1,12 +1,5 @@
local M = {} local M = {}
-- got from http://lua-users.org/wiki/StringInterpolation
function M.interp(s, tab)
return (s:gsub("($%b{})", function(w)
return tab[w:sub(3, -2)] or w
end))
end
function M.apply_colorscheme() function M.apply_colorscheme()
local colors_name = vim.api.nvim_get_var "colors_name" local colors_name = vim.api.nvim_get_var "colors_name"
package.loaded[colors_name] = nil package.loaded[colors_name] = nil