# all files / Core/Components/Checkbox/ CheckboxDirective.js

100% Statements 12/12
100% Branches 4/4
100% Functions 2/2
100% Lines 12/12

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43

    1

    1

    1

    1
    4

    1
    4
    1

    3
    1

    2

    1
     'use strict';

    // Utilities:
    var _ = require('lodash');
    var fs = require('fs');

    // Dependencies:
    var camelcase = require('change-case').camel;

    // Module:
    var Core = require('../../Core');

    var CheckboxDirective = function () {
        return {
            restrict: 'E',

            scope: {
                model: '=',
                label: '@'
            },

            /* eslint-disable no-path-concat */
            template: fs.readFileSync(__dirname + '/Checkbox.html', 'utf8'),
            /* eslint-enable no-path-concat */

            link: link
        };

        function link ($scope) {
            if (_.isUndefined($scope.model)) {
                throw new Error('The "tractor-checkbox" directive requires a "model" attribute.');
            }

            if (_.isUndefined($scope.label)) {
                throw new Error('The "tractor-checkbox" directive requires an "label" attribute.');
            }

            $scope.property = camelcase($scope.label);
        }
    };

    Core.directive('tractorCheckbox', CheckboxDirective);