10

I'm wanting to pull in Twitter's Bootstrap into my Grails 3 app. What's the best way to do this? I neither want to place the source under version control nor reference remote CDNs.

Adding "org.grails:grails-bootstrap:3.0.1" as a compilation dependency in my build.gradle pulls down the associated JAR, but how do I plumb this into my application to ultimately be able to reference Bootstrap classes from my views/GSPs?

deluan
  • 1,865
  • 12
  • 14
tomwadeson
  • 141
  • 1
  • 5

4 Answers4

7

Webjars worked for me, I've used the webjars link in my application.js and in my application.css, but the links are not always well defined (see typeahead example)

application.js:

//= require jquery-2.1.3.js
//= require_tree .
//= require_self
//= require /webjars/bootstrap/3.3.5/js/bootstrap.min
//= require /webjars/bootstrap-tagsinput/0.5/bootstrap-tagsinput
//= require /webjars/typeaheadjs/0.11.1/typeahead.bundle.js

application.css:

/*
*= require main
*= require mobile
*= require_self
*= require /webjars/bootstrap/3.3.5/css/bootstrap-theme
*= require /webjars/bootstrap/3.3.5/css/bootstrap
*= require /webjars/bootstrap-tagsinput/0.5/bootstrap-tagsinput
*/
boraas
  • 929
  • 1
  • 10
  • 24
  • How you reference to webjars? as dependecy? I receive error during compile, that no such assets '/webjars/bootstrap/3.3.5/css/bootstrap-theme' and for all other links. In cache of grails I see webjar, but seems like it should be placed in 'assets' folder of grails project? – sphinks Aug 26 '15 at 21:13
  • you need to add the dependency in your build.gradle file (see [webjars](http://www.webjars.org/) to look up the dependency of your needs). For bootstrap 3.3.5 it is: `compile 'org.webjars:bootstrap:3.3.5'`. – boraas Aug 27 '15 at 13:36
  • Yes, I have do it before write a comment. So error appears with dependency. Some other actions performed? – sphinks Aug 27 '15 at 14:49
  • nope `dependencies { ... compile "org.grails:grails-web-boot" compile 'org.webjars:typeaheadjs:0.11.1' compile 'org.webjars:bootstrap:3.3.5' compile 'org.webjars:bootstrap-tagsinput:0.5' compile 'org.webjars.bower:bootstrap-table:1.8.1' ... runtime "org.grails.plugins:asset-pipeline" ... // Note: It is recommended to update to a more robust driver (Chrome, Firefox etc.) testRuntime 'org.seleniumhq.selenium:selenium-htmlunit-driver:2.44.0' console "org.grails:grails-console" }` – boraas Aug 28 '15 at 07:48
  • I have add only this compile 'org.webjars:bootstrap:3.3.5', may be I should add some other webjar to proper work. I'll check, thanks. – sphinks Aug 28 '15 at 14:33
  • Are you able to add attributes like `media="screen, projection"` to the full css include? e.g. `` – Jonathan Airey Sep 08 '15 at 10:39
2

I don't think there is any usable Bootstrap plugin for Grails 3 yet. I think it is easier to include WebJars Bootstrap in your project and then reference the files in your gsp's or layouts.

I don't have a workable example ready, but take a look at this code snippet: https://github.com/canoo/open-dolphin-lazybones-templates/commit/d1a2c3bc4d0852a331f66287314b6348d6e76e14

deluan
  • 1,865
  • 12
  • 14
0

You should be using this plugin and the documentation tells you exactly what to do.

Javascript grails-app/assets/javascripts/application.js:

//= require bootstrap

Stylesheet grails-app/assets/javascripts/application.css:

/*
*= require bootstrap
*/
Gregg
  • 34,973
  • 19
  • 109
  • 214
  • Hi Gregg. The documentation references BuildConfig.groovy, which I believe has been discontinued in Grails 3. Could you advise how to reference this plugin in the "new" way? – tomwadeson May 28 '15 at 14:56
  • Wouldn't you add it to your build.gradle? I'm sorry, I honestly don't know for sure. I'm avoiding Grails 3. :) Assuming it is still using the asset-pipeline I'd still believe it applies. – Gregg May 28 '15 at 15:04
0

I'm using this plugin kensiprell/bootstrap-framework and added following path into .gitignore so that resources are downloaded upon first run.

/grails-app/assets/javascripts/bootstrap
/grails-app/assets/javascripts/bootstrap-all.js
/grails-app/assets/stylesheets/font-awesome
/grails-app/assets/stylesheets/bootstrap
/grails-app/assets/stylesheets/font-awesome-less.less
/grails-app/assets/stylesheets/bootstrap-less.less
/grails-app/assets/stylesheets/bootstrap-all.css
/grails-app/assets/stylesheets/font-awesome-all.css
mehmood
  • 301
  • 3
  • 19