{item}
{/}if RUBY_PLATFORM == 'opal' else require 'benchmark' require 'volt/server/html_parser/view_parser' describe ViewParser do it "should parse content bindings" do html = "
Some {content} binding, {name}
" view = ViewParser.new(html, "main/main/main") expect(view.templates).to eq({ 'main/main/main/body' => { 'html' => 'Some binding,
', 'bindings' => { 0 => ["lambda { |__p, __t, __c, __id| ContentBinding.new(__p, __t, __c, __id, Proc.new { content }) }"], 1 => ["lambda { |__p, __t, __c, __id| ContentBinding.new(__p, __t, __c, __id, Proc.new { name }) }"] } } }) end it "should parse if bindings" do html = <<-ENDSome {#if showing == :text} text {#elsif showing == :button} {#else} link {/}
END view = ViewParser.new(html, "main/main/main") expect(view.templates).to eq( { "main/main/main/body/__ifg0/__if0" => { "html" => "\n text\n " }, "main/main/main/body/__ifg0/__if1" => { "html" => "\n \n " }, "main/main/main/body/__ifg0/__if2" => { "html" => "\n link\n " }, "main/main/main/body" => { "html" => "\n Some\n \n
\n", "bindings" => { 0 => [ "lambda { |__p, __t, __c, __id| IfBinding.new(__p, __t, __c, __id, [[Proc.new { showing == :text }, \"main/main/main/body/__ifg0/__if0\"], [Proc.new { showing == :button }, \"main/main/main/body/__ifg0/__if1\"], [nil, \"main/main/main/body/__ifg0/__if2\"]]) }" ] } } }) end it "should handle nested if's" do html = <<-ENDSome {#if showing == :text} {#if sub_item} sub item text {/} {#else} other {/}
END view = ViewParser.new(html, "main/main/main") expect(view.templates).to eq( { "main/main/main/body/__ifg0/__if0/__ifg0/__if0" => { "html"=>"\n sub item text\n " }, "main/main/main/body/__ifg0/__if0" => { "html" => "\n \n ", "bindings" => { 0 => [ "lambda { |__p, __t, __c, __id| IfBinding.new(__p, __t, __c, __id, [[Proc.new { sub_item }, \"main/main/main/body/__ifg0/__if0/__ifg0/__if0\"]]) }" ] } }, "main/main/main/body/__ifg0/__if1" => { "html" => "\n other\n " }, "main/main/main/body" => { "html" => "\n Some\n \n
\n", "bindings" => { 0 => [ "lambda { |__p, __t, __c, __id| IfBinding.new(__p, __t, __c, __id, [[Proc.new { showing == :text }, \"main/main/main/body/__ifg0/__if0\"], [nil, \"main/main/main/body/__ifg0/__if1\"]]) }" ] } } }) end it "should parse each bindings" do html = <<-END{item}
{/}This text goes in the body
END view = ViewParser.new(html, "main/main/main") expect(view.templates).to eq( { "main/main/main/title" => { "html" => "\n This text goes in the title\n\n " }, "main/main/main/body" => { "html" => "\nThis text goes in the body
\n" } }) end it "should keep the html inside of a textarea if there are no bindings" do html = <<-END END view = ViewParser.new(html, "main/main/main") expect(view.templates).to eq({ "main/main/main/body" => { "html" => " \n" } }) end it "should setup bindings for textarea values" do html = <<-END END view = ViewParser.new(html, "main/main/main") expect(view.templates).to eq({"main/main/main/body"=>{"html"=>" \n", "bindings"=>{"id1"=>["lambda { |__p, __t, __c, __id| AttributeBinding.new(__p, __t, __c, __id, \"value\", Proc.new { awesome }, Proc.new { |val| self.awesome=(val) }) }"]}}}) end end end