GithubHelp home page GithubHelp logo

webjars-play's Introduction

WebJars-Play

Introduction

This project provides a Play framework controller so that developers using Play can easily access WebJars from their code.

In summary you need to configure a route in your Play application:

# Enable webjar based resources to be returned
GET     /webjars/*file              controllers.WebJarAssets.at(file)

...and then use WebJars within your views:

<script type='text/javascript' src='@routes.WebJarAssets.at(WebJarAssets.locate("jquery.min.js"))'></script>

A user guide for this plugin can be found within the WebJars Documentation.

Requirejs

For single page JavaScript applications support has been provided for the popular require.js toolkit. The webjar-play controller can serve up a flavor of require.js so that the following types of expression will work from JavaScript:

define(['webjars!angular.js'], 
  function() {

The webjars! directive will cause require.js to locate WebJar resources on the server in a similar manner to calling WebJarAssets.locate within views. The difference is that this locating is all done in JavaScript on the client side.

To enable JavaScript WebJar loading declare require.js in a familiar way:

<script data-main="js/app" src="lib/require.js"></script>

...and then configure some routes in your Play! application:

# Obtain require.js with built-in knowledge of how webjars resources can be
# resolved
GET     /lib/require.js             controllers.WebJarAssets.requirejs()

# Enable webjar based resources to be returned
GET     /webjars/*file              controllers.WebJarAssets.at(file)

You're all set - no Play views required!

An example of the require.js support can be found in the angular-seed-play project.

Releasing webjars-play

  1. Set the release version in project/Build.scala
  2. Commit
  3. Tag git v2.x.y-z
  4. Release: sbt publish

webjars-play's People

Contributors

huntc avatar jamesward avatar

Watchers

James Cloos avatar Bùi Việt Thành avatar

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.