1 | # Play 2.0 tips and tricks |
---|
2 | |
---|
3 | ## To use Play Framework 2 with Twitter Bootstrap 2: |
---|
4 | |
---|
5 | ### Renaming the Bootstrap include files |
---|
6 | * Build Play from last sources (near RC3) (Since less version has been updated to 1.2 ) |
---|
7 | * Copy bootstrap's less files into `app/assets/stylesheets/bootstrap` |
---|
8 | * Add `bootstrap/_` before each `bootstrap.less` import declaration and rename each file the same way ( This is the convention to not compile theses files while packaging compiled assets ) |
---|
9 | * Move `bootstrap.less` file into `app/assets/stylesheets` |
---|
10 | |
---|
11 | This can be done with a script like this (run in `app/assets/stylesheets/bootstrap`) |
---|
12 | |
---|
13 | ```bash |
---|
14 | for a in *.less; do mv $a _$a; done |
---|
15 | sed -i "" 's|@import "|@import "bootstrap/_|' _bootstrap.less |
---|
16 | mv _bootstrap.less ../bootstrap.less |
---|
17 | sed -i "" 's|@import "|@import "bootstrap/_|' _responsive.less |
---|
18 | mv _responsive.less ../bootstrap-responsive.less |
---|
19 | ``` |
---|
20 | |
---|
21 | ### Alternative: using the `Build.scala` configuration file |
---|
22 | * Copy bootstrap's less files into `app/assets/stylesheets/bootstrap` |
---|
23 | * Modify the `project/Build.scala` file to filter out the Bootstrap LESS files we *don't* want to compile: |
---|
24 | |
---|
25 | * Define a new [BuildPath](https://github.com/harrah/xsbt/wiki/Paths) resolver function: |
---|
26 | |
---|
27 | ```scala |
---|
28 | // Only compile the bootstrap bootstrap.less file and any other *.less file in the stylesheets directory |
---|
29 | def customLessEntryPoints(base: File): PathFinder = ( |
---|
30 | (base / "app" / "assets" / "stylesheets" / "bootstrap" * "bootstrap.less") +++ |
---|
31 | (base / "app" / "assets" / "stylesheets" * "*.less") |
---|
32 | ) |
---|
33 | ``` |
---|
34 | |
---|
35 | *Note:* this wil only compile `stylesheets/bootstrap/bootstrap.less` and `stylesheets/*.less` files. If you have any other LESS files in other subdirectories under `stylesheets`; adjust the function accordingly. |
---|
36 | |
---|
37 | * Override the default `lessEntryPoints` setting key with the new function: |
---|
38 | |
---|
39 | ```scala |
---|
40 | val main = PlayProject(appName, appVersion, appDependencies, mainLang = JAVA).settings( |
---|
41 | lessEntryPoints <<= baseDirectory(customLessEntryPoints) |
---|
42 | ) |
---|
43 | ``` |
---|
44 | |
---|
45 | * Include the `bootstrap.min.css` file in your view(s): |
---|
46 | |
---|
47 | ```html |
---|
48 | <link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/bootstrap/bootstrap.min.css")" /> |
---|
49 | ``` |
---|
50 | |
---|
51 | |
---|
52 | ## MongoDB |
---|
53 | |
---|
54 | When using [Salat](https://github.com/novus/salat), make sure to disable SQL evolutions in your `application.conf` via `evolutionplugin=disabled` or you will run into inexplicable ClassCastExceptions. |
---|