acidjazz/larjectus

Adds the power of objectus to Laravel and Lumen

v0.9 2016-09-05 06:47 UTC

This package is auto-updated.

Last update: 2024-10-29 04:25:36 UTC


README

Allows you to use Objectus seamlessly in Laravel 5 and Lumen

Total Downloads Latest Stable Version License Build Status Dependency Status Coverage Status codecov Codacy Badge

What this does

  • Combines your .env and config/ options with as many YAML and JSON files and directories you want to add inside config/
  • Allows for functionality to share this data in any language(s) your resources/ or public/ folders might use

Why would I want this

Most all of my projects have extended configuration, everything from style guides to site copy, this allows stylus/css and coffeescript/javascript access to this data

Requirements

Installation

Require this package with Composer

composer require acidjazz/larjectus

Laravel

Once Composer has installed or updated your packages you need to register Larjectus with Laravel itself. Open up config/app.php and find the providers key, towards the end of the file, and add 'Larjectus\ServiceProvider', to the end:

'providers' => [
  ...
    Larjectus\ServiceProvider::class,
],

Lumen

For usage with Lumen, add the service provider in bootstrap/app.php.

$app->register(Larjectus\ServiceProvider::class);

configuration

gulpfile.js example(s)

Your gulp task is different from how Objectus works, here is an example of compiling a JSON version of your config for JavaScript access:

🚨 Note the secure array where i remove any secure data, like DB passwords and AWS credentials. 🚨

exec = require('child_process').exec;

objectify = function() {
  var config, secure;
  config = {};
  secure = ['auth', 'database'];
  return exec('php artisan larjectus:config', function(error, result, stderr) {
    var dim, i, len, pubconfig;
    if (error) {
      notify(error);
    }
    this.config = JSON.parse(result);
    pubconfig = this.config;
    for (i = 0, len = secure.length; i < len; i++) {
      dim = secure[i];
      delete pubconfig[dim];
    }
    return fs.writeFileSync('public/js/config.js', "config="+JSON.stringify(pubconfig)+";", 'utf8');
  });
};

objectify();

gulp.task('larjectus', objectify);

gulp.task('watch', function() {
  gulp.watch('config/**/*', ['larjectus']);
);

Here is an example of giving config access to stylus you would need the sample gulp task above :

stylus = require('gulp-stylus');

gulp.task('stylus', function() {
  return gulp.src('resources/stylus/main.styl')
    .pipe(stylus({
      rawDefine: {
        config: config
      }
    }).on('error', notify.onError(function(error) {
      return {
        title: 'Stylus error: ' + error.name,
        message: error.message,
        sound: 'Pop'
      };
    })))
  .pipe(gulp.dest('public/css/'))
  .pipe(sync.stream());
}