css, dom, html, templates, xpath
In Ideas on 19.11.2008 at 23:51
In this post i would like to sum up my thought about using pure HTML files as fully functional templates. I’ve examined this pattern for about a year and i have to say it creates real order in application structure and lifecycle.
What means “pure” ?
- Pure like plain, nothing else than HTML
- Fully validable
- Readable in any browser
- Editable in any HTML editor
bash, dom, php, phpQuery, scraping
In Web Scraping on 05.11.2008 at 17:11
When some project doesn’t use SVN or any other version-control system (or you can’t use it) you have to download things manually. I don’t have to say that nobody wants to do this, so what can you do to not do it ? You can simulate yourself doing it…
Example below downloads latest release of madwifi branch with new HAL (which i need for my WiFi adapter).
#!/usr/bin/php
find('table tr')->slice(-2, -1)->downloadTo('/target/local/path');
}
?>
Now, to get latest release all i need is to run above script from command line. One missing thing is checking if anything has changed but i leave it to you to resolve ;)
For files which names doesn’t change you can just use wget, like so:
wget 'http://host.net/somefile.zip' -O new-name.zip
actionscript, jquery, perl, php, phpQuery, python, ruby
In The Net on 01.11.2008 at 11:03
jQuery besides achieving such successes as being used by Google or Micro$soft also has ports to other major languages. Most of them are designed to be server-side what opens doors for new uses to the library.
jQuery ports to other languages:
Below some snippets showing each implementation in few lines.
PHP
foreach($doc['ul > li'] as $li) {
pq($li)->addClass('my-new-class');
->filter(':last')
->addClass('last-li');
}
$doc['ul > li:last']
->addClass('last-li');
Ruby
# load the RedHanded home page
doc = Hpricot(open("http://redhanded.hobix.com/index.html"))
# change the CSS class on links
(doc/"span.entryPermalink").set("class", "newLinks")
Perl
pQuery("http://google.com/search?q=pquery")
->find("h2")
->each(sub {
my $i = shift;
print $i + 1, ") ", pQuery($_)->text, "n";
});
ActionScript
// add enterFrame event handler
$(stage).enterFrame(function(event:Event):void {
$("RoundRect").attr("color", function(...args):uint {
return Math.random() * 0xffffff;
});
});
List comes from phpQuery wiki page. Do you know any other ports ? Share it in comments.
Update 09.12.08
New jQuery port has been released. This time it’s powered by Python and named PyQuery. Here’s the code:
Python
p = d("#hello")
p.addClass("toto")
p.attr.id = "plop"
p.prependTo(d('#test'))