Пример #1
0
        public void TestScientificWithFunctionExpression()
        {
            var context = new TemplateContext();

            context.BuiltinObject.SetValue("clear", DelegateCustomFunction.CreateFunc <ScriptExpression, string>(FunctionClear), false);
            context.BuiltinObject.SetValue("history", DelegateCustomFunction.Create <object>(FunctionHistory), false);

            var template = Template.Parse("clear history", lexerOptions: new LexerOptions()
            {
                Lang = ScriptLang.Scientific,
                Mode = ScriptMode.ScriptOnly
            });

            var test = template.Render(context);

            Assert.AreEqual("history", test);

            template = Template.Parse("clear history * 5", lexerOptions: new LexerOptions()
            {
                Lang = ScriptLang.Scientific,
                Mode = ScriptMode.ScriptOnly
            });
            test = template.Render(context);
            Assert.AreEqual("history*5", test);
        }
Пример #2
0
        public BuiltinsObject(SiteObject parent) : base(parent)
        {
            Site   = parent;
            _pages = new Dictionary <UPath, ContentObject>();
            parent.SetValue(SiteVariables.Builtins, this, true);
            Head = parent.Scripts.CompileAnonymous("include 'builtins/head.sbn-html'");

            // Helpers used for declaring panels (e.g {{NOTE do}}This is a note.{{end}}
            var helpers = @"
# Defines the generic alert helper function
func ALERT
    `<div class='` + (($0 + ` ` + $.class) | string.rstrip ) + `' role='alert'>`
        `<div class='` + $0 + `-heading'>`
            `<span class='` + $0 + `-icon'></span><span class='` + $0 + `-heading-text'></span>`
        `</div>`
        `<div class='` + $0 + `-content'>` + '\n\n'
            $1
        `</div>`
    '</div>\n\n'
end

# Defines alert functions
func NOTE; ALERT 'lunet-alert-note' class:$.class @$0; end
func TIP; ALERT 'lunet-alert-tip' class:$.class @$0; end
func WARNING; ALERT 'lunet-alert-warning' class:$.class @$0; end
func IMPORTANT; ALERT 'lunet-alert-important' class:$.class @$0; end
func CAUTION; ALERT 'lunet-alert-caution' class:$.class @$0; end
func CALLOUT; ALERT 'lunet-alert-callout' class:$.class @$0; end
";

            parent.Scripts.TryImportScript(helpers, "internal_helpers", this, ScriptFlags.AllowSiteFunctions, out _);
            SetValue("ref", DelegateCustomFunction.CreateFunc((Func <TemplateContext, string, string>)UrlRef), true);
            SetValue("relref", DelegateCustomFunction.CreateFunc((Func <TemplateContext, string, string>)UrlRelRef), true);

            // Add our own to_rfc822
            var dateTimeFunctions = (DateTimeFunctions)Site.Scripts.Builtins["date"];

            dateTimeFunctions.Import("to_rfc822", (Func <DateTime, string>)ToRFC822);

            Site.Content.AfterLoadingProcessors.Add(this);
        }
Пример #3
0
 protected void RegisterFunction <T1, T2, T3, T4, T5, T6>(string name, Func <T1, T2, T3, T4, T5, T6> func, string category = null)
 {
     RegisterCustomFunction(name, DelegateCustomFunction.CreateFunc(func), category);
 }
Пример #4
0
 protected void RegisterAction <T1, T2, T3, T4>(string name, Action <T1, T2, T3, T4> action, string category = null)
 {
     RegisterCustomFunction(name, DelegateCustomFunction.Create(action), category);
 }
Пример #5
0
 private static DelegateCustomFunction Wrap(Func <KalkLongValue, object> func)
 {
     return(DelegateCustomFunction.CreateFunc(func));
 }
Пример #6
0
 public void RegisterFunction(string name, Func <object, object> func, string category = null)
 {
     RegisterFunction(name, DelegateCustomFunction.CreateFunc(func), category);
 }
Пример #7
0
 public void RegisterFunction(string name, Func <object[], KalkMatrix <float> > func, string category = null)
 {
     RegisterFunction(name, DelegateCustomFunction.CreateFunc(func), category);
 }
Пример #8
0
 protected void RegisterAction(string name, Action action, string category = null)
 {
     RegisterFunction(name, DelegateCustomFunction.Create(action), category);
 }