<commit_before># tael.js
# Copyright (c) 2015 <NAME>
# MIT License
error = require './error.coffee'

tiles = [
    type: 'container'
]

newTile = (parent) ->
    # Add a new tile to the `tiles` array.
    pushTile = ->
        # Push a new tile to the `tiles` array and return its index.
        (
            tiles.push
                type: 'leaf'
        ) - 1
    switch parent.type
        # Modify the parent tile and append one or two new tile(s) to the
        # `tiles` array.
        when 'container'
            # Create only one tile; 'container' is the top-level tile.
            parent.child = do pushTile
        when 'leaf'
            # Create two tiles; converts the 'leaf' tile into a 'branch' tile
            # before inserting the two new 'leaf' tiles into the 
            # newly-classified 'branch' tile.
            parent =
                type: 'branch'
                children:
                    left: do pushTile
                    right: do pushTile
                layout:
                    split: 'horizontal'
                    divider_location: 1
        when 'branch'
            error.throw "Branch tiles cannot spawn new children post-creation."

newTile tiles[0]

module.exports = ->
    ($ document).ready ->
        ($ '.tael-container')
        .append(
            ($ '<div>')
            .addClass 'tael-node-leaf'
            .text 'Hello, world!'
        )
<commit_msg>Add working Tael functionality<commit_after># tael.js
# Copyright (c) 2015 <NAME>
# MIT License
error = require './error.coffee'
ref = require './lib/ref.js'

tiles = [
    new ref
        type: 'container'
        child: undefined
]

newTile = (tiles, parent_id) ->
    # Add a new tile to the `tiles` array.
    pushTile = ->
        # Push a new tile to the `tiles` array and return its index.
        (
            tiles.push new ref
                    type: 'leaf'
                    content:
                        # To be added to
                        dom: null
                        data: 'foo'
        ) - 1
    
    addLeafToContainer = (parent) ->
        # Create only one tile and add it as the child of the supplied parent.
        # As the container tile is the top-level tile, it has only a single
        # child tile.
        parent.tile.value.child = do pushTile
    
    addLeavesToLeaf = (parent) ->
        # Create two tiles; convert the 'leaf' tile into a 'branch' tile
        # before inserting the two new 'leaf' tiles into the newly-classified
        # 'branch' tile.
        parent.tile.value =
            type: 'branch'
            children:
                left: do pushTile
                right: do pushTile
            layout:
                split: 'horizontal'
                divider_location: 0.5
    
    parent =
        id: parent_id
        tile: tiles[parent_id]
    
    switch parent.tile.value.type
        # Modify the parent tile and append one or two new tile(s) to the
        # `tiles` array.
        when 'container'
            addLeafToContainer parent
        when 'leaf'
            addLeavesToLeaf parent
        when 'branch'
            error.throw "Branch tiles cannot spawn new children post-creation."

newTile tiles, 0

module.exports = ->
    ($ document).ready ->
        ($ '.tael-container')
        .append(
            ($ '<div>')
            .addClass 'tael-node-leaf'
            .text tiles[1].value.content.data
        )

{'fraction_non_alphanumeric': 0.09159859976662778, 'fraction_numerical': 0.004667444574095682, 'mean_word_length': 1.4545454545454546, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, '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': '1157631', 'n_tokens_mistral': 964, 'n_tokens_neox': 925, 'n_words': 325}