Permalink
Browse files

using cascading translation scope, cache assets config option

  • Loading branch information...
1 parent 57ba03f commit 0c4e99c1d54c0abbfe883e46f1cafd7ffdff0593 @olvlvl committed Nov 28, 2010
Showing with 74 additions and 43 deletions.
  1. +5 −0 CHANGELOG
  2. +3 −1 config/core.php
  3. +3 −1 wd2cform.php
  4. +2 −2 wddocument.php
  5. +60 −39 wdelement.php
  6. +1 −0 wdform.php
View
@@ -5,6 +5,11 @@
[NEW] Using the WdElement::walk() method, the WdElement::get_named_elements() method can
recursively retrive the named elements of a elements.
+[NEW] Using the cascading translation scope feature of the new WdI18n class.
+
+[NEW] The 'cache assets' core config option can be used to enable assets caching by the
+WdDocument class.
+
View
@@ -16,5 +16,7 @@
'WdRanger' => $root . 'wdranger.php',
'WdTemplatedElement' => $root . 'wdtemplatedelement.php',
'WdTemplatedForm' => $root . 'wdtemplatedform.php',
- )
+ ),
+
+ 'cache assets' => false
);
View
@@ -126,7 +126,9 @@ protected function getInnerHTML()
$label .= ' for="' . $child_id . '"';
}
- $label .= '>' . t($text);
+ $label .= '>';
+
+ $label .= self::translate_label($text);
if ($is_required)
{
View
@@ -256,7 +256,7 @@ public function __toString()
(
array
(
- WdFileCache::T_REPOSITORY => WdCore::getConfig('repository.cache') . '/document'
+ WdFileCache::T_REPOSITORY => WdCore::$config['repository.cache'] . '/document'
)
);
@@ -350,7 +350,7 @@ public function __toString()
(
array
(
- WdFileCache::T_REPOSITORY => WdCore::getConfig('repository.cache') . '/document'
+ WdFileCache::T_REPOSITORY => WdCore::$config['repository.cache'] . '/document'
)
);
View
@@ -43,6 +43,12 @@ class WdElement
const T_GROUP = '#group';
const T_GROUPS = '#groups';
const T_TYPE = '#type';
+
+ /**
+ * The T_INNER_HTML tag is used to define the inner HTML of an element.
+ * If the value of the tag is NULL, the markup will be self-closing.
+ */
+
const T_INNER_HTML = '#innerHTML';
const T_LABEL = '#element-label';
const T_LABEL_POSITION = '#element-label-position';
@@ -65,6 +71,7 @@ class WdElement
const T_WEIGHT = '#weight';
static $inputs = array('button', 'form', 'input', 'option', 'select', 'textarea');
+ static private $has_attribute_value = array('button', 'input', 'option');
#
#
@@ -165,31 +172,7 @@ public function __construct($type, $tags=array())
break;
}
- #
- # parse some tags
- #
-
- if (isset($tags[self::T_CHILDREN]))
- {
- $this->addChildren($tags[self::T_CHILDREN]);
- }
-
- if (array_key_exists(self::T_INNER_HTML, $tags))
- {
- // TODO-20100203: this should be moved elsewhere, in the getInnerHTML method I guess
-
- #
- # The T_INNER_HTML tag is used to define the inner HTML of an element.
- # If the tag is NULL, the markup will be self-closing.
- #
-
- $this->innerHTML = $tags[self::T_INNER_HTML];
- }
-
- foreach ($tags as $tag => $value)
- {
- $this->set($tag, $value);
- }
+ $this->set($tags);
}
/**
@@ -203,17 +186,34 @@ public function set($name, $value=null)
{
foreach ($name as $tag => $value)
{
- $this->tags[$tag] = $value;
+ $this->set($tag, $value);
}
}
else
{
$this->tags[$name] = $value;
}
- if ($name == self::T_DATASET)
+ switch ($name)
{
- $this->dataset = $value;
+ case self::T_CHILDREN:
+ {
+ $this->children = array();
+ $this->addChildren($value);
+ }
+ break;
+
+ case self::T_DATASET:
+ {
+ $this->dataset = $value;
+ }
+ break;
+
+ case self::T_INNER_HTML:
+ {
+ $this->innerHTML = $value;
+ }
+ break;
}
}
@@ -256,7 +256,7 @@ public function removeClass($class)
* @return string
*/
- public function composeClass()
+ protected function compose_class()
{
$value = $this->get('class');
$classes = $this->classes;
@@ -448,7 +448,14 @@ protected function getMarkup()
# its markup.
#
- $inner = $this->getInnerHTML();
+ try
+ {
+ $inner = $this->getInnerHTML();
+ }
+ catch (Exception $e)
+ {
+ $inner = $e->getMessage();
+ }
#
#
@@ -460,7 +467,7 @@ protected function getMarkup()
# class
#
- $class = $this->composeClass();
+ $class = $this->compose_class();
if ($class)
{
@@ -483,11 +490,16 @@ protected function getMarkup()
continue;
}
+ if ($name == 'value' && !in_array($this->tagName, self::$has_attribute_value))
+ {
+ continue;
+ }
+
#
# We discard the `disabled`, `name` and `value` attributes for non input type elements
#
- if (($name == 'disabled' || $name == 'name' || $name == 'value') && !in_array($this->tagName, self::$inputs))
+ if (($name == 'disabled' || $name == 'name') && !in_array($this->tagName, self::$inputs))
{
continue;
}
@@ -512,7 +524,12 @@ protected function getMarkup()
$value = json_encode($value);
}
- $rc .= ' data-' . $name . '="' . wd_entities($value) . '"';
+ if ($value === null)
+ {
+ continue;
+ }
+
+ $rc .= ' data-' . $name . '="' . (is_numeric($value) ? $value : wd_entities($value)) . '"';
}
#
@@ -904,12 +921,6 @@ public function __toString()
$selected = $this->get('value');
- #
- # and remove them from our attribute list
- #
-
- $this->set('value', null);
-
#
# this is the 'template' child
#
@@ -1224,4 +1235,14 @@ public function walk($callback, $userdata, $stop=null)
call_user_func($callback, $this, $userdata, $stop_value);
}
+
+ static protected function translate_label($label)
+ {
+ if (!is_array($label))
+ {
+ return t($label, array(), array('scope' => array('form', 'label')));
+ }
+
+ return t($label[0], array(), array('scope' => $label[1]));
+ }
}
View
@@ -480,6 +480,7 @@ static public function selectElementLabel($element)
# remove HTML markups from the label
#
+ $label = self::translate_label($label);
$label = strip_tags($label);
return $label;

0 comments on commit 0c4e99c

Please sign in to comment.