support for generating Markdown; basic support for Moonscript
steve donovan
10 years ago
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 | ]] |
142 | 142 | |
143 | 143 | function ldoc.display_name(item) |
144 | 144 | 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 -- | |
146 | 146 | else return name end |
147 | 147 | end |
148 | 148 | |
228 | 228 | local out,err = template.substitute(module_template,{ |
229 | 229 | ldoc = ldoc, |
230 | 230 | module = ldoc.module, |
231 | _escape = ldoc.template_escape | |
231 | 232 | }) |
232 | 233 | ldoc.root = false |
233 | 234 | if not out then quit("template failed: "..err) end |
237 | 238 | |
238 | 239 | args.dir = args.dir .. path.sep |
239 | 240 | |
240 | if ldoc.css then -- has CSS been copied? | |
241 | if css then -- has CSS been copied? | |
241 | 242 | check_file(args.dir..css, path.join(args.style,css)) |
242 | 243 | end |
243 | 244 | |
258 | 259 | -- write out the per-module documentation |
259 | 260 | -- note that we reset the internal ordering of the 'kinds' so that |
260 | 261 | -- 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 | |
262 | 265 | for m in mods:iter() do |
263 | 266 | local kind, lkind, modules = unpack(m) |
264 | 267 | check_directory(args.dir..lkind) |
277 | 280 | end |
278 | 281 | out,err = template.substitute(module_template,{ |
279 | 282 | module=m, |
280 | ldoc = ldoc | |
283 | ldoc = ldoc, | |
284 | _escape = ldoc.template_escape | |
281 | 285 | }) |
282 | 286 | if not out then |
283 | 287 | quit('template failed for '..m.name..': '..err) |
4 | 4 | |
5 | 5 | local class = require 'pl.class' |
6 | 6 | local utils = require 'pl.utils' |
7 | local List = require 'pl.List' | |
7 | 8 | local tools = require 'ldoc.tools' |
8 | 9 | local lexer = require 'ldoc.lexer' |
9 | 10 | local quit = utils.quit |
261 | 262 | return 'comment',v:sub(1,-3) |
262 | 263 | end |
263 | 264 | |
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() } |
228 | 228 | |
229 | 229 | if lang:empty_comment(v) then -- ignore rest of empty start comments |
230 | 230 | t,v = tok() |
231 | if t == 'space' and not v:match '\n' then | |
232 | t,v = tok() | |
233 | end | |
231 | 234 | end |
232 | 235 | |
233 | 236 | while t and t == 'comment' do |
116 | 116 | ['.cpp'] = cc, |
117 | 117 | ['.cxx'] = cc, |
118 | 118 | ['.C'] = cc, |
119 | ['.mm'] = cc | |
119 | ['.mm'] = cc, | |
120 | ['.moon'] = lang.moon, | |
120 | 121 | } |
121 | 122 | |
122 | 123 | ------- ldoc external API ------------ |
186 | 187 | 'file','project','title','package','format','output','dir','ext', 'topics', |
187 | 188 | 'one','style','template','description','examples', 'pretty', 'charset', 'plain', |
188 | 189 | 'readme','all','manual_url', 'ignore', 'colon', 'sort', 'module_file', |
189 | 'boilerplate','merge', 'wrap', 'not_luadoc', | |
190 | 'boilerplate','merge', 'wrap', 'not_luadoc', 'template_escape', | |
190 | 191 | 'no_return_or_parms','no_summary','full_description','backtick_references', 'custom_see_handler', |
191 | 192 | } |
192 | 193 | ldoc_contents = tablex.makeset(ldoc_contents) |
572 | 573 | |
573 | 574 | ldoc.css, ldoc.templ = 'ldoc.css','ldoc.ltp' |
574 | 575 | |
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 | ||
575 | 583 | local function style_dir (sname) |
576 | 584 | local style = ldoc[sname] |
577 | 585 | local dir |
586 | if style==false and sname == 'style' then | |
587 | args.style = false | |
588 | ldoc.css = false | |
589 | end | |
578 | 590 | if style then |
579 | 591 | if style == true then |
580 | 592 | dir = config_dir |