View OneTimeDataExample.groovy
This file contains 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
@TestFor(MyController) | |
@TestMixin(OneTimeDataUnitTestMixin) | |
class MyControllerSpec extends Specification { | |
def setup() { | |
mockOneTimeData(this, controller) | |
} | |
def "should fail"() { | |
given: |
View OneTimeDataUnitTestMixin.groovy
This file contains 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
class OneTimeDataUnitTestMixin extends GrailsUnitTestMixin { | |
def mockOneTimeData(spec, controller) { | |
spec.metaClass.otdData = [:] | |
spec.metaClass.otdId = 1 | |
controller.metaClass.oneTimeData << { Closure dataSetup -> | |
dataSetup.delegate = spec.otdData | |
dataSetup() | |
spec.otdId | |
} |
View advice.js
This file contains 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
(function (exports) { | |
//usage | |
//withAdvice.call(targetObject); | |
//mixin augments target object with around, before and after methods | |
//method is the base method, advice is the augmenting function | |
exports.withAdvice = function() { | |
['before', 'after', 'around'].forEach(function(m) { | |
this[m] = function(method, advice) { | |
if (typeof this[method] == 'function') { |
View index.gsp
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta name="layout" content="main"/> | |
<title>Javascript Components</title> | |
</head> | |
<body> | |
<button onclick="TestDialog.openDialog();">OpenDialog</button> | |
<g:render template="/layouts/test-dialog"/> | |
</body> |
View testDialog.js
This file contains 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
var TestDialog = (function($) { | |
var $dialog; | |
$(function() { | |
$dialog = $('#test-dialog'); | |
$dialog.dialog({ | |
autoOpen: false, | |
width: 300, | |
height: 200 |
View testDialog.css
This file contains 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
.test-dialog-content { | |
font-weight: normal; | |
color: red; | |
} |
View ApplicationResources.groovy
This file contains 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
modules = { | |
application { | |
resource url:'js/application.js' | |
} | |
test_dialog { | |
dependsOn 'jquery, jquery-ui' | |
resource url:'css/testDialog.css' | |
resource url:'js/testDialog.js' | |
} | |
} |
View _test-dialog.gsp
This file contains 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
<r:require module="test_dialog"/> | |
<div id="test-dialog" title="Test Dialog"> | |
<div class="test-dialog-content"> | |
This is a test. | |
</div> | |
</div> |
View requirejs-url-setup.js
This file contains 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
UrlMappings.config.forEach(function(mapping) { | |
app[mapping.verb](mapping.route, function(req, res) { | |
require(['app/controller/' + mapping.controller], function(Controller) { | |
Controller[mapping.action](req, res); | |
}); | |
}); | |
}); |
View require-express-setup.js
This file contains 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
app.all('/:controller/:action/:id?', function(req, res) { | |
require(['app/controller/' + req.params.controller], function(Controller) { | |
Controller[req.params.action](req, res); | |
}); | |
}); | |
app.all('/:controller', function(req, res) { | |
require(['app/controller/' + req.params.controller], function(Controller) { | |
Controller.index(req, res); | |
}); |
NewerOlder