#254

<script>:31: undefined method `append' for nil:NilClass

    • Created on: Tue, Jul 26 2011 (10 months ago)
    • Reported by: Yang Zhang
    • Assigned to: -
    • Milestone: -
    • Estimate: None/Small/Medium/Large None
    • Status: New
    • Priority: Normal (3)
    • Component: scalate-core
    • Permission type: None
    I'm getting this exception from including an (empty) :sass block:


    <script>:31: undefined method `append' for nil:NilClass
    (NoMethodError) (of class java.lang.String)
    
    at org.fusesource.scalate.jruby.Sass.filter(Sass.scala:70)
    at org.fusesource.scalate.RenderContext$class.filter(RenderContext.scala:275)
    at org.fusesource.scalate.DefaultRenderContext.filter(DefaultRenderContext.scala:30)
    at org.fusesource.scalate.RenderContext$class.value(RenderContext.scala:234)
    at org.fusesource.scalate.DefaultRenderContext.value(DefaultRenderContext.scala:30)
    at scalate.templates.$_scalate_$hello$dashscalate_jade$.$_scalate_$render(hello-scalate.jade.scala:35)
    at scalate.templates.$_scalate_$hello$dashscalate_jade.render(hello-scalate.jade.scala:62)
    at org.fusesource.scalate.RenderContext$$anonfun$render$1$$anonfun$apply$mcV$sp$1.apply$mcV$sp(RenderContext.scala:390)
    at org.fusesource.scalate.RenderContext$$anonfun$render$1$$anonfun$apply$mcV$sp$1.apply(RenderContext.scala:390)
    at org.fusesource.scalate.RenderContext$$anonfun$render$1$$anonfun$apply$mcV$sp$1.apply(RenderContext.scala:390)
    at org.fusesource.scalate.RenderContext$class.withUri(RenderContext.scala:446)
    at org.fusesource.scalate.DefaultRenderContext.withUri(DefaultRenderContext.scala:30)
    at org.fusesource.scalate.RenderContext$$anonfun$render$1.apply$mcV$sp(RenderContext.scala:389)
    at org.fusesource.scalate.RenderContext$$anonfun$render$1.apply(RenderContext.scala:389)
    at org.fusesource.scalate.RenderContext$$anonfun$render$1.apply(RenderContext.scala:389)
    at org.fusesource.scalate.RenderContext$class.withAttributes(RenderContext.scala:420)
    at org.fusesource.scalate.DefaultRenderContext.withAttributes(DefaultRenderContext.scala:30)
    at org.fusesource.scalate.RenderContext$class.render(RenderContext.scala:388)
    at org.fusesource.scalate.DefaultRenderContext.render(DefaultRenderContext.scala:30)
    at org.scalatra.scalate.ScalateSupport$class.renderTemplate(ScalateSupport.scala:44)
    ...


    The source:


     def filter(context: RenderContext, content: String) = {
    
       val sassPaths = List[String]()
       var result: StringBuffer = new StringBuffer
       jruby.put("@result", result)
       jruby.run(
         "require 'haml-3.0.25/lib/sass'",
         "options = {}",
         "options[:load_paths] = ["+sassPaths.map("'"+_+"'").mkString(",")+"]",
         "options[:cache_location] = '"+engine.workingDirectory+"/sass'",
         "options[:style] = " + (if (engine.isDevelopmentMode)
    ":expanded" else ":compressed") + "",
         "options[:line_comments] = " + (if (engine.isDevelopmentMode)
    "true" else "false") + "",
         "options[:syntax] = :"+syntax,
         "content = <<SCALATE_SASS_EOF\n"+content+"\nSCALATE_SASS_EOF",
         "tree = ::Sass::Engine.new(content, options).to_tree",
         "@result.append(tree.render)") match {
         case Right(result) => result.toString
         case Left((exception, errors)) =>
           val err1 = """(?m)([a-zA-Z_0-9-]+[.]s[ca]ss:\d+:.+)$""".r
           val err2 = """([(]s[ca]ss[)]:\d+:.+)$""".r
           errors match {
             case err1(msg) => throw new TemplateException(msg, exception)
             case err2(msg) => throw new TemplateException(msg, exception)
           }
           throw new TemplateException(errors, exception)
       }
     }


    So the @result.append seems to be the culprit.

    The problem appears to be due to my using:


    renderTemplate("WEB-INF/scalate/templates/hello-scalate.jade")


    instead of (note the leading slash):


    renderTemplate("/WEB-INF/scalate/templates/hello-scalate.jade")


    Not sure how this is manifesting itself in the given exception,
    though, especially since on removing the :sass block everything works.
  • Followers
     
    Ico-users Yang Zhang 
     
    Attachments
    No attachments
    Associations
     
    No associations
    Activity
    Time Expenditure
    Loading