37
Enhancing OpenCms front end development with Sass and Grunt OpenCms Days November 3, 2014

OpenCms Days 2014 - Enhancing OpenCms front end development with Sass and Grunt

Embed Size (px)

Citation preview

Page 1: OpenCms Days 2014 - Enhancing OpenCms front end development with Sass and Grunt

Enhancing OpenCmsfront end developmentwith Sass and Grunt

OpenCms DaysNovember 3, 2014

Page 2: OpenCms Days 2014 - Enhancing OpenCms front end development with Sass and Grunt

Our goals

● Edit and compile Sass files directly in VFS

● Integrate Grunt Js

● Build a plug & play solution

Page 3: OpenCms Days 2014 - Enhancing OpenCms front end development with Sass and Grunt

Nesting

● Nest selectors within a parent selector

● Clear and organized code

● Code faster

Page 4: OpenCms Days 2014 - Enhancing OpenCms front end development with Sass and Grunt

Overview

● Short introduction to Sass

● What is Grunt js

● Our implementation: Glide

Page 5: OpenCms Days 2014 - Enhancing OpenCms front end development with Sass and Grunt

What is Sass

● Syntactically Awesome Style Sheet

● adds functionality to CSS

● CSS-like syntax

● Sass compiles to CSS

Page 6: OpenCms Days 2014 - Enhancing OpenCms front end development with Sass and Grunt

Nesting

Page 7: OpenCms Days 2014 - Enhancing OpenCms front end development with Sass and Grunt

Variables

● Only define a value once

● Easy maintenance

● Reusable code for modules

Page 8: OpenCms Days 2014 - Enhancing OpenCms front end development with Sass and Grunt

Variables

Page 9: OpenCms Days 2014 - Enhancing OpenCms front end development with Sass and Grunt

Colors in SASS

● Automatic conversion of hex to RGBA

● Functions on color:

darken and lighten, saturate, desaturate, fade, adjust the hue, inverted, complementary colors, mix colors, shade and tint

Page 10: OpenCms Days 2014 - Enhancing OpenCms front end development with Sass and Grunt

Colors in SASS

Page 11: OpenCms Days 2014 - Enhancing OpenCms front end development with Sass and Grunt

Extend

● Inherit style from another class

● Create placeholder style

● Keep code clean

Page 12: OpenCms Days 2014 - Enhancing OpenCms front end development with Sass and Grunt

Extend

Page 13: OpenCms Days 2014 - Enhancing OpenCms front end development with Sass and Grunt

mixin

● Functions that output CSS

● Similar to javascript

● Create a personal library

Page 14: OpenCms Days 2014 - Enhancing OpenCms front end development with Sass and Grunt

mixin

Page 15: OpenCms Days 2014 - Enhancing OpenCms front end development with Sass and Grunt

mixin

Page 16: OpenCms Days 2014 - Enhancing OpenCms front end development with Sass and Grunt

mixin

Page 17: OpenCms Days 2014 - Enhancing OpenCms front end development with Sass and Grunt

mixin

Page 18: OpenCms Days 2014 - Enhancing OpenCms front end development with Sass and Grunt

..and there is more!

● Control directives

if/else for while each

● Math operations

Page 19: OpenCms Days 2014 - Enhancing OpenCms front end development with Sass and Grunt

..and there is more!

Page 20: OpenCms Days 2014 - Enhancing OpenCms front end development with Sass and Grunt

..and there is more!

Page 21: OpenCms Days 2014 - Enhancing OpenCms front end development with Sass and Grunt

Compass

● Framework on the top of Sass

● Pre-built mixins

● Great for cross browser css3 support

Page 22: OpenCms Days 2014 - Enhancing OpenCms front end development with Sass and Grunt

Grunt

Grunt is a task runner that allows the automation of mundane development work

Page 23: OpenCms Days 2014 - Enhancing OpenCms front end development with Sass and Grunt

Why Grunt

● from simple workflow enhancements, to

complete production build systems

● active plugin development community

(~3600 plugins)

Page 24: OpenCms Days 2014 - Enhancing OpenCms front end development with Sass and Grunt

Automation in grunt

● Watch .scss, jsp and js

● Compile sass/compass

● Minify css for online project

● Minify javascript

● Auto publish

● Livereload

Page 25: OpenCms Days 2014 - Enhancing OpenCms front end development with Sass and Grunt

live reload

● Wait

● Concentrate

● Save time

Page 26: OpenCms Days 2014 - Enhancing OpenCms front end development with Sass and Grunt

Demo: extreme livereload

Page 27: OpenCms Days 2014 - Enhancing OpenCms front end development with Sass and Grunt

Glide

Page 28: OpenCms Days 2014 - Enhancing OpenCms front end development with Sass and Grunt

Demo: Glide in action

Page 29: OpenCms Days 2014 - Enhancing OpenCms front end development with Sass and Grunt

Overview 2nd part

● Glide implementation

● Configuration

● Installation: OpenCms 9 demo website

Page 30: OpenCms Days 2014 - Enhancing OpenCms front end development with Sass and Grunt

Glide implementation

● Grunt Process runs in a dedicated thread

● A pointer is stored in the ServletContext

● All users share a single Grunt instance

● Only members of the authorized group see and interact with Glide

● All the Java code is in a JSP for quick customization

Page 31: OpenCms Days 2014 - Enhancing OpenCms front end development with Sass and Grunt

Grunt optimization

● Sass cache files are stored outside the OpenCms VFS

● Configuration file is parameterized

● Required node packages are already bundled

● No symlinks as they're not supported by network shared folder

Page 32: OpenCms Days 2014 - Enhancing OpenCms front end development with Sass and Grunt

Server requirements

● Install Node and Compass

● Mount OpenCms network share

● Open port for livereload

users don't have to install anything on their workstations

Page 33: OpenCms Days 2014 - Enhancing OpenCms front end development with Sass and Grunt

OpenCms Module requirements

Page 34: OpenCms Days 2014 - Enhancing OpenCms front end development with Sass and Grunt

Configuration

Page 35: OpenCms Days 2014 - Enhancing OpenCms front end development with Sass and Grunt

Demo: installation in the 9.0.1 demo site

● drag & drop in an element group (the footer)

● configure Glide

● restart Grunt so it watches the new module

● change a formatter (e.g. Jumbotron)

● create Sass and JS files

Page 36: OpenCms Days 2014 - Enhancing OpenCms front end development with Sass and Grunt

Download Glide

www.opencmsitalia.it/glide

● main module

● demo site

Page 37: OpenCms Days 2014 - Enhancing OpenCms front end development with Sass and Grunt

Thanks!Alessandro Magnolo & Marco Rho

contact us at [email protected]