//

//  Created by Lennart Stolz on 03.07.15.

//  Copyright (c) 2016 Lennart Stolz. All rights reserved.

//


import Foundation


/// Function to create the lstolz.com webiste.

func createWebsite(withFactory factory: HTMLFactory) {


    // This is the part where I should be polite.

    let greeting = factory.element(tag: "h1", content: "Hello Visitor")

    print(greeting)

    let subline = factory.element(tag: "h2", content: "Welcome to my website")

    print(subline)

    

    // Not sure if I'm an attention-seeker or just a self-publicist.

    let about = factory.element(tag: "h2", content: "About me")

    print(about)

    

    let firstName = "Lennart"

    let lastName  = "Stolz"

    let aboutContent = factory.element(tag: "p", content: "I'm \(firstName) \(lastName)")

    print(aboutContent)

    

    

    // I'm just getting older and better. (Neal Schon)

    let dateFormatter = NSDateFormatter()

    dateFormatter.dateFormat = "dd.MM.y"

    guard let dateOfBirth = dateFormatter.dateFromString("20.03.1989") else {

        // Should never happen but force unwraps cut me to the quick.

        return

    }

    

    let now = NSDate()

    let calendar = NSCalendar.currentCalendar()

    

    let years = calendar.components(.Year, fromDate: dateOfBirth, toDate: now, options: []).year

    print(factory.element(tag: "p", content: "I'm \(years) years old."))

    // Stop here before getting a shaggy dog story.

}


/// A tiny factory to provide html elements.

class HTMLFactory {


    /**

     Method to create an html element with opening and closing tag for a given content.

     

     - Parameters:

        - tag:      The html tag which should be used for this element.

        - content:  The text which should be displayed within the html element.

     

     - Returns: The aggregated html element.

     */

    func element(tag tag: String, content: String) -> String {

        return "<\(tag)>\(content)</\(tag)>"

    }

}


let factory = HTMLFactory()

createWebsite(withFactory: factory)

Hello Visitor

Welcome to my website

About me

I'm Lennart Stolz.

I'm 27 years old.

I to code!
Beside Swift I speak a bunch of programming languages fluently.


To keep in touch just contact me on: