Codebase list lua-ldoc / 94dc198
support for generating Markdown; basic support for Moonscript steve donovan 10 years ago
5 changed file(s) with 84 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
0 return [[
1 > local lev = ldoc.level or 2
2 > local lev1,lev2 = ('#'):rep(lev),('#'):rep(lev+1)
3 > for kind, items in module.kinds() do
4 > local kitem = module.kinds:get_item(kind)
5 > if kitem then
6 $(lev1) $(ldoc.descript(kitem))
7
8 > end
9 > for item in items() do
10 $(lev2) $(ldoc.display_name(item))
11
12 $(ldoc.descript(item))
13
14 > end
15 > end
16 ]]
142142
143143 function ldoc.display_name(item)
144144 local name = item.display_name or item.name
145 if item.type == 'function' or item.type == 'lfunction' then return name..' '..item.args
145 if item.type == 'function' or item.type == 'lfunction' then return name..' '..item.args --  
146146 else return name end
147147 end
148148
228228 local out,err = template.substitute(module_template,{
229229 ldoc = ldoc,
230230 module = ldoc.module,
231 _escape = ldoc.template_escape
231232 })
232233 ldoc.root = false
233234 if not out then quit("template failed: "..err) end
237238
238239 args.dir = args.dir .. path.sep
239240
240 if ldoc.css then -- has CSS been copied?
241 if css then -- has CSS been copied?
241242 check_file(args.dir..css, path.join(args.style,css))
242243 end
243244
258259 -- write out the per-module documentation
259260 -- note that we reset the internal ordering of the 'kinds' so that
260261 -- e.g. when reading a topic the other Topics will be listed first.
261 ldoc.css = '../'..css
262 if css then
263 ldoc.css = '../'..css
264 end
262265 for m in mods:iter() do
263266 local kind, lkind, modules = unpack(m)
264267 check_directory(args.dir..lkind)
277280 end
278281 out,err = template.substitute(module_template,{
279282 module=m,
280 ldoc = ldoc
283 ldoc = ldoc,
284 _escape = ldoc.template_escape
281285 })
282286 if not out then
283287 quit('template failed for '..m.name..': '..err)
44
55 local class = require 'pl.class'
66 local utils = require 'pl.utils'
7 local List = require 'pl.List'
78 local tools = require 'ldoc.tools'
89 local lexer = require 'ldoc.lexer'
910 local quit = utils.quit
261262 return 'comment',v:sub(1,-3)
262263 end
263264
264 return { lua = Lua(), cc = CC() }
265 local Moon = class(Lua)
266
267 function Moon:_init()
268 self.line_comment = '^%-%-+' -- used for stripping
269 self.start_comment_ = '^%s*%-%-%-+' -- used for doc comment line start
270 self.block_comment = '^%-%-%[=*%[%-+' -- used for block doc comments
271 self.end_comment_ = '[^%-]%-%-+\n$' ---- exclude --- this kind of comment ---
272 self:finalize()
273 end
274
275 function Moon:item_follows (t,v,tok)
276 if t == 'iden' then
277 local name,t,v = v, tnext(tok) --tools.get_fun_name(tok,v)
278 if name == 'class' then
279 name = v
280 --name,t,v = tools.get_fun_name(tok,v)
281 -- class!
282 return function(tags,tok)
283 tags:add('class','type')
284 tags:add('name',name)
285 end
286 elseif t == '=' or t == ':' then -- function/method
287 t,v = tnext(tok)
288 return function(tags,tok)
289 if not tags.name then
290 tags:add('name',name)
291 end
292 if t == '(' then
293 tags.formal_args = tools.get_parameters(tok)
294 else
295 tags.formal_args = List()
296 end
297 tags:add('class','function')
298 end
299 else
300 return nil
301 end
302 end
303 end
304
305 return { lua = Lua(), cc = CC(), moon = Moon() }
228228
229229 if lang:empty_comment(v) then -- ignore rest of empty start comments
230230 t,v = tok()
231 if t == 'space' and not v:match '\n' then
232 t,v = tok()
233 end
231234 end
232235
233236 while t and t == 'comment' do
116116 ['.cpp'] = cc,
117117 ['.cxx'] = cc,
118118 ['.C'] = cc,
119 ['.mm'] = cc
119 ['.mm'] = cc,
120 ['.moon'] = lang.moon,
120121 }
121122
122123 ------- ldoc external API ------------
186187 'file','project','title','package','format','output','dir','ext', 'topics',
187188 'one','style','template','description','examples', 'pretty', 'charset', 'plain',
188189 'readme','all','manual_url', 'ignore', 'colon', 'sort', 'module_file',
189 'boilerplate','merge', 'wrap', 'not_luadoc',
190 'boilerplate','merge', 'wrap', 'not_luadoc', 'template_escape',
190191 'no_return_or_parms','no_summary','full_description','backtick_references', 'custom_see_handler',
191192 }
192193 ldoc_contents = tablex.makeset(ldoc_contents)
572573
573574 ldoc.css, ldoc.templ = 'ldoc.css','ldoc.ltp'
574575
576 if args.ext == 'md' then
577 ldoc.templ = 'ldoc.mdtp'
578 ldoc.template_escape = '>'
579 ldoc.style = false
580 args.ext = '.md'
581 end
582
575583 local function style_dir (sname)
576584 local style = ldoc[sname]
577585 local dir
586 if style==false and sname == 'style' then
587 args.style = false
588 ldoc.css = false
589 end
578590 if style then
579591 if style == true then
580592 dir = config_dir