Posted By

xurde on 07/12/06


Tagged

css class match


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

alvaroisorna
episod
webstic


class_if_match


 / Published in: Ruby
 

This very simple but useful helper lets you putting some particular class tag to an html entity in case of coincidence of two arguments given. This case is very usual when building rhtml code and quite painful for programming it at the ERB. The most normal use is for

  1. Helper:
  2.  
  3. def class_if_match (class_id, arg_1, arg_2)
  4. if arg_1 == arg_2
  5. return 'class="' + class_id + '"'
  6. else
  7. return nil
  8. end
  9. end
  10.  
  11. Example
  12.  
  13. rhtml file:
  14. <li <%= class_if_match ('active-item', item, @active_item) %>> the item </li>
  15.  
  16. css file:
  17. .active-item
  18. {
  19. font-weight: bold;
  20. }

Report this snippet  

You need to login to post a comment.