Example #1
0
        void parseAndPersistBehaviors(JsString sheet)
        {
            JsString       classSelector;
            JsRegExpResult randoriVendorItemsResult;
            JsRegExpResult randoriVendorItemInfoResult;
            JsRegExpResult CSSClassSelectorNameResult;

            /*
             * This regular expression then grabs all of the class selectors
             * \.[\w\W]*?\}
             *
             * This expression finds an -randori vendor prefix styles in the current cssSelector and returns 2 groups, the first
             * is the type, the second is the value
             *
             * \s?-randori-([\w\W]+?)\s?:\s?["']?([\w\W]+?)["']?;
             *
             */

            var allClassSelectors = new JsRegExp(@"^[\w\W]*?\}", "gm");

            const string RANDORI_VENDOR_ITEM_EXPRESSION = @"\s?-randori-([\w\W]+?)\s?:\s?[""']?([\w\W]+?)[""']?;";
            //These two are the same save for the global flag. The global flag seems to disable all capturing groups immediately
            var anyVendorItems = new JsRegExp(RANDORI_VENDOR_ITEM_EXPRESSION, "g");

            //This is the same as the one in findRelevant classes save for the the global flag... which is really important
            //The global flag seems to disable all capturing groups immediately
            var eachVendorItem = new JsRegExp(RANDORI_VENDOR_ITEM_EXPRESSION);

            var      classSelectorName = new JsRegExp(@"^(.+?)\s+?{", "m");
            JsString CSSClassSelectorName;
            JsString randoriVendorItemStr;

            var selectors = sheet.match(allClassSelectors);

            if (selectors != null)
            {
                for (int i = 0; i < selectors.length; i++)
                {
                    classSelector = selectors[i];

                    randoriVendorItemsResult = classSelector.match(anyVendorItems);
                    if (randoriVendorItemsResult != null)
                    {
                        CSSClassSelectorNameResult = classSelector.match(classSelectorName);
                        CSSClassSelectorName       = CSSClassSelectorNameResult[1];

                        for (int j = 0; j < randoriVendorItemsResult.length; j++)
                        {
                            randoriVendorItemStr        = randoriVendorItemsResult[j];
                            randoriVendorItemInfoResult = randoriVendorItemStr.match(eachVendorItem);
                            map.addCSSEntry(CSSClassSelectorName, randoriVendorItemInfoResult[1], randoriVendorItemInfoResult[2]);
                            if (HtmlContext.window.console != null)
                            {
                                HtmlContext.console.log(CSSClassSelectorName + " specifies a " + randoriVendorItemInfoResult[1] + " implemented by class " + randoriVendorItemInfoResult[2]);
                            }
                        }
                    }
                }
            }
        }
Example #2
0
        // based on https://github.com/JamesMGreene/currentExecutingScript
        private static string ScriptFileFromStack(JsString stack)
        {
            var matches = stack.match(@"(data:text\/javascript(?:;[^,]+)?,.+?|(?:|blob:)(?:http[s]?|file):\/\/[\/]?.+?\/[^:\)]*?)(?::\d+)(?::\d+)?");

            if (!matches.As <bool>())
            {
                matches = stack.match(@"^(?:|[^:@]*@|.+\)@(?=data:text\/javascript|blob|http[s]?|file)|.+?\s+(?: at |@)(?:[^:\(]+ )*[\(]?)(data:text\/javascript(?:;[^,]+)?,.+?|(?:|blob:)(?:http[s]?|file):\/\/[\/]?.+?\/[^:\)]*?)(?::\d+)(?::\d+)?");
                if (!matches.As <bool>())
                {
                    matches = stack.match(@"\)@(data:text\/javascript(?:;[^,]+)?,.+?|(?:|blob:)(?:http[s]?|file):\/\/[\/]?.+?\/[^:\)]*?)(?::\d+)(?::\d+)?");
                    if (!matches.As <bool>())
                    {
                        return(null);
                    }
                }
            }
            return(matches[1]);
        }
        void parseLine(JsString line)
        {
            if (line.length == 0)
            {
                //empty line, bail
                return;
            }

            JsRegExp       isComment       = new JsRegExp(@"^[#!]");
            JsRegExpResult isCommentResult = line.match(isComment);

            if (isCommentResult != null)
            {
                //its a comment, bail
                return;
            }

            JsRegExp       tokenize       = new JsRegExp(@"^(\w+)\s?=\s?([\w\W]+?)[\n\r]+");
            JsRegExpResult tokenizeResult = line.match(tokenize);
            JsString       key;
            JsString       strValue;
            dynamic        value;

            if (tokenizeResult != null && tokenizeResult.length == 3)
            {
                key   = tokenizeResult[1];
                value = tokenizeResult[2];

                strValue = value;
                if (strValue.indexOf(",") != -1)
                {
                    //this is an array, tokenize it
                    value = strValue.split(',');
                }

                keyValuePairs[key] = value;
            }
        }
        private void resolveParentClassFromDefinition(JsString qualifiedClassName, JsString classDefinition)
        {
            //\$Inherit\(net.digitalprimates.service.LabelService,([\w\W]*?)\)
            JsString inheritString = @"\$Inherit\(";

            inheritString += qualifiedClassName;
            inheritString += @",\s*(.*?)\)";
            JsRegExpResult inheritResult = classDefinition.match(inheritString);

            //Do we inherit from anything?
            if (inheritResult != null)
            {
                //Resolve the parent class first
                resolveClassName(inheritResult[1]);
            }
        }
        void parseResult(JsString responseText)
        {
            //get each line
            JsRegExp       eachLine       = new JsRegExp(@"[\w\W]+?[\n\r]+", "g");
            JsRegExpResult eachLineResult = responseText.match(eachLine);

            this.fileLoaded = true;

            if (eachLineResult != null)
            {
                for (int i = 0; i < eachLineResult.length; i++)
                {
                    parseLine(eachLineResult[i]);
                }
            }
        }
Example #6
0
        public jQuery renderTemplateClone(JsObject data)
        {
            JsString token;
            JsString field;
            dynamic  dereferencedValue;
            var      keyRegex  = new JsRegExp(@"\{[\w\W]+?\}", "g");
            var      foundKeys = templateAsString.match(keyRegex);
            var      output    = templateAsString;

            if (foundKeys != null)
            {
                for (int j = 0; j < foundKeys.length; j++)
                {
                    token = foundKeys[j];
                    field = returnFieldName(token);

                    if (field.indexOf(".") != -1)
                    {
                        dereferencedValue = resolveComplexName(data, field);
                    }
                    else if (field != "*")
                    {
                        dereferencedValue = data[field];
                    }
                    else
                    {
                        dereferencedValue = data;
                    }

                    output = output.replace(token, dereferencedValue);
                }
            }

            jQuery fragmentJquery = jQueryContext.J("<div></div>");

            fragmentJquery.append(output);

            return(fragmentJquery);
        }
Example #7
0
 // based on https://github.com/JamesMGreene/currentExecutingScript
 private static string ScriptFileFromStack(JsString stack)
 {
     var matches = stack.match(@"(data:text\/javascript(?:;[^,]+)?,.+?|(?:|blob:)(?:http[s]?|file):\/\/[\/]?.+?\/[^:\)]*?)(?::\d+)(?::\d+)?");
     if (!matches.As<bool>())
     {
         matches = stack.match(@"^(?:|[^:@]*@|.+\)@(?=data:text\/javascript|blob|http[s]?|file)|.+?\s+(?: at |@)(?:[^:\(]+ )*[\(]?)(data:text\/javascript(?:;[^,]+)?,.+?|(?:|blob:)(?:http[s]?|file):\/\/[\/]?.+?\/[^:\)]*?)(?::\d+)(?::\d+)?");
         if (!matches.As<bool>())
         {
             matches = stack.match(@"\)@(data:text\/javascript(?:;[^,]+)?,.+?|(?:|blob:)(?:http[s]?|file):\/\/[\/]?.+?\/[^:\)]*?)(?::\d+)(?::\d+)?");
             if (!matches.As<bool>())
             {
                 return null;
             }
         }
     }
     return matches[1];
 }
        void parseAndPersistBehaviors(JsString sheet)
        {
            JsString classSelector;
            JsRegExpResult randoriVendorItemsResult;
            JsRegExpResult randoriVendorItemInfoResult;
            JsRegExpResult CSSClassSelectorNameResult;
            /*
             * This regular expression then grabs all of the class selectors
             * \.[\w\W]*?\}
             *
             * This expression finds an -randori vendor prefix styles in the current cssSelector and returns 2 groups, the first
             * is the type, the second is the value
             *
             * \s?-randori-([\w\W]+?)\s?:\s?["']?([\w\W]+?)["']?;
             *
             */

            var allClassSelectors = new JsRegExp(@"^[\w\W]*?\}", "gm");

            const string RANDORI_VENDOR_ITEM_EXPRESSION = @"\s?-randori-([\w\W]+?)\s?:\s?[""']?([\w\W]+?)[""']?;";
            //These two are the same save for the global flag. The global flag seems to disable all capturing groups immediately
            var anyVendorItems = new JsRegExp(RANDORI_VENDOR_ITEM_EXPRESSION, "g");

            //This is the same as the one in findRelevant classes save for the the global flag... which is really important
            //The global flag seems to disable all capturing groups immediately
            var eachVendorItem = new JsRegExp(RANDORI_VENDOR_ITEM_EXPRESSION);

            var classSelectorName = new JsRegExp(@"^(.+?)\s+?{","m");
            JsString CSSClassSelectorName;
            JsString randoriVendorItemStr;

            var selectors = sheet.match(allClassSelectors);

            if (selectors != null ) {
                for (int i = 0; i < selectors.length; i++) {
                    classSelector = selectors[i];

                    randoriVendorItemsResult = classSelector.match(anyVendorItems);
                    if (randoriVendorItemsResult != null) {

                        CSSClassSelectorNameResult = classSelector.match(classSelectorName);
                        CSSClassSelectorName = CSSClassSelectorNameResult[1];

                        for (int j = 0; j < randoriVendorItemsResult.length; j++) {
                            randoriVendorItemStr = randoriVendorItemsResult[j];
                            randoriVendorItemInfoResult = randoriVendorItemStr.match(eachVendorItem);
                            map.addCSSEntry(CSSClassSelectorName, randoriVendorItemInfoResult[1], randoriVendorItemInfoResult[2]);
                            if (HtmlContext.window.console != null) {
                                HtmlContext.console.log(CSSClassSelectorName + " specifies a " + randoriVendorItemInfoResult[1] + " implemented by class " + randoriVendorItemInfoResult[2]);
                            }
                        }
                    }
                }
            }
        }
        void parseResult( JsString responseText )
        {
            //get each line
            JsRegExp eachLine = new JsRegExp(@"[\w\W]+?[\n\r]+", "g");
            JsRegExpResult eachLineResult = responseText.match( eachLine );

            this.fileLoaded = true;

            if (eachLineResult != null) {
                for ( int i=0;i<eachLineResult.length;i++) {
                    parseLine( eachLineResult[ i ] );
                }
            }
        }
        void parseLine(JsString line)
        {
            if ( line.length == 0 ) {
                //empty line, bail
                return;
            }

            JsRegExp isComment = new JsRegExp(@"^[#!]");
            JsRegExpResult isCommentResult = line.match(isComment);

            if ( isCommentResult != null ) {
                //its a comment, bail
                return;
            }

            JsRegExp tokenize = new JsRegExp(@"^(\w+)\s?=\s?([\w\W]+?)[\n\r]+");
            JsRegExpResult tokenizeResult = line.match(tokenize);
            JsString key;
            JsString strValue;
            dynamic value;

            if ( tokenizeResult != null && tokenizeResult.length == 3) {
                key = tokenizeResult[ 1 ];
                value = tokenizeResult[ 2 ];

                strValue = value;
                if (strValue.indexOf( "," ) != -1 ) {
                    //this is an array, tokenize it
                    value = strValue.split( ',' );
                }

                keyValuePairs[ key ] = value;
            }
        }
        private void resolveParentClassFromDefinition(JsString qualifiedClassName, JsString classDefinition)
        {
            //\$Inherit\(net.digitalprimates.service.LabelService,([\w\W]*?)\)
            JsString inheritString = @"\$Inherit\(";
            inheritString += qualifiedClassName;
            inheritString += @",\s*(.*?)\)";
            JsRegExpResult inheritResult = classDefinition.match(inheritString);

            //Do we inherit from anything?
            if (inheritResult != null) {
                //Resolve the parent class first
                resolveClassName(inheritResult[1]);
            }
        }
        public static JsDate RFC3339StringToLocalDate(JsString dateString)
        {
            JsDate localDate = null;

            if (dateString == null || dateString.length != 10 ) {
                throw new JsError("Invalid Date String");
            }

            var dateMatch = new JsRegExp(@"(\d\d\d\d)-(\d\d)-(\d\d)");
            var match = dateString.match(dateMatch);

            if (match != null) {
                dynamic yearString = match[1];
                dynamic monthString = match[2];
                dynamic dayString = match[3];

                localDate = new JsDate(yearString, monthString-1, dayString);
            }

            return localDate;
        }