File: wiki.lua

package info (click to toggle)
darktable 1.4.2-1%2Bdeb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 19,940 kB
  • ctags: 22,185
  • sloc: ansic: 181,925; cpp: 32,612; lisp: 4,681; xml: 4,046; sh: 2,002; makefile: 395; python: 315; perl: 114; awk: 110; asm: 46
file content (152 lines) | stat: -rw-r--r-- 4,207 bytes parent folder | download | duplicates (3)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
require "content"
doc = require "core"
table = require "table"
dump = require("darktable.debug").dump
local page_name="/redmine/projects/darktable/wiki/LuaAPI"

local parse_doc_node

local function sorted_pairs (t, f)
	local a = {}
	for n in pairs(t) do table.insert(a, n) end
	table.sort(a, f)
	local i = 0      -- iterator variable
	local iter = function ()   -- iterator function
		i = i + 1
		if a[i] == nil then return nil
		else return a[i], t[a[i]]
		end
	end
	return iter
end

local function get_node_with_link(node,name)
	return "\""..name.."\":"..page_name.."#"..doc.get_name(node)
end

local function get_reported_type(node,simple)
	if not doc.get_attribute(node,"reported_type") then
		doc.debug_print(node)
		error("all types should have a reported type")
	end
	local rtype = doc.get_attribute(node,"reported_type")
	if type(rtype) ~= "string" then
		rtype = get_node_with_link(rtype,doc.get_name(rtype))
	end
	if rtype == "documentation node" then rtype = nil end
	if rtype == "dt_singleton" then rtype = nil end
	if( rtype and not simple and doc.get_attribute(node,"signature")) then
		rtype = rtype.."( "
		local sig = doc.get_attribute(node,"signature")
		for k,v in pairs(sig) do
			if(doc.get_attribute(v,"optional")) then
				rtype = rtype.."[ _"..doc.get_short_name(v).."_ : "..get_reported_type(v,true).."]"
			else
				rtype = rtype.."_"..doc.get_short_name(v).."_ : "..get_reported_type(v,true)
			end
			if next(sig,k) then
				rtype = rtype..", "
			end
		end
		rtype = rtype.." )"
	end
	if(not simple and doc.get_attribute(node,"ret_val")) then
		rtype = rtype.." : "..get_reported_type(doc.get_attribute(node,"ret_val",true))
	end
	return rtype
end


local function print_content(node)
	local rtype = get_reported_type(node)
	local result = ""
	if  rtype then
		result = result .."\t*type* : "..rtype.."\n\n"
	end
	result = result ..doc.get_text(node).."\n"
	local concat=""
	for k2,v2 in sorted_pairs(node._luadoc_attributes) do
		if not doc.get_attribute(doc.toplevel.attributes[k2],"skiped") then
			concat = concat..get_node_with_link(doc.toplevel.attributes[k2],k2).." "
		end
	end
	if concat ~="" then
		result = result.."\t*Attributes* : "..concat.."\n"
	end

	result = result.."\n"
	local sig = doc.get_attribute(node,"signature")
	if(sig) then
		for k,v in pairs(sig) do
			result = result .. parse_doc_node(v,node,doc.get_short_name(v)).."\n";
		end
		result = result.."\n"
	end
	local ret_val = doc.get_attribute(node,"ret_val")
	if(ret_val) then
		result = result .. parse_doc_node(ret_val,node,doc.get_short_name(ret_val)).."\n";
		result = result.."\n"
	end
	for k,v in doc.unskiped_children(node) do
		result = result .. parse_doc_node(v,node,k).."\n";
	end
	return result;
end

local function depth(node)
	if doc.get_name(node) == "" then return 0 end
	return depth(doc.get_main_parent(node)) +1
end

parse_doc_node = function(node,parent,prev_name)
	local node_name
	local parent_name = doc.get_name(parent)
	local result = ""
	if doc.is_main_parent(node,parent,prev_name) then
		node_name = doc.get_name(node)
	else
		if parent_name == "" then
			node_name = prev_name
		else 
			node_name =  doc.get_name(parent).."."..prev_name
		end
	end

	local depth = depth(node);
	if depth > 6 then depth = 6 end

	if(node._luadoc_type == "param") then
		local tmp_node = doc.get_main_parent(node)
		local tmp_string = "p"
		while doc.get_attribute(tmp_node,"reported_type") == "function" do
			tmp_string = tmp_string.."("
			tmp_node = doc.get_main_parent(tmp_node)
		end
		if(node:get_short_name() == "return") then
			result = result .. tmp_string.."(#"..doc.get_name(node).."). _return_\n\n"
		else
			result = result .. tmp_string.."(#"..doc.get_name(node).."). *"..node:get_short_name().."*\n\n"
		end
	elseif depth ~= 0 then
		result = result .. "h"..depth.."(#"..doc.get_name(node).."). "..prev_name.."\n\n"
	end
	if(not doc.is_main_parent(node,parent,prev_name) ) then
		result = result .. "see "..get_node_with_link(node,doc.get_name(node)).."\n\n"
	else
		result = result .. print_content(node,parent)
	end
	return result;
end


M = {}

M.page_name = page_name

function M.get_doc()
	return "{{toc}}\n\n"..parse_doc_node(doc.toplevel,nil,"")
end



return M;