Skip to content

Instantly share code, notes, and snippets.

@havvg
Created October 31, 2012 16:57
Show Gist options
  • Save havvg/3988287 to your computer and use it in GitHub Desktop.
Save havvg/3988287 to your computer and use it in GitHub Desktop.
Symfony2 + Jasmine = JasmineHandler
{% extends '::base.html.twig' %}
{% block title %}Ormigo Client-Side Testing Range{% endblock %}
{% block stylesheets %}
{% stylesheets
filter="?yui_css"
output="css/jasmine.css"
'../vendor/pivotal/jasmine/lib/jasmine-core/jasmine.css'
%}
<link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}
{% endblock %}
{% block head %}
{{ parent() }}
{% javascripts
filter="?yui_js"
output="js/jasmine.js"
'../vendor/pivotal/jasmine/lib/jasmine-core/jasmine.js'
'../vendor/pivotal/jasmine/lib/jasmine-core/jasmine-html.js'
%}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}
{% javascripts
filter="?yui_js"
output="js/jasmine.js"
'../app/Resources/js/jasmine/spec/*.js'
%}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}
<script>
(function () {
var jasmineEnv = jasmine.getEnv();
jasmineEnv.updateInterval = 1000;
var trivialReporter = new jasmine.TrivialReporter();
jasmineEnv.addReporter(trivialReporter);
jasmineEnv.specFilter = function (spec) {
return trivialReporter.specFilter(spec);
};
var currentWindowOnload = window.onload;
window.onload = function () {
if (currentWindowOnload) {
currentWindowOnload();
}
execJasmine();
};
function execJasmine() {
jasmineEnv.execute();
}
})();
</script>
{% endblock %}
{% block container %}{% endblock %}
{% block footer %}{% endblock %}
<?php
namespace Ormigo\Tests;
use Symfony\Component\Templating\EngineInterface;
use Symfony\Component\HttpFoundation\Response;
class JasmineHandler
{
protected $templating;
protected $template;
public function __construct(EngineInterface $templating, $template = '::jasmine.html.twig')
{
$this->templating = $templating;
$this->template = $template;
}
public function testAction()
{
return new Response($this->templating->render($this->template));
}
}
_jasmine:
pattern: '/_jasmine'
defaults: { _controller: 'jasmine_handler:testAction' }
services:
jasmine_handler:
class: Ormigo\Tests\JasmineHandler
arguments:
- '@templating'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment