Development

Changeset 13097

You must first sign up to be able to contribute.

Changeset 13097

Show
Ignore:
Timestamp:
11/18/08 07:58:24 (1 year ago)
Author:
Kris.Wallsmith
Message:

[1.2] added support for conditional comments to stylesheets and javascripts (closes #1677)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.2/lib/helper/AssetHelper.php

    r12409 r13097  
    9595 * 
    9696 * @return string XHTML compliant <script> tag(s) 
    97  * @see    javascript_path  
     97 * @see    javascript_path 
    9898 */ 
    9999function javascript_include_tag() 
     
    105105  foreach ($sources as $source) 
    106106  { 
    107      
    108107    $absolute = false; 
    109108    if (isset($sourceOptions['absolute'])) 
     
    112111      $absolute = true; 
    113112    } 
    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'])) 
    116122    { 
    117123      $source = javascript_path($source, $absolute); 
     
    121127      unset($sourceOptions['raw_name']); 
    122128    } 
     129 
    123130    $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; 
    128142} 
    129143 
     
    146160 * 
    147161 * @return string file path to the stylesheet file 
    148  * @see    stylesheet_tag   
     162 * @see    stylesheet_tag 
    149163 */ 
    150164function stylesheet_path($source, $absolute = false) 
     
    179193 * 
    180194 * @return string XHTML compliant <link> tag(s) 
    181  * @see    stylesheet_path  
     195 * @see    stylesheet_path 
    182196 */ 
    183197function stylesheet_tag() 
     
    195209      $absolute = true; 
    196210    } 
    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'])) 
    199220    { 
    200221      $source = stylesheet_path($source, $absolute); 
     
    204225      unset($sourceOptions['raw_name']); 
    205226    } 
     227 
    206228    $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"; 
    208237  } 
    209238 
     
    261290 * - file name, like "rss.gif", that gets expanded to "/images/rss.gif" 
    262291 * - file name without extension, like "logo", that gets expanded to "/images/logo.png" 
    263  *  
     292 * 
    264293 * @param  string $source    asset name 
    265294 * @param  bool   $absolute  return absolute path ? 
    266295 * 
    267296 * @return string file path to the image file 
    268  * @see    image_tag   
     297 * @see    image_tag 
    269298 */ 
    270299function image_path($source, $absolute = false) 
     
    293322 * 
    294323 * @return string XHTML compliant <img> tag 
    295  * @see    image_path  
     324 * @see    image_path 
    296325 */ 
    297326function image_tag($source, $options = array()) 
     
    311340  } 
    312341 
    313   if(!isset($options['raw_name'])) 
     342  if (!isset($options['raw_name'])) 
    314343  { 
    315344    $options['src'] = image_path($source, $absolute); 
     
    323352  if (isset($options['alt_title'])) 
    324353  { 
    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    } 
    328363    unset($options['alt_title']); 
    329364  } 
     
    403438 * 
    404439 * @return string XHTML compliant <meta> tag(s) 
    405  * @see    include_http_metas  
     440 * @see    include_http_metas 
    406441 * @see    sfWebResponse::addMeta() 
    407442 */ 
     
    531566 * 
    532567 * @return string  XHTML compliant <script> tag(s) 
    533  * @see    javascript_include_tag  
     568 * @see    javascript_include_tag 
    534569 */ 
    535570function dynamic_javascript_include_tag($uri, $absolute = false, $options = array()) 
  • branches/1.2/lib/helper/TagHelper.php

    r9967 r13097  
    5151{ 
    5252  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 */ 
     65function comment_as_conditional($condition, $content) 
     66{ 
     67  return "<!--[if $condition]>$content<![endif]-->"; 
    5368} 
    5469 
     
    136151 * </code> 
    137152 * 
    138  * @param  string $name   field name  
     153 * @param  string $name   field name 
    139154 * @param  string $value  field value 
    140155 * 
     
    156171 * 
    157172 * @param  array $options 
    158  * @return array returns properly formatted options  
     173 * @return array returns properly formatted options 
    159174 */ 
    160175function _convert_options($options) 
  • branches/1.2/test/functional/fixtures/project/apps/frontend/config/view.yml

    r2069 r13097  
    1010    language:     en 
    1111 
    12   stylesheets:    [main] 
     12  stylesheets: 
     13    - main 
     14    - 
     15      ie6: 
     16        condition: lte IE 6 
    1317 
    1418  javascripts:    [ ] 
  • branches/1.2/test/functional/genericTest.php

    r11805 r13097  
    1919// default main page 
    2020$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() 
    2728; 
    2829 
  • branches/1.2/test/unit/helper/AssetHelperTest.php

    r12409 r13097  
    1616require_once(dirname(__FILE__).'/../../../lib/helper/AssetHelper.php'); 
    1717 
    18 $t = new lime_test(59, new lime_output_color()); 
     18$t = new lime_test(61, new lime_output_color()); 
    1919 
    2020class myRequest 
     
    9898  '<link rel="stylesheet" type="text/css" media="screen" href="style" />'."\n",  
    9999  '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'); 
    100103 
    101104// javascript_include_tag() 
     
    117120  '<script type="text/javascript" src="/js/xmlhr.js" defer="defer"></script>'."\n",  
    118121  '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'); 
    119125 
    120126// javascript_path() 

The Sensio Labs Network

Since 1998, Sensio Labs has been promoting the Open-Source software movement by providing quality web application development, training, consulting.
Sensio Labs also supports several large Open-Source projects.