Permalink
Browse files

Adds `grunt-modules` example.

  • Loading branch information...
Paul Cuthbertson
Paul Cuthbertson committed Mar 27, 2016
1 parent 179c7e1 commit ab663c9204636b171dbe9b6d90019d00e926d038
@@ -1,7 +1,7 @@
{
"name": "grunt-starlight-hello-world",
"version": "1.0.0",
- "description": "Working example of using `grunt-starlight`.",
+ "description": "A simple working example of using `grunt-starlight`.",
"repository": {
"type": "git",
"url": "git+https://github.com/paulcuth/starlight-examples.git"
View
@@ -0,0 +1,32 @@
+module.exports = function(grunt) {
+
+ grunt.initConfig({
+ starlight: {
+ hello: {
+ src: 'src/*.lua',
+ dest: 'dist/app.lua.js',
+ },
+ options: {
+ main: 'app.lua',
+ basePath: 'src'
+ }
+ },
+
+ babel: {
+ options: {
+ plugins: ['transform-es2015-destructuring']
+ },
+ hello: {
+ src: 'dist/app.lua.js',
+ dest: 'dist/app.lua.js',
+ }
+ }
+ });
+
+ grunt.loadNpmTasks('grunt-starlight');
+ grunt.loadNpmTasks('grunt-babel');
+
+ // Default task.
+ grunt.registerTask('default', ['starlight:hello', 'babel:hello']);
+
+};
View
@@ -0,0 +1,16 @@
+# grunt-modules
+
+An example of using modules and `require()` in `grunt-starlight` to precompile a set of Lua scripts into JavaScript and use in a webpage.
+
+
+## Instructions.
+
+Navigate to the `grunt-modules` directory in a terminal, then install dependencies and run the build.
+This will compile `/src/app.lua` to `/dist/app.lua.js`.
+
+```
+npm install
+grunt
+```
+
+When the build is successful, view `/index.html` in your browser and you should see a form to calculate Fibonacci numbers.
View
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html>
+ <body>
+ <p>
+ <input value="20" />
+ <button>Fibonacci</button>
+ </p>
+ <p class="result"></p>
+
+ <script src="http://paulcuth.me.uk/starlight/browser-lib/starlight.js"></script>
+ <script src="dist/app.lua.js"></script>
+ </body>
+</html>
View
@@ -0,0 +1,27 @@
+{
+ "name": "grunt-starlight-hello-world",
+ "version": "1.0.0",
+ "description": "A working example of using modules in `grunt-starlight`.",
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/paulcuth/starlight-examples.git"
+ },
+ "keywords": [
+ "Lua",
+ "JavaScript",
+ "Grunt",
+ "examples"
+ ],
+ "author": "Paul Cuthbertson",
+ "license": "MIT",
+ "bugs": {
+ "url": "https://github.com/paulcuth/starlight-examples/issues"
+ },
+ "homepage": "https://github.com/paulcuth/starlight-examples#readme",
+ "devDependencies": {
+ "babel-plugin-transform-es2015-destructuring": "^6.6.5",
+ "grunt-babel": "^6.0.0",
+ "grunt-cli": "^1.1.0",
+ "grunt-starlight": "^0.1.7"
+ }
+}
View
@@ -0,0 +1,14 @@
+local fibonacci = require('fibonacci')
+window.extract()
+
+
+local ui = {
+ input = document:querySelector('input'),
+ button = document:querySelector('button'),
+ result = document:querySelector('.result'),
+}
+
+ui.button:addEventListener('click', function ()
+ local result = fibonacci(tonumber(ui.input.value))
+ ui.result.textContent = 'Result: '..result
+end)
@@ -0,0 +1,11 @@
+--from: https://gist.github.com/SegFaultAX/2772595
+function fibonacci(n)
+ local a, b = 0, 1
+
+ for i = 1, n do
+ a, b = b, a + b
+ end
+ return a
+end
+
+return fibonacci

0 comments on commit ab663c9

Please sign in to comment.