Esempio n. 1
0
        public void ToScriptMethod(string methodName, StringBuilder builder)
        {
            string contents;

            using (var reader = new StreamReader(_sourceLoader.OpenViewStream()))
                contents = reader.ReadToEnd();

            builder.AppendLine();
            requires.ForEach(require => builder.AppendLine(string.Format("require '{0}'", require)));

            if (!String.IsNullOrEmpty(methodName))
            {
                builder.AppendLine("def " + methodName);
            }

            // TODO: Change for  precompiled Regex.CompileToAssembly(...)
            Regex           scriptBlocks = new Regex("<%.*?%>", RegexOptions.Singleline);
            MatchCollection matches      = scriptBlocks.Matches(contents);

            int currentIndex    = 0;
            int blockBeginIndex = 0;

            foreach (Match match in matches)
            {
                blockBeginIndex = match.Index;
                RubyScriptBlock block = RubyScriptBlock.Parse(contents.Substring(currentIndex, blockBeginIndex - currentIndex));
                if (!String.IsNullOrEmpty(block.Content))
                {
                    builder.AppendLine(block.Content);
                }

                block = RubyScriptBlock.Parse(match.Value);
                builder.AppendLine(block.Content);
                currentIndex = match.Index + match.Length;
            }

            if (currentIndex < contents.Length - 1)
            {
                RubyScriptBlock endBlock = RubyScriptBlock.Parse(contents.Substring(currentIndex));
                builder.Append(endBlock.Content);
            }

            if (!String.IsNullOrEmpty(methodName))
            {
                builder.AppendLine();
                builder.AppendLine("end");
            }
        }
Esempio n. 2
0
        // create an input from a resource name
        public ICompilerInput CreateInput(string name)
        {
            IViewSource viewSrc = ViewSourceLoader.GetViewSource(name);

            if (viewSrc == null)
            {
                throw new Exception(string.Format("{0} is not a valid view", name));
            }
            // I need to do it this way because I can't tell
            // when to dispose of the stream.
            // It is not expected that this will be a big problem, the string
            // will go away after the compile is done with them.
            using (var stream = new StreamReader(viewSrc.OpenViewStream()))
            {
                return(new StringInput(name, stream.ReadToEnd()));
            }
        }
Esempio n. 3
0
 public Stream OpenViewStream()
 {
     return(_source.OpenViewStream());
 }
Esempio n. 4
0
 protected override Stream ObtainStream()
 {
     return(viewSource.OpenViewStream());
 }