Last active
December 16, 2015 13:08
-
-
Save idiomatic/5439303 to your computer and use it in GitHub Desktop.
MERGED TO lawloop/mayhem
AngularJS controller decorator and components
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 = angular.module 'app' | |
app.directive 'demo', -> | |
restrict: 'E' | |
scope: true | |
templateUrl: 'demo.html' |
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
inject = (args...) -> args | |
simple_controller = (injections..., constructor) -> | |
inject '$scope', injections..., (args...) -> constructor.call args... | |
controller = (injections..., constructor) -> | |
inject '$scope', injections..., ($scope, args...) -> | |
for k, v of constructor.call $scope, args... | |
$scope[k] = v | |
app = angular.module 'app', [] | |
app.controller 'option1', inject '$location', '$scope', ($location, $scope) -> | |
$scope.d = new Date() | |
$scope.bonk = -> | |
$scope.d = new Date() | |
console.log "first oif" | |
app.controller | |
option2: | |
simple_controller '$location', '$scope', ($location, $scope) -> | |
$scope.d = new Date() | |
$scope.bonk = -> | |
$scope.d = new Date() | |
console.log "second oif" | |
option3: simple_controller -> | |
@d = new Date() | |
@bonk = -> | |
@d = new Date() | |
console.log "third oif" | |
option4: controller -> | |
@d = new Date() | |
bonk: -> | |
@d = new Date() | |
console.log "fourth oif" |
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 ng-app="app"> | |
<head> | |
<script type="text/ng-template" id="demo.html"> | |
<div class="demo"> | |
Name: <input type="text" ng-model="name" /> {{name}} | |
{{d | date:'yyyy-MM-ddTHH:mm:ssZ'}} | |
<button ng-click="bonk()">bonk</button> | |
</div> | |
</script> | |
</head> | |
<body> | |
<demo ng-controller="option1"></demo> | |
<demo ng-controller="option2"></demo> | |
<demo ng-controller="option3"></demo> | |
<demo ng-controller="option4"></demo> | |
<!-- <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.6/angular.min.js"></script> --> | |
<script src="angular.min.js"></script> | |
<script src="controllers.js"></script> | |
<script src="components.js"></script> | |
</body> | |
</html> |
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
port = 8080 | |
http = require 'http' | |
url = require 'url' | |
path = require 'path' | |
fs = require 'fs' | |
server = http.createServer (request, response) -> | |
p = path.join process.cwd(), url.parse(request.url).pathname | |
if p[p.length - 1] is path.sep | |
p += 'index.html' | |
fs.createReadStream(p) | |
.on 'error', (error) -> | |
response.writeHead 404 | |
response.end 'not found\n' | |
.pipe(response) | |
server.listen port |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment