File: sample_files.lua

package info (click to toggle)
awesome 4.3-8.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,468 kB
  • sloc: ansic: 14,508; sh: 526; makefile: 46
file content (32 lines) | stat: -rw-r--r-- 945 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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