Giter VIP home page Giter VIP logo

generator-uswds's Introduction

generator-uswds

A Yeoman generator for the U.S. Draft Web Design Standards!

Install it

This isn't published on npm yet, but for now you can install it with:

npm install -g github:18F/generator-uswds

Alternatively (or if you want to contribute!) you can clone this repo then run:

npm install
npm link

Run it

cd my-new-project
yo uswds

Project layout

After you run this generator, your directory structure should look like this:

your-project/
├── css/
├── fonts/
├── images/
├── js/
├── sass/
├── page-templates/
└── package.json

Note the pattern: each type of file gets its own top-level directory, and (with the exception of css) each of them has a vendor/uswds subtree containing the static USWDS assets of that type. This layout is meant to accommodate the addition of site-specific assets alongside USWDS. Each directory contains a README.md (in Markdown) describing its contents. Here is an overview:

css

The css directory contains CSS generated from the Sass source files in scss. The CSS files are minified to discourage direct editing.

fonts

The USWDS custom fonts (Merriweather and Source Sans Pro) live in the fonts/vendor/uswds directory. Additional fonts can be placed in this directory and referenced from the [Sass][#sass].

images

The USWDS images live in the images/vendor/uswds directory. Additional images can be placed in this directory, and may be referenced relatively from the Sass, e.g. in background-image properties via url(../images/path/to/image.png).

js

The js directory contains your site's JavaScript:

  1. js/vendor/uswds contains both minified and un-minified versions of uswds.js. You should always use uswds.min.js in your templates unless you need to be able to debug USWDS and lack a browser with [source map] support.
  2. main.js is a placeholder for your site's custom scripts, and is imported out of the box in the page templates.

page-templates

This directory contains both of the USWDS page templates as standalone HTML files. We suggest copying these files and customizing them for your needs rather than editing them in place. This can make it easier to test customizations that you make to the Sass, and allows you to compare changes that you've made in other pages to the originals if you end up breaking something by accident.

sass

The sass directory contains all of the Sass source files for the USWDS and a main.scss file from which you can customize the system. We suggest working in this file to get a feel for it, then factoring your work into additional Sass "partials" for more component-oriented CSS rules. For instance, you could organize your sass directory like this:

├── my-project/
|   ├── _all.scss
|   └── # other files imported by _all.scss
├── vendor/uswds/...
├── _variables.scss
└── main.scss

Then your main.scss could be structured like so:

# this should go before importing uswds
@import 'variables';
@import 'vendor/uswds/all';
# and this should go after if your styles override uswds rules in any way
@import 'my-project/all';

See tasks below for more information on regenerating the CSS files from Sass.

package.json

Your package.json tells npm about your project's JavaScript dependencies. After your directory is created, the Yeoman generator runs npm install to install the depenencies used for building your CSS file(s) from the Sass sources.

Tasks

The package.json defines the following tasks in the scripts section:

  • npm start (or npm run start)

    Starts a web server in your project directory so that you can preview your site at http://127.0.0.1:8080.

  • npm run build:css

    Regenerates the CSS from the Sass source files.

  • npm run build

    Runs npm run build:css. In the future we may include other build commands for different asset types.

generator-uswds's People

Contributors

shawnbot avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar

generator-uswds's Issues

Reorganize USWDS assets

After working on USWDS and observing how other projects incorporate its assets, I think that organizing different types of assets into top-level directories each with vendor/uswds subdirs is a bad approach. It's much better to put them into a single subdir that can be either updated or blown away and recreated when upgrading rather than having to manage images, CSS, fonts, and JavaScript individually. The new layout should look something like this:

your-project/
├─ assets/
|  └─ uswds/
|     ├─ css/
|     ├─ images/
|     ├─ js/
|     ├─ sass/
|     ├─ LICENSE.md
|     └─ README.md
└─ package.json

Perhaps the assets/uswds path should be configurable? /shrug

Incorporate the Jekyll template as a generator?

If we decide to go with publishing the Jekyll template as a generator (18F/federalist-uswds-template#1), then we could nix the git submodule here and instead compose it:

npm i --save generator-uswds-jekyll
// app/index.js
install: function() {
  this.composeWith('uswds-jekyll');
},

Of course, the other way that we could do this is to keep the scaffolding in this repo and just re-run the generator to refresh the assets in the template repo. That would mean:

  1. Remove the git submodule and copy the template files into this repo under app/templates/jekyll.
  2. Add a package.json to the template repo that runs yo uswds --jekyll --sass to update. (There's currently no update script because that repo is the "source of truth" for templates.)

@hbillings @cmc333333, what do you think?

Update README

The README needs to be updated to reflect the new asset layout(s) — namely, that all static assets are now placed under ./assets/uswds rather than top-level, type-specific directories like ./js/uswds and ./css/uswds. We should also document the possible configurations:

  1. Jekyll with Sass
  2. Jekyll without Sass (CSS only)
  3. Static files only (just the assets/uswds directory)
  4. Static files + node-sass

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.