Changeset 353

Show
Ignore:
Timestamp:
03/14/08 19:50:27 (2 months ago)
Author:
ingy
Message:
...
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/ingy/pQuery/lib/pQuery.pm

    r351 r353  
    4242    return; 
    4343} 
    44  
    45 sub eq { 
    46     my ($this, $i) = @_; 
    47     return $this->_pushStack($this->[$i]); 
    48 } 
    49  
    5044 
    5145################################################################################ 
     
    127121} 
    128122 
    129 sub _pushStack { 
     123sub pushStack { 
    130124    my ($this, $elems) = @_; 
    131125    my $ret = pQuery($elems); 
     
    155149} 
    156150 
    157 # XXX Needs test 
    158151sub index { 
    159152    my ($this, $elem) = @_; 
     
    166159} 
    167160 
    168 # sub attr { 
     161sub attr { # (name, value, type) 
     162    # TODO - Get/set a named attribute 
     163
     164 
     165sub css { # (key, value) 
     166    # TODO - Get/set a css attribute 
     167
     168 
     169# TODO/XXX Made up. Not ported yet. 
     170sub text { 
     171    # TODO - Get/set text value 
     172    my $this = shift; 
     173    my $text = ''; 
     174 
     175    $this->each(sub { 
     176        _to_text($_, \$text); 
     177    }); 
     178 
     179    $text =~ s/\s+/ /g; 
     180    $text =~ s/\s$//; 
     181 
     182    return $text; 
     183
     184 
     185sub wrapAll { # (html) 
     186    # TODO - Wrap element with HTML 
     187
     188 
     189sub wrapInner { # (html) 
     190    # TODO - Wrap sub elements with HTML 
     191
     192 
     193sub wrap { # (html) 
     194    # TODO - Wrap current objects with HTML 
     195
     196 
     197sub append { # (@_) 
     198    # TODO - Append arguments to current objects 
     199
     200 
     201sub prepend { # (@_) 
     202    # TODO - Prepend arguments to current objects 
     203
     204 
     205sub before { # (@_) 
     206    # TODO - Insert arguments before current objects 
     207
     208 
     209sub after { # (@_) 
     210    # TODO - Insert arguments after current objects 
     211
     212 
     213sub end { 
     214    my $this = shift; 
     215    return $this->_prevObject || pQuery([]); 
     216
     217 
     218# XXX - Not really ported yet. 
     219# sub find { 
     220#     my $this = shift; 
     221#     my $selector = shift or return; 
     222#     my $elems = []; 
     223#     $this->each(sub { 
     224#         _find_elems($_, $selector, $elems); 
     225#     }); 
     226#     return $this->pushStack($elems); 
    169227# } 
    170228 
     229# sub find { 
     230#     my ($this, $selector) = @_; 
     231#     my $elems = pQuery::map($this, sub { 
     232 
     233 
     234 
     235sub clone { # (events) 
     236    # TODO - Not sure if we need this one. 
     237} 
     238 
     239sub filter { # (selector) 
     240    # TODO - A kind of grep 
     241} 
     242 
     243sub not { # (selector) 
     244    # TODO - An anti-grep?? 
     245} 
     246 
     247sub add { # (selector) 
     248    # TODO - Some kind of merge 
     249} 
     250 
     251sub is { # (selector) 
     252    # TODO - One element matches the selector 
     253} 
     254 
     255sub hasClass { 
     256    my ($this, $selector) = @_; 
     257    $this.is(".$selector"); 
     258} 
     259 
     260sub val { # (value) 
     261    # TODO Get/set 
     262} 
     263 
     264# XXX - Not really ported yet. 
    171265sub html { 
    172266    my $this = shift; 
     
    182276} 
    183277 
     278# Not a jQuery function. 
    184279sub toHtml { 
    185280    my $this = shift; 
     
    188283} 
    189284 
    190 sub text { 
    191     my $this = shift; 
    192     my $text = ''; 
    193  
    194     $this->each(sub { 
    195         _to_text($_, \$text); 
     285# TODO - Not tested 
     286sub replaceWith { # (value) 
     287    my ($this, $value) = @_; 
     288    return $this->after($value)->remove; 
     289
     290 
     291# TODO - Not tested 
     292sub eq { 
     293    my ($this, $i) = @_; 
     294    return $this->pushStack($this->[$i]); 
     295
     296 
     297sub slice { #(i, j) 
     298    # TODO - Behave like JS slice() 
     299
     300 
     301sub map { 
     302    my ($this, $callback) = @_; 
     303    return $this->pushStack(__map($this, sub { 
     304        my ($elem, $i) = @_; 
     305        return $callback->($elem, $i, $elem); 
     306    })); 
     307
     308 
     309# TODO - Not tested 
     310sub andSelf { 
     311    my $this = shift; 
     312    return $this.add($this->prevObject); 
     313
     314 
     315sub data { # (key, value) 
     316    # TODO - Not sure 
     317
     318 
     319sub removeData { # (key) 
     320    # TODO - Not Sure 
     321
     322 
     323sub domManip { 
     324    my ($this, $args, $table, $reverse, $callback) = @_; 
     325    my $elems; 
     326    return $this->each(sub { 
     327        if (! defined $elems) { 
     328            $elems = $args; 
     329            @$elems = reverse @$elems 
     330              if $reverse; 
     331        } 
     332        pQuery::each($elems, sub { 
     333            $callback->($this, $_); 
     334        }); 
    196335    }); 
    197  
    198     $text =~ s/\s+/ /g; 
    199     $text =~ s/\s$//; 
    200  
    201     return $text; 
    202 
    203  
    204 sub find { 
    205     my $this = shift; 
    206     my $selector = shift or return; 
    207     my $elems = []; 
    208     $this->each(sub { 
    209         _find_elems($_, $selector, $elems); 
    210     }); 
    211     return $this->_pushStack($elems); 
    212 
    213  
    214 sub end { 
    215     my $this = shift; 
    216     return $this->_prevObject; 
    217 
     336
     337 
     338################################################################################ 
     339# "Class" methods 
     340################################################################################ 
     341# sub noConflict {} 
     342# sub isFunction {} 
     343# sub isXMLdoc {} 
     344# sub globalEval {} 
     345# sub nodeName {} 
     346# sub cache {} 
     347# sub data {} 
     348# sub removeData {} 
     349# sub each {} 
     350# sub prop {} 
     351# sub className {} 
     352# sub swap {} 
     353# sub css {} 
     354# sub curCSS {} 
     355# sub clean {} 
     356# sub attr {} 
     357# sub trim {} 
     358# sub makeArray {} 
     359# sub inArray {} 
     360# sub merge {} 
     361# sub unique {} 
     362# sub grep {} 
     363# sub map {} 
     364# sub unique {} 
     365 
     366################################################################################ 
     367# Selector functions 
     368################################################################################ 
     369 
    218370 
    219371################################################################################ 
     
    260412        if ($elem->{_tag} eq $selector) { 
    261413            push @$elems, $elem; 
    262              
    263414        } 
    264415    } 
     
    541692element from the array of elements in the pQuery object. 
    542693 
    543 This method will fetch the HTML content of the URL and return a 
    544 HTML::Response object. 
     694Givn a URL, this method will fetch the HTML content of the URL and 
     695return a HTML::Response object. 
    545696 
    546697    my $html = pQuery.get("http://google.com")->content; 
  • trunk/src/ingy/pQuery/t/misc.t

    r351 r353  
    1 use t::TestpQuery tests => 11
     1use t::TestpQuery tests => 9
    22 
    33use pQuery; 
     
    2222is $pq->index("Bozo"), -1, 'index() method works when no match'; 
    2323 
    24 is $pq->find('b')->each(sub { pass "One time" })->end->length, 3, 'End works';