Skip to content

Commit

Permalink
Solves #38: handle defs without parens in ControllerS
Browse files Browse the repository at this point in the history
  • Loading branch information
jokade committed Apr 4, 2015
1 parent 3c90bf8 commit a2d1dc5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
5 changes: 4 additions & 1 deletion src/main/scala/biz/enef/angulate/impl/ControllerMacros.scala
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,10 @@ protected[angulate] trait ControllerMacroUtils {
(funcs map { func =>
val funcName = func.name.toString
val (params,args) = makeArgsList(func)
q"""global.Object.defineProperty(scope,$funcName,literal(value = (..$params) => ctrl.$func(..$args)))"""
if(func.paramLists.isEmpty)
q"""global.Object.defineProperty(scope,$funcName,literal(get = () => ctrl.$func))"""
else
q"""global.Object.defineProperty(scope,$funcName,literal(value = (..$params) => ctrl.$func(..$args)))"""
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protected[angulate] class DirectiveMacros(val c: blackbox.Context) extends Macro
ddo
}):js.Function)
"""
println(carray)
//println(carray)

val tree = q"""{import scala.scalajs.js
import js.Dynamic.{global,literal}
Expand Down
17 changes: 9 additions & 8 deletions src/main/scala/biz/enef/angulate/impl/MacroBase.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,20 @@ protected[angulate] abstract class MacroBase {
|${showCode(tree)}
""".stripMargin, true )


protected[this] def makeArgsList(f: MethodSymbol) = {
f.paramLists.head.map( p => {
val name = TermName(c.freshName("x"))
(q"$name: ${p.typeSignature}", q"$name")
}).unzip
}
protected[this] def makeArgsList(f: MethodSymbol) =
if(f.paramLists.isEmpty)
(List(),List())
else
f.paramLists.head.map( p => {
val name = TermName(c.freshName("x"))
(q"$name: ${p.typeSignature}", q"$name")
}).unzip

protected[this] def getDINames(f: MethodSymbol) = {
f.paramLists.head.map{ p=>
p.annotations.find( _.tree.tpe =:= namedAnnotation ).map { a =>
val name = a.tree.children.tail.head.toString
// TODO: that's ludicrous... what is thr right way to unquote the string???
// TODO: that's ludicrous... what is the right way to unquote the string???
name.substring(1,name.length-1)
}.getOrElse(p.name.toString)
}
Expand Down

0 comments on commit a2d1dc5

Please sign in to comment.