diff --git a/app/bower.json b/app/bower.json index 77763db..ea85f08 100644 --- a/app/bower.json +++ b/app/bower.json @@ -13,7 +13,9 @@ "motion-ui": "~1.1.0", "foundation-sites": "~6.2.0", "motion-ui": "~1.2.2", - "requirejs": "latest" + "requirejs": "latest", + "underscore": "latest", + "autosize": "latest" }, "ignore": [ "**/.*", diff --git a/app/index.html b/app/index.html index 670b888..4e426e7 100644 --- a/app/index.html +++ b/app/index.html @@ -6,12 +6,11 @@ Foundation for Sites + -
-
- -
+
+
diff --git a/app/js/app.js b/app/js/app.js index fd0fd1b..1c8d1e8 100644 --- a/app/js/app.js +++ b/app/js/app.js @@ -3,19 +3,18 @@ requirejs.config({ "jquery": '../assets/jquery/dist/jquery.min', "foundation": '../assets/foundation-sites/dist/foundation.min', "what-input": '../assets/what-input/what-input.min', - "motion-ui": '../assets/motion-ui/dist/motion-ui.min' + "motion-ui": '../assets/motion-ui/dist/motion-ui.min', + "underscore": '../assets/underscore/underscore-min', + "autosize": '../assets/autosize/dist/autosize.min' }, shim: { "foundation": ['jquery'] } }); + // Add any foundation modules you require to the end of this line. -require(['jquery', 'foundation', 'what-input'], function($) { - // Foundation JavaScript - // Documentation can be found at: http://foundation.zurb.com/docs - $(document).load(function() { - $(this).foundation(); - alert('haba'); - }); +require(['paas', 'jquery', 'foundation', 'what-input'], function(PaaS, $) { + $(this).foundation(); + PaaS.init(); }); \ No newline at end of file diff --git a/app/js/paas.js b/app/js/paas.js new file mode 100644 index 0000000..fd981eb --- /dev/null +++ b/app/js/paas.js @@ -0,0 +1,62 @@ +/** + * Created by Aliaksei Syrel on 02/09/16. + */ +define(['jquery', 'underscore', 'autosize'], function($, _, autosize){ + + function PaaS() { + var _this = this; + var pillar = $('#pillar'); + var preview = $('#preview'); + + _this.initalize = function () { + _this.attachPillarListener(); + _this.load(); + autosize(pillar); + }; + + _this.onPillarChanged = function() { + var text = pillar.val(); + $.post(/*'http://127.0.0.1:6561/'*/'http://paas.syrel.ch/render/html', { pillar: text }, + function( data ) { + preview.html( data ); + }); + }; + + _this.attachPillarListener = function () { + var oldValue = pillar.val(); + var preview = _.debounce(function(){ + var newValue = pillar.val(); + if (newValue != oldValue) { + oldValue = newValue; + _this.onPillarChanged(); + _this.save(); + } + },300); + pillar.on('input change keyup keydown paste', preview); + }; + + _this.save = function () { + var file = pillar.val(); + // sets the file string to hold the data + localStorage.setItem('pillar', JSON.stringify(file)); + }; + + _this.load = function () { + var autosave = localStorage.getItem('pillar'); + if (_.isUndefined(autosave)) return; + // parses the string (btw. its UTF-8) + var text = JSON.parse(autosave); + //modifies the textarea with the id="inputTextArea" + pillar.val(text); + _this.onPillarChanged(); + }; + + _this.initalize(); + } + + PaaS.init = function() { + new PaaS(); + }; + + return PaaS; +}); \ No newline at end of file diff --git a/app/scss/_settings.scss b/app/scss/_settings.scss index df56c6a..2bf92b5 100644 --- a/app/scss/_settings.scss +++ b/app/scss/_settings.scss @@ -46,7 +46,7 @@ // --------- $global-font-size: 100%; -$global-width: rem-calc(1200); +$global-width: rem-calc(1600); $global-lineheight: 1.5; $foundation-palette: ( primary: #2199e8, diff --git a/app/scss/paas.scss b/app/scss/paas.scss index 065ca3c..4d6e418 100644 --- a/app/scss/paas.scss +++ b/app/scss/paas.scss @@ -1,3 +1,15 @@ -.haba { - background: red; +.full-height { + height: 100%; +} + +textarea { + overflow: none; + display: block; + resize: vertical; + font-family: monospace; + font-size: 95%; +} + +#preview { + padding-left: rem-calc(40); } \ No newline at end of file diff --git a/server/install.sh b/server/install.sh new file mode 100644 index 0000000..7551cb5 --- /dev/null +++ b/server/install.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +dir="pharo" + +RED='\033[0;31m' +BLUE='\033[0;34m' +NC='\033[0m' # No Color + +rm -rf "$dir" +mkdir "$dir" +cd "$dir" + +echo -e "${BLUE}Downloading Pharo 4.0...${NC}" +wget http://files.pharo.org/platform/Pharo4.0-linux-oldLibC.zip + +echo -e "${BLUE}Extracting...${NC}" +unzip Pharo4.0-linux-oldLibC.zip + +mv pharo4.0/* ./ +rm -rf pharo4.0 + +echo -e "${BLUE}Installing Pillar...${NC}" +./pharo -vm-display-null shared/Pharo4.0.image eval --save "Gofer it url: 'http://smalltalkhub.com/mc/Pier/Pillar/main/'; configurationOf: 'Pillar'; loadDevelopment" + +echo -e "${BLUE}Installing PaaS (Pillar as a service)...${NC}" +./pharo -vm-display-null shared/Pharo4.0.image eval --save "Metacello new baseline: 'PaaS'; repository: 'github://syrel/paas/src'; load: #core" diff --git a/server/render_html.php b/server/render_html.php new file mode 100644 index 0000000..2c02979 --- /dev/null +++ b/server/render_html.php @@ -0,0 +1,11 @@ +/dev/null >/dev/null &"); + return($PID); + } + + static function isRunning($name){ + exec("pgrep $name", $pids); + return !empty($pids); + } +}; + +if(!exec::isRunning('pharo')) { + echo exec::run('bash --login -c "./start.sh '.$PORT.'"'); +} + +function render ($mode, $pillar) { + global $PORT; + if (strlen($pillar) == 0) + return ''; + $url = 'http://'.$_SERVER['SERVER_NAME'].':'.$PORT.'/'.$mode; + $options = array( + 'http' => array( + 'header' => "Content-type: text/html", + 'method' => 'POST', + 'content' => $pillar + ) + ); + $context = stream_context_create($options); + $result = file_get_contents($url, false, $context); + if ($result === FALSE) { /* Handle error */ } + + return $result; +} \ No newline at end of file diff --git a/server/start.sh b/server/start.sh new file mode 100644 index 0000000..5959a78 --- /dev/null +++ b/server/start.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +dir="pharo" +port="6561" + +if [ "$#" -gt 0 ]; then + port=$1 +fi + +RED='\033[0;31m' +BLUE='\033[0;34m' +NC='\033[0m' # No Color + +cd $dir + +if pgrep "pharo" > /dev/null +then + echo "Already running" +else + echo -e "${BLUE}Starting server on port ${port}...${NC}" + ./pharo -vm-display-null shared/Pharo4.0.image eval --no-quit "PaaSBackend startOn: $port" &>/dev/null &disown +fi