doc: Add the default theme to the sample files

Also add the gears to make this more flexible in the future.
This commit is contained in:
Emmanuel Lepage Vallee 2017-02-25 16:19:12 -05:00
parent b697777498
commit 2ddbbfb70c
3 changed files with 78 additions and 2 deletions

View File

@ -408,8 +408,23 @@ add_custom_command(
${BUILD_DIR}/script_files/rc.lua
)
# Create a target for the auto-generated awesomerc.lua
add_custom_target(generate_awesomerc DEPENDS ${BUILD_DIR}/awesomerc.lua)
add_custom_command(
OUTPUT ${BUILD_DIR}/script_files/theme.lua
COMMAND lua ${SOURCE_DIR}/docs/sample_theme.lua ${BUILD_DIR}/script_files/
)
# Create a target for the auto-generated awesomerc.lua and other files
add_custom_target(generate_awesomerc DEPENDS
${BUILD_DIR}/awesomerc.lua
${BUILD_DIR}/script_files/theme.lua
${BUILD_DIR}/script_files/rc.lua
${SOURCE_DIR}/awesomerc.lua
${BUILD_DIR}/docs/06-appearance.md
${SOURCE_DIR}/docs/05-awesomerc.md.lua
${SOURCE_DIR}/docs/sample_theme.lua
${SOURCE_DIR}/docs/sample_files.lua
${SOURCE_DIR}/awesomerc.lua
)
#}}}

32
docs/sample_files.lua Normal file
View File

@ -0,0 +1,32 @@
-- Take a Lua file and add it to the documentation sample files.
-- Also add \` to generate all links
-- Tell ldoc to generate links
local function add_links(line)
for _, module in ipairs {
"awful", "wibox", "gears", "naughty", "menubar", "beautiful"
} do
if line:match(module.."%.") then
line = line:gsub("("..module.."[.a-zA-Z]+)", "`%1`")
end
end
return "-- "..line
end
return function(name, input_path, output_path, header)
local input = assert(io.open(input_path))
local output_script = {header}
-- Escape all lines
for line in input:lines() do
table.insert(output_script, add_links(line))
end
-- Add the script name
table.insert(output_script, "-- @script "..name)
output_path = assert(io.open(output_path, "w"))
output_path:write(table.concat(output_script, "\n"))
output_path:close()
end

29
docs/sample_theme.lua Normal file
View File

@ -0,0 +1,29 @@
--- Take the default theme and add it to ldoc as a sample file.
local output_path = ...
local path = debug.getinfo(1,"S").source:gsub("sample_theme.*",""):gsub("@","")
package.path = path .. '?.lua;' .. package.path
require("sample_files")(
"theme.lua",
path.."../themes/default/theme.lua",
output_path.."/theme.lua",
[[---------------------------------------------------------------------------
--- The default theme file.
--
-- If you wish to create a custom theme, copy this file to
-- `~/.config/awesome/mytheme.lua`
-- and replace:
--
-- beautiful.init(awful.util.get_themes_dir() .. "default/theme.lua")
--
-- with
--
-- beautiful.init(awful.util.getdir("config") .. "mytheme.lua")
--
-- in your `rc.lua`.
--
-- Here is the default theme content:
--
--]]
)