Example #1
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"));
 }
Example #2
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"];
 }
Example #3
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);
 }
 /**
  * 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;"/>');
 }
Example #5
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;
     }));
 }