Skip to content

Commit

Permalink
Merge branch 'v0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
beNjiox committed Jan 9, 2014
2 parents 1dbe9f8 + 0954296 commit 3a2adcf
Show file tree
Hide file tree
Showing 20 changed files with 738 additions and 209 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,9 @@ composer.lock
Thumbs.db
.vagrant/
dump.rdb

*.scssc

*.cdncache

node_modules
143 changes: 143 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
var PROD_DEST = "../www/"
var PUBLIC_PATH = "./public/"
/*global module:false*/
module.exports = function(grunt) {

grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),

/* TEMPLATING */

template: {
views: {
options: {
data: {
env: 'dev'
},
},
files: {
'./public/index.html': PUBLIC_PATH + './index.tpl'
}
},
prod: {
options: {
data: {
env: 'prod'
}
},
files: {
'./public/index.html': PUBLIC_PATH + './index.tpl'
}
},
dev: {
options: {
data: {
env: 'dev'
}
},
files: {
'./public/index.html': PUBLIC_PATH + './index.tpl'
}
},
},

/* COMPILE OUR COFFEE SCRIPTS FILES */

coffee: {
dist: {
options: {
bare: true
},
files: [{
expand: true,
cwd: PUBLIC_PATH + 'js',
src: ['{,*/}*.coffee'],
dest: PUBLIC_PATH + 'js',
ext: '.js'
}]
}
},

/* CONCAT AND MINIFY OUR JS FILES */

uglify: {
options: {
banner: '/*! <%= pkg.name %> - v<%= pkg.version %> - ' +
'<%= grunt.template.today("yyyy-mm-dd") %> */',
mangle:false
},
my_target: {
files: {
'app.js': [
PUBLIC_PATH + "js/storage.coffee"
]
}
}
},

/* COMPILE OUR SCSS FILES */

sass: {
options: {
banner: '/*! <%= pkg.name %> - v<%= pkg.version %> - ' +
'<%= grunt.template.today("yyyy-mm-dd") %> */'
},
dist: {
files: [{
expand: true,
src: ['public/css/*.scss'],
ext: '.css'
}]
}
},

/* COMPRESS CSS RULE */

cssmin: {
minify: {
files: {
'css/app.css': ['css/app.css']
}
}
},

/* OUR WATCH RULES */

watch: {
html: {
files: ['app/**/*.blade.php', 'public/partials/*.html'],
options: {
livereload: true
}
},
coffee: {
files: ['public/js/*.coffee'],
tasks: ['coffee'],
options: {
livereload: true
}
},
scss: {
files: ['public/css/*.scss'],
tasks: ['sass'],
options: {
livereload: true
}
},
}

});

grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-coffee');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-template');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-cssmin');


grunt.registerTask('dev', ['watch']);
grunt.registerTask('prod', ['clean:prod' , 'sass', 'cssmin', 'coffee', 'uglify', 'template:prod', 'htmlmin' ]);
};
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@ Roadmap
[x] Basic UI (jQuery based)
[x] Boilerplate provisioning file
# V0.2 - UI revamp :
[] UI Using angularJS
[] Better error handling (client side)
[] UI limitations of X items
[] Masked Input for hexadecimal
[x] UI Using angularJS
[x] Improved UI details
[x] Improved routing
[x] Grunt introduced
# V0.3 - Backend improvment:
[x] getAll now account for limits
[] Http Middleware limit
[] Exception on Errors
[] Pagination handling
Expand Down
13 changes: 9 additions & 4 deletions app/controllers/ColorsController.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
<?php

function is_hexadecimal($color)
{
return preg_match('/^#[a-f0-9]{6}$/i', $color);
}

use Larabooster\ColorRepositoryInterface;

class ColorsController extends BaseController {

protected $color;

public function __construct(ColorRepositoryInterface $color)
Expand Down Expand Up @@ -34,7 +39,7 @@ public function store()
if ($this->color->exists($code))
{
$errors['msg'] = "color '{$code}' already exists in this storage!";
return Response::json($errors, 400);
return Response::json($errors, 400);
}

$this->color->add($code);
Expand All @@ -51,13 +56,13 @@ public function delete()
$this->color->delete(Input::get('code'));
return Response::json(null, 204);
}

$errors = [
'errors' => 'VALIDATION_FAIL',
'msg' => 'You should pass a code to be able to delete a color.'
];

return Response::json(400, $errors);
return Response::json($errors, 400);

}
}
6 changes: 3 additions & 3 deletions app/lib/Larabooster/DbColorRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use Larabooster\ColorRepositoryInterface;

class DbColorRepository implements ColorRepositoryInterface
class DbColorRepository implements ColorRepositoryInterface
{

public $whoami = "MySQL";
Expand All @@ -26,11 +26,11 @@ public function add($code)

public function getAll($limit = 10)
{
$colors_raw = \Color::orderBy('id', 'desc')->get()->toArray();
$colors_raw = \Color::orderBy('id', 'desc')->take($limit)->get()->toArray();
$colors = [];
foreach ($colors_raw as $color) {
$colors[] = $color['code'];
}
return $colors;
}
}
}
8 changes: 4 additions & 4 deletions app/lib/Larabooster/MemcacheColorRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function add($code)
}

public function delete($code)
{
{
if (!(\Cache::has('colors')))
return false;
$colors = \Cache::get('colors');
Expand All @@ -52,7 +52,7 @@ public function getAll($limit = 10)
{
$colors = \Cache::get('colors');
}
\Log::info(print_r($colors, true));
return array_reverse($colors);
$colors = array_reverse($colors);
return array_splice($colors, 0, $limit);
}
}
}
4 changes: 2 additions & 2 deletions app/lib/Larabooster/RedisColorRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public function delete($code)

public function getAll($limit = 10)
{
$redis_colors = \Redis::smembers('colors');
return $redis_colors;
$redis_colors = array_reverse(\Redis::smembers('colors'));
return array_splice($redis_colors, 0, $limit);
}

}
79 changes: 26 additions & 53 deletions app/routes.php
Original file line number Diff line number Diff line change
@@ -1,62 +1,35 @@
<?php

function is_hexadecimal($color)
{
return preg_match('/^#[a-f0-9]{6}$/i', $color);
}

use Larabooster\DbColorRepository;
use Larabooster\MemcacheColorRepository;
use Larabooster\RedisColorRepository;

Route::get('/', function()
{
$MySQL_storage = new ColorsController(new DbColorRepository);
$memcache_storage = new ColorsController(new MemcacheColorRepository);
$redis_storage = new ColorsController(new RedisColorRepository);

$mysql_colors = $MySQL_storage->getAll();
$memcache_colors = $memcache_storage->getAll();
$redis_colors = $redis_storage->getAll();

$to_view = [
'mysql_colors' => $mysql_colors,
'memcache_colors' => $memcache_colors,
'redis_colors' => $redis_colors
];

return View::make('home')->with($to_view);
{
return View::make('home');
});

Route::group(array('prefix' => 'api'), function()
{
Route::post('mysql', function() {
$controller = new ColorsController(new DbColorRepository);
return $controller->store();
});

Route::delete('mysql', function() {
$controller = new ColorsController(new DbColorRepository);
return $controller->delete();
});

Route::post('memcache', function() {
$controller = new ColorsController(new MemcacheColorRepository);
return $controller->store();
});

Route::delete('memcache', function() {
$controller = new ColorsController(new MemcacheColorRepository);
return $controller->delete();
});

Route::post('redis', function() {
$controller = new ColorsController(new RedisColorRepository);
return $controller->store();
});

Route::delete('redis', function() {
$controller = new ColorsController(new RedisColorRepository);
return $controller->delete();
});
$storages = [
'mysql' => [ 'repo' => 'Larabooster\DbColorRepository' ],
'memcache' => [ 'repo' => 'Larabooster\MemcacheColorRepository' ],
'redis' => [ 'repo' => 'Larabooster\RedisColorRepository' ]
];

foreach ($storages as $kStorage => $vStorage)
{
Route::group(array('prefix' => $kStorage), function() use ($kStorage, $vStorage) {

$controller = new ColorsController(new $vStorage['repo']);

Route::get("/", function() use ($controller) {
return $controller->getAll(3);
});
Route::post("/", function() use ($controller) {
return $controller->store();
});
Route::delete("/", function() use ($controller) {
return $controller->delete();
});

});
}
});
1 change: 1 addition & 0 deletions app/start/global.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,4 @@
*/

require app_path().'/filters.php';

Loading

0 comments on commit 3a2adcf

Please sign in to comment.