Skip to content

Commit

Permalink
edit manager for my project.
Browse files Browse the repository at this point in the history
  • Loading branch information
HyanCat committed Nov 28, 2014
1 parent 228c690 commit a37dd7e
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 22 deletions.
79 changes: 58 additions & 21 deletions src/Modbase/AssetManager/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use \Illuminate\Filesystem\Filesystem as Filesystem;
use \Illuminate\Support\Facades\Config as Config;
use \Illuminate\Support\Facades\HTML;

class Manager {

Expand Down Expand Up @@ -29,49 +30,85 @@ public function __construct(Filesystem $files)
}

/**
* Get HTML for all stylesheets of the bundle
*
* @param string $bundle
* @return string
* Get HTML for stylesheet of the bundle
*
*@param $bundle
* @param string $folder
* @param array $option ['index' => 0, 'name'=>'style.name']
* Important: name should not contain '-'.
*
* @return string stylesheet html
*/
public function styles($bundle)
public function styles($bundle, $folder = 'css', $option = ['index' => 0])
{
// If we didn't parse the file before, then do it now
if (!$this->data)
{
$this->parseVersionsFile();
}

// Create link tags for all stylesheets
foreach ($this->data[$bundle.'.styles'] as $style)
{
$styles[] = '<link rel="stylesheet" href="/css/'.$style.'" />'.PHP_EOL;
// Parser style file with bundle
$style = '';
if (array_key_exists('index', $option)) {
$index = intval($option['index']);
$filename = $this->data[$bundle.'.styles'][$index];
$style = HTML::style($folder.'/'.$filename);
}
else if (array_key_exists('name', $option)) {
$name = strval($option['name']);
foreach ($this->data[$bundle.'.styles'] as $filename) {
$pieces = explode('-', $filename);
if ($name == $pieces[0]) {
$style = HTML::style($folder.'/'.$filename);
break;
}
}
}
else {
$style = HTML::style($folder.'/'.$this->data[$bundle.'.styles'][0]);
}

return join(PHP_EOL, $styles);
return $style.PHP_EOL;
}

/**
* Get HTML for all JavaScripts of the bundle
*
* @param string $bundle
* @return string
* Get HTML for javascript of the bundle
* @param $bundle
* @param string $folder
* @param array $option ['index' => 0, 'name'=>'script.name']
* Important: name should not contain '-'.
*
* @return string javascript html
*/
public function scripts($bundle)
public function scripts($bundle, $folder = 'css', $option = ['index' => 0])
{
// If we didn't parse the file before, then do it now
if (!$this->data)
{
$this->parseVersionsFile();
}

// Create script tags for all JavaScripts
foreach ($this->data[$bundle.'.scripts'] as $script)
{
$scripts[] = '<script src="/js/'.$script.'"></script>'.PHP_EOL;
// Parser script file with bundle
$script = '';
if (array_key_exists('index', $option)) {
$index = intval($option['index']);
$filename = $this->data[$bundle.'.scripts'][$index];
$script = HTML::script($folder.'/'.$filename);
}
else if (array_key_exists('name', $option)) {
$name = strval($option['name']);
foreach ($this->data[$bundle.'.styles'] as $filename) {
$pieces = explode('-', $filename);
if ($name == $pieces[0]) {
$script = HTML::script($folder.'/'.$filename);
break;
}
}
}
else {
$script = HTML::script($folder.'/'.$this->data[$bundle.'.scripts'][0]);
}

return join(PHP_EOL, $scripts);
return $script.PHP_EOL;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/config/config.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php

return [
'file' => 'assets.json',
'file' => 'asset_manifest.json',
];

0 comments on commit a37dd7e

Please sign in to comment.