0001    // The MIT License
0002    //
0003    // Copyright (c) 2015 Gwendal Roué
0004    //
0005    // Permission is hereby granted, free of charge, to any person obtaining a copy
0006    // of this software and associated documentation files (the "Software"), to deal
0007    // in the Software without restriction, including without limitation the rights
0008    // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
0009    // copies of the Software, and to permit persons to whom the Software is
0010    // furnished to do so, subject to the following conditions:
0011    //
0012    // The above copyright notice and this permission notice shall be included in
0013    // all copies or substantial portions of the Software.
0014    //
0015    // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0016    // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0017    // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
0018    // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
0019    // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
0020    // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
0021    // THE SOFTWARE.
0022    
0023    // =============================================================================
0024    // MARK: - TagType
0025    
0026    /**
0027    The type of a tag, variable or section. See the documentation of `Tag` for more
0028    information.
0029    */
0030    public enum TagType
SectionTag.swift:39
    let type: TagType = .Section
Tag.swift:83
    var type: TagType { get }
VariableTag.swift:37
    let type: TagType = .Variable
{ 0031 0032 /// The type of tags such as `{{name}}` and `{{{body}}}`. 0033 case Variable
HTMLEscapeHelper.swift:51
        case .Variable:
JavascriptEscapeHelper.swift:51
        case .Variable:
Box.swift:180
                case .Variable:
Box.swift:237
                case .Variable:
Box.swift:294
                case .Variable:
Box.swift:351
                case .Variable:
CoreFunctions.swift:502
        case .Variable:
CoreFunctions.swift:619
        case .Variable:
MustacheBox.swift:478
                case .Variable:
RenderingEngine.swift:160
            case .Variable:
VariableTag.swift:37
    let type: TagType = .Variable
0034 0035 /// The type of section tags such as `{{#user}}...{{/user}}`. 0036 case Section
HTMLEscapeHelper.swift:59
        case .Section:
JavascriptEscapeHelper.swift:58
        case .Section:
Logger.swift:77
                    if tag.type == .Section {
Logger.swift:84
                    if tag.type == .Section {
Box.swift:183
                case .Section:
Box.swift:240
                case .Section:
Box.swift:297
                case .Section:
Box.swift:354
                case .Section:
CoreFunctions.swift:505
        case .Section:
CoreFunctions.swift:684
        case .Section:
MustacheBox.swift:487
                case .Section:
RenderingEngine.swift:163
            case .Section:
SectionTag.swift:39
    let type: TagType = .Section
0037 } 0038 0039 0040 // ============================================================================= 0041 // MARK: - Tag 0042 0043 /** 0044 Tag instances represent Mustache tags that render values: 0045 0046 - variable tags: `{{name}}` and `{{{body}}}` 0047 - section tags: `{{#user}}...{{/user}}` 0048 0049 You may meet the Tag class when you implement your own `RenderFunction`, 0050 `WillRenderFunction` or `DidRenderFunction`, or filters that perform custom 0051 rendering (see `FilterFunction`). 0052 0053 See also: 0054 0055 - RenderFunction 0056 - WillRenderFunction 0057 - DidRenderFunction 0058 */ 0059 public protocol Tag
HTMLEscapeHelper.swift:49
    private func willRender(tag: Tag, box: MustacheBox) -> MustacheBox {
JavascriptEscapeHelper.swift:49
    private func willRender(tag: Tag, box: MustacheBox) -> MustacheBox {
CoreFunctions.swift:750
    public let tag: Tag
CoreFunctions.swift:810
public typealias WillRenderFunction = (tag: Tag, box: MustacheBox) -> MustacheBox
CoreFunctions.swift:862
public typealias DidRenderFunction = (tag: Tag, box: MustacheBox, string: String?) -> Void
LocatedTag.swift:9
protocol LocatedTag: Tag {
: class, CustomStringConvertible { 0060 0061 // IMPLEMENTATION NOTE 0062 // 0063 // Tag is a class-only protocol so that the Swift compiler does not crash 0064 // when compiling the `tag` property of RenderingInfo. 0065 0066 /** 0067 The type of the tag: variable or section: 0068 0069 let render: RenderFunction = { (info: RenderingInfo) in 0070 switch info.tag.type { 0071 case .Variable: 0072 return Rendering("variable") 0073 case .Section: 0074 return Rendering("section") 0075 } 0076 } 0077 0078 let template = try! Template(string: "{{object}}, {{#object}}...{{/object}}") 0079 0080 // Renders "variable, section" 0081 try! template.render(Box(["object": Box(render)])) 0082 */ 0083 var type
HTMLEscapeHelper.swift:50
        switch tag.type {
JavascriptEscapeHelper.swift:50
        switch tag.type {
Logger.swift:77
                    if tag.type == .Section {
Logger.swift:84
                    if tag.type == .Section {
Box.swift:179
                switch info.tag.type {
Box.swift:236
                switch info.tag.type {
Box.swift:293
                switch info.tag.type {
Box.swift:350
                switch info.tag.type {
CoreFunctions.swift:501
        switch info.tag.type {
CoreFunctions.swift:618
        switch info.tag.type {
MustacheBox.swift:477
                switch info.tag.type {
RenderingEngine.swift:159
            switch tag.type {
: TagType { get } 0084 0085 /** 0086 The literal and unprocessed inner content of the tag. 0087 0088 A section tag such as `{{# person }}Hello {{ name }}!{{/ person }}` returns 0089 "Hello {{ name }}!". 0090 0091 Variable tags such as `{{ name }}` have no inner content: their inner 0092 template string is the empty string. 0093 0094 // {{# pluralize(count) }}...{{/ }} renders the plural form of the section 0095 // content if the `count` argument is greater than 1. 0096 let pluralize = Filter { (count: Int?, info: RenderingInfo) in 0097 0098 // Pluralize the inner content of the section tag: 0099 var string = info.tag.innerTemplateString 0100 if count > 1 { 0101 string += "s" // naive 0102 } 0103 0104 return Rendering(string) 0105 } 0106 0107 let template = try! Template(string: "I have {{ cats.count }} {{# pluralize(cats.count) }}cat{{/ }}.") 0108 template.registerInBaseContext("pluralize", Box(pluralize)) 0109 0110 // Renders "I have 3 cats." 0111 let data = ["cats": ["Kitty", "Pussy", "Melba"]] 0112 try! template.render(Box(data)) 0113 */ 0114 var innerTemplateString
CoreFunctions.swift:514
            let templateString = lambda(info.tag.innerTemplateString)
: String { get } 0115 0116 /// The delimiters of the tag. 0117 var tagDelimiterPair
CoreFunctions.swift:512
            templateRepository.configuration.tagDelimiterPair = info.tag.tagDelimiterPair
: TagDelimiterPair { get } 0118 0119 /** 0120 Returns the rendering of the tag's inner content. All inner tags are 0121 evaluated with the provided context. 0122 0123 This method does not return a String, but a Rendering value that wraps both 0124 the rendered string and its content type (HTML or Text). 0125 0126 The contentType is HTML, unless specified otherwise by `Configuration`, or 0127 a `{{% CONTENT_TYPE:TEXT }}` pragma tag. 0128 0129 // The strong RenderFunction below wraps a section in a <strong> HTML tag. 0130 let strong: RenderFunction = { (info: RenderingInfo) -> Rendering in 0131 let rendering = try info.tag.render(info.context) 0132 return Rendering("<strong>\(rendering.string)</strong>", .HTML) 0133 } 0134 0135 let template = try! Template(string: "{{#strong}}Hello {{name}}{{/strong}}") 0136 template.registerInBaseContext("strong", Box(strong)) 0137 0138 // Renders "<strong>Hello Arthur</strong>" 0139 try! template.render(Box(["name": Box("Arthur")])) 0140 0141 - parameter context: The context stack for evaluating mustache tags. 0142 - parameter error: If there is a problem rendering the tag, throws an 0143 error that describes the problem. 0144 - returns: The rendering of the tag. 0145 0146 */ 0147 func render
ZipFilter.swift:78
            return try info.tag.render(context)
Box.swift:186
                        return try info.tag.render(info.context.extendedContext(Box(boolValue: self)))
Box.swift:195
                        return try info.tag.render(info.context)
Box.swift:243
                        return try info.tag.render(info.context.extendedContext(Box(value: self)))
Box.swift:252
                        return try info.tag.render(info.context)
Box.swift:300
                        return try info.tag.render(info.context.extendedContext(Box(value: self)))
Box.swift:309
                        return try info.tag.render(info.context)
Box.swift:357
                        return try info.tag.render(info.context.extendedContext(Box(value: self)))
Box.swift:366
                        return try info.tag.render(info.context)
Box.swift:895
            return try info.tag.render(info.context)
Box.swift:938
                    return try info.tag.render(info.context.extendedContext(self.mustacheBoxWithSetValue(value, box: box)))
Box.swift:994
                    return try info.tag.render(info.context.extendedContext(self.mustacheBoxWithArrayValue(value, box: box)))
CoreFunctions.swift:689
            return try info.tag.render(context)
MustacheBox.swift:494
                    return try info.tag.render(context)
RenderingEngine.swift:172
                    rendering = try tag.render(context)
(context: Context) throws -> Rendering 0148 } 0149