Skip to content

Commit 99ffdc7

Browse files
committed
switch from Assetic to gulp
1 parent 7de08b5 commit 99ffdc7

20 files changed

+232
-57
lines changed

.bowerrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"directory": "vendor/bower_components"
3+
}

.gitignore

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
vendor/
22
node_modules/
3-
src/config/parameters.yml
3+
src/App/Resources/config/parameters.yml
4+
src/App/Resources/assets/rev-manifest.json
45
ansible/inventories/*
56
ansible/inventories/group_vars/*
7+
/web/css
8+
/web/js
9+
/web/font

ansible/roles/app/tasks/main.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
- name: Run NPM
77
sudo: false
88
shell: /usr/bin/npm install chdir={{ project_root }}
9+
- name: Run bower
10+
sudo: false
11+
shell: /usr/local/bin/bower install chdir={{ project_root }}
912
- name: Copy parameters.yml file
1013
sudo: false
11-
template: src=parameters.tpl dest={{project_root}}/src/config/parameters.yml mode=644
14+
template: src=parameters.tpl dest={{project_root}}/src/App/Resources/config/parameters.yml mode=644

bower.json

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "bicpi-homepage",
3+
"version": "0.0.0",
4+
"authors": [
5+
"Philipp Rieber <[email protected]>"
6+
],
7+
"dependencies": {
8+
"jquery": "~1.9.1",
9+
"font-awesome": "~3.2.1",
10+
"bootstrap-sass": "v2.3.2.2"
11+
}
12+
}

dump-assets

-36
This file was deleted.

gulpfile.js

+132
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
var gulp = require('gulp');
2+
var plugins = require('gulp-load-plugins')();
3+
var del = require('del');
4+
var Q = require('q');
5+
6+
var config = {
7+
assetsDir: 'src/App/Resources/assets',
8+
sassPattern: '**/*.scss',
9+
production: !!plugins.util.env.production,
10+
sourceMaps: !plugins.util.env.production,
11+
bowerDir: 'vendor/bower_components',
12+
revManifestPath: 'src/App/Resources/assets/rev-manifest.json'
13+
};
14+
var app = {};
15+
16+
app.addStyle = function(paths, outputFilename) {
17+
return gulp.src(paths)
18+
.pipe(plugins.plumber())
19+
.pipe(plugins.if(config.sourceMaps, plugins.sourcemaps.init()))
20+
.pipe(plugins.sass())
21+
.pipe(plugins.concat('css/'+outputFilename))
22+
.pipe(config.production ? plugins.minifyCss() : plugins.util.noop())
23+
.pipe(plugins.rev())
24+
.pipe(plugins.if(config.sourceMaps, plugins.sourcemaps.write('.')))
25+
.pipe(gulp.dest('web'))
26+
// write the rev-manifest.json file for gulp-rev
27+
.pipe(plugins.rev.manifest(config.revManifestPath, {
28+
merge: true
29+
}))
30+
.pipe(gulp.dest('.'));
31+
};
32+
33+
app.addScript = function(paths, outputFilename) {
34+
return gulp.src(paths)
35+
.pipe(plugins.plumber())
36+
.pipe(plugins.if(config.sourceMaps, plugins.sourcemaps.init()))
37+
.pipe(plugins.concat('js/'+outputFilename))
38+
.pipe(config.production ? plugins.uglify() : plugins.util.noop())
39+
.pipe(plugins.rev())
40+
.pipe(plugins.if(config.sourceMaps, plugins.sourcemaps.write('.')))
41+
.pipe(gulp.dest('web'))
42+
// write the rev-manifest.json file for gulp-rev
43+
.pipe(plugins.rev.manifest(config.revManifestPath, {
44+
merge: true
45+
}))
46+
.pipe(gulp.dest('.'));
47+
};
48+
49+
app.copy = function(srcFiles, outputDir) {
50+
return gulp.src(srcFiles)
51+
.pipe(gulp.dest(outputDir));
52+
};
53+
54+
var Pipeline = function() {
55+
this.entries = [];
56+
};
57+
Pipeline.prototype.add = function() {
58+
this.entries.push(arguments);
59+
};
60+
61+
Pipeline.prototype.run = function(callable) {
62+
var deferred = Q.defer();
63+
var i = 0;
64+
var entries = this.entries;
65+
66+
var runNextEntry = function() {
67+
// see if we're all done looping
68+
if (typeof entries[i] === 'undefined') {
69+
deferred.resolve();
70+
return;
71+
}
72+
73+
// pass app as this, though we should avoid using "this"
74+
// in those functions anyways
75+
callable.apply(app, entries[i]).on('end', function() {
76+
i++;
77+
runNextEntry();
78+
});
79+
};
80+
runNextEntry();
81+
82+
return deferred.promise;
83+
};
84+
85+
gulp.task('styles', function() {
86+
var pipeline = new Pipeline();
87+
88+
pipeline.add([
89+
config.assetsDir+'/css/bootstrap.less',
90+
config.bowerDir+'/font-awesome/css/font-awesome.css',
91+
config.assetsDir+'/css/styles.scss'
92+
], 'main.css');
93+
94+
// pipeline.add([
95+
// config.assetsDir+'/sass/dinosaur.scss'
96+
// ], 'dinosaur.css');
97+
98+
return pipeline.run(app.addStyle);
99+
});
100+
101+
gulp.task('scripts', function() {
102+
var pipeline = new Pipeline();
103+
104+
pipeline.add([
105+
config.bowerDir+'/jquery/jquery.js',
106+
config.assetsDir+'/js/bootstrap.min.js',
107+
config.assetsDir+'/js/main.js'
108+
], 'site.js');
109+
110+
return pipeline.run(app.addScript);
111+
});
112+
113+
gulp.task('fonts', function() {
114+
return app.copy(
115+
config.bowerDir+'/font-awesome/font/*',
116+
'web/font'
117+
);
118+
});
119+
120+
gulp.task('clean', function() {
121+
del.sync(config.revManifestPath);
122+
del.sync('web/css/*');
123+
del.sync('web/js/*');
124+
del.sync('web/fonts/*');
125+
});
126+
127+
gulp.task('watch', function() {
128+
gulp.watch(config.assetsDir+'/'+config.sassPattern, ['styles']);
129+
gulp.watch(config.assetsDir+'/js/**/*.js', ['scripts']);
130+
});
131+
132+
gulp.task('default', ['clean', 'styles', 'scripts', 'fonts', 'watch']);

package.json

+14-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
{
22
"name": "bicpi-homepage",
33
"description": "The bicpi homepage",
4-
"dependencies": {
5-
"uglify-js2": "*",
6-
"uglifycss": "*",
7-
"less": "<2.0.0"
4+
"devDependencies": {
5+
"del": "^1.1.1",
6+
"gulp": "^3.8.11",
7+
"gulp-concat": "^2.5.2",
8+
"gulp-if": "^1.2.5",
9+
"gulp-load-plugins": "^0.8.1",
10+
"gulp-minify-css": "^0.5.1",
11+
"gulp-plumber": "^1.0.0",
12+
"gulp-rev": "^3.0.1",
13+
"gulp-sass": "^1.3.3",
14+
"gulp-sourcemaps": "^1.5.0",
15+
"gulp-uglify": "^1.1.0",
16+
"gulp-util": "^3.0.4",
17+
"q": "^1.2.0"
818
}
919
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/* import bootstrap components from bootstrap-dedicated folder */
2+
@import "../../../vendor/bower_components/bootstrap-sass/vendor/assets/stylesheets/bootstrap";
3+
@import "../../../vendor/bower_components/bootstrap-sass/vendor/assets/stylesheets/bootstrap-responsive";
4+
5+
/* custom settings that deviate from Bootstrap's default values */
6+
$sansFontFamily: "Trebuchet MS", Tahoma, sans-serif, Arial;
7+
$baseLineHeight: 18px;
8+
$navbarBackground: #E9F2F9;
9+
$navbarText: #407AB1;
10+
$navbarLinkColor: #407AB1;
11+
$heroUnitBackground: #BEDCF4;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/views/home.twig src/App/Resources/views/home.twig

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<link rel="apple-touch-icon-precomposed" href="http://philipp-rieber.net/apple-touch-icon-precomposed.png" />
1515
<link type="text/plain" rel="author" href="/humans.txt">
1616
<link href="/all.css" rel="stylesheet">
17+
<link href="{{ 'css/main.css'|asset_version }}" rel="stylesheet">
1718
<link rel="shortcut icon" href="/favicon.ico" type="image/ico">
1819
<!--[if lt IE 9]>
1920
<script src="html5shiv.js"></script>
@@ -296,7 +297,7 @@
296297
</div>
297298
</footer>
298299

299-
<script src="/all.js"></script>
300+
<script src="{{ 'js/site.js'|asset_version }}"></script>
300301
<script type="text/javascript">
301302
var _gaq = _gaq || [];
302303
_gaq.push(['_setAccount', 'UA-19245446-3']);
File renamed without changes.
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace App\Twig;
4+
5+
class AssetVersionExtension extends \Twig_Extension
6+
{
7+
private $appDir;
8+
9+
public function __construct($appDir)
10+
{
11+
$this->appDir = $appDir;
12+
}
13+
14+
public function getFilters()
15+
{
16+
return array(
17+
new \Twig_SimpleFilter('asset_version', array($this, 'getAssetVersion')),
18+
);
19+
}
20+
21+
public function getAssetVersion($filename)
22+
{
23+
$manifestPath = $this->appDir.'/Resources/assets/rev-manifest.json';
24+
if (!file_exists($manifestPath)) {
25+
throw new \Exception(sprintf('Cannot find manifest file: "%s"', $manifestPath));
26+
}
27+
28+
$paths = json_decode(file_get_contents($manifestPath), true);
29+
if (!isset($paths[$filename])) {
30+
throw new \Exception(sprintf('There is no file "%s" in the version manifest!', $filename));
31+
}
32+
33+
return $paths[$filename];
34+
}
35+
36+
public function getName()
37+
{
38+
return 'asset_version';
39+
}
40+
}

src/assets/css/bootstrap.less

-11
This file was deleted.

web/index.php

+9-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Symfony\Component\Yaml\Yaml;
66
use Gregwar\Captcha\CaptchaBuilder;
7+
use App\Twig\AssetVersionExtension;
78

89
function shuffle_assoc(&$array) {
910
$keys = array_keys($array);
@@ -20,7 +21,7 @@ function shuffle_assoc(&$array) {
2021
}
2122

2223
$app = new Silex\Application();
23-
$app['parameters'] = Yaml::parse(__DIR__.'/../src/config/parameters.yml');
24+
$app['parameters'] = Yaml::parse(__DIR__.'/../src/App/Resources/config/parameters.yml');
2425
$app['debug'] = $app['parameters']['debug'];
2526
if ($app['debug']) {
2627
ini_set('display_errors', true);
@@ -30,10 +31,15 @@ function shuffle_assoc(&$array) {
3031
$app->register(
3132
new Silex\Provider\TwigServiceProvider(),
3233
array(
33-
'twig.path' => dirname(__DIR__) . '/src/views',
34+
'twig.path' => dirname(__DIR__) . '/src/App/Resources/views',
3435
'twig.form.templates' => array('form_div_layout.html.twig', 'form_layout.twig')
3536
)
3637
);
38+
$app['twig'] = $app->extend("twig", function (\Twig_Environment $twig, Silex\Application $app) {
39+
$twig->addExtension(new AssetVersionExtension(dirname(__DIR__) . '/src/App'));
40+
41+
return $twig;
42+
});
3743
$app->register(new Silex\Provider\SwiftmailerServiceProvider(), array(
3844
'swiftmailer.options' => array(
3945
'host' => $app['parameters']['mailer_host'],
@@ -156,7 +162,7 @@ function (Symfony\Component\HttpFoundation\Request $request) use ($app) {
156162
}
157163
}
158164

159-
$skillsRaw = \Symfony\Component\Yaml\Yaml::parse(dirname(__DIR__).'/src/config/skills.yml');
165+
$skillsRaw = \Symfony\Component\Yaml\Yaml::parse(dirname(__DIR__).'/src/App/Resources/config/skills.yml');
160166
$skills = array();
161167
foreach ($skillsRaw as $weight => $skillGroup) {
162168
foreach ($skillGroup as $skill) {

0 commit comments

Comments
 (0)