Skip to content

Instantly share code, notes, and snippets.

@atika
Created March 10, 2016 10:58
Show Gist options
  • Save atika/926592e2f3bdf5f18b8e to your computer and use it in GitHub Desktop.
Save atika/926592e2f3bdf5f18b8e to your computer and use it in GitHub Desktop.
CodeRunner compilation script to have Javascript, HTML and CSS in the same file
// The first script tag is optional if you start with javascript
//<script>
$(document).ready(function () {
$("body").append("<br>jQuery said AngularJS rocks!");
alert($(document).html());
});
angular.module('PricesApp', [])
.controller("PriceController", function () {
this.quantity = 1;
this.references = [
{title:'Men', price:'20', checked:true},
{title:'Women', price:'18', checked:false},
{title:'Children', price:'12', checked:false}
];
this.finalPrice = function(){
var price = (this.quantity * 1) * (this.selectedRef * 1 + this.selectedRef * 0.2) || 0;
return price + " Euros";
}
});
//<html>
<div ng-app="PricesApp" ng-controller="PriceController as prices">
<input type="text" ng-model="name" placeholder="Enter your name">
<div class="test">Hello {{name}}!</div>
<br>
<form>
{{prices.references.length}} references available:
<br><br>
<div ng-repeat="ref in prices.references">
<input type="radio" name="type" value="{{ref.price}}" ng-model="prices.selectedRef" checked="{{ref.checked}}" >{{ref.title}}<br>
</div>
<input type="number" min="1" placeholder="Quantity" ng-model="prices.quantity">
</form>
<h3>Total: {{prices.finalPrice()}} T.T.C</h3>
</div>
<script src="http://localhost:1337/vorlon.js"></script>
//<css>
body {
font-family: 'HelveticaNeue-Light'
}
.test {
padding: 10px;
background-color:red;
color:white;
}
input {
margin: 8px 10px;
padding: 2px 5px;
}
#!/bin/bash
# This is a CodeRunner compile script. Compile scripts are used to compile
# code before being run using the run command specified in CodeRunner
# preferences. This script is invoked with the following properties:
#
# Current directory: The directory of the source file being run
#
# Arguments $1-$n: User-defined compile flags
#
# Environment: $CR_FILENAME Filename of the source file being run
# $CR_ENCODING Encoding code of the source file
# $CR_TMPDIR Path of CodeRunner's temporary directory
#
# This script should have the following return values:
#
# Exit status: 0 on success (CodeRunner will continue and execute run command)
#
# Output (stdout): On success, one line of text which can be accessed
# using the $compiler variable in the run command
#
# Output (stderr): Anything outputted here will be displayed in
# the CodeRunner console
/usr/bin/env ruby <<-EORUBY
current = "script"
model = '<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<style type="text/css">
%s
</style>
</head>
<body>
%s
<script type="text/javascript">
%s
</script>
</body>
</html>'
data = {
"script" => Array.new,
"html" => Array.new,
"css" => Array.new
}
File.open("$CR_FILENAME").each do |line|
if bloc = /\/\/<(script|html|css)>/.match(line) then
current = bloc[1].strip
next
end
if line !~ /^$/
data[current].push(line.strip)
end
#puts line
end
#puts data.inspect
printf(model, data['css'].join(" "), data['html'].join(""), data['script'].join("\\n") )
EORUBY
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment