Changeset 13097
- Timestamp:
- 11/18/08 07:58:24 (1 year ago)
- Files:
-
- branches/1.2/lib/helper/AssetHelper.php (modified) (14 diffs)
- branches/1.2/lib/helper/TagHelper.php (modified) (3 diffs)
- branches/1.2/test/functional/fixtures/project/apps/frontend/config/view.yml (modified) (1 diff)
- branches/1.2/test/functional/fixtures/project/web/css/ie6.css (added)
- branches/1.2/test/functional/genericTest.php (modified) (1 diff)
- branches/1.2/test/unit/helper/AssetHelperTest.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.2/lib/helper/AssetHelper.php
r12409 r13097 95 95 * 96 96 * @return string XHTML compliant <script> tag(s) 97 * @see javascript_path 97 * @see javascript_path 98 98 */ 99 99 function javascript_include_tag() … … 105 105 foreach ($sources as $source) 106 106 { 107 108 107 $absolute = false; 109 108 if (isset($sourceOptions['absolute'])) … … 112 111 $absolute = true; 113 112 } 114 115 if(!isset($sourceOptions['raw_name'])) 113 114 $condition = null; 115 if (isset($sourceOptions['condition'])) 116 { 117 $condition = $sourceOptions['condition']; 118 unset($sourceOptions['condition']); 119 } 120 121 if (!isset($sourceOptions['raw_name'])) 116 122 { 117 123 $source = javascript_path($source, $absolute); … … 121 127 unset($sourceOptions['raw_name']); 122 128 } 129 123 130 $options = array_merge(array('type' => 'text/javascript', 'src' => $source), $sourceOptions); 124 $html .= content_tag('script', '', $options)."\n"; 125 } 126 127 return $html; 131 $tag = content_tag('script', '', $options); 132 133 if (!is_null($condition)) 134 { 135 $tag = comment_as_conditional($condition, $tag); 136 } 137 138 $html .= $tag."\n"; 139 } 140 141 return $html; 128 142 } 129 143 … … 146 160 * 147 161 * @return string file path to the stylesheet file 148 * @see stylesheet_tag 162 * @see stylesheet_tag 149 163 */ 150 164 function stylesheet_path($source, $absolute = false) … … 179 193 * 180 194 * @return string XHTML compliant <link> tag(s) 181 * @see stylesheet_path 195 * @see stylesheet_path 182 196 */ 183 197 function stylesheet_tag() … … 195 209 $absolute = true; 196 210 } 197 198 if(!isset($sourceOptions['raw_name'])) 211 212 $condition = null; 213 if (isset($sourceOptions['condition'])) 214 { 215 $condition = $sourceOptions['condition']; 216 unset($sourceOptions['condition']); 217 } 218 219 if (!isset($sourceOptions['raw_name'])) 199 220 { 200 221 $source = stylesheet_path($source, $absolute); … … 204 225 unset($sourceOptions['raw_name']); 205 226 } 227 206 228 $options = array_merge(array('rel' => 'stylesheet', 'type' => 'text/css', 'media' => 'screen', 'href' => $source), $sourceOptions); 207 $html .= tag('link', $options)."\n"; 229 $tag = tag('link', $options); 230 231 if (!is_null($condition)) 232 { 233 $tag = comment_as_conditional($condition, $tag); 234 } 235 236 $html .= $tag."\n"; 208 237 } 209 238 … … 261 290 * - file name, like "rss.gif", that gets expanded to "/images/rss.gif" 262 291 * - file name without extension, like "logo", that gets expanded to "/images/logo.png" 263 * 292 * 264 293 * @param string $source asset name 265 294 * @param bool $absolute return absolute path ? 266 295 * 267 296 * @return string file path to the image file 268 * @see image_tag 297 * @see image_tag 269 298 */ 270 299 function image_path($source, $absolute = false) … … 293 322 * 294 323 * @return string XHTML compliant <img> tag 295 * @see image_path 324 * @see image_path 296 325 */ 297 326 function image_tag($source, $options = array()) … … 311 340 } 312 341 313 if (!isset($options['raw_name']))342 if (!isset($options['raw_name'])) 314 343 { 315 344 $options['src'] = image_path($source, $absolute); … … 323 352 if (isset($options['alt_title'])) 324 353 { 325 //set as alt and title but do not overwrite explicitly set 326 if(!isset($options['alt'])) $options['alt'] = $options['alt_title']; 327 if(!isset($options['title'])) $options['title'] = $options['alt_title']; 354 // set as alt and title but do not overwrite explicitly set 355 if (!isset($options['alt'])) 356 { 357 $options['alt'] = $options['alt_title']; 358 } 359 if (!isset($options['title'])) 360 { 361 $options['title'] = $options['alt_title']; 362 } 328 363 unset($options['alt_title']); 329 364 } … … 403 438 * 404 439 * @return string XHTML compliant <meta> tag(s) 405 * @see include_http_metas 440 * @see include_http_metas 406 441 * @see sfWebResponse::addMeta() 407 442 */ … … 531 566 * 532 567 * @return string XHTML compliant <script> tag(s) 533 * @see javascript_include_tag 568 * @see javascript_include_tag 534 569 */ 535 570 function dynamic_javascript_include_tag($uri, $absolute = false, $options = array()) branches/1.2/lib/helper/TagHelper.php
r9967 r13097 51 51 { 52 52 return "<![CDATA[$content]]>"; 53 } 54 55 /** 56 * Wraps the content in conditional comments. 57 * 58 * @param string $condition 59 * @param string $content 60 * 61 * @return string 62 * 63 * @see http://msdn.microsoft.com/en-us/library/ms537512(VS.85).aspx 64 */ 65 function comment_as_conditional($condition, $content) 66 { 67 return "<!--[if $condition]>$content<![endif]-->"; 53 68 } 54 69 … … 136 151 * </code> 137 152 * 138 * @param string $name field name 153 * @param string $name field name 139 154 * @param string $value field value 140 155 * … … 156 171 * 157 172 * @param array $options 158 * @return array returns properly formatted options 173 * @return array returns properly formatted options 159 174 */ 160 175 function _convert_options($options) branches/1.2/test/functional/fixtures/project/apps/frontend/config/view.yml
r2069 r13097 10 10 language: en 11 11 12 stylesheets: [main] 12 stylesheets: 13 - main 14 - 15 ie6: 16 condition: lte IE 6 13 17 14 18 javascripts: [ ] branches/1.2/test/functional/genericTest.php
r11805 r13097 19 19 // default main page 20 20 $b-> 21 get('/')-> 22 isStatusCode(200)-> 23 isRequestParameter('module', 'default')-> 24 isRequestParameter('action', 'index')-> 25 checkResponseElement('body', '/congratulations/i')-> 26 checkResponseElement('link[href="/sf/sf_default/css/screen.css"]') 21 getAndCheck('default', 'index', '/')-> 22 with('response')->begin()-> 23 checkElement('body', '/congratulations/i')-> 24 checkElement('link[href="/sf/sf_default/css/screen.css"]')-> 25 checkElement('link[href="/css/main.css"]')-> 26 contains('<!--[if lte IE 6]><link rel="stylesheet" type="text/css" media="screen" href="/css/ie6.css" /><![endif]-->')-> 27 end() 27 28 ; 28 29 branches/1.2/test/unit/helper/AssetHelperTest.php
r12409 r13097 16 16 require_once(dirname(__FILE__).'/../../../lib/helper/AssetHelper.php'); 17 17 18 $t = new lime_test( 59, new lime_output_color());18 $t = new lime_test(61, new lime_output_color()); 19 19 20 20 class myRequest … … 98 98 '<link rel="stylesheet" type="text/css" media="screen" href="style" />'."\n", 99 99 'stylesheet_tag() can take a raw_name option to bypass file name decoration'); 100 $t->is(stylesheet_tag('style', array('condition' => 'IE 6')), 101 '<!--[if IE 6]><link rel="stylesheet" type="text/css" media="screen" href="/css/style.css" /><![endif]-->'."\n", 102 'stylesheet_tag() can take a condition option'); 100 103 101 104 // javascript_include_tag() … … 117 120 '<script type="text/javascript" src="/js/xmlhr.js" defer="defer"></script>'."\n", 118 121 'javascript_include_tag() can take additional html options like defer'); 122 $t->is(javascript_include_tag('xmlhr', array('condition' => 'IE 6')), 123 '<!--[if IE 6]><script type="text/javascript" src="/js/xmlhr.js"></script><![endif]-->'."\n", 124 'javascript_include_tag() can take a condition option'); 119 125 120 126 // javascript_path()

