Skip to content

Commit

Permalink
Initial version
Browse files Browse the repository at this point in the history
  • Loading branch information
Stijn Geselle committed Feb 9, 2014
0 parents commit ae4109d
Show file tree
Hide file tree
Showing 11 changed files with 235 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Auto detect text files and perform LF normalization
* text=auto

# Custom for Visual Studio
*.cs diff=csharp
*.sln merge=union
*.csproj merge=union
*.vbproj merge=union
*.fsproj merge=union
*.dbproj merge=union

# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/vendor
composer.phar
composer.lock
.DS_Store
12 changes: 12 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
language: php

php:
- 5.3
- 5.4
- 5.5

before_script:
- curl -s http://getcomposer.org/installer | php
- php composer.phar install --dev

script: phpunit
21 changes: 21 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "modbase/asset-manager",
"description": "A very basic asset manager to be used in combination with versioned assets.",
"license": "MIT",
"authors": [
{
"name": "Stijn Geselle",
"email": "[email protected]"
}
],
"require": {
"php": ">=5.3.0",
"illuminate/support": "4.1.*"
},
"autoload": {
"psr-0": {
"Modbase\\AssetManager\\": "src/"
}
},
"minimum-stability": "stable"
}
18 changes: 18 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
>
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix=".php">./tests/</directory>
</testsuite>
</testsuites>
</phpunit>
43 changes: 43 additions & 0 deletions src/Modbase/AssetManager/AssetManagerServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php namespace Modbase\AssetManager;

use Illuminate\Support\ServiceProvider;

class AssetManagerServiceProvider extends ServiceProvider {

/**
* Bootstrap the application events.
*
* @return void
*/
public function boot()
{
$this->package('modbase/asset-manager');
}

/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->app->singleton('modbase.asset', 'Modbase\AssetManager\Manager');

$this->app->booting(function()
{
$loader = \Illuminate\Foundation\AliasLoader::getInstance();
$loader->alias('Asset', 'Modbase\AssetManager\Facade\Asset');
});
}

/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return array('modbase.asset');
}

}
14 changes: 14 additions & 0 deletions src/Modbase/AssetManager/Facade/Asset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php namespace Modbase\AssetManager\Facade;

use Illuminate\Support\Facades\Facade;

class Asset extends Facade {

/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor() { return 'modbase.asset'; }

}
96 changes: 96 additions & 0 deletions src/Modbase/AssetManager/Manager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php namespace Modbase\AssetManager;

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

class Manager {

/**
* Decoded contents of the JSON file
*
* @var array
*/
protected $data;

/**
* @var \Illuminate\Filesystem\Filesystem
*/
protected $files;

/**
* Create a new manager
*
* @param \Illuminate\Filesystem\Filesystem $files
* @return void
*/
public function __construct(Filesystem $files)
{
$this->files = $files;
}

/**
* Get HTML for all stylesheets of the bundle
*
* @param string $bundle
* @return string
*/
public function styles($bundle)
{
// 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;
}

return join(PHP_EOL, $styles);
}

/**
* Get HTML for all JavaScripts of the bundle
*
* @param string $bundle
* @return string
*/
public function scripts($bundle)
{
// 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;
}

return join(PHP_EOL, $scripts);
}

/**
* Get the assets file and contents.
*
* @return array
*/
protected function getVersionsFile()
{
return $this->files->get(base_path().'/'.Config::get('asset-manager::config.file'));
}

/**
* JSON decode the assets file
*
* @return array
*/
protected function parseVersionsFile()
{
$this->data = json_decode($this->getVersionsFile(), true);
}
}
Empty file added src/config/.gitkeep
Empty file.
5 changes: 5 additions & 0 deletions src/config/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

return [
'file' => 'assets.json',
];
Empty file added tests/.gitkeep
Empty file.

0 comments on commit ae4109d

Please sign in to comment.