1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.millscript.millscript.functions;
23
24 import org.millscript.commons.util.IList;
25 import org.millscript.commons.vfs.VFile;
26 import org.millscript.millscript.Prefs;
27 import org.millscript.millscript.render.HTMLRenderer;
28 import org.millscript.millscript.vm.Machine;
29 import org.millscript.millscript.vm.Package;
30
31 /**
32 * This class implements the MillScript <code>htmlFragmentFile</code> function.
33 */
34 public class HtmlFragmentFileFunction extends AbstractOutputFileFunction {
35
36 /**
37 * Constructs a new HtmlFileFunction for the specified package.
38 *
39 * @param pack the package this function belongs to
40 */
41 public HtmlFragmentFileFunction( final Package pack ) {
42 super( pack );
43 }
44
45 /**
46 * @see org.millscript.millscript.functions.Function#apply(org.millscript.millscript.vm.Machine, int)
47 */
48 @Override
49 public void apply( final Machine mc, final int nargs ) {
50 if ( nargs >= 1 ) {
51 final IList< Object > list = mc.popArgsList( nargs - 1, false );
52
53 Page page = toPage( mc.popObject() );
54 page.createDirectoryFor();
55
56 VFile file = page.getFile();
57
58 new HTMLRenderer( mc.getConfig(), file ).renderAsFragment( list );
59
60 Prefs.fragCount += 1;
61
62
63 mc.pushObject( page );
64 } else {
65
66 checkNargs( mc, 2, nargs );
67 }
68 }
69
70 /**
71 * @see org.millscript.millscript.functions.AbstractOutputFileFunction#getDefaultExtension()
72 */
73 @Override
74 public String getDefaultExtension() {
75 return "html";
76 }
77
78 }