scala-news-reader

rss/atom news reader in scala

git clone https://9o.is/git/scala-news-reader.git

Boot.scala

(3012B)


      1 package bootstrap.liftweb
      2 
      3 import scala.xml.{ Null, UnprefixedAttribute }
      4 import javax.mail.internet.MimeMessage
      5 
      6 import net.liftweb._
      7 import common._
      8 import http._
      9 import util._
     10 import util.Helpers._
     11 
     12 import com.joereader.config._
     13 import com.joereader.model.{ SystemUser, User }
     14 
     15 import bootstrap.liftmodules._
     16 import GoogleAnalytics.dsl._
     17 import net.liftmodules.extras.{ Gravatar, LiftExtras }
     18 import net.liftmodules.mongoauth.MongoAuth
     19 import net.liftweb.http.SHtml.ChoiceHolder
     20 import net.liftweb.sitemap.SiteMap
     21 import net.liftweb.http.js.jquery.JqJsCmds.FadeIn
     22 
     23 /**
     24  * A class that's instantiated early and run.  It allows the application
     25  * to modify lift's environment
     26  */
     27 class Boot extends Loggable {
     28   def boot() {
     29     logger.info("Run Mode: " + Props.mode.toString)
     30 
     31     // init mongodb
     32     MongoConfig.init()
     33 
     34     // init auth-mongo
     35     MongoAuth.authUserMeta.default.set(User)
     36     MongoAuth.loginTokenAfterUrl.default.set(Site.password.url)
     37     MongoAuth.siteName.default.set("Read Means")
     38     MongoAuth.systemEmail.default.set(SystemUser.user.email.is)
     39     MongoAuth.systemUsername.default.set(SystemUser.user.name.is)
     40 
     41     // For S.loggedIn_? and TestCond.loggedIn/Out builtin snippet
     42     LiftRules.loggedInTest = Full(() => User.isLoggedIn)
     43 
     44     // Gravatar
     45     Gravatar.defaultImage.default.set("jcabrra.files.wordpress.com/2013/06/mr_noman.jpg")
     46 
     47     // config an email sender
     48     SmtpMailer.init()
     49 
     50     // where to search snippet
     51     LiftRules.addToPackages("com.joereader")
     52 
     53     // Google analytics
     54     GoogleAnalytics.init {
     55       only when Props.productionMode
     56     }
     57 
     58     // set the default htmlProperties
     59     LiftRules.htmlProperties.default.set((r: Req) =>
     60       new Html5Properties(r.userAgent))
     61 
     62     // Build SiteMap
     63     SiteMap.enforceUniqueLinks = false
     64     LiftRules.setSiteMap(Site.siteMap)
     65 
     66     // Error handler
     67     ErrorHandler.init()
     68 
     69     // 404 handler
     70     LiftRules.uriNotFound.prepend(NamedPF("404handler") {
     71       case (req, failure) =>
     72         NotFoundAsTemplate(ParsePath(List("404"), "html", absolute = false, endSlash = false))
     73     })
     74 
     75     // Show the spinny image when an Ajax call starts
     76     LiftRules.ajaxStart =
     77       Full(() => LiftRules.jsArtifacts.show("ajax-spinner").cmd)
     78 
     79     // Make the spinny image go away when it ends
     80     LiftRules.ajaxEnd =
     81       Full(() => LiftRules.jsArtifacts.hide("ajax-spinner").cmd)
     82 
     83     // Force the request to be UTF-8
     84     LiftRules.early.append(_.setCharacterEncoding("UTF-8"))
     85 
     86     // Init Extras
     87     LiftExtras.init()
     88 
     89     // don't include the liftAjax.js code. It's served statically.
     90     LiftRules.autoIncludeAjaxCalc.default.set(() =>
     91       (session: LiftSession) => false)
     92 
     93     // Twitter Bootstrap css fix radio inputs by surrounding with label
     94     ChoiceHolder.htmlize = ci => evalElemWithId((id, e) =>
     95       <label for={ id }>{ e } { ci.key.toString }</label>)(ci.xhtml)
     96 
     97     // API
     98     LiftRules.dispatch.append(com.joereader.lib.ImageUpload)
     99     LiftRules.statelessDispatch.append(com.joereader.snippet.Sitemap)
    100   }
    101 }