Archives de catégorie : Scala

Liftweb sample bootstrap with sbt-plugins

Project source accessible in github at https://github.com/heralight/lift_basic_runmode

  • Lift 2.5-M3
  • sbt-runMode (development, production)
  • sbt-js
  • sbt-less
  • modernizr
  • jquery 1.8.3
  • conditional runMode snippet
  • Twitter Bootstrap included to illustrate the use of sbt shell tasks

Goal

Optimize build process in development and production by:

  • conditional compilation js and style files depending on mode configuration.
  • concat file or not
  • compress file or not
  • simplify debugging by separating files in development mode.
  • test production output easily
  • Add custom sbt task like bash script and link to actions

Installation

Uses sbt-plugins plugins.

The current version 0.6-M1 does not work properly with jetty v8. To fix this problem, you can use my fork.


In a temp directory git clone git://github.com/heralight/sbt-plugins.git 
cd sbt-plugin
clean-cache publish-local 

Structure

css and less in main/css js, coffeescript, template in main/js

These directories will be filtered and copied to resourceManaged and include in webappResources.

main js and css name : « app »

naming convention

if filename contains (rules in build.sbt)

  • .p. == production
  • .d. == development
  • .a. == add to output directory, will be included in webAppRessources path and war package.(a.p.xxx, a.d.xxx, a.xxx)

e.g.:

  • app.a.d.css => main css file in development and this file will be included to output directory.
  • app.a.p.js => main js file in production and this file will be included to output directory.
  • app-part.less => not parsed if not import in any « a » file.

Usages

start in development:

development:start 

start in production:

production:start 

stop in development:

development:stop 

stop in production:

production:stop 

dst and pst will do a stop and a start.

compile css manually:

xxmode:less 

compile js manually:

xxmode:js 

clean output:

xxmode:clean 
to clean only css xxmode:less::clean
to clean only js xxmode:js::clean 

Alias

already set in .sbtrc

 

    alias dst=;development:stop;development:start
    alias pst=;production:stop;production:start
    alias dsl= ;development:stop;~development:start
    alias psl= ;production:stop;~production:start
    alias dstop=development:stop
    alias dstart=development:start
    alias dc = development:compile
    alias pstop=production:stop
    alias pstart=production:start
    alias pc = production:compile
    alias dclean=development:clean
    alias pclean=production:clean
    alias djclean=development:js::clean
    alias dlclean=development:less::clean

 

Recommendation

make a clean before swapping modes.

For more details on sbt-plugins, refer to sbt-plugins Readme.

To go further, I recommend you mix this project with the lift-mongo.g8 produced by Tim Nelson.

Add Custom sbt Task (0.10+)

Simple Call Shell command in build.sbt:

TaskKey[Unit]("echo-simple") := {
List("sh", "-c", "(cd src/main/; echo \"YOUPI\")") ! ;
}

Without Name in build.scala, can be use as dependency:

import sbt.Project.Initialize    
val shEchoTask :  Initialize[Task[Unit]] = (streams) map {
        s => {
          List("sh", "-c", "(echo \"YOUPI\"") ! ;
          s.log.info("Echo")
        }
    }

use it in Build.sbt:

compile.in(Compile) <<= compile.in(Compile) dependsOn(shEchoTask)

With Name in Build.scala, can be use as dependency:

  val shEchoTask = TaskKey[Unit]("echo-simple-task")

  val shEchoAction = (streams) map {
    s => {
     List("sh", "-c", "(echo \"YOUPI\"") ! ;
      s.log.info("Echo")
    }
  }

  lazy val root = Project("root", file("."),
    settings = Defaults.defaultSettings ++ Seq(
    // Link task with action
      shEchoTask in Compile <<= shEchoAction,
    // add dependency
      compile in Compile <<= compile in Compile dependsOn (shEchoTask in Compile)
    ))

partial source: http://comments.gmane.org/gmane.comp.lang.scala.simple-build-tool/1768

Implémentation de Crudify pour Lift MongoDB

Besoins d’une partie administration rapide pour votre application web Lift avec MongoDB?
Je peux au moins vous simplifier la vie avec une génération automatique des commandes CRUD List / Edit / Delete de votre modèle.

Ci-dessous en lien, une classe pour mongoDB de Crudify, elle gère que le premier niveau et les types simple, après, à vous de l’étendre.
Cette implémentation utilise la bibliothèque Rogue de FourSquare.

Classe

https://github.com/heralight/Lift-MongoDb-Crudify/blob/master/src/main/scala/code/lib/MongoCrudify.scala

Projet de test

https://github.com/heralight/Lift-MongoDb-Crudify

D’autres liens utiles sur Crudify et lift

https://github.com/timperrett/lift-in-action // Chapitre 5 pour Crudify
http://neuralmonkey.blogspot.fr/search/label/lift // crudify + lift
http://neuralmonkey.blogspot.fr/2009/08/lift-listing-entities-without-crudify.html
https://github.com/tromberg/Winglet/blob/master/src/main/scala/be/romberg/liftweb/util/MBindHelper.scala // Crudify like
http://www.assembla.com/spaces/liftweb/wiki/MapperBinder
https://github.com/oliverdaff/Lift-Shopping
http://www.assembla.com/wiki/show/liftweb/Creating_the_UI_for_Mapper_entities
https://groups.google.com/forum/?fromgroups#!topic/liftweb/r52KTSwpv2s // How to customize CRUDify HTML
https://groups.google.com/forum/?fromgroups#!searchin/liftweb/admin/liftweb/yzyMn0IKJ4Y/ViXKgFWzJ0QJ // CRUDify with SquerylRecord & one-to-many relationship

Si vous avez des suggestions…