public function cat(HTML $other) { if ($other instanceof HTMLArray) { $this->_content = array_merge($this->_content, $other->content()); return $this; } $this->_content[] = $other; return $this; }
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")); }
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"); }
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"]; }
public function __construct($content) { $this->_content = H::text($content); }
/** * Test weather '"' in input values gets rendered correctly. */ function testRendersQuotesCorrectly() { $html = H::tag("span", array("foo" => "\"bar\"")); $this->assertEquals($html->render(), '<span foo=""bar""/>'); }
public function getContent(RenderDict $dict, $name) { return H::text(""); }
public function buildWithDict(RenderDict $dict) { return H::concat($this->_l->buildWithDict($dict), $this->_r->buildWithDict($dict)); }
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); }
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; })); }
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); }
public function buildWithDict(RenderDict $dict) { return H::nop(); }
/** * Get a new HTML by concatenating $this and $other. */ public function cat(HTML $right) { return HTML::concat($this, $right); }
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"); }