private void compileTemplate(string templateLocation)
 {
     var lines = File.ReadAllLines(templateLocation + ".htm");
     using (var file = File.CreateText(templateLocation + ".rhtml"))
     {
         foreach (var line in lines)
         {
             var node = new NodeParser(line, getVisitors());
             node.Parse(file);
         }
         file.Close();
     }
 }
        public void Given_an_array_of_styles_pass_it_to_the_view_style_renderer()
        {
            const string line = "<!--#{styles}-->";
            const string expectedResult = "RenderCss(writer);\r\n";
            var visitors = new List<INodeVisitor>
                               {
                                   new StyleNodeVisitor()
                               };
            var node = new NodeParser(line, visitors);
            var sw = new StringWriter();
            node.Parse(sw);

            Assert.That(sw.ToString(), Is.EqualTo(expectedResult));
        }
		public void Given_a_foreach_node_replace_the_line_with_the_right_code()
		{
			const string line = "<!--#{foreach movie in movies}-->";
			const string expectedResult = "for movie in movies\r\n";
			var visitors = new List<INodeVisitor>
			                   {
			                       new ForEachNodeVisitor()
			                   };
			var node = new NodeParser(line, visitors);
			var sw = new StringWriter();
			node.Parse(sw);

			Assert.That(sw.ToString(), Is.EqualTo(expectedResult));
		}
		public void Given_an_ifnodeEnd_replace_the_line_with_the_right_code()
		{
			const string line = "<!--#{endif}-->";
			const string expectedResult = "end\r\n";
			var visitors = new List<INodeVisitor>
			                   {
			                       new IfNodeVisitor()
			                   };
			var node = new NodeParser(line, visitors);
			var sw = new StringWriter();
			node.Parse(sw);

			Assert.That(sw.ToString(), Is.EqualTo(expectedResult));
		}
        public void Given_an_area_variable_TextVisitor_ignores_it()
        {
            const string line = "<tr><td>#{area.LeftNavBar}</td></tr>";
            const string expectedResult = "<tr><td>#{area.LeftNavBar}</td></tr>";
            var visitors = new List<INodeVisitor>
                               {
                                   new TextNodeVisitor()
                               };
            var node = new NodeParser(line, visitors);
            var sw = new StringWriter();
            node.Parse(sw);

            Assert.That(sw.ToString(), Is.EqualTo(expectedResult));
        }
        public void Given_an_array_of_metaTags_pass_it_to_the_view_meta_renderer()
        {
            const string line = "<!--#{metatags}-->";
            const string expectedResult = "RenderCollection((IList<IRenderable>)Model.MetaTags, writer);\r\n";

            var visitors = new List<INodeVisitor>
                               {
                                   new MetaNodeVisitor()
                               };
            var node = new NodeParser(line, visitors);
            var sw = new StringWriter();
            node.Parse(sw);

            Assert.That(sw.ToString(), Is.EqualTo(expectedResult));
        }
		public void Given_a_text_node_Should_convert_the_line_to_a_string_and_assign_to_self_dot_output()
		{
			const string line = @"<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN"">";
			const string expectedResult = @"self.output += ""<!DOCTYPE HTML PUBLIC \""-//W3C//DTD HTML 4.0 Transitional//EN\"">\r\n""
";
			var visitors = new List<INodeVisitor>
			                   {
			                       new TextNodeVisitor()
			                   };
			var node = new NodeParser(line, visitors);
			var sw = new StringWriter();
			node.Parse(sw);

			Assert.That(sw.ToString(), Is.EqualTo(expectedResult));
		}
        public void Given_a_collection_of_visitors_Should_run_them_in_the_visitors_order()
        {
            var line = string.Empty;
            var expectedResult = "First Visitor\nSecond Visitor\nThird Visitor\n";
            var visitors = new List<INodeVisitor>
                               {
                                   new ThirdVisitor(),
                                    new SecondVisitor(),
                                   new FirstVisitor()
                               };
            var node = new NodeParser(line, visitors);
            var sw = new StringWriter();
            node.Parse(sw);

            Assert.That(sw.ToString(), Is.EqualTo(expectedResult));
        }
        public void Given_a_text_node_with_a_variable_with_propeties_it_call_GetString_object_property_path()
        {
            const string line = "<div>#{movie.Title}</div>";
            const string expectedResult = "writer.Write( string.Format(\"<div>{0}</div>\",Model.Data.GetString(movie,\"movie.Title\")) );\r\n";
            var visitors = new List<INodeVisitor>
                               {
                                   new TextNodeVisitor()
                               };
            var node = new NodeParser(line, visitors);
            var sw = new StringWriter();
            node.Parse(sw);

            Assert.That(sw.ToString(), Is.EqualTo(expectedResult));
        }
		public void Given_a_phrase_with_1_underscore_at_the_end_Should_replace_them_with_1_plus_signs()
		{
			const string line = "#{phrases.Themes_}";
			const string expectedResult = "\" + localization.GetPhrase(\"Themes+\",lang) + \"";
			var visitors = new List<INodeVisitor>
			                   {
			                       new PhraseNodeVisitor()
			                   };
			var node = new NodeParser(line, visitors);
			var sw = new StringWriter();
			node.Parse(sw);

			Assert.That(sw.ToString(), Is.EqualTo(expectedResult));
		}
		public void Given_a_phrase_with_underscores_in_the_middle_Should_replace_them_with_spaces()
		{
			const string line = "#{phrases.Hunk_Of_the_day}";
			const string expectedResult = "\" + localization.GetPhrase(\"Hunk Of the day\",lang) + \"";
			var visitors = new List<INodeVisitor>
			                   {
			                       new PhraseNodeVisitor()
			                   };
			var node = new NodeParser(line, visitors);
			var sw = new StringWriter();
			node.Parse(sw);

			Assert.That(sw.ToString(), Is.EqualTo(expectedResult));
		}
		public void Given_just_an_area_convert_it_in_a_foreach_and_call_Render_on_the_IWidgets()
		{
			const string line = "#{area.LeftNavBar}";
			const string expectedResult = "var arealeftnavbar = Model.Areas.FirstOrDefault(a=>a.Name.ToLower() == \"leftnavbar\");\r\nRenderCollection((IList<IRenderable>)arealeftnavbar.Layout, writer);\r\n";
			var visitors = new List<INodeVisitor>
			                   {
			                       new AreaNodeVisitor()
			                   };
			var node = new NodeParser(line, visitors);
			var sw = new StringWriter();
			node.Parse(sw);

			Assert.That(sw.ToString(), Is.EqualTo(expectedResult));
		}
		public void Given_a_line_with_a_phrase_Should_replace_the_phrase_and_leave_the_rest_of_the_line_as_it_was()
		{
			const string line = "<div>#{property} #{phrases.Themes_}</div>";
			const string expectedResult = "<div>#{property} \" + localization.GetPhrase(\"Themes+\",lang) + \"</div>";
			var visitors = new List<INodeVisitor>
			                   {
			                       new PhraseNodeVisitor()
			                   };
			var node = new NodeParser(line, visitors);
			var sw = new StringWriter();
			node.Parse(sw);

			Assert.That(sw.ToString(), Is.EqualTo(expectedResult));
		}
        public void Given_a_foreach_node_replace_the_line_with_the_right_code()
        {
            const string line = "<!--#{foreach movie in movies}-->";
            const string expectedResult = "var movies = Model.Data.GetIEnumerable(\"movies\");\r\n if (movies != null){\r\n foreach(var movie in movies){\r\n";
            var visitors = new List<INodeVisitor>
                               {
                                   new ForEachNodeVisitor()
                               };
            var node = new NodeParser(line, visitors);
            var sw = new StringWriter();
            node.Parse(sw);

            Assert.That(sw.ToString(), Is.EqualTo(expectedResult));
        }
        public void Given_an_ifnode_replace_the_line_with_the_right_code()
        {
            const string line = "<!--#{if display}-->";
            const string expectedResult = "if (Model.Data.IsTrue(\"display\")){\r\n";
            var visitors = new List<INodeVisitor>
                               {
                                   new IfNodeVisitor()
                               };
            var node = new NodeParser(line, visitors);
            var sw = new StringWriter();
            node.Parse(sw);

            Assert.That(sw.ToString(), Is.EqualTo(expectedResult));
        }
        public void Parsing_the_Title_Should_call_Model_dot_Title()
        {
            const string line = "<title>#{title}</title>";
            const string expectedResult = "writer.Write( string.Format(\"<title>{0}</title>\",Model.PageTitle) );\r\n";
            var visitors = new List<INodeVisitor>
                               {
                                   new TextNodeVisitor()
                               };
            var node = new NodeParser(line, visitors);
            var sw = new StringWriter();
            node.Parse(sw);

            Assert.That(sw.ToString(), Is.EqualTo(expectedResult));
        }
        public void Given_a_text_node_with_more_than_one_variable_in_it_creates_a_line_of_code()
        {
            const string line = "<div>#{movie}<img src=\"#{imgSrc}\" border=\"0\"/></div><p>#{movie}</p>";
            const string expectedResult = "writer.Write( string.Format(\"<div>{0}<img src=\\\"{1}\\\" border=\\\"0\\\"/></div><p>{0}</p>\",Model.Data.GetString(\"movie\"),Model.Data.GetString(\"imgSrc\")) );\r\n";
            var visitors = new List<INodeVisitor>
                               {
                                   new TextNodeVisitor()
                               };
            var node = new NodeParser(line, visitors);
            var sw = new StringWriter();
            node.Parse(sw);

            Assert.That(sw.ToString(), Is.EqualTo(expectedResult));
        }
		public void Given_a_phrase_Should_use_the_localization_service_to_call_the_phrase()
		{
			const string line = "#{phrases.Themes}";
			const string expectedResult = "\" + localization.GetPhrase(\"Themes\",lang) + \"";
			var visitors = new List<INodeVisitor>
			                   {
			                       new PhraseNodeVisitor()
			                   };
			var node = new NodeParser(line, visitors);
			var sw = new StringWriter();
			node.Parse(sw);

			Assert.That(sw.ToString(), Is.EqualTo(expectedResult));
		}
        public void Given_a_text_node_encapsulate_the_line_in_a_stream_write()
        {
            const string line = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">";
            const string expectedResult = "writer.Write(\"<!DOCTYPE HTML PUBLIC \\\"-//W3C//DTD HTML 4.0 Transitional//EN\\\">\");\r\n";
            var visitors = new List<INodeVisitor>
                               {
                                   new TextNodeVisitor()
                               };
            var node = new NodeParser(line, visitors);
            var sw = new StringWriter();
            node.Parse(sw);

            Assert.That(sw.ToString(),Is.EqualTo(expectedResult));
        }
        public void Given_a_text_node_with_a_variable_in_it_creates_a_line_of_code()
        {
            const string line = "<div>#{movie}</div>";
            const string expectedResult = "writer.Write( string.Format(\"<div>{0}</div>\",Model.Data.GetString(\"movie\")) );\r\n";
            var visitors = new List<INodeVisitor>
                               {
                                   new TextNodeVisitor()
                               };
            var node = new NodeParser(line, visitors);
            var sw = new StringWriter();
            node.Parse(sw);

            Assert.That(sw.ToString(), Is.EqualTo(expectedResult));
        }