Skip to content

Commit

Permalink
Merge branch '2.0'
Browse files Browse the repository at this point in the history
* 2.0: (90 commits)
  Removing old stylist command
  Using ::class notation
  Using ::class notation
  Preparing 2.5.0 versions
  Preparing 2.5.0 changelogs
  CLosing css stack
  Using the @Push js stacks over the scripts section
  Using the @Push css stacks over the styles section
  New changelog item
  Remove the ckeditor inclusion on create/edit view stubs
  Adding changelog item
  Adding back the correct old input for the body field
  Adding changelog item for core module
  Creating a non translatable textarea component and make it usable with same @editor directive
  Fixing field name variable echo
  Moving assets inclusion to component
  Using new blade directives
  Bringing back the js and css stacks on main views
  Moving css and js stacks outside the component. Making field and label name dynamic
  Create a blade directive to use @editor
  ...
  • Loading branch information
nWidart committed Jul 16, 2017
2 parents 91a2056 + 35c1d5b commit d7183b4
Show file tree
Hide file tree
Showing 145 changed files with 2,334 additions and 357 deletions.
1 change: 1 addition & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ $finder = PhpCsFixer\Finder::create()
'bootstrap',
'tests',
'node_modules',
'views',
])
->notPath('server.php')
;
Expand Down
33 changes: 33 additions & 0 deletions Modules/Core/Blade/AsgardEditorDirective.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Modules\Core\Blade;

class AsgardEditorDirective
{
private $content;
private $lang;
private $fieldName;
private $labelName;

public function show($arguments)
{
$this->extractArguments($arguments);

if ($this->lang !== null) {
return asgard_i18n_editor($this->fieldName, $this->labelName, $this->content, $this->lang);
}
return asgard_editor($this->fieldName, $this->labelName, $this->content);
}

/**
* Extract the possible arguments as class properties
* @param array $arguments
*/
private function extractArguments(array $arguments)
{
$this->fieldName = array_get($arguments, 0);
$this->labelName = array_get($arguments, 1);
$this->content = array_get($arguments, 2);
$this->lang = array_get($arguments, 3);
}
}
13 changes: 13 additions & 0 deletions Modules/Core/Blade/Facades/AsgardEditorDirective.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Modules\Core\Blade\Facades;

use Illuminate\Support\Facades\Facade;

class AsgardEditorDirective extends Facade
{
protected static function getFacadeAccessor()
{
return 'core.asgard.editor';
}
}
6 changes: 6 additions & 0 deletions Modules/Core/Composers/AssetsViewComposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Illuminate\Contracts\View\View;
use Illuminate\Http\Request;
use Modules\Core\Events\CollectingAssets;
use Modules\Core\Events\EditorIsRendering;
use Modules\Core\Foundation\Asset\Manager\AssetManager;
use Modules\Core\Foundation\Asset\Pipeline\AssetPipeline;
use Modules\Core\Foundation\Asset\Types\AssetTypeFactory;
Expand Down Expand Up @@ -48,7 +50,11 @@ public function compose(View $view)
$this->assetPipeline->requireCss(config('asgard.core.core.admin-required-assets.css'));
$this->assetPipeline->requireJs(config('asgard.core.core.admin-required-assets.js'));

event($editor = new EditorIsRendering($this->assetPipeline));
event(new CollectingAssets($this->assetPipeline));

$view->with('cssFiles', $this->assetPipeline->allCss());
$view->with('jsFiles', $this->assetPipeline->allJs());
$view->with('editor', $editor);
}
}
3 changes: 3 additions & 0 deletions Modules/Core/Config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
'workshop',
'setting',
'media',
'tag',
'page',
'translation',
],

/*
Expand Down
14 changes: 14 additions & 0 deletions Modules/Core/Config/core.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@
*/
'skin' => 'skin-blue',

/*
|--------------------------------------------------------------------------
| WYSIWYG Backend Editor
|--------------------------------------------------------------------------
| Define which editor you would like to use for the backend wysiwygs.
| These classes are event handlers, listening to EditorIsRendering
| you can define your own handlers and use them here
| Options:
| - \Modules\Core\Events\Handlers\LoadCkEditor::class
| - \Modules\Core\Events\Handlers\LoadSimpleMde::class
*/
'wysiwyg-handler' => \Modules\Core\Events\Handlers\LoadCkEditor::class,
/*
|--------------------------------------------------------------------------
| Custom CKeditor configuration file
Expand Down Expand Up @@ -84,6 +96,7 @@
'selectize-default.css' => ['module' => 'core:vendor/selectize/dist/css/selectize.default.css'],
'animate.css' => ['theme' => 'vendor/animate.css/animate.min.css'],
'pace.css' => ['theme' => 'vendor/admin-lte/plugins/pace/pace.min.css'],
'simplemde.css' => ['theme' => 'vendor/simplemde/dist/simplemde.min.css'],
// Javascript
'bootstrap.js' => ['theme' => 'vendor/bootstrap/dist/js/bootstrap.min.js'],
'mousetrap.js' => ['theme' => 'js/vendor/mousetrap.min.js'],
Expand All @@ -110,6 +123,7 @@
'pace.js' => ['theme' => 'vendor/admin-lte/plugins/pace/pace.min.js'],
'moment.js' => ['theme' => 'vendor/admin-lte/plugins/daterangepicker/moment.min.js'],
'clipboard.js' => ['theme' => 'vendor/clipboard/dist/clipboard.min.js'],
'simplemde.js' => ['theme' => 'vendor/simplemde/dist/simplemde.min.js'],
],

/*
Expand Down
22 changes: 22 additions & 0 deletions Modules/Core/Contracts/EntityIsChanging.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Modules\Core\Contracts;

interface EntityIsChanging
{
/**
* Get the attributes used to create or modify an entity
* @return array
*/
public function getAttributes();
/**
* Set the attributes used to create or modify an entity
* @param array $attributes
*/
public function setAttributes(array $attributes);
/**
* Get the original attributes untouched by other listeners
* @return array
*/
public function getOriginal();
}
63 changes: 63 additions & 0 deletions Modules/Core/Events/AbstractEntityHook.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

namespace Modules\Core\Events;

abstract class AbstractEntityHook
{
/**
* Contains the attributes which can be changed by other listeners
* @var array
*/
private $attributes;
/**
* Contains the original attributes which cannot be changed
* @var array
*/
private $original;

public function __construct(array $attributes)
{
$this->attributes = $attributes;
$this->original = $attributes;
}

/**
* @return array
*/
public function getAttributes()
{
return $this->attributes;
}

/**
* @param string $attribute
* @param null $default
* @return string|null
*/
public function getAttribute($attribute, $default = null)
{
return data_get($this->attributes, $attribute, $default);
}

/**
* @param array $attributes
*/
public function setAttributes(array $attributes)
{
$this->attributes = array_replace_recursive($this->attributes, $attributes);
}

/**
* @param string|null $key
* @param string|null $default
* @return array
*/
public function getOriginal($key = null, $default = null)
{
if ($key !== null) {
return data_get($this->original, $key, $default);
}

return $this->original;
}
}
65 changes: 65 additions & 0 deletions Modules/Core/Events/CollectingAssets.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

namespace Modules\Core\Events;

use Modules\Core\Foundation\Asset\Pipeline\AssetPipeline;

class CollectingAssets
{
/**
* @var AssetPipeline
*/
private $assetPipeline;

public function __construct(AssetPipeline $assetPipeline)
{
$this->assetPipeline = $assetPipeline;
}

/**
* @param string $asset
* @return AssetPipeline
*/
public function requireJs($asset)
{
return $this->assetPipeline->requireJs($asset);
}

/**
* @param string $asset
* @return AssetPipeline
*/
public function requireCss($asset)
{
return $this->assetPipeline->requireCss($asset);
}

/**
* Match a single route
* @param string|array $route
* @return bool
*/
public function onRoute($route)
{
$request = request();

return str_is($route, $request->route()->getName());
}

/**
* Match multiple routes
* @param array $routes
* @return bool
*/
public function onRoutes(array $routes)
{
$request = request();

foreach ($routes as $route) {
if (str_is($route, $request->route()->getName()) === true) {
return true;
}
}
return false;
}
}
107 changes: 107 additions & 0 deletions Modules/Core/Events/EditorIsRendering.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php

namespace Modules\Core\Events;

use Modules\Core\Foundation\Asset\Pipeline\AssetPipeline;

class EditorIsRendering
{
/**
* @var AssetPipeline
*/
private $assetPipeline;
private $editorClass;
private $editorJsPartial;
private $editorCssPartial;
private $editorComponents = [
'i18n' => 'core::components.i18n.textarea',
'normal' => 'core::components.textarea',
];

public function __construct(AssetPipeline $assetPipeline)
{
$this->assetPipeline = $assetPipeline;
}

public function addJs($asset)
{
$this->assetPipeline->requireJs($asset);

return $this;
}

public function addCss($asset)
{
$this->assetPipeline->requireCss($asset);

return $this;
}

/**
* @return mixed
*/
public function getEditorClass()
{
return $this->editorClass;
}

/**
* @param mixed $editorClass
*/
public function setEditorClass($editorClass)
{
$this->editorClass = $editorClass;
}

/**
* @return mixed
*/
public function getEditorJsPartial()
{
return $this->editorJsPartial;
}

/**
* @param mixed $editorJsPartial
*/
public function setEditorJsPartial($editorJsPartial)
{
$this->editorJsPartial = $editorJsPartial;
}

/**
* @return mixed
*/
public function getEditorCssPartial()
{
return $this->editorCssPartial;
}

/**
* @param mixed $editorCssPartial
*/
public function setEditorCssPartial($editorCssPartial)
{
$this->editorCssPartial = $editorCssPartial;
}

public function getI18nComponentName()
{
return $this->editorComponents['i18n'];
}

public function setI18nComponentName($componentName)
{
$this->editorComponents['i18n'] = $componentName;
}

public function getComponentName()
{
return $this->editorComponents['normal'];
}

public function setComponentName($componentName)
{
$this->editorComponents['normal'] = $componentName;
}
}
16 changes: 16 additions & 0 deletions Modules/Core/Events/Handlers/LoadCkEditor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Modules\Core\Events\Handlers;

use Modules\Core\Events\EditorIsRendering;

class LoadCkEditor
{
public function handle(EditorIsRendering $editor)
{
$editor->addJs('ckeditor.js');
$editor->setEditorClass('ckeditor');

return false;
}
}
Loading

0 comments on commit d7183b4

Please sign in to comment.