[Project] Use 2 spaces for indentation
This commit is contained in:
@@ -2,51 +2,51 @@ import Foundation
|
||||
|
||||
/// A container for template variables.
|
||||
public class Context : Equatable {
|
||||
var dictionaries:[Dictionary<String, AnyObject>]
|
||||
var dictionaries:[Dictionary<String, AnyObject>]
|
||||
|
||||
public init(dictionary:Dictionary<String, AnyObject>) {
|
||||
dictionaries = [dictionary]
|
||||
}
|
||||
public init(dictionary:Dictionary<String, AnyObject>) {
|
||||
dictionaries = [dictionary]
|
||||
}
|
||||
|
||||
public init() {
|
||||
dictionaries = []
|
||||
}
|
||||
public init() {
|
||||
dictionaries = []
|
||||
}
|
||||
|
||||
public subscript(key: String) -> AnyObject? {
|
||||
/// Retrieves a variable's value, starting at the current context and going upwards
|
||||
get {
|
||||
for dictionary in reverse(dictionaries) {
|
||||
if let value:AnyObject = dictionary[key] {
|
||||
return value
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
public subscript(key: String) -> AnyObject? {
|
||||
/// Retrieves a variable's value, starting at the current context and going upwards
|
||||
get {
|
||||
for dictionary in reverse(dictionaries) {
|
||||
if let value:AnyObject = dictionary[key] {
|
||||
return value
|
||||
}
|
||||
}
|
||||
|
||||
/// Set a variable in the current context, deleting the variable if it's nil
|
||||
set(value) {
|
||||
if dictionaries.count > 0 {
|
||||
var dictionary = dictionaries.removeLast()
|
||||
dictionary[key] = value
|
||||
dictionaries.append(dictionary)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
public func push() {
|
||||
push(Dictionary<String, String>())
|
||||
}
|
||||
|
||||
public func push(dictionary:Dictionary<String, String>) {
|
||||
/// Set a variable in the current context, deleting the variable if it's nil
|
||||
set(value) {
|
||||
if dictionaries.count > 0 {
|
||||
var dictionary = dictionaries.removeLast()
|
||||
dictionary[key] = value
|
||||
dictionaries.append(dictionary)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public func pop() {
|
||||
dictionaries.removeLast()
|
||||
}
|
||||
public func push() {
|
||||
push(Dictionary<String, String>())
|
||||
}
|
||||
|
||||
public func push(dictionary:Dictionary<String, String>) {
|
||||
dictionaries.append(dictionary)
|
||||
}
|
||||
|
||||
public func pop() {
|
||||
dictionaries.removeLast()
|
||||
}
|
||||
}
|
||||
|
||||
public func ==(lhs:Context, rhs:Context) -> Bool {
|
||||
return lhs.dictionaries == rhs.dictionaries
|
||||
return lhs.dictionaries == rhs.dictionaries
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user