<commit_before>open class JsonView {
    public let spec: Json
    public unowned let screen: GScreen

    // This constructor allows dynamic instantiation of child classes.
    public required init(_ spec: Json, _ screen: GScreen) {
        self.spec = spec
        self.screen = screen
    }

    private func initGenericAttributes(backend: UIView) {
        if let view = backend as? IView {
            initBackgroundColor(view)
            initWidth(view)
            initHeight(view)
            initPadding(view)
        }
    }

    private func color(from str: String) -> UIColor {
        switch str {
        case "transparent":
            return UIColor.clear
        default:
            return UIColor(hex: str)
        }
    }

    private func initBackgroundColor(_ view: IView) {
        if let str = spec["backgroundColor"].string {
            _ = view.color(bg: color(from: str))
        }
    }

    private func initWidth(_ view: IView) {
        if let width = spec["width"].presence {
            if let val = width.string {
                switch val {
                case "wrapContent":
                    _ = view.width(.wrapContent)
                case "matchParent":
                    _ = view.width(.matchParent)
                default:
                    _ = view.width(width.intValue)
                }
            } else if let val = width.int {
                _ = view.width(width.intValue)
            }
        }
    }

    private func initHeight(_ view: IView) {
        if let height = spec["height"].presence {
            if let val = height.string {
                switch val {
                case "wrapContent":
                    _ = view.height(.wrapContent)
                case "matchParent":
                    _ = view.height(.matchParent)
                default:
                    _ = view.height(height.intValue)
                }
            } else if let val = height.int {
                _ = view.height(height.intValue)
            }
        }
    }

    private func initPadding(_ view: IView) {
        let padding = spec["padding"]
        _ = view.paddings(top: padding["top"].float, left: padding["left"].float, bottom: padding["bottom"].float, right: padding["right"].float)
    }

    open func initView() -> UIView {
        fatalError("Need implementation")
    }

    func createView() -> UIView {
        let view = initView()
        initGenericAttributes(backend: view)
        return view
    }

    static func create(spec: Json, screen: GScreen) -> JsonView? {
        if let klass = JsonUi.loadClass(name: spec["view"].stringValue, type: JsonView.self) as? JsonView.Type {
            return klass.init(spec, screen)
        }
        GLog.w("Failed loading view: \(spec)")
        return nil
    }
}
<commit_msg>Make sure button in hamburger's middle can be stretched<commit_after>open class JsonView {
    public let spec: Json
    public unowned let screen: GScreen

    // This constructor allows dynamic instantiation of child classes.
    public required init(_ spec: Json, _ screen: GScreen) {
        self.spec = spec
        self.screen = screen
    }

    private func initGenericAttributes(backend: UIView) {
        if let view = backend as? UIView & IView {
            initBackgroundColor(view)
            initWidth(view)
            initHeight(view)
            initPadding(view)
        }
    }

    private func color(from str: String) -> UIColor {
        switch str {
        case "transparent":
            return UIColor.clear
        default:
            return UIColor(hex: str)
        }
    }

    private func initBackgroundColor(_ view: IView) {
        if let str = spec["backgroundColor"].string {
            view.color(bg: color(from: str))
        }
    }

    private func initWidth(_ view: IView) {
        if let width = spec["width"].presence {
            if let val = width.string {
                switch val {
                case "wrapContent":
                    view.width(.wrapContent)
                case "matchParent":
                    view.width(.matchParent)
                default:
                    view.width(width.intValue)
                }
            } else if let val = width.int {
                view.width(width.intValue)
            }
        }
    }

    private func initHeight(_ view: UIView & IView) {
        if let height = spec["height"].presence {
            if let val = height.string {
                switch val {
                case "wrapContent":
                    view.height(.wrapContent)
                case "matchParent":
                    view.height(.matchParent)
                    // Needed for high hugging views (e.g. UILabel, UIButton) in a stretchable panel, e.g.
                    // the middle part of a hamburger panel.
                    ViewHelper.minimumHugging(view: view, axis: .vertical)
                default:
                    view.height(height.intValue)
                }
            } else if let val = height.int {
                view.height(height.intValue)
            }
        }
    }

    private func initPadding(_ view: IView) {
        let padding = spec["padding"]
        view.paddings(top: padding["top"].float, left: padding["left"].float, bottom: padding["bottom"].float, right: padding["right"].float)
    }

    open func initView() -> UIView {
        fatalError("Need implementation")
    }

    func createView() -> UIView {
        let view = initView()
        initGenericAttributes(backend: view)
        return view
    }

    static func create(spec: Json, screen: GScreen) -> JsonView? {
        if let klass = JsonUi.loadClass(name: spec["view"].stringValue, type: JsonView.self) as? JsonView.Type {
            return klass.init(spec, screen)
        }
        GLog.w("Failed loading view: \(spec)")
        return nil
    }
}

{'fraction_non_alphanumeric': 0.09732401568092722, 'fraction_numerical': 0.0, 'mean_word_length': 1.578207381370826, 'pattern_counts': {'":': 10, '<': 3, '<?xml version=': 0, '>': 11, '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': '6709152', 'n_tokens_mistral': 1575, 'n_tokens_neox': 1512, 'n_words': 410}