Skip to content
This repository has been archived by the owner on Jun 25, 2018. It is now read-only.

Commit

Permalink
test with grunt
Browse files Browse the repository at this point in the history
  • Loading branch information
romainnorberg committed Apr 29, 2016
1 parent 5696de3 commit 2f95e70
Show file tree
Hide file tree
Showing 57 changed files with 6,359 additions and 406 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@
/node_modules
/web/vendor

**/.sass-cache/*

app/config/_set_env_vars.php
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ php:
- 7.0

before_script:
- gem install sass
- cp app/config/parameters.yml.dist app/config/parameters.yml
- composer install
- npm install -g bower
Expand Down
209 changes: 105 additions & 104 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,110 +1,111 @@
// Gruntfile.js
module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-symlink');
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-uglify');

// Création du répertoire d'image pour l'application s'il n'existe pas.
grunt.file.mkdir('app/Resources/public/images/');

// properties are css files
// values are less files
var filesLess = {};

// Configuration du projet
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),

// Définition de la tache 'less'
// https://github.com/gruntjs/grunt-contrib-less
less: {
bundles: {
options: {
compress: true,
yuicompress: true,
optimization: 2
grunt.initConfig({
// Définition de la tache 'symlink'
// https://github.com/gruntjs/grunt-contrib-symlink
symlink: {
// app/Resources/public/ doit être disponible via web/bundles/app/
app: {
dest: 'web/bundles/app',
relativeSrc: '../../app/Resources/public/',
options: {type: 'dir'}
}
},
files: filesLess
}
},
// Définition de la tache 'symlink'
// https://github.com/gruntjs/grunt-contrib-symlink
symlink: {
// app/Resources/public/ doit être disponible via web/bundles/app/
app: {
dest: 'web/bundles/app',
relativeSrc: '../../app/Resources/public/',
options: {type: 'dir'}
}
},
concat: {
dist: {
src: [
'web/vendor/jquery/dist/jquery.js',
'web/vendor/bootstrap/js/transition.js',
'web/vendor/bootstrap/js/alert.js',
'web/vendor/bootstrap/js/modal.js',
'web/vendor/bootstrap/js/dropdown.js',
'web/vendor/bootstrap/js/scrollspy.js',
'web/vendor/bootstrap/js/tab.js',
'web/vendor/bootstrap/js/tooltip.js',
'web/vendor/bootstrap/js/popover.js',
'web/vendor/bootstrap/js/button.js',
'web/vendor/bootstrap/js/collapse.js',
'web/vendor/bootstrap/js/carousel.js',
'web/vendor/bootstrap/js/typeahead.js',
'web/vendor/bootstrap/js/affix.js',
'web/bundles/app/js/main.js'
],
dest: 'web/built/app/js/main.js'
}
},
// Lorsque l'on modifie des fichiers LESS, il faut relancer la tache 'css'
// Lorsque l'on modifie des fichiers JS, il faut relancer la tache 'javascript'
watch: {
css: {
files: ['web/bundles/*/less/*.less'],
tasks: ['css']
},
javascript: {
files: ['web/bundles/app/js/*.js'],
tasks: ['javascript']
}
},
uglify: {
dist: {
files: {
'web/built/app/js/main.min.js': ['web/built/app/js/main.js']
}
}
}
});

// Default task(s).
grunt.registerTask('default', ['css', 'javascript']);
grunt.registerTask('css', ['less:discovering', 'less']);
grunt.registerTask('javascript', ['concat', 'uglify']);
grunt.registerTask('assets:install', ['symlink']);
grunt.registerTask('deploy', ['assets:install', 'default']);
grunt.registerTask('less:discovering', 'This is a function', function() {
// LESS Files management
// Source LESS files are located inside : bundles/[bundle]/less/
// Destination CSS files are located inside : built/[bundle]/css/
var mappingFileLess = grunt.file.expandMapping(
['*/less/*.less', '*/less/*/*.less'],
'web/built/', {
cwd: 'web/bundles/',
rename: function(dest, matchedSrcPath, options) {
return dest + matchedSrcPath.replace(/less/g, 'css');
sass: {
// this is the "production" Sass config used with the "grunt buildcss" command
dist: {
options: {
style: 'compressed',
loadPath: 'web/vendor/bootstrap-sass/assets/stylesheets'
},
files: {
'web/built/app/css/main.css': 'web/bundles/app/scss/main.sass'
}
}
},
coffee: {
compile: {
options: {
join: true
},
files: {
'web/bundles/tmp/main.js': ['web/bundles/app/coffee/*.coffee']
}
}
},
// configure the "grunt watch" task
watch: {
sass: {
files: 'web/bundles/app/scss/*.sass',
tasks: ['buildcss']
},
coffee: {
files: 'web/bundles/app/coffee/*.coffee',
tasks: ['buildjs']
}
},
// concat
concat: {
js: {
src: [
'web/vendor/jquery/dist/jquery.js',
'web/vendor/bootstrap-sass/assets/javascripts/bootstrap/transition.js',
'web/vendor/bootstrap-sass/assets/javascripts/bootstrap/alert.js',
'web/vendor/bootstrap-sass/assets/javascripts/bootstrap/modal.js',
'web/vendor/bootstrap-sass/assets/javascripts/bootstrap/dropdown.js',
'web/vendor/bootstrap-sass/assets/javascripts/bootstrap/scrollspy.js',
'web/vendor/bootstrap-sass/assets/javascripts/bootstrap/tab.js',
'web/vendor/bootstrap-sass/assets/javascripts/bootstrap/tooltip.js',
'web/vendor/bootstrap-sass/assets/javascripts/bootstrap/popover.js',
'web/vendor/bootstrap-sass/assets/javascripts/bootstrap/button.js',
'web/vendor/bootstrap-sass/assets/javascripts/bootstrap/collapse.js',
'web/vendor/bootstrap-sass/assets/javascripts/bootstrap/carousel.js',
'web/vendor/bootstrap-sass/assets/javascripts/bootstrap/typeahead.js',
'web/vendor/bootstrap-sass/assets/javascripts/bootstrap/affix.js',
'web/vendor/photoswipe/dist/photoswipe.js',
'web/bundles/tmp/modernizr-custom.js',
'web/bundles/tmp/main.js'
],
dest: 'web/built/app/js/main.js'
},
css: {
src: [
'web/built/app/css/main.css',
'web/vendor/photoswipe/dist/photoswipe.css'
],
dest: 'web/built/app/css/main.min.css'
}
},
// minify
uglify: {
dist: {
files: {
'web/built/app/js/main.min.js': ['web/built/app/js/main.js']
}
}
},
modernizr: {
dist: {
"dest" : "web/bundles/tmp/modernizr-custom.js",
"crawl" : false,
"options": [
"setClasses"
],
"uglify": true,
"tests" : ['svg']
}
}
});

grunt.util._.each(mappingFileLess, function(value) {
// Why value.src is an array ??
filesLess[value.dest] = value.src[0];
});
});

grunt.loadNpmTasks('grunt-symlink');
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-contrib-coffee');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks("grunt-modernizr");

grunt.registerTask('default', ['buildcss', 'buildjs']);
grunt.registerTask('buildcss', ['sass:dist', 'concat:css']);
grunt.registerTask('buildjs', ['modernizr:dist', 'coffee:compile', 'concat:js', 'uglify']);
grunt.registerTask('assets:install', ['symlink']);
};
3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
],
"dependencies": {
"jquery": "2.1.3",
"bootstrap": "3.3.5"
"bootstrap-sass": "3.3.1",
"photoswipe": "4.1.1"
}
}
16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
"author": "Romain Norberg <romainnorberg@gmail.com>",
"private": true,
"dependencies": {
"grunt": "~0.4.1",
"grunt-contrib-less": "~0.6.1",
"grunt-contrib-concat": "~0.3.0",
"grunt-contrib-watch": "~0.4.4",
"grunt": "0.4.5",
"grunt-contrib-sass": "~0.8.1",
"grunt-contrib-coffee": "~1.0.0",
"grunt-contrib-watch": "~0.6.1",
"grunt-contrib-concat": "~1.0.1",
"grunt-symlink": "~0.4.0",
"grunt-contrib-jshint": "~0.6.0",
"grunt-contrib-uglify": "~0.2.2"
}
"grunt-contrib-uglify": "~0.2.2",
"grunt-modernizr": "~1.0.2"
},
"devDependencies": {}
}
34 changes: 34 additions & 0 deletions src/AppBundle/Resources/public/coffee/construct-tim.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# default

$(document).ready ->

# svg fallback
if !Modernizr.svg
imgs = $('img[data-fallback]')
imgs.attr 'src', imgs.data('fallback')

# svg replace
jQuery('img.svg-replace').each ->
$img = jQuery(this)
imgID = $img.attr('id')
imgClass = $img.attr('class')
imgURL = $img.attr('src')
jQuery.get imgURL, ((data) ->
# Get the SVG tag, ignore the rest
$svg = jQuery(data).find('svg')
# Add replaced image's ID to the new SVG
if typeof imgID != 'undefined'
$svg = $svg.attr('id', imgID)
# Add replaced image's classes to the new SVG
if typeof imgClass != 'undefined'
$svg = $svg.attr('class', imgClass + ' replaced-svg')
# Remove any invalid XML tags as per http://validator.w3.org
$svg = $svg.removeAttr('xmlns:a')
# Replace image with new SVG
$btn = jQuery "<div class='replaced-svg-container'>"
$btn.append $svg
$img.parent().prepend $btn
$img.hide()
return
), 'xml'
return
Loading

0 comments on commit 2f95e70

Please sign in to comment.