Created
February 6, 2009 14:31
-
-
Save speedmax/59413 to your computer and use it in GitHub Desktop.
H2o hacking guide
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
H2o hacking guide | |
argument parsing. | |
===================== | |
* variable name turns to ":variable" which uses ruby symbol style string to indicate if its a variable and to speed up context lookup | |
* arguments are seperated by comma | |
* anything looks like named argument(name: "peter", age: 18) will parse into a option style array | |
H2o_Parser::parseArguments("variable") | |
// outputs ':variable' | |
H2o_Parser::parseArguments('person | speak "hello world", time: "today"') | |
// outputs array(':person', array(':speak', '"hello world"', array('time'=>'"today"') | |
context lookup and manipulation | |
===================== | |
All variable and data passed into h2o are stored in the context object for variable name lookup.. | |
1. Resolve a variable, number, string, boolean in the given context | |
context->resolve('person.name') | |
2. Setting variable | |
context->set('person', array('name'=>'peter', 'age'=>18)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% load 'load_entries' %} | |
{% load_entries name:'entries', immediate:true, format:'native', days_ago:"99999", paginate:true, max_per_page: 15 %} | |
<ul> | |
{% for entry in entries %} | |
<li>{{ entry.name | links_to entry.url }}</li> | |
{% endfor %} | |
</ul> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
h2o::addTag('load_entries'); | |
class Load_entries_tag extends H2o_Node { | |
var $options; | |
function __construct($argstring, $parser, $pos=0) { | |
$args = H2o_Parser::parseArguments($argstring); | |
} | |
function render($context, $stream) { | |
// Do your SQL query | |
$entries = Entry::getInstance()->findAll($this->options); | |
$context->set('entries', $entries); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment