From 6dfbdd38cc3a2f769e63307658ad060a48d62f7b Mon Sep 17 00:00:00 2001 From: Bayram Aliev Date: Wed, 18 Jun 2014 20:24:39 +0700 Subject: [PATCH] First beta-release --- composer.json | 20 ++++ src/Elvendor/Imgjss/ImgjssServiceProvider.php | 106 ++++++++++++++++++ src/config/config.php | 11 ++ 3 files changed, 137 insertions(+) create mode 100755 composer.json create mode 100755 src/Elvendor/Imgjss/ImgjssServiceProvider.php create mode 100755 src/config/config.php diff --git a/composer.json b/composer.json new file mode 100755 index 0000000..666feb7 --- /dev/null +++ b/composer.json @@ -0,0 +1,20 @@ +{ + "name": "elvendor/imgjss", + "description": "", + "authors": [ + { + "name": "Elvendod", + "email": "bayram4ik@gmail.com" + } + ], + "require": { + "php": ">=5.4.0", + "illuminate/support": "4.2.*" + }, + "autoload": { + "psr-0": { + "Elvendor\\Imgjss\\": "src/" + } + }, + "minimum-stability": "stable" +} diff --git a/src/Elvendor/Imgjss/ImgjssServiceProvider.php b/src/Elvendor/Imgjss/ImgjssServiceProvider.php new file mode 100755 index 0000000..631641f --- /dev/null +++ b/src/Elvendor/Imgjss/ImgjssServiceProvider.php @@ -0,0 +1,106 @@ +package('elvendor/imgjss'); + + $app = $this->app; + $blade = $app['blade.compiler']; + $html = $app['html']; + + $html->macro('css', function($path, $attrs = [], $timestamp = null, $secure = null) use($app) + { + return $app['html']->style($this->process($path, '.css', $timestamp), $attrs, $secure); + }); + + $html->macro('js', function($path, $attrs = [], $timestamp = null, $secure = null) use($app) + { + return $app['html']->script($this->process($path, '.js', $timestamp), $attrs, $secure); + }); + + $html->macro('img', function($path, $attrs = [], $timestamp = null, $secure = null) use($app) + { + return $app['html']->image($this->process($path, null, $timestamp), @$attrs['alt'] ? $attrs['alt'] : null, $attrs, $secure); + }); + + $blade->extend(function($view) use($html) + { + return preg_replace("/@css(.*)/", "", $view); + }); + + $blade->extend(function($view) use($html) + { + return preg_replace("/@js(.*)/", "", $view); + }); + + $blade->extend(function($view) use($html) + { + return preg_replace("/@img(.*)/", "", $view); + }); + + } + + public function process($path, $ext = null, $timestamp = null) + { + + $app = $this->app; + $config = $app['config']->get('imgjss::config'); + + if($ext !== null && $ext !== strrchr($path, ".")) + { + $path .= $ext; + } + + // Get the full path to the asset. + $absolutePath = public_path($path); + + if (!file_exists($absolutePath)) + { + throw new NotFoundHttpException('Asset not found: ' . $path); + } + + $timestamp = !is_null($timestamp) ? $timestamp : $config['timestamp']; + + return $timestamp ? $path . $config['qstring'] . filemtime($absolutePath) : $path; + + } + + /** + * Register the service provider. + * + * @return void + */ + public function register() + { + // + } + + /** + * Get the services provided by the provider. + * + * @return array + */ + public function provides() + { + return array(); + } + +} diff --git a/src/config/config.php b/src/config/config.php new file mode 100755 index 0000000..fdf0099 --- /dev/null +++ b/src/config/config.php @@ -0,0 +1,11 @@ + false, + + 'qstring' => '?t=' +]; \ No newline at end of file