cfpb / regulations-site

(DEPRECATED) Web interface for viewing U.S. federal regulations and other regulatory information
Other
28 stars 43 forks source link

:warning: THIS REPO IS DEPRECATED (12/3/2018) :warning:

Please migrate to using cfgov-refresh.

regulations-site

Build Status

An interface for viewing regulations data. This project combines all of the data from a parsed regulation and generates navigable, accessible HTML, complete with associated information.

This repository is part of a larger project. To read about it, please see http://cfpb.github.io/eregulations/.

Features

Screenshot

eRegs

Requirements

This application lives in two worlds, roughly translating to a Python, Django app, and a Backbone, Javascript app, which communicate through the Django templates.

Quick start

If you're familiar with Python and Node environments, after cloning this repo:

$ mkvirtualenv regsite
$ workon regsite
$ pip install -r requirements.txt
$ ./frontendbuild.sh
$ python manage.py runserver

Python

Requirements are retrieved and/or build automatically via pip (see below).

If running tests:

Setup & Running

This project uses requirements*.txt files for defining dependencies, so you can get up and running with pip:

$ pip install -r requirements.txt       # modules required for execution
$ pip install -r requirements_test.txt  # modules required for running tests
$ pip install -r requirements_dev.txt   # helpful modules for developers

With that, you can start the development server:

$ python manage.py runserver

Building the documentation

For most tweaks, you will simply need to run the Sphinx documentation builder again.

$ ./bin/sphinx-build -b dirhtml -d docs/_build/doctrees/ docs/ docs/_build/dirhtml/

The output will be in docs/_build/dirhtml.

If you are adding new modules, you may need to re-run the skeleton build script first:

$ rm docs/regulations*.rst
$ ./bin/sphinx-apidoc -F -o docs regulations

JavaScript Application

Code

The application code in JavaScript uses Backbone.js as a foundation, though in some non-standard ways. If you plan to do work on this layer, it is recommended that you acquaint yourself with this starter documentation.

Environment

The front end of the site uses a number of JavaScript libraries and frameworks to create the unique experience of navigating and reading a regulation, as you can see at http://consumerfinance.gov/eregulations. If you'd like to modify the JavaScript layer, you should set up the build and testing environment.

If you run the application with env = "built" in your local_settings.py and would like to use the UI as it ships with this project, you can skip this.

The application's UI itself uses a number of dependencies that you can see in package.json. To start, we are going to be concerned with the foundations of the environment:

Front end environment setup

Node/npm

The front-end development environment relies on on Node (version 4+) and npm for package management. To install Node, we recommend nvm:

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.30.2/install.sh | bash # install nvm and run it's setup scripts
nvm install 4 # install node 4
nvm alias default 4 # set node 4 as the default

Alternately you can install Node by:

Global npm packages

You will need to install the Grunt command line interface using npm.

cd regulations-site
npm install -g grunt-cli

Installing dependencies

The rest of the dependencies you will need are managed by npm. Do:

npm install

Configuration JSON

In the root of the repository, copy example-config.json to config.json and edit as necessary. Grunt depends on these settings to carry out tasks.

Running the application

Once all of the Python and front end dependencies have been met, compile the CSS and JavaScript and start the server:

$ grunt
$ ./bin/django runserver

Building the documentation

For most tweaks, you will simply need to run the Sphinx documentation builder again.

$ ./bin/sphinx-build -b dirhtml -d docs/_build/doctrees/ docs/ docs/_build/dirhtml/

The output will be in docs/_build/dirhtml.

If you are adding new modules, you may need to re-run the skeleton build script first:

$ rm docs/regulations*.rst
$ ./bin/sphinx-apidoc -F -o docs regulations

Additional front end information

Running Grunt tasks

There are a number of tasks configured in Gruntfile.js. On the last lines, you will find tasks that group subtasks into common goals. Running grunt build will run unit, functional and lint tests, and compress static assets. Its recommended that you run this task before deploying changes.

Unit and Functional Tests

The Grunt build will run a suite of Selenium tests written in Python and a small suite of Mocha.js unit tests. All tests run in Sauce Labs. These tests run as part of the grunt build tasks. To use these, a little extra environment setup is required.

Sauce Labs Configuration

After you create a Sauce Labs account:

For functional tests
For unit tests

Font files

The CSS styles for this project refer to some font files which cannot be distributed publicly (see definitions in regulations/static/regulations/css/less/fonts.less). These fonts need to live under a fonts subdirectory of wherever static assets are served from, e.g. /static/fonts. There are fallback fonts defined which will be used if the desired fonts are not available.

If you want to install self-hosted fonts locally for use in development, you can place the font files in repo subdirectory static.in/cfgov-fonts/fonts/ and restart the local web server. If you are a CFPB employee, you can perform this step with:

cd static.in/ && git clone https://[GHE]/CFGOV/cfgov-fonts/

where [GHE] is our GitHub Enterprise URL.

See the cfgov-refresh Webfonts documentation for a similar setup.

Configuration

Update notices

Define an EREGS_REGULATION_UPDATES Django setting in order to temporarily place a notice on the landing page of regulations that are in the process of being updated. For example, to turn on this notice for regulations for part 1003 and part 1005, define:

# in your Django settings file
EREGS_REGULATION_UPDATES = ['1003', '1005']

Content for this notice can be found in regulations/templates/regulations/generic_landing.html.