Skip to content

Commit

Permalink
added sample jinja extension
Browse files Browse the repository at this point in the history
  • Loading branch information
stanfeldman committed Jul 31, 2012
1 parent b4f4651 commit 9f51769
Show file tree
Hide file tree
Showing 11 changed files with 181 additions and 0 deletions.
18 changes: 18 additions & 0 deletions html/frame.html
@@ -0,0 +1,18 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>frames</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#frmSite').load(function(){
$("#frmSite").contents().find("#item2").css("background-color","#BADA55");
console.log("lala");
});
});
</script>
</head>
<body>
<iframe src="file:///home/stanislavfeldman/projects/samples/html/tree.html" width="600" height="400" id='frmSite'></iframe>
</body>
</html>
70 changes: 70 additions & 0 deletions js/1.js
@@ -0,0 +1,70 @@
console.log("hi");
var x = 7;
function sum(a, b)
{
console.log(arguments);
console.log(arguments.callee);
return a+b;
}
console.log(sum(3, 5));
function fac(num)
{
if(num <= 1)
return 1;
else
return num * fac(num-1);
}
console.log(fac(99));
var calc = {
op1: 555,
op2: 5,
sum: function() { return this.op1 + this.op2; }
}
console.log(calc.sum());
console.log(calc.sum.call({op1: 4, op2:7}));
function get_func(x)
{
var y = 0;
y += x;
return function() { return y; }
}
console.log(get_func(1)());
console.log(get_func(2)());
uid = (function()
{
var id = 0;
return function() { return id++; }
})();
console.log(uid());
console.log(uid());

function Rect(w, h)
{
this.w = w;
this.h = h;
}
Rect.prototype.area = function() { return this.w*this.h; }

r = new Rect(5,6);
console.log(r.area());
console.log(r.hasOwnProperty("area"));

function PosRect(x, y, w, h)
{
Rect.call(this, w, h);
this.x = x;
this.y = y;
}
PosRect.prototype = new Rect();
delete PosRect.prototype.w;
delete PosRect.prototype.h;
PosRect.prototype.constructor = PosRect;
PosRect.prototype.contains = function(x, y)
{
return (x > this.x && x < this.x + this.w && y > this.y && y < this.y + this.h);
}

pr = new PosRect(2, 2, 4, 4);
console.log(pr.contains(3,3));
console.log(pr.area());
console.log(Object.prototype.toString.apply(pr));
Empty file.
9 changes: 9 additions & 0 deletions python/jinja_exts/controllers/controller1.py
@@ -0,0 +1,9 @@
from kiss.views.templates import TemplateResponse
from kiss.controllers.core import Controller
from kiss.core.application import Application


class Controller1:
def get(self, request):
return TemplateResponse("view.html", { "foo": "bar", "users": [{"url": "google.com", "username": "brin"}] })

8 changes: 8 additions & 0 deletions python/jinja_exts/main.py
@@ -0,0 +1,8 @@
from settings import options
from kiss.core.application import Application


app = Application(options)
app.start()


22 changes: 22 additions & 0 deletions python/jinja_exts/settings.py
@@ -0,0 +1,22 @@
from os import path
current_dir = path.dirname(path.abspath(__file__))
import sys
sys.path.append("/home/stanislavfeldman/projects/python/kiss.py")
sys.path.append("/home/stanislavfeldman/projects/python/compressinja/")
sys.path.append("/home/stanislavfeldman/projects/python/putils/")
sys.path.append("/home/stanislavfeldman/projects/python/pev/")
from kiss.core.application import Application
from controllers.controller1 import Controller1


options = {
"urls": {
"": Controller1
},
"views": {
"templates_path": "views.templates",
"static_path": "views.static",
"templates_extensions": ["views.extensions.Simple"],
}
}

Empty file.
16 changes: 16 additions & 0 deletions python/jinja_exts/views/extensions.py
@@ -0,0 +1,16 @@
from jinja2.ext import Extension
from jinja2 import nodes
from jinja2 import Markup

class Simple(Extension):
tags = set(["simple"])

def parse(self, parser):
stream = parser.stream
tag_token = stream.next()
arg_token = stream.next()
arg = nodes.Const(arg_token.value, lineno=arg_token.lineno)
return nodes.Output([self.call_method('_render', [arg])]).set_lineno(tag_token.lineno)

def _render(self, arg):
return Markup("<h1>Simple tag with arg: %s</h1>" % arg)
Empty file.
14 changes: 14 additions & 0 deletions python/jinja_exts/views/templates/view.html
@@ -0,0 +1,14 @@
<html>
<head>
<title>цукцк</title>
</head>
<body>
<div>{{ foo }}</div>
<div>{% simple "lala" %}</div>
<ul>
{% for user in users %}
<li><a href="{{ user.url }}">{{ user.username }}</a></li>
{% endfor %}
</ul>
</body>
</html>
24 changes: 24 additions & 0 deletions ruby/1.rb
@@ -0,0 +1,24 @@
x = 555
puts "hi, num: #{x}"
def f(name)
puts "hello, #{name}"
end
f("stas")
class Greeter
def initialize(name="world")
@name = name
end
def hi(name=nil)
if name.nil?
name = @name
end
puts "hi, #{name}"
end
end
g = Greeter.new("sam")
class Greeter
attr_accessor :name
end
g.hi("boris")
g.name = "sammm"
puts g.name

0 comments on commit 9f51769

Please sign in to comment.