Exemplo n.º 1
0
 public function cat(HTML $other)
 {
     if ($other instanceof HTMLArray) {
         $this->_content = array_merge($this->_content, $other->content());
         return $this;
     }
     $this->_content[] = $other;
     return $this;
 }
Exemplo n.º 2
0
 function depth_first_searches()
 {
     $is_text = V::fn(function ($html) {
         return $html instanceof HTMLText;
     });
     $get_text = V::fn(function ($html) {
         return $html->content();
     });
     return array(array(H::text("Hello World"), $is_text, $get_text, "Hello World"), array(H::nop(), $is_text, $get_text, null), array(H::tag("foo", array(), H::text("Hello World")), $is_text, $get_text, "Hello World"), array(H::tag("foo", array(), H::concat(H::text("Hello World"), H::text("Hello World"))), $is_text, $get_text, "Hello World"), array(H::tag("foo", array(), H::concat(H::tag("bar", array(), H::concat(H::text("Hello World"), H::text("Blub"))), H::text("Blaw"))), $is_text, $get_text, "Hello World"));
 }
Exemplo n.º 3
0
 public function testMappedTwice()
 {
     $d = new RenderDict(array("foo" => "bar"), V::val(0));
     $n = NameSource::instantiate("test");
     $f = F::text("foobar");
     $rdict1 = null;
     $rhtml1 = null;
     $rdict2 = null;
     $rhtml2 = null;
     $transformation = V::fn(function ($dict, $html) use(&$rdict1, &$rhtml1) {
         $rdict1 = $dict;
         $rhtml1 = $html;
         return H::nop();
     });
     $transformation2 = V::fn(function ($dict, $html) use(&$rdict2, &$rhtml2) {
         $rdict2 = $dict;
         $rhtml2 = $html;
         return H::text("baz");
     });
     $f2 = $f->mapHTML($transformation)->mapHTML($transformation2);
     $i = $f2->instantiate($n);
     $r1 = $i["builder"]->build();
     $this->assertInstanceOf("Lechimp\\Formlets\\Internal\\RenderDict", $rdict1);
     $this->assertInstanceOf("Lechimp\\Formlets\\Internal\\RenderDict", $rdict2);
     $this->assertInstanceOf("Lechimp\\Formlets\\Internal\\HTMLText", $rhtml1);
     $this->assertInstanceOf("Lechimp\\Formlets\\Internal\\HTMLNop", $rhtml2);
     $this->assertEquals($rhtml1->render(), "foobar");
     $this->assertEquals($rhtml2->render(), "");
     $this->assertInstanceOf("Lechimp\\Formlets\\Internal\\HTMLText", $r1);
     $this->assertEquals($r1->render(), "baz");
     $r2 = $i["builder"]->buildWithDict($d);
     $this->assertInstanceOf("Lechimp\\Formlets\\Internal\\RenderDict", $rdict1);
     $this->assertInstanceOf("Lechimp\\Formlets\\Internal\\RenderDict", $rdict2);
     $this->assertEquals($d, $rdict1);
     $this->assertEquals($d, $rdict2);
     $this->assertInstanceOf("Lechimp\\Formlets\\Internal\\HTMLText", $rhtml1);
     $this->assertInstanceOf("Lechimp\\Formlets\\Internal\\HTMLNop", $rhtml2);
     $this->assertEquals($rhtml1->render(), "foobar");
     $this->assertEquals($rhtml2->render(), "");
     $this->assertInstanceOf("Lechimp\\Formlets\\Internal\\HTMLText", $r2);
     $this->assertEquals($r2->render(), "baz");
 }
Exemplo n.º 4
0
 public function __construct($id, $action, $attrs, IFormlet $formlet)
 {
     if (!preg_match("#[a-zA-Z][a-zA-Z0-9_]+#", $id)) {
         throw new Exception("Form::__construct: '{$id}' can not be used as " . "id. Only use numbers and digits.");
     }
     C::guardIsFormlet($formlet);
     C::guardIsString($id);
     C::guardIsString($action);
     $attrs = Value::defaultTo($attrs, array());
     C::guardEachAndKeys($attrs, "C::guardIsString", "C::guardIsString");
     $this->_id = $id;
     $this->_input = null;
     $this->_result = null;
     $attrs["method"] = "post";
     $attrs["action"] = $action;
     $formlet = $formlet->mapHTML(V::fn(function ($dict, $html) use($attrs) {
         return H::tag("form", $attrs, $html);
     }));
     $name_source = NameSource::instantiate($this->_id);
     $repr = $formlet->instantiate($name_source);
     $this->_builder = $repr["builder"];
     $this->_collector = $repr["collector"];
 }
Exemplo n.º 5
0
 public function __construct($content)
 {
     $this->_content = H::text($content);
 }
Exemplo n.º 6
0
 /**
  * Test weather '"' in input values gets rendered correctly. 
  */
 function testRendersQuotesCorrectly()
 {
     $html = H::tag("span", array("foo" => "\"bar\""));
     $this->assertEquals($html->render(), '<span foo="&quot;bar&quot;"/>');
 }
Exemplo n.º 7
0
 public function getContent(RenderDict $dict, $name)
 {
     return H::text("");
 }
Exemplo n.º 8
0
 public function buildWithDict(RenderDict $dict)
 {
     return H::concat($this->_l->buildWithDict($dict), $this->_r->buildWithDict($dict));
 }
Exemplo n.º 9
0
 public function buildWithDict(RenderDict $dict)
 {
     $attributes = $this->_callback_object->getAttributes($dict, $this->_name);
     $content = $this->_callback_object->getContent($dict, $this->_name);
     return H::tag($this->_tag_name, $attributes, $content);
 }
Exemplo n.º 10
0
 public static function with_errors(Formlet $other)
 {
     return $other->mapHTML(V::fn(function ($dict, $html) {
         $name = self::html_get_depth_first_name($html);
         if ($name === null) {
             throw new Exception("_with_errors applied to un-named Formlet.");
         }
         $errors = $dict->errors($name);
         if ($errors === null) {
             return $html;
         }
         foreach ($errors as $error) {
             $html = H::concat($html, H::tag("span", array("class" => "error"), H::text($error)));
         }
         return $html;
     }));
 }
Exemplo n.º 11
0
 public static function html_apply_to_depth_first_name(HTML $html, FunctionValue $fn)
 {
     return $html->depthFirst(V::fn(function ($html) {
         return $html instanceof HTMLTag && $html->attribute("name");
     }), $fn);
 }
Exemplo n.º 12
0
 public function buildWithDict(RenderDict $dict)
 {
     return H::nop();
 }
Exemplo n.º 13
0
 /**
  * Get a new HTML by concatenating $this and $other.
  */
 public function cat(HTML $right)
 {
     return HTML::concat($this, $right);
 }
Exemplo n.º 14
0
 public function testMappedTwiceBuilder()
 {
     $d = new RenderDict(array("foo" => "bar"), V::val(0));
     $b = new TextBuilder("foobar");
     $rdict1 = null;
     $rhtml1 = null;
     $rdict2 = null;
     $rhtml2 = null;
     $transformation = V::fn(function ($dict, $html) use(&$rdict1, &$rhtml1) {
         $rdict1 = $dict;
         $rhtml1 = $html;
         return H::nop();
     });
     $transformation2 = V::fn(function ($dict, $html) use(&$rdict2, &$rhtml2) {
         $rdict2 = $dict;
         $rhtml2 = $html;
         return H::text("baz");
     });
     $b2 = $b->map($transformation)->map($transformation2);
     $r1 = $b2->build();
     $this->assertInstanceOf("Lechimp\\Formlets\\Internal\\RenderDict", $rdict1);
     $this->assertInstanceOf("Lechimp\\Formlets\\Internal\\RenderDict", $rdict2);
     $this->assertInstanceOf("Lechimp\\Formlets\\Internal\\HTMLText", $rhtml1);
     $this->assertInstanceOf("Lechimp\\Formlets\\Internal\\HTMLNop", $rhtml2);
     $this->assertEquals($rhtml1->render(), "foobar");
     $this->assertEquals($rhtml2->render(), "");
     $this->assertInstanceOf("Lechimp\\Formlets\\Internal\\HTMLText", $r1);
     $this->assertEquals($r1->render(), "baz");
     $r2 = $b2->buildWithDict($d);
     $this->assertInstanceOf("Lechimp\\Formlets\\Internal\\RenderDict", $rdict1);
     $this->assertInstanceOf("Lechimp\\Formlets\\Internal\\RenderDict", $rdict2);
     $this->assertEquals($d, $rdict1);
     $this->assertEquals($d, $rdict2);
     $this->assertInstanceOf("Lechimp\\Formlets\\Internal\\HTMLText", $rhtml1);
     $this->assertInstanceOf("Lechimp\\Formlets\\Internal\\HTMLNop", $rhtml2);
     $this->assertEquals($rhtml1->render(), "foobar");
     $this->assertEquals($rhtml2->render(), "");
     $this->assertInstanceOf("Lechimp\\Formlets\\Internal\\HTMLText", $r2);
     $this->assertEquals($r2->render(), "baz");
 }