Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract databinding concerns from Context
- Loading branch information
1 parent
d7d2b65
commit a95dd44
Showing
13 changed files
with
276 additions
and
300 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.gilt.handlebars.context | ||
|
||
trait Binding[T] { | ||
val isUndefined: Boolean | ||
def filterEmptyLike: Binding[T] | ||
protected def isValueless: Boolean | ||
def get: T | ||
def toOption: Option[T] | ||
def renderString: String | ||
def isTruthy: Boolean | ||
def isCollection: Boolean | ||
def isDictionary: Boolean | ||
def isPrimitive = ! isCollection && ! isDictionary | ||
def asCollection: Iterable[Binding[T]] | ||
def traverse(key: String, args: List[Any]): Binding[T] // If traversing a function-like, args are optionally provided | ||
} | ||
|
||
trait FullBinding[T] extends Binding[T] { | ||
protected val data: T | ||
if (data.isInstanceOf[Binding[_]]) { | ||
throw new Exception("Bug! You tried to wrap a binding with a binding. Don't do that!") | ||
} | ||
def toOption: Option[T] = Some(data) | ||
def get = data | ||
override def toString = s"FullBinding(${data})" | ||
def filterEmptyLike = | ||
if (isValueless) | ||
VoidBinding[T] | ||
else | ||
this | ||
} | ||
|
||
trait VoidBinding[T] extends Binding[T] { | ||
val isUndefined = true | ||
def toOption: Option[T] = None | ||
def renderString = "" | ||
def isValueless = true | ||
def filterEmptyLike = this | ||
def traverse(key: String, args: List[Any]) = this | ||
lazy val asCollection = Seq() | ||
def get = throw new RuntimeException("Tried to get value where not defined") | ||
def isCollection = false | ||
def isDictionary = false | ||
def isTruthy = false | ||
override def toString = "VoidBinding" | ||
} | ||
|
||
object VoidBinding extends VoidBinding[Any] { | ||
def apply[T]: VoidBinding[T] = this.asInstanceOf[VoidBinding[T]] | ||
} |
11 changes: 0 additions & 11 deletions
11
src/main/scala/com/gilt/handlebars/context/CacheableContext.scala
This file was deleted.
Oops, something went wrong.
62 changes: 0 additions & 62 deletions
62
src/main/scala/com/gilt/handlebars/context/ClassCacheableContext.scala
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.