Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

using cascading translation scope, cache assets config option

  • Loading branch information...
commit 0c4e99c1d54c0abbfe883e46f1cafd7ffdff0593 1 parent 57ba03f
Olivier Laviale authored November 28, 2010
5  CHANGELOG
@@ -5,6 +5,11 @@
5 5
 [NEW] Using the WdElement::walk() method, the WdElement::get_named_elements() method can
6 6
 recursively retrive the named elements of a elements.
7 7
 
  8
+[NEW] Using the cascading translation scope feature of the new WdI18n class.
  9
+
  10
+[NEW] The 'cache assets' core config option can be used to enable assets caching by the
  11
+WdDocument class.
  12
+
8 13
 
9 14
 
10 15
 
4  config/core.php
@@ -16,5 +16,7 @@
16 16
 		'WdRanger' => $root . 'wdranger.php',
17 17
 		'WdTemplatedElement' => $root . 'wdtemplatedelement.php',
18 18
 		'WdTemplatedForm' => $root . 'wdtemplatedform.php',
19  
-	)
  19
+	),
  20
+
  21
+	'cache assets' => false
20 22
 );
4  wd2cform.php
@@ -126,7 +126,9 @@ protected function getInnerHTML()
126 126
 						$label .= ' for="' . $child_id . '"';
127 127
 					}
128 128
 
129  
-					$label .= '>' . t($text);
  129
+					$label .= '>';
  130
+
  131
+					$label .= self::translate_label($text);
130 132
 
131 133
 					if ($is_required)
132 134
 					{
4  wddocument.php
@@ -256,7 +256,7 @@ public function __toString()
256 256
 				(
257 257
 					array
258 258
 					(
259  
-						WdFileCache::T_REPOSITORY => WdCore::getConfig('repository.cache') . '/document'
  259
+						WdFileCache::T_REPOSITORY => WdCore::$config['repository.cache'] . '/document'
260 260
 					)
261 261
 				);
262 262
 
@@ -350,7 +350,7 @@ public function __toString()
350 350
 				(
351 351
 					array
352 352
 					(
353  
-						WdFileCache::T_REPOSITORY => WdCore::getConfig('repository.cache') . '/document'
  353
+						WdFileCache::T_REPOSITORY => WdCore::$config['repository.cache'] . '/document'
354 354
 					)
355 355
 				);
356 356
 
99  wdelement.php
@@ -43,6 +43,12 @@ class WdElement
43 43
 	const T_GROUP = '#group';
44 44
 	const T_GROUPS = '#groups';
45 45
 	const T_TYPE = '#type';
  46
+
  47
+	/**
  48
+	 * The T_INNER_HTML tag is used to define the inner HTML of an element.
  49
+	 * If the value of the tag is NULL, the markup will be self-closing.
  50
+	 */
  51
+
46 52
 	const T_INNER_HTML = '#innerHTML';
47 53
 	const T_LABEL = '#element-label';
48 54
 	const T_LABEL_POSITION = '#element-label-position';
@@ -65,6 +71,7 @@ class WdElement
65 71
 	const T_WEIGHT = '#weight';
66 72
 
67 73
 	static $inputs = array('button', 'form', 'input', 'option', 'select', 'textarea');
  74
+	static private $has_attribute_value = array('button', 'input', 'option');
68 75
 
69 76
 	#
70 77
 	#
@@ -165,31 +172,7 @@ public function __construct($type, $tags=array())
165 172
 			break;
166 173
 		}
167 174
 
168  
-		#
169  
-		# parse some tags
170  
-		#
171  
-
172  
-		if (isset($tags[self::T_CHILDREN]))
173  
-		{
174  
-			$this->addChildren($tags[self::T_CHILDREN]);
175  
-		}
176  
-
177  
-		if (array_key_exists(self::T_INNER_HTML, $tags))
178  
-		{
179  
-			// TODO-20100203: this should be moved elsewhere, in the getInnerHTML method I guess
180  
-
181  
-		    #
182  
-		    # The T_INNER_HTML tag is used to define the inner HTML of an element.
183  
-		    # If the tag is NULL, the markup will be self-closing.
184  
-		    #
185  
-
186  
-			$this->innerHTML = $tags[self::T_INNER_HTML];
187  
-		}
188  
-
189  
-		foreach ($tags as $tag => $value)
190  
-		{
191  
-			$this->set($tag, $value);
192  
-		}
  175
+		$this->set($tags);
193 176
 	}
194 177
 
195 178
 	/**
@@ -203,7 +186,7 @@ public function set($name, $value=null)
203 186
 		{
204 187
 			foreach ($name as $tag => $value)
205 188
 			{
206  
-				$this->tags[$tag] = $value;
  189
+				$this->set($tag, $value);
207 190
 			}
208 191
 		}
209 192
 		else
@@ -211,9 +194,26 @@ public function set($name, $value=null)
211 194
 			$this->tags[$name] = $value;
212 195
 		}
213 196
 
214  
-		if ($name == self::T_DATASET)
  197
+		switch ($name)
215 198
 		{
216  
-			$this->dataset = $value;
  199
+			case self::T_CHILDREN:
  200
+			{
  201
+				$this->children = array();
  202
+				$this->addChildren($value);
  203
+			}
  204
+			break;
  205
+
  206
+			case self::T_DATASET:
  207
+			{
  208
+				$this->dataset = $value;
  209
+			}
  210
+			break;
  211
+
  212
+			case self::T_INNER_HTML:
  213
+			{
  214
+				$this->innerHTML = $value;
  215
+			}
  216
+			break;
217 217
 		}
218 218
 	}
219 219
 
@@ -256,7 +256,7 @@ public function removeClass($class)
256 256
 	 * @return string
257 257
 	 */
258 258
 
259  
-	public function composeClass()
  259
+	protected function compose_class()
260 260
 	{
261 261
 		$value = $this->get('class');
262 262
 		$classes = $this->classes;
@@ -448,7 +448,14 @@ protected function getMarkup()
448 448
 		# its markup.
449 449
 		#
450 450
 
451  
-		$inner = $this->getInnerHTML();
  451
+		try
  452
+		{
  453
+			$inner = $this->getInnerHTML();
  454
+		}
  455
+		catch (Exception $e)
  456
+		{
  457
+			$inner = $e->getMessage();
  458
+		}
452 459
 
453 460
 		#
454 461
 		#
@@ -460,7 +467,7 @@ protected function getMarkup()
460 467
 		# class
461 468
 		#
462 469
 
463  
-		$class = $this->composeClass();
  470
+		$class = $this->compose_class();
464 471
 
465 472
 		if ($class)
466 473
 		{
@@ -483,11 +490,16 @@ protected function getMarkup()
483 490
 				continue;
484 491
 			}
485 492
 
  493
+			if ($name == 'value' && !in_array($this->tagName, self::$has_attribute_value))
  494
+			{
  495
+				continue;
  496
+			}
  497
+
486 498
 			#
487 499
 			# We discard the `disabled`, `name` and `value` attributes for non input type elements
488 500
 			#
489 501
 
490  
-			if (($name == 'disabled' || $name == 'name' || $name == 'value') && !in_array($this->tagName, self::$inputs))
  502
+			if (($name == 'disabled' || $name == 'name') && !in_array($this->tagName, self::$inputs))
491 503
 			{
492 504
 				continue;
493 505
 			}
@@ -512,7 +524,12 @@ protected function getMarkup()
512 524
 				$value = json_encode($value);
513 525
 			}
514 526
 
515  
-			$rc .= ' data-' . $name . '="' . wd_entities($value) . '"';
  527
+			if ($value === null)
  528
+			{
  529
+				continue;
  530
+			}
  531
+
  532
+			$rc .= ' data-' . $name . '="' . (is_numeric($value) ? $value : wd_entities($value)) . '"';
516 533
 		}
517 534
 
518 535
 		#
@@ -905,12 +922,6 @@ public function __toString()
905 922
 				$selected = $this->get('value');
906 923
 
907 924
 				#
908  
-				# and remove them from our attribute list
909  
-				#
910  
-
911  
-				$this->set('value', null);
912  
-
913  
-				#
914 925
 				# this is the 'template' child
915 926
 				#
916 927
 
@@ -1224,4 +1235,14 @@ public function walk($callback, $userdata, $stop=null)
1224 1235
 
1225 1236
 		call_user_func($callback, $this, $userdata, $stop_value);
1226 1237
 	}
  1238
+
  1239
+	static protected function translate_label($label)
  1240
+	{
  1241
+		if (!is_array($label))
  1242
+		{
  1243
+			return t($label, array(), array('scope' => array('form', 'label')));
  1244
+		}
  1245
+
  1246
+		return t($label[0], array(), array('scope' => $label[1]));
  1247
+	}
1227 1248
 }
1  wdform.php
@@ -480,6 +480,7 @@ static public function selectElementLabel($element)
480 480
 		# remove HTML markups from the label
481 481
 		#
482 482
 
  483
+		$label = self::translate_label($label);
483 484
 		$label = strip_tags($label);
484 485
 
485 486
 		return $label;

0 notes on commit 0c4e99c

Please sign in to comment.
Something went wrong with that request. Please try again.