Development

Changeset 8994

You must first sign up to be able to contribute.

Changeset 8994

Show
Ignore:
Timestamp:
05/16/08 05:03:11 (2 months ago)
Author:
Carl.Vondrick
Message:

sfHighlight: added support for sfSearch

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfHighlightPlugin/trunk/lib/highlight/xfHighlightToken.class.php

    r8890 r8994  
    88 */ 
    99 
     10// create an xfTokenInterface if unavailable from sfSearch 
     11// this is neccessary to remove the dependency on sfSearch 
     12if (!interface_exists('xfTokenInterface', true)) 
     13{ 
     14  /** 
     15   * Token interface to achieve duck typing 
     16   * 
     17   * @package sfHighlight 
     18   * @subpackage Highlight 
     19   * @author Carl Vondrick 
     20   * @see sfSearch's xfTokenInterface 
     21   */ 
     22  interface xfTokenInterface 
     23  { 
     24  } 
     25} 
     26 
    1027/** 
    1128 * The highlight token. 
     
    1532 * @author Carl Vondrick 
    1633 */ 
    17 final class xfHighlightToken 
     34final class xfHighlightToken implements xfTokenInterface 
    1835{ 
    1936  /** 
     
    95112   * System to sort the tokens 
    96113   * 
    97    * @param xfHighlightToken $a 
    98    * @param xfHighlightToken $b 
     114   * @param xfTokenInterface $a 
     115   * @param xfTokenInterface $b 
    99116   * @returns int The sort code for usort 
    100117   */ 
    101   static public function getSortCode(xfHighlightToken $a, xfHighlightToken $b) 
     118  static public function getSortCode(xfTokenInterface $a, xfTokenInterface $b) 
    102119  { 
    103120    if ($a->getStart() < $b->getStart()) 
  • plugins/sfHighlightPlugin/trunk/lib/highlight/xfHighlighter.class.php

    r8890 r8994  
    5656    } 
    5757  } 
    58  
     58   
    5959  /** 
    6060   * Does the highlighting on the reader. 
  • plugins/sfHighlightPlugin/trunk/lib/reader/xfHighlightReader.interface.php

    r8890 r8994  
    3232   * Replaces a token with the new text in the correct text. 
    3333   * 
    34    * @param xfHighlightToken $token 
     34   * @param xfTokenInterface $token 
    3535   * @param string $new 
    3636   */ 
    37   public function replaceText(xfHighlightToken $token, $new); 
     37  public function replaceText(xfTokenInterface $token, $new); 
    3838} 
    3939 
  • plugins/sfHighlightPlugin/trunk/lib/reader/xfHighlightReaderDOM.class.php

    r8890 r8994  
    114114   * @see xfHighlightReader 
    115115   */ 
    116   public function replaceText(xfHighlightToken $token, $replacement) 
     116  public function replaceText(xfTokenInterface $token, $replacement) 
    117117  { 
    118118    $node = $this->texts[$this->position]; 
  • plugins/sfHighlightPlugin/trunk/lib/reader/xfHighlightReaderString.class.php

    r8890 r8994  
    6767   * @see xfHighlightReader 
    6868   */ 
    69   public function replaceText(xfHighlightToken $token, $new) 
     69  public function replaceText(xfTokenInterface $token, $new) 
    7070  { 
    7171    $newText  = substr($this->text, 0, $token->getStart()); 
  • plugins/sfHighlightPlugin/trunk/lib/tokenizer/xfHighlightTokenizer.interface.php

    r8890 r8994  
    1818{ 
    1919  /** 
    20    * Tokenizes the text and returns an array of xfHighlightToken-s 
     20   * Tokenizes the text and returns an array of xfTokenInterface 
    2121   * 
    2222   * @param string $text The text to tokenize 
    23    * @returns array of xfHighlightToken 
     23   * @returns array of xfTokenInterface 
    2424   */ 
    2525  public function tokenize($text); 
  • plugins/sfHighlightPlugin/trunk/test/bootstrap/unit.php

    r8890 r8994  
    88 */ 
    99 
    10 define('SF_LIB_DIR', '/home/carl/symfony/1.1/lib')
     10require dirname(__FILE__) . '/../../../sfSearchPlugin/test/bootstrap/unit.php'
    1111 
    12 set_include_path(get_include_path() . PATH_SEPARATOR . SF_LIB_DIR); 
    1312set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/../../lib'); 
    1413set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/../../test'); 
    1514 
    16 require 'vendor/lime/lime.php'; 
  • plugins/sfHighlightPlugin/trunk/test/unit/highlight/xfHighlighterTest.php

    r8890 r8994  
    2020require 'reader/xfHighlightReaderString.class.php'; 
    2121 
    22 $t = new lime_test(2, new lime_output_color); 
     22$t = new lime_test(3, new lime_output_color); 
    2323 
    2424$keywords = array( 
     
    3333 
    3434$t->isa_ok($reader, 'xfHighlightReaderString', '->highlight() returns a xfHighlightReader'); 
     35$t->is($reader->getText(), 'FOO is better than BAR if only because of the small amount of [baz]', '->highlight() highlights the string according to the reader and keywords'); 
    3536 
    36 $t->is($reader->getText(), 'FOO is better than BAR if only because of the small amount of [baz]', '->highlight() highlights the string according to the reader and keywords'); 
     37$t->is($h->highlight(new xfHighlightReaderString('baz! bow before baz for i am baz'))->getText(), '[baz]! bow before [baz] for i am [baz]', '->highlight() works with changing string length');