Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A One Web Boilerplate for all your Responsive Web needs. Powered by Apache SSI, SMACSS, Sass and RequireJS. Also includes Ant build script with several useful tools, as well as an SSI-based fork of adactio's Pattern-Primer (https://github.com/akikoo/Pattern-Primer). For more modern test-driven workflow, see https://github.com/akikoo/grunt-fronte…

branch: master
README.md

One Web/Mobile First Responsive Boilerplate

What is it?

The One Web Front-end Boilerplate is a modular framework for building responsive websites with Apache Server Side Includes (http://httpd.apache.org/docs/2.2/howto/ssi.html), SMACSS (Scalable and Modular Architecture for CSS, http://smacss.com/), Sass preprocessor (http://sass-lang.com/), and RequireJS (http://requirejs.org/).

This boilerplate draws code from many other projects, combining various solutions into a custom, modular, and responsive front-end build framework. It's packed with goodies, building on many of the industry best practices found in the resources listed under Credits. The project also includes Ant build script that runs code quality tools against JavaScript and CSS files, minifying and concatenating them at the end of the process.

The One Web Boilerplate works well for me which is why I'm publishing it here for you to use and improve. It basically extends popular boilerplates, including 320 and Up (https://github.com/malarkey/320andup/), HTML5 Boilerplate (http://html5boilerplate.com/), Mobile Boilerplate (http://html5boilerplate.com/mobile/), ZURB Foundation (http://foundation.zurb.com/), Twitter Bootstrap (http://twitter.github.com/bootstrap/), and many others, with Server Side Includes. The framework can easily be plugged into Continuous Integration solutions, such as Jenkins: http://jenkins-ci.org.

This framework also includes a dynamic grid system called the Fluid Grid: http://akikoo.github.com/Fluid-Grid/. Sass/Compass is used by default, both in One Web Boilerplate and the Fluid Grid.

File structure

There are two main directories: /build and /webroot.

  • /build contains Ant build script and all the tools you need to make your frontend build. Common build properties are defined in /build/config/project.properties. There's also a folder called masterpage, which is used as a blueprint for creating new pages.

  • /webroot contains two subdirectories: /assets and /html.

  • /webroot/assets contains all the Sass and LESS files, stylesheets, JavaScript files and theme images.

  • /webroot/html contains all the HTML files, generated by Apache Server Side Includes. HTML properties are defined in /webroot/config.shtml.

Dev files are in /webroot/assets and /webroot/html. Optimised files are in /build/publish/assets and /build/publish/html.

Build tools

Environment setup

Apache Ant

Apache SSI

To permit SSI on your server, see this article: http://httpd.apache.org/docs/2.2/howto/ssi.html

Ruby (you need this if you use Sass/Compass)

On OS X, you'll already have Ruby installed. On Windows, see http://rubyinstaller.org/downloads/. For installing Sass, see http://sass-lang.com/tutorial.html. For installing Compass, see http://compass-style.org/install/. You should use it, it's awesome.

All the other tools needed in the local build are in the tools folder.

Build configuration

After Apache Ant, SSI, Ruby, Sass and Compass setup, you need to do two more things to configure the build:

  1. In /build/config/project.properties, look for 'web.home' in line number 124. Change the path to your local directory.
  2. In that same file, look for 'web.url' in line number 126. Create an Apache virtualhost that points to the location you defined for 'web.home' above.

If you get the "java.lang.OutOfMemoryError: PermGen space" error during the build on OS X (I did), try running this in your terminal: export ANT_OPTS=-XX:MaxPermSize=256m

You should now be up and running with both the environment and the local build.

Things you need to know

  • A CSS preprocessor, either Sass (http://sass-lang.com/), default option with Compass (http://compass-style.org/), or LESS (http://lesscss.org/) is used to compile the stylesheets. If you don't want to use a preprocessor, you can of course work with the CSS files directly. By default, it's assumed that you compile Sass or LESS files on your local machine, and let the build process do the CSSLint check on your generated CSS files. (There are tasks for Sass and LESS processing in /build/build.xml, namely <css.compile.sass /> and <css.compile.less /> macrodef calls, but they are commented out.) To compile CSS files on your local machine, type one of the following commands in the terminal (replace the '{pathtoworkingcopy}' with your local path):

    a) using Sass: sass --watch /{pathtoworkingcopy}/webroot/assets/scss:/{pathtoworkingcopy}/webroot/assets/css

    b) using Compass with Sass: compass watch /{pathtoworkingcopy}/webroot/assets

    For more info, see Sass and Compass documentation.

  • Media Queries are based on 16px default font size and defined in ems. The framework is designed to be modular so you should split the rules into logical modules, and place the styles in /webroot/assets/scss/components/modules. For more info on how to categorize your CSS, see SMACSS: http://smacss.com/.

  • JavaScript should not be relied on for layout. That's why I've adopted a bulletproof solution from Nicholas Zakas and Tantek Çelik: http://www.nczonline.net/blog/2011/03/22/using-html5-semantic-elements-today/ and http://tantek.com/presentations/2010/11/html5-now/.

  • Don't use IDs in CSS selectors. Use classes, or ARIA landmark roles instead (referenced with CSS attribute selectors). See also http://oli.jp/2011/ids/.

Logic

HTML

CSS - A number of stylesheets by default, compiled and imported by Sass, included in the following order:

  • /webroot/assets/css/common/normalize.css (third-party reset styles)
  • /webroot/assets/scss/common/elements.scss (global, mobile first styles, containing only common colour and typographic rules for basic experience to all users)
  • /webroot/assets/scss/common/utilities.scss (helper styles from HTML5 Boilerplate and HTML5 Mobile Boilerplate)
  • /webroot/assets/scss/common/base.scss (base stylesheet that imports the above mentioned three stylesheets)
  • /webroot/assets/scss/components/layout.scss (page layout rules)
  • /webroot/assets/scss/components/module.scss (module base stylesheet that imports all the modules)
  • /webroot/assets/scss/components/state.scss (state rules for layout and modules)
  • /webroot/assets/scss/components/theme.scss (theme styles)
  • /webroot/assets/scss/main.scss (layout with Media Queries for responsive, enhanced design for smartphones, tablets and larger screens)
  • /webroot/assets/scss/main-ie.scss (layout without Media Queries for legacy IE 6/7/8 browsers).

Scalable and Modular Architecture for CSS (SMACSS, http://smacss.com/) is used by default. main.scss and main-ie.scss are the main stylesheets that @import all the common styles. Note that styles are @import-ed only for development. For production, the build script inlines and minifies styles in the same order that you @import-ed them. Nice, eh? But keep in mind that you have to @import the core styles (see above) before anything else.

Remember that if you work with Sass, you should only do changes in /webroot/assets/scss/ directory, as the files in /webroot/assets/css/ will obviously be the generated ones, rewritten on each save.

New stylesheets you create should be placed in /webroot/assets/scss/components/modules. Remember to add @import rules for any new styles. After the base styles, the order in which the module stylesheets are included should't matter (you write your styles carefully, right?) The idea is that module styles inherit only from base rules, not from other modules.

config.rb file in /assets is used for passing compile options to Compass. By default you don't need to touch that file. If you want to edit it, see Compass documentation.

JavaScript

  • Third-party plugins are included in /webroot/assets/js/lib. Custom scripts are in /webroot/assets/js/modules. Dependancies are managed by RequireJS (http://requirejs.org/), a script loader that supports AMD (Asynchronous Module Definition) API. Script paths and their dependencies are defined in /webroot/assets/js/config.js. Scripts are imported in /webroot/assets/js/main.js. In the optimized script bundle, almond.js (https://github.com/jrburke/almond) is used in place of require.js, to package everything in just one script file.

Ant build process

To build your project, do the following

This assumes you've set up the build, as explained in Build configuration.

  1. Open terminal and go to /path_to_your_project/build
  2. Run ant -buildfile build.xml

The sequence of events is then as follows:

  1. Old build directory called /publish is deleted
  2. /publish directory is recreated, and build timestamps are added as text files
  3. HTML header and footer files are edited, to include minified and concatenated assets, created during the build
  4. SHTML snippets are called to generate full HTML web pages
  5. SHTML snippets are called to generate HTML modules
  6. SHTML file extensions are changed to HTML and all pages are copied to build/publish/html. Compressed HTML versions are copied to build/publish/html-compressed
  7. Component, module, page and template lists are generated, to be included in the project root index page
  8. HTML header and footer files are reverted, to include separate assets again (we'll continue developing!)
  9. CSSLint tool is run against all CSS files (however excluding third-party stylesheets)
  10. JSHint tool is run against JavaScript code (excluding third-party scripts)
  11. JSDoc documentation is created and placed in build/publish/docs/jsdocs
  12. CSS files are concatenated by inlining all @import-ed styles, producing two files: main.css and main-ie.css (one with and one without Media Queries). This way, we can keep the CSS rules separate from the actual Media Queries. Both files are then minified and placed in build/publish/assets/css.
  13. JavaScript files are minified and concatenated and placed in /build/publish/assets/js/lib (currently only Modernizr and require.js.) Note that compiled require.js contains the original require.js and all the modules, loaded with almond require/define shim.
  14. Unoptimised images are copied to /build/publish/assets/img
  15. Temporary directory that was used during the build is deleted
  16. That's it!

Congratulations! You now have a brand new /build/publish directory that has the following four directories:

  • HTML files (/build/publish/html),
  • Compressed HTML files (/build/publish/html-compressed),
  • Minified and concatenated CSS and JS files (/build/publish/assets), and
  • JSDoc documentation (/build/publish/docs/jsdocs).

You can now deploy the site using your favourite Continuous Integration server. It could be Jenkins (http://jenkins-ci.org) or Bamboo (http://www.atlassian.com/software/bamboo/). You decide.

Please note that the earlier version of this framework that uses the Yahoo YUI compressor is tagged here: https://github.com/akikoo/one-web-boilerplate/tags. Nowadays I prefer this framework to use RequireJS with an optimizer that manages dependencies in a much easier way.

Another note: I prefer Sass preprocessor nowadays because it's more powerful (especially with Compass) and because it's actively maintained and developed. This means that I'm not anymore actively maintaining the LESS files in this framework. Just wanted to let you know. However do let me know if you have any LESS issues so I can try to fix them (I'd be more up for it if I knew someone out there was still using LESS with this framework...).

One more thing: you should obviously exclude /build/publish directory from version control because that directory is cleaned up and recreated on each build. No need to track changes to that.

To-Do:

  • Small tweaks here and there...

Thanks and good luck!

Credits

Boilerplates:

Generic build/deploy process optimization:

  • Thanks to Dennis Green-Lieber (@dennislieber: http://twitter.com/dennislieber) for promoting the use of the framework and for great suggestions and ideas for making it better.

Solutions:

Media queries:

Inspiration:

Markup:

Images:

CSS:

JavaScript:

There's no mobile, everything's mobile.

Something went wrong with that request. Please try again.