Commit 547438cc authored by hxgf's avatar hxgf 🎧

v1 rc2

parent fae9eb67
.DS_Store
\ No newline at end of file
......@@ -2,10 +2,12 @@
// custom global functions
// -------------------------------------------------------
// CUSTOM GLOBAL FUNCTIONS
// -------------------------------------------------------
/*
function hello($o){
function literally($o){
return $o;
}
*/
......@@ -16,7 +18,10 @@
// custom handlebars helpers
// -------------------------------------------------------
// CUSTOM HANDLEBARS HELPERS
// -------------------------------------------------------
/*
$engine->addHelper('nl2br', function($template, $context, $args, $source) {
......
......@@ -3,39 +3,9 @@
$app->get('/', function(){
$planet_group[] = array(
'one' => 'Mercury',
'two' => 'Venus',
'three' => 'Earth'
);
$planet_group[] = array(
'one' => 'Mars',
'two' => 'Jupiter',
'three' => 'Saturn',
'four' => 'Uranus'
);
$planet_group[] = array(
'one' => 'Neptune',
'two' => 'Pluto',
'three' => 'Nibiru'
);
$data = array(
'snacks' => array(
'Carrots',
'Hay',
'Sugar Cubes',
'Oats'
),
'planet_group' => $planet_group
);
$GLOBALS['app']->render_template(array(
'template' => 'index',
'title' => $GLOBALS['site_title'],
'data' => $data
));
});
......@@ -44,136 +14,81 @@ $app->get('/', function(){
$app->get('/demo', function(){
/*
EXAMPLE RESPONSES
$app->get('/', function(){
// so many response options!
// render handlebars template (stereo abstraction)
// $GLOBALS['app']->render_template(array(
// 'template' => 'planets',
// 'title' => 'planetas',
// 'layout' => false,
// 'data' => array(
// 'righteous_content' => 'for_sure'
// )
// ));
// render a normal handlebars template
echo $GLOBALS['engine']->render('index', []);
// require a given php/html/whatever page
// require __DIR__ . '/pages/whatever.html';
// send an array as json for handy api responses
// $GLOBALS['app']->json_response(array(
// 'righteous_content' => 'for sure'
// ));
// send whatever responses, headers, redirects
// header("Location: http://partyphysics.com/");
// or execute any php code...do literally whatever you want
});
$app->get('/planets/*', function(){
$GLOBALS['app']->render_template(array(
'template' => 'stereo_planets',
'title' => 'planetas',
'data' => array()
));
});
// map homepage
$app->get('/planets/[*:whatever]', function($whatever){
echo $whatever;
$normal_array[] = array(
'one' => '1',
'two' => '2',
'three' => '3'
$planet_group[] = array(
'title' => 'Gas Giants',
'planets' => [array(
'name' => 'Jupiter'
), array(
'name' => 'Neptune'
), array(
'name' => 'Uranus'
)]
);
$normal_array[] = array(
'one' => '4',
'two' => '5',
'three' => '69'
$planet_group[] = array(
'title' => 'Moons',
'planets' => [array(
'name' => 'Luna',
'note' => 'Earth\'s moon, also known as "moon"'
), array(
'name' => 'IO'
), array(
'name' => 'Ganymede'
), array(
'name' => 'Europa'
), array(
'name' => 'Phobos'
), array(
'name' => 'Deimos'
), array(
'name' => 'Callisto'
), array(
'name' => 'Kale'
)]
);
$normal_array[] = array(
'one' => '17',
'two' => '28',
'three' => '93'
$planet_group[] = array(
'title' => 'Exoplanets',
'planets' => [array(
'name' => 'Pluto'
), array(
'name' => 'Nibiru',
'note' => 'commonly referred to as "Planet X"'
), array(
'name' => 'Dave'
)]
);
$planet_group[] = array(
'title' => 'Potentially Habitable Planets',
'planets' => [array(
'name' => 'Earth'
), array(
'name' => 'Mars'
), array(
'name' => 'Europa'
)]
);
$data = array(
'planets' => array(
"Mercury",
"Venus",
"Earth",
"Mars",
"ganymede",
"charon",
"europa",
"proscion"
'snacks' => array(
'Carrots',
'Hay',
'Sugar Cubes',
'Oats',
'Apples',
'Weaker Horses'
),
'normal_array' => $normal_array
'planet_group' => $planet_group
);
$GLOBALS['app']->render_template(array(
'template' => 'stereo_planets',
'title' => 'planetas',
'layout' => false,
'template' => 'demo',
'title' => $GLOBALS['site_title'] . ' - Template Demonstration',
'data' => $data
));
});
$app->get('/admin', function(){
$data = $GLOBALS['app']->api_request('/admin/events/screen',
array(
));
$data['current_events'] = true;
$data['current_events_all'] = true;
$GLOBALS['app']->render_template(array(
'layout' => 'admin',
'template' => 'admin/admin-events',
'title' => 'Admin - Events - ' . $GLOBALS['site_title'],
'data' => $data
));
});
*/
@import url("normalize.css");
@import url("basscss.min.css");
@import url("lib/normalize.css");
@import url("lib/basscss.min.css");
@import url("lib/basscss.modules.min.css");
@import url("https://fonts.googleapis.com/css?family=Inconsolata:400,700");
body, body * {
font-family: 'Inconsolata', 'Courier New', courier, monospace;
font-family: 'Courier New', courier, monospace;
}
/* vertical centering :) */
html, body{
height: 100%;
}
.vertical-container {
display: table;
height: 100%;
margin: 0 auto;
}
.vertical-center {
display: table-cell;
vertical-align: middle;
}
.hello-world{
font-size: 500%;
}
.hello-world a{
color: #111;
text-decoration: none;
}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
......@@ -19,16 +19,11 @@ require 'stereo/stereo-core.php';
$app = new StereoSystem;
/*
// db init
$dbh = stereo_db_init();
*/
$GLOBALS['database'] = $app->db_init();
require 'controllers/_global.php';
require 'controllers/_routes.php';
$match = $router->match();
if($match && is_callable($match['target'])){
......@@ -38,6 +33,3 @@ if($match && is_callable($match['target'])){
'status' => 404
));
}
// db cleanup? idk whatever w/ pdo see 0.0.4
\ No newline at end of file
This diff is collapsed.
MIT License
Copyright (c) 2010-2016 Jonathan Youngblood (Hex Girlfriend) <[email protected]>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
\ No newline at end of file
......@@ -13,19 +13,10 @@
<body>
[[outlet]]
[[outlet]]
<!--[if lte IE 8]>
<script src="//js/vendor/jquery-legacy.min.js"></script>
<![endif]-->
<!--[if !lte IE 8]><!-->
<script src="/js/vendor/jquery.min.js"></script>
<!--<![endif]-->
<script src="/js/vendor/js.cookie.js"></script>
<script src="/js/lib/jquery.min.js"></script>
<script src="/js/lib/js.cookie.js"></script>
<script src="/js/app.js"></script>
</body>
</html>
<div style="width: 500px; margin: 0 auto;">
<br /><br />
{{> partial-horse}}
<br /><br />
<h3 class="mb1">Things horses like to eat:</h3>
<ul class="mt0 pl2">
{{#each snacks}}
<li>{{this}}</li>
{{/each}}
</ul>
<br />
<hr /><hr />
<br />
<h3>Celestial Bodies <i><small>(complex array example)</small></i></h3>
{{#each planet_group}}
<h4 class="mb0">{{title}}</h4>
<ul class="mt0 pl2">
{{#each planets}}
<li>{{name}}{{#if note}} <i><small>({{note}})</small></i>{{/if}}</li>
{{/each}}
</ul>
{{/each}}
<br />
<hr /><hr />
<br />
Refer to <a href="http://stereotk.com">http://stereotk.com</a> for complete documentation and more examples.
<br /><br />
<hr /><hr />
<br />
<br /><br /><br /><br />
<br /><br /><br /><br />
</div>
<div style="width: 500px; margin: 0 auto;">
<br /><br />
{{> partial-horse}}
<br /><br />
<h2>Things I like to eat</h2>
<ul>
{{#each snacks}}
<li>{{this}}</li>
{{/each}}
</ul>
<br /><br />
<h3>Favorite Planets (complex array example)</h3>
{{#each planet_group}}
<ol>
<li>{{one}}</li>
<li>{{two}}</li>
<li>{{three}}</li>
{{#if four}}<li>{{four}}</li>{{/if}}
</ol>
{{/each}}
</div>
<div class="vertical-container">
<div class="vertical-center hello-world">
<a href="/demo"></a>
</div>
</div>
\ No newline at end of file
......@@ -5,10 +5,91 @@
\/\_____\ \ \_\ \ \_____\ \ \_\ \_\ \ \_____\ \ \_____\
\/_____/ \/_/ \/_____/ \/_/ /_/ \/_____/ \/_____/
Version: 1.0.0 (pre-release)
Internet Tool Kit v1.0.0
```
### Literally the easiest way to make web sites with PHP
Literally the easiest way to build intelligent server-rendered web sites with PHP.
\ No newline at end of file
### FEATURES
- [Easy & flexible router](http://altorouter.com/) with pretty urls
- [Handlebars](http://handlebarsjs.com/) templates
- Simple/intuitive application structure
- Convenient MYSQL CRUD functionality
- Helpful utility functions *(for working with cookies, http requests, sending email, etc)*
- Sensible *(but minimal)* front-end boilerplate
- Works with most shared web hosting providers
### Just look how easy it is to make all of these responses:
Render a normal Handlebars template
```
$app->get('/handlebars-normal', function(){
echo $GLOBALS['engine']->render('handlebars-example', array(
'righteous_content' => 'for_sure'
));
});
```
Render a Handlebars template (w/ special STEREO helpers)
```
$app->get('/handlebars-fancy', function(){
$GLOBALS['app']->render_template(array(
'template' => 'planets',
'title' => 'Cool Planets',
'layout' => false,
'data' => array(
'righteous_content' => 'for_sure',
'planets' => array(
'Mercury', 'Venus', 'Earth', 'Nibiru'
)
)
));
});
```
Show a normal PHP / HTML document
```
$app->get('/normal-page', function(){
require __DIR__ . '/pages/whatever.html';
});
```
Send an array as JSON for handy API responses
```
$app->post('/json-response', function(){
$GLOBALS['app']->render_json(array(
'righteous_content' => 'for sure'
));
});
```
Set headers, do redirects
```
$app->get('/whatever', function(){
header("Location: http://partyphysics.com/");
});
```
or execute any PHP code...do literally whatever you want!
### Read the full documentation: [http://stereotk.com/docs](http://stereotk.com/docs)
<?php
$GLOBALS['site_title'] = 'HELLO'; // ex: 'Party Physics'
$GLOBALS['site_title'] = 'STEREO'; // ex: 'Party Physics'
$GLOBALS['site_code'] = ''; // ex: 'partyphysics'
$GLOBALS['site_url'] = ''; // ex: 'patryphysics.com'
$GLOBALS['api_root'] = false; // 'http://partyphysics.com/api'
$GLOBALS['site_url'] = ''; // ex: 'partyphysics.com'
// $GLOBALS['database']['type'] = ''; // db type (mysql, postgres)
// $GLOBALS['database']['host'] = ''; // host name
// $GLOBALS['database']['name'] = ''; // db name
// $GLOBALS['database']['user'] = ''; // db user name
// $GLOBALS['database']['password'] = ''; // db password
// $GLOBALS['settings']['api_root'] = ''; // ex: 'https://api.partyphysics.com/api'
// $GLOBALS['settings']['database']['host'] = 'localhost'; // host name
// $GLOBALS['settings']['database']['name'] = ''; // db name
// $GLOBALS['settings']['database']['user'] = ''; // db user name
// $GLOBALS['settings']['database']['password'] = ''; // db password
// $GLOBALS['settings']['mailgun_api_key'] = '';
// $GLOBALS['settings']['mailgun_api_domain'] = '';
// in case you need it:
// date_default_timezone_set('America/Chicago');
......
<?php
// see also: a bunch of (unused, reference) helpers in stereo/HandlebarsHelpers
// transform string to lowercase
$engine->addHelper('lowercase', function($template, $context, $args, $source) {
$parsed_args = $template->parseArguments($args);
if (count($parsed_args) != 1) {
throw new \InvalidArgumentException(
'"lowercase" helper expects exactly one argument.'
);
throw new \InvalidArgumentException(
'"lowercase" helper expects exactly one argument.'
);
}
return strtolower($context->get($parsed_args[0]));
});
// escape quotes
// escape quotes
$engine->addHelper('addslashes', function($template, $context, $args, $source) {
$parsed_args = $template->parseArguments($args);
if (count($parsed_args) != 1) {
throw new \InvalidArgumentException(
'"lowercase" helper expects exactly one argument.'
);
throw new \InvalidArgumentException(
'"lowercase" helper expects exactly one argument.'
);
}
return addslashes($context->get($parsed_args[0]));
});
// format_timestamp
// given a js date object (well, mongodb date object)
// fixit treat as unix if unix
// return raw date obj as "m/d/YYYY - h:m am/pm"
// {{format_timestamp data.date_start}}
$engine->addHelper('format_timestamp', function($template, $context, $args, $source) {
$parsed_args = $template->parseArguments($args);
return date("m/d/Y - g:ia", strtotime($context->get($parsed_args[0])));
......@@ -45,7 +42,6 @@ $engine->addHelper('format_timestamp', function($template, $context, $args, $sou
// given a js date object
// return raw date obj as m/d/YYYY
// {{format_date_edit data.date_start}}
$engine->addHelper('format_date_edit', function($template, $context, $args, $source) {
$parsed_args = $template->parseArguments($args);
return date("m/d/Y", strtotime($context->get($parsed_args[0])));
......@@ -59,7 +55,6 @@ $engine->addHelper('format_date_edit', function($template, $context, $args, $sou
// {{to_fixed data.total}} 0.00
// {{to_fixed data.total 4}} 0.0000
// {{to_fixed data.total 0}} 0
$engine->addHelper('to_fixed', function($template, $context, $args, $source) {
$parsed_args = $template->parseArguments($args);
$precision = 2;
......@@ -77,7 +72,6 @@ $engine->addHelper('to_fixed', function($template, $context, $args, $source) {
// nl2br
// transform line breaks to "<br />"
// {{{nl2br data.description}}}
$engine->addHelper('nl2br', function($template, $context, $args, $source) {
$parsed_args = $template->parseArguments($args);
return nl2br($context->get($parsed_args[0]));
......@@ -90,7 +84,6 @@ $engine->addHelper('nl2br', function($template, $context, $args, $source) {
// return true(/false) if this item is(/is not) in the array
// {{#in_array "green" data.colors_array}}it's in the array!{{else}}it's not in :({{/in_array}}
// can be a csv string, too
$engine->addHelper('in_array', function($template, $context, $args, $source) {
$parsed_args = $template->parseArguments($args);
if (gettype($context->get($parsed_args[1])) == 'array'){
......@@ -99,14 +92,14 @@ $engine->addHelper('in_array', function($template, $context, $args, $source) {
$condition = (in_array($context->get($parsed_args[0]), str_getcsv($context->get($parsed_args[1]))));
}
if ($condition) {
$template->setStopToken('else');
$buffer = $template->render($context);
$template->setStopToken(false);
$template->setStopToken('else');
$buffer = $template->render($context);
$template->setStopToken(false);
} else {
$template->setStopToken('else');
$template->discard();
$template->setStopToken(false);
$buffer = $template->render($context);
$template->setStopToken('else');
$template->discard();
$template->setStopToken(false);
$buffer = $template->render($context);
}
return $buffer;
});
......@@ -117,19 +110,18 @@ $engine->addHelper('in_array', function($template, $context, $args, $source) {
// return true if the first thing equals either the second or third thing
// {{#if_either data.word "shit" "fuck"}}it's true :){{else}}it's false :({{/if_either}}
// data.word = "shit" so this will be true
$engine->addHelper('if_either', function($template, $context, $args, $source) {
$parsed_args = $template->parseArguments($args);
$condition = ($context->get($parsed_args[0]) == $context->get($parsed_args[1]) || $context->get($parsed_args[0]) == $context->get($parsed_args[2]));
if ($condition) {
$template->setStopToken('else');
$buffer = $template->render($context);
$template->setStopToken(false);
$template->setStopToken('else');
$buffer = $template->render($context);
$template->setStopToken(false);
} else {
$template->setStopToken('else');
$template->discard();
$template->setStopToken(false);
$buffer = $template->render($context);
$template->setStopToken('else');
$template->discard();
$template->setStopToken(false);
$buffer = $template->render($context);
}
return $buffer;
});
......@@ -143,41 +135,32 @@ $engine->addHelper('if_either', function($template, $context, $args, $source) {
// {{#is shit "in" data.word}}yes :){{else}}no :({{/is}}
// 2nd param can beither array or csv
// {{#is data.var_1 "typeof" data.var_2}}yes :){{else}}no :({{/is}}
$engine->addHelper('is', function($template, $context, $args, $source) {
$parsed_args = $template->parseArguments($args);
$l = $context->get($parsed_args[0]);
$operator = $context->get($parsed_args[1]);
$r = $context->get($parsed_args[2]);
if ($operator == '=='){
$condition = ($l == $r);
}
if ($operator == '==='){
$condition = ($l === $r);
}
if ($operator == 'not' || $operator == '!='){
$condition = ($l != $r);
}
}
if ($operator == '<'){
$condition = ($l < $r);
}
if ($operator == '>'){
$condition = ($l > $r);
}
if ($operator == '<='){
$condition = ($l <= $r);
}
if ($operator == '>='){
$condition = ($l >= $r);
}