net.liftmodules.FoBoTB.snippet.FoBo.TBResources.scala Maven / Gradle / Ivy
package net.liftmodules.FoBoTB.snippet.FoBo
import scala.xml.{ NodeSeq, Text }
import net.liftweb.util._
import net.liftweb.common._
import net.liftweb.http._
import net.liftweb._
import Helpers._
/**
* ==TBResources Snippet==
*
* This snippet class lets you inject FoBo Bootstrap 2.x resources into your templates.
* Instead of hand write the resource tags you can use this helper snippet to inject it for you.
*
* '''Example''' Invoke with
* {{{ data-lift="FoBo.TBResources.functionName?paramName=paramValue&...." }}}
* For more examples see the individual transform functions.
* @since v1.3
*/
class TBResources extends StatefulSnippet {
def dispatch = {
case "injectJS" => injectJS
case "injectCSS" => injectCSS
}
/**
* '''Snippet Params:'''
*
* - '''Param''' ''resources'' - A comma separated list of FoBo managed Bootstrap 2.x js resources.
*
* '''Example'''
* {{{ }}}
* or making bootstrap.js implicit.
* {{{ }}}
*
* '''Result:''' This example will result in the following being injected in place of the snippet invocation:
* {{{
*
*
* }}}
*
* @since v1.3
*/
def injectJS:net.liftweb.util.CssSel = {
def transform(res: List[String]): List[scala.xml.Elem] = {
val res2 = if(!res.contains("bootstrap")) "bootstrap" :: res else res
val result = (for {
r <- res2
} yield )
result
}
val res = S.attr("resources").map(x => x.split(',').map(x => x.trim).toList.distinct).openOr(List())
" *" #> transform(res)
}
/**
* '''Snippet Params:'''
*
* - '''Param''' ''resources'' - A comma separated list of FoBo managed Bootstrap 2.x css resources.
*
* '''Example'''
* {{{ }}}
* or making bootstrap.css and bootstrap-responsive.css implicit.
* {{{ }}}
*
* '''Result:''' This example will result in the following being injected in place of the snippet invocation:
* {{{
*
*
* }}}
*
* @since v1.3
*/
def injectCSS:net.liftweb.util.CssSel = {
def transform(res: List[String]):List[scala.xml.Elem] = {
val res2 = if(!res.contains("bootstrap")) "bootstrap" :: res else res
val res3 = if(!res.contains("bootstrap-responsive")) "bootstrap-responsive" :: res2 else res2
val result = (for {
r <- res3
} yield )
result
}
val res = S.attr("resources").map(x => x.split(',').map(x => x.trim).toList.distinct).openOr(List())
" *" #> transform(res)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy