<commit_before>//
//  NKLayoutTestable.swift
//  NKit
//
//  Created by <NAME> on 9/23/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import UIKit

public protocol NKLayoutTestable {
    static var viewController: UIViewController { get }
    static var shouldAddNavigationBar: Bool {get}
    static var size: CGSize {get}
    static var backgroundColor: UIColor {get}
}

public extension NKLayoutTestable where Self: UIView {
    public static var viewController: UIViewController {
        let controller = UIViewController()
        let view = self.init()
        controller.view.addSubview(view)
        controller.view.backgroundColor = self.backgroundColor
        
        if self.size == CGSize.zero {
            view.snp.makeConstraints({ (make) in
                make.top.equalTo(0).offset(nk_statusBarHeight)
                make.leading.trailing.equalTo(0)
            })
        } else {
            view.snp.makeConstraints({ (make) in
                make.top.equalTo(0).offset(nk_statusBarHeight)
                make.leading.equalTo(0)
                make.size.equalTo(self.size)
            })
        }
        
        if self.shouldAddNavigationBar {
            return UINavigationController(rootViewController: controller)
        }
        
        return controller
    }
    
    public static var size: CGSize {
        return CGSize.zero
    }
    
    public static var backgroundColor: UIColor {
        return UIColor.white
    }
    
    public static var shouldAddNavigationBar: Bool {
        return false
    }
}

public extension NKLayoutTestable where Self: UIViewController {
    public static var viewController: UIViewController {<commit_msg>added NKLayoutModelable to test some kind of model<commit_after>//
//  NKLayoutTestable.swift
//  NKit
//
//  Created by <NAME> on 9/23/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import UIKit
import NTZStackView
import RxSwift
import RxCocoa

public protocol NKLayoutTestable {
    static var viewController: UIViewController { get }
    static var shouldAddNavigationBar: Bool {get}
    static var size: CGSize {get}
    static var backgroundColor: UIColor {get}
}

public protocol NKLayoutModelable {
    associatedtype Model
    func config(model: Model)
    static var models: [Model] {get}
}

public extension NKLayoutTestable where Self: UIView {
    public static var viewController: UIViewController {
        let controller = UIViewController()
        let view = self.init()
        controller.view.addSubview(view)
        controller.view.backgroundColor = self.backgroundColor
        
        if self.size == CGSize.zero {
            view.snp.makeConstraints({ (make) in
                make.top.equalTo(0).offset(nk_statusBarHeight)
                make.leading.trailing.equalTo(0)
            })
        } else {
            view.snp.makeConstraints({ (make) in
                make.top.equalTo(0).offset(nk_statusBarHeight)
                make.leading.equalTo(0)
                make.size.equalTo(self.size)
            })
        }
        
        if self.shouldAddNavigationBar {
            return UINavigationController(rootViewController: controller)
        }
        
        return controller
    }
    
    public static var size: CGSize {
        return CGSize.zero
    }
    
    public static var backgroundColor: UIColor {
        return UIColor.white
    }
    
    public static var shouldAddNavigationBar: Bool {
        return false
    }
}

public extension NKLayoutTestable where Self: UIView, Self: NKLayoutModelable {
    public static var viewController: UIViewController {
        let controller = UIViewController()
        let view = self.init()
        controller.view.addSubview(view)
        controller.view.backgroundColor = self.backgroundColor
        
        if self.size == CGSize.zero {
            view.snp_makeConstraints(closure: { (make) in
                make.top.equalTo(0).offset(nk_statusBarHeight)
                make.leading.trailing.equalTo(0)
            })
        } else {
            view.snp_makeConstraints(closure: { (make) in
                make.top.equalTo(0).offset(nk_statusBarHeight)
                make.leading.equalTo(0)
                make.size.equalTo(self.size)
            })
        }
        
        if self.shouldAddNavigationBar {
            return UINavigationController(rootViewController: controller)
        }
        
        let models = self.models
        var i = 0
        func setConfig(index: Int) {
            if (0..<models.count) ~= index {
                i = index
                view.config(models[i])
            }
        }
        
        controller.view.nk_addSubview(TZStackView.nk_row()) {
            $0.backgroundColor = UIColor.grayColor()
            $0.alpha = 0.3
            $0.snp_makeConstraints(closure: { (make) in
                make.bottom.trailing.equalTo(0).inset(20)
            })
            
            $0
                .nk_addArrangedSubview(UIButton()) {
                    $0.setTitle("-", forState: .Normal)
                    $0.contentEdgeInsets = UIEdgeInsets.init(top: 10, left: 10, bottom: 10, right: 10)
                    $0.titleLabel?.font = UIFont.systemFontOfSize(20)
                    $0.setTitleColor(UIColor.blackColor(), forState: .Normal)
                    $0.setBackgroundImage(UIImage.nk_fromColor(UIColor.blueColor()), forState: .Highlighted)
                    $0.rx_tap.bindNext({ 
                        setConfig(i - 1)
                    }).addDisposableTo(controller.nk_disposeBag)
                }
                .nk_addArrangedSubview(UIButton()) {
                    $0.setTitle("+", forState: .Normal)
                    $0.contentEdgeInsets = UIEdgeInsets.init(top: 10, left: 10, bottom: 10, right: 10)
                    $0.titleLabel?.font = UIFont.systemFontOfSize(20)
                    $0.setTitleColor(UIColor.blackColor(), forState: .Normal)
                    $0.setBackgroundImage(UIImage.nk_fromColor(UIColor.blueColor()), forState: .Highlighted)
                    $0.rx_tap.bindNext({
                        setConfig(i + 1)
                    }).addDisposableTo(controller.nk_disposeBag)
            }
            
        }
        
        setConfig(0)
        
        
        return controller
    }
    
    public static var size: CGSize {
        return CGSize.zero
    }
    
    public static var backgroundColor: UIColor {
        return UIColor.whiteColor()
    }
    
    public static var shouldAddNavigationBar: Bool {
        return false
    }
}

public extension NKLayoutTestable where Self: UIViewController {
    public static var viewController: UIViewController {
{'fraction_non_alphanumeric': 0.0878317924246943, 'fraction_numerical': 0.011333134506412169, 'mean_word_length': 1.8455663979635129, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '120796', 'n_tokens_mistral': 1947, 'n_tokens_neox': 1813, 'n_words': 395}