This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 231131
Collapse All | Expand All

(-)api.knockout/build.xml (+5 lines)
Line 0 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project basedir="." default="netbeans" name="api.knockout">
3
    <description>Builds, tests, and runs the project org.netbeans.api.knockout</description>
4
    <import file="../nbbuild/templates/projectized.xml"/>
5
</project>
(-)api.knockout/manifest.mf (+5 lines)
Line 0 Link Here
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.netbeans.api.knockout
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/api/knockout/Bundle.properties
4
OpenIDE-Module-Specification-Version: 1.0
5
(-)api.knockout/nbproject/project.properties (+2 lines)
Line 0 Link Here
1
javac.source=1.7
2
javac.compilerargs=-Xlint -Xlint:-serial
(-)api.knockout/nbproject/project.xml (+85 lines)
Line 0 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project xmlns="http://www.netbeans.org/ns/project/1">
3
    <type>org.netbeans.modules.apisupport.project</type>
4
    <configuration>
5
        <data xmlns="http://www.netbeans.org/ns/nb-module-project/3">
6
            <code-name-base>org.netbeans.api.knockout</code-name-base>
7
            <module-dependencies>
8
                <dependency>
9
                    <code-name-base>org.netbeans.modules.editor.mimelookup</code-name-base>
10
                    <build-prerequisite/>
11
                    <compile-dependency/>
12
                    <run-dependency>
13
                        <release-version>1</release-version>
14
                        <specification-version>1.32</specification-version>
15
                    </run-dependency>
16
                </dependency>
17
                <dependency>
18
                    <code-name-base>org.netbeans.modules.html.editor</code-name-base>
19
                    <build-prerequisite/>
20
                    <compile-dependency/>
21
                    <run-dependency>
22
                        <release-version>2</release-version>
23
                        <specification-version>2.52</specification-version>
24
                    </run-dependency>
25
                </dependency>
26
                <dependency>
27
                    <code-name-base>org.netbeans.modules.html.lexer</code-name-base>
28
                    <build-prerequisite/>
29
                    <compile-dependency/>
30
                    <run-dependency>
31
                        <release-version>1</release-version>
32
                        <specification-version>1.29</specification-version>
33
                    </run-dependency>
34
                </dependency>
35
                <dependency>
36
                    <code-name-base>org.netbeans.modules.lexer</code-name-base>
37
                    <build-prerequisite/>
38
                    <compile-dependency/>
39
                    <run-dependency>
40
                        <release-version>2</release-version>
41
                        <specification-version>1.52</specification-version>
42
                    </run-dependency>
43
                </dependency>
44
                <dependency>
45
                    <code-name-base>org.netbeans.modules.parsing.api</code-name-base>
46
                    <build-prerequisite/>
47
                    <compile-dependency/>
48
                    <run-dependency>
49
                        <release-version>1</release-version>
50
                        <specification-version>9.0</specification-version>
51
                    </run-dependency>
52
                </dependency>
53
                <dependency>
54
                    <code-name-base>org.openide.filesystems</code-name-base>
55
                    <build-prerequisite/>
56
                    <compile-dependency/>
57
                    <run-dependency>
58
                        <specification-version>9.0</specification-version>
59
                    </run-dependency>
60
                </dependency>
61
                <dependency>
62
                    <code-name-base>org.openide.util.lookup</code-name-base>
63
                    <build-prerequisite/>
64
                    <compile-dependency/>
65
                    <run-dependency>
66
                        <specification-version>8.21</specification-version>
67
                    </run-dependency>
68
                </dependency>
69
            </module-dependencies>
70
            <test-dependencies>
71
                <test-type>
72
                    <name>unit</name>
73
                    <test-dependency>
74
                        <code-name-base>org.netbeans.libs.testng</code-name-base>
75
                        <compile-dependency/>
76
                    </test-dependency>
77
                </test-type>
78
            </test-dependencies>
79
            <public-packages>
80
                <package>org.netbeans.modules.knockout.impl</package>
81
                <package>org.netbeans.spi.knockout</package>
82
            </public-packages>
83
        </data>
84
    </configuration>
85
</project>
(-)api.knockout/src/org/netbeans/api/knockout/Bundle.properties (+1 lines)
Line 0 Link Here
1
OpenIDE-Module-Name=Knockout Model Provider API
(-)api.knockout/src/org/netbeans/spi/knockout/Bindings.java (+210 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2013 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2013 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.spi.knockout;
43
44
import java.util.ArrayList;
45
import java.util.HashSet;
46
import java.util.LinkedHashSet;
47
import java.util.List;
48
import java.util.Set;
49
import org.netbeans.spi.knockout.BindingsProvider.Response;
50
import org.openide.filesystems.FileObject;
51
import org.openide.util.Lookup;
52
53
/**
54
 * Allows structural description of a <code>ko.applyBindings</code> parameter.
55
 * Register as {@link BindingsProvider}. When called build description of JSON
56
 * types using methods like {@link #stringProperty(java.lang.String, boolean)}
57
 * and then pass the result into
58
 * {@link Response#applyBindings(org.netbeans.spi.knockout.Bindings)} method.
59
 *
60
 * @author Jaroslav Tulach <jtulach@netbeans.org>
61
 */
62
public final class Bindings {
63
64
    private final String name;
65
    private final List<Bindings> subBindings = new ArrayList<>();
66
    private final List<String> props = new ArrayList<>();
67
68
    private Bindings(String name) {
69
        this.name = name;
70
    }
71
72
    /**
73
     * Defines new variable with provided name and assigns a JSON object into
74
     * it. The created instance is a builder - continue calling its various
75
     * builder methods like {@link #intProperty(java.lang.String, boolean)}.
76
     *
77
     * @param name name of variable (must be valid JavaScript identifier)
78
     * @return empty JSON object ready to be filled using
79
     * {@link #doubleProperty(java.lang.String, boolean)}, and other methods
80
     */
81
    public static Bindings create(String name) {
82
        return new Bindings(name);
83
    }
84
85
    /**
86
     * Generates a boolean property (with value <code>true</code>) into the JSON
87
     * class.
88
     *
89
     * @param name name of variable (must be valid JavaScript identifier)
90
     * @param array should this property be an array of just a single value
91
     * @return this object
92
     */
93
    public final Bindings booleanProperty(String name, boolean array) {
94
        addProp(name, array, "true");
95
        return this;
96
    }
97
98
    /**
99
     * Generates a string property (with value <code>''</code>) into the JSON
100
     * class.
101
     *
102
     * @param name name of variable (must be valid JavaScript identifier)
103
     * @param array should this property be an array of just a single value
104
     * @return this object
105
     */
106
    public final Bindings stringProperty(String name, boolean array) {
107
        addProp(name, array, "''");
108
        return this;
109
    }
110
111
    /**
112
     * Generates a integer property (with value <code>0</code>) into the JSON
113
     * class.
114
     *
115
     * @param name name of variable (must be valid JavaScript identifier)
116
     * @param array should this property be an array of just a single value
117
     * @return this object
118
     */
119
    public final Bindings intProperty(String name, boolean array) {
120
        addProp(name, array, "0");
121
        return this;
122
    }
123
124
    /**
125
     * Generates a floating point property (with value <code>0.1</code>) into
126
     * the JSON class.
127
     *
128
     * @param name name of variable (must be valid JavaScript identifier)
129
     * @param array should this property be an array of just a single value
130
     * @return this object
131
     */
132
    public final Bindings doubleProperty(String name, boolean array) {
133
        addProp(name, array, "0.1");
134
        return this;
135
    }
136
137
    /**
138
     * Generates complex subtype based on another {@link Bindings} class.
139
     *
140
     * @param name name of variable (must be valid JavaScript identifier)
141
     * @param binding another description of a JSON like object
142
     * @param array should this property be an array of just a single value
143
     * @return this object
144
     */
145
    public final Bindings modelProperty(String name, Bindings binding, boolean array) {
146
        subBindings.add(binding);
147
        addProp(name, array, binding.name);
148
        return this;
149
    }
150
151
    final String generate() {
152
        StringBuilder sb = new StringBuilder();
153
        //sb.append("(function() {\n");
154
        HashSet<Bindings> visited = new HashSet<>();
155
        LinkedHashSet<Bindings> lhs = new LinkedHashSet<>();
156
        walkBindings(visited, lhs);
157
        for (Bindings b : lhs) {
158
            b.generate(sb);
159
        }
160
        sb.append("  ko.applyBindings(").append(name).append(");\n");
161
        //sb.append("}());");
162
        return sb.toString();
163
    }
164
165
    private void generate(StringBuilder sb) {
166
        sb.append("var ").append(name).append(" = {");
167
        String sep = "\n";
168
        for (String s : props) {
169
            sb.append(sep).append("  ").append(s);
170
            sep = ",\n";
171
        }
172
        sb.append("\n};\n");
173
    }
174
175
    private void addProp(String name, boolean array, String value) {
176
        if (array) {
177
            value = "[ " + value + " ]";
178
        }
179
        if (name.contains("\"")) {
180
            throw new IllegalStateException("Wrong name " + name);
181
        }
182
        props.add('\"' + name + "\" : " + value);
183
    }
184
185
    private void walkBindings(Set<Bindings> visited, Set<Bindings> collect) {
186
        if (!visited.add(this)) {
187
            return;
188
        }
189
        for (Bindings b : subBindings) {
190
            b.walkBindings(visited, collect);
191
        }
192
        collect.add(this);
193
    }
194
195
    static {
196
        new SPIAccessor() {
197
            @Override
198
            protected String findBindings(FileObject fo) {
199
                Response r = new Response();
200
                for (BindingsProvider p : Lookup.getDefault().lookupAll(BindingsProvider.class)) {
201
                    p.findBindings(fo, r);
202
                    if (r.bindings != null) {
203
                        return r.bindings.generate();
204
                    }
205
                }
206
                return null;
207
            }
208
        };
209
    }
210
}
(-)api.knockout/src/org/netbeans/spi/knockout/BindingsProvider.java (+65 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2013 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2013 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.spi.knockout;
43
44
import org.openide.filesystems.FileObject;
45
46
/**
47
 *
48
 * @author Jaroslav Tulach <jtulach@netbeans.org>
49
 */
50
public interface BindingsProvider {
51
52
    public void findBindings(FileObject htmlFile, Response r);
53
54
    public static final class Response {
55
56
        Bindings bindings;
57
58
        Response() {
59
        }
60
61
        public void applyBindings(Bindings bindings) {
62
            this.bindings = bindings;
63
        }
64
    }
65
}
(-)api.knockout/src/org/netbeans/spi/knockout/SPIAccessor.java (+67 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2013 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2013 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.spi.knockout;
43
44
import org.openide.filesystems.FileObject;
45
46
/**
47
 *
48
 * @author Jaroslav Tulach <jtulach@netbeans.org>
49
 */
50
public abstract class SPIAccessor {
51
52
    private static SPIAccessor DEFAULT;
53
54
    static {
55
        Bindings.create("");
56
    }
57
58
    public static String findModelFor(FileObject fo) {
59
        return DEFAULT.findBindings(fo);
60
    }
61
62
    protected SPIAccessor() {
63
        DEFAULT = this;
64
    }
65
66
    protected abstract String findBindings(FileObject fo);
67
}
(-)api.knockout/test/unit/src/org/netbeans/spi/knockout/BindingsNGTest.java (+104 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2013 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2013 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.spi.knockout;
43
44
import javax.script.ScriptEngine;
45
import javax.script.ScriptEngineManager;
46
import javax.script.ScriptException;
47
import org.testng.annotations.BeforeMethod;
48
import org.testng.annotations.Test;
49
import static org.testng.Assert.*;
50
51
/**
52
 *
53
 * @author Jaroslav Tulach <jtulach@netbeans.org>
54
 */
55
public class BindingsNGTest {
56
    private ScriptEngine eng;
57
58
    public BindingsNGTest() {
59
    }
60
61
    @BeforeMethod public void initEngine() {
62
        ScriptEngineManager sem = new ScriptEngineManager();
63
        eng = sem.getEngineByMimeType("text/javascript");
64
    }
65
66
    @Test public void generateTwitterModel() throws Exception {
67
        Bindings tweet = Bindings.create("Tweet").
68
            stringProperty("from_user", false).
69
            intProperty("from_user_id", false);
70
71
        Bindings tweeters = Bindings.create("Tweeters").
72
            stringProperty("name", false).
73
            stringProperty("userNames", true);
74
75
        Bindings twitterClient = Bindings.create("TwitterClient");
76
        twitterClient.
77
            stringProperty("activeTweetersName", false).
78
            stringProperty("activeTweeters", true).
79
            stringProperty("userNameToAdd", false).
80
            booleanProperty("loading", false).
81
            modelProperty("currentTweets", tweet, true).
82
            modelProperty("savedLists", tweeters, true);
83
84
        String txt = twitterClient.generate();
85
86
        assertValidJS(txt);
87
88
        assertNotNull(eng.eval("ko"));
89
        assertNotNull(eng.eval("ko.value"));
90
        assertEquals(eng.eval("ko.value.loading"), true, "Boolean values are set to true");
91
        assertEquals(eng.eval("ko.value.currentTweets[0].from_user_id"), 0d, "Boolean values are set to true");
92
    }
93
94
    private void assertValidJS(String txt) {
95
        assertNotNull(txt, "We have some script");
96
        try {
97
            eng.eval("ko = {}; ko.applyBindings = function(val) { ko.value = val; }");
98
            eng.eval(txt);
99
        } catch (ScriptException ex) {
100
            throw new AssertionError(txt, ex);
101
        }
102
    }
103
104
}
(-)html.editor/manifest.mf (-1 / +1 lines)
Lines 2-6 Link Here
2
OpenIDE-Module: org.netbeans.modules.html.editor/2
2
OpenIDE-Module: org.netbeans.modules.html.editor/2
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/html/editor/resources/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/html/editor/resources/Bundle.properties
4
OpenIDE-Module-Layer: org/netbeans/modules/html/editor/resources/layer.xml
4
OpenIDE-Module-Layer: org/netbeans/modules/html/editor/resources/layer.xml
5
OpenIDE-Module-Specification-Version: 2.51
5
OpenIDE-Module-Specification-Version: 2.52
6
AutoUpdate-Show-In-Client: false
6
AutoUpdate-Show-In-Client: false
(-)html.editor/nbproject/project.xml (-1 / +2 lines)
Lines 541-546 Link Here
541
            <friend-packages>
541
            <friend-packages>
542
                <friend>com.ext4yii.editor</friend>
542
                <friend>com.ext4yii.editor</friend>
543
                <friend>nl.truesoftware.blendsdk</friend>
543
                <friend>nl.truesoftware.blendsdk</friend>
544
                <friend>org.netbeans.api.knockout</friend>
544
                <friend>org.netbeans.modules.css.visual</friend>
545
                <friend>org.netbeans.modules.css.visual</friend>
545
                <friend>org.netbeans.modules.groovy.gsp</friend>
546
                <friend>org.netbeans.modules.groovy.gsp</friend>
546
                <friend>org.netbeans.modules.html.angular</friend>
547
                <friend>org.netbeans.modules.html.angular</friend>
Lines 549-556 Link Here
549
                <friend>org.netbeans.modules.html.ojet</friend>
550
                <friend>org.netbeans.modules.html.ojet</friend>
550
                <friend>org.netbeans.modules.javascript.editing</friend>
551
                <friend>org.netbeans.modules.javascript.editing</friend>
551
                <friend>org.netbeans.modules.javascript2.editor</friend>
552
                <friend>org.netbeans.modules.javascript2.editor</friend>
552
                <friend>org.netbeans.modules.javascript2.requirejs</friend>
553
                <friend>org.netbeans.modules.javascript2.nodejs</friend>
553
                <friend>org.netbeans.modules.javascript2.nodejs</friend>
554
                <friend>org.netbeans.modules.javascript2.requirejs</friend>
554
                <friend>org.netbeans.modules.php.latte</friend>
555
                <friend>org.netbeans.modules.php.latte</friend>
555
                <friend>org.netbeans.modules.ruby.rhtml</friend>
556
                <friend>org.netbeans.modules.ruby.rhtml</friend>
556
                <friend>org.netbeans.modules.web.clientproject</friend>
557
                <friend>org.netbeans.modules.web.clientproject</friend>
(-)html.knockout/nbproject/project.xml (+8 lines)
Lines 15-20 Link Here
15
                    </run-dependency>
15
                    </run-dependency>
16
                </dependency>
16
                </dependency>
17
                <dependency>
17
                <dependency>
18
                    <code-name-base>org.netbeans.api.knockout</code-name-base>
19
                    <build-prerequisite/>
20
                    <compile-dependency/>
21
                    <run-dependency>
22
                        <specification-version>1.0</specification-version>
23
                    </run-dependency>
24
                </dependency>
25
                <dependency>
18
                    <code-name-base>org.netbeans.api.progress</code-name-base>
26
                    <code-name-base>org.netbeans.api.progress</code-name-base>
19
                    <build-prerequisite/>
27
                    <build-prerequisite/>
20
                    <compile-dependency/>
28
                    <compile-dependency/>
(-)html.knockout/src/org/netbeans/modules/html/knockout/KOJsEmbeddingProviderPlugin.java (+13 lines)
Lines 65-72 Link Here
65
import org.netbeans.modules.html.knockout.KODataBindContext.ParentContext;
65
import org.netbeans.modules.html.knockout.KODataBindContext.ParentContext;
66
import org.netbeans.modules.html.knockout.model.KOModel;
66
import org.netbeans.modules.html.knockout.model.KOModel;
67
import org.netbeans.modules.javascript2.editor.api.lexer.JsTokenId;
67
import org.netbeans.modules.javascript2.editor.api.lexer.JsTokenId;
68
import org.netbeans.spi.knockout.SPIAccessor;
68
import org.netbeans.modules.parsing.api.Embedding;
69
import org.netbeans.modules.parsing.api.Embedding;
69
import org.netbeans.modules.parsing.api.Snapshot;
70
import org.netbeans.modules.parsing.api.Snapshot;
71
import org.openide.filesystems.FileObject;
70
import org.openide.util.Pair;
72
import org.openide.util.Pair;
71
73
72
/**
74
/**
Lines 100-105 Link Here
100
102
101
    private KODataBindContext currentTemplateContext;
103
    private KODataBindContext currentTemplateContext;
102
104
105
    private String generatedSource;
106
103
    public KOJsEmbeddingProviderPlugin() {
107
    public KOJsEmbeddingProviderPlugin() {
104
        JS_LANGUAGE = Language.find(KOUtils.JAVASCRIPT_MIMETYPE); //NOI18N
108
        JS_LANGUAGE = Language.find(KOUtils.JAVASCRIPT_MIMETYPE); //NOI18N
105
        this.stack = new LinkedList();
109
        this.stack = new LinkedList();
Lines 114-119 Link Here
114
        if(!KOModel.getModel(parserResult).containsKnockout()) {
118
        if(!KOModel.getModel(parserResult).containsKnockout()) {
115
            return false;
119
            return false;
116
        }
120
        }
121
122
        FileObject fo = snapshot.getSource().getFileObject();
123
        if (fo != null) {
124
            generatedSource = SPIAccessor.findModelFor(fo);
125
        }
117
        return true;
126
        return true;
118
    }
127
    }
119
128
Lines 341-346 Link Here
341
        StringBuilder sb = new StringBuilder();
350
        StringBuilder sb = new StringBuilder();
342
        sb.append("(function(){\n"); // NOI18N
351
        sb.append("(function(){\n"); // NOI18N
343
352
353
        if (generatedSource != null) {
354
            sb.append(generatedSource).append("\n");
355
        }
356
344
        // for now this is actually just a placeholder
357
        // for now this is actually just a placeholder
345
        sb.append("var $element;\n");
358
        sb.append("var $element;\n");
346
359
(-)nbbuild/cluster.properties (+1 lines)
Lines 296-301 Link Here
296
        api.debugger,\
296
        api.debugger,\
297
        api.java.classpath,\
297
        api.java.classpath,\
298
        api.java.classpath.nb,\
298
        api.java.classpath.nb,\
299
        api.knockout,\
299
        api.xml,\
300
        api.xml,\
300
        api.xml.ui,\
301
        api.xml.ui,\
301
        bugtracking,\
302
        bugtracking,\
(-)sample.bindingsprovider/build.xml (+5 lines)
Line 0 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project basedir="." default="netbeans" name="sample.bindingsprovider">
3
    <description>Builds, tests, and runs the project org.netbeans.modules.sample.bindingsprovider</description>
4
    <import file="../nbbuild/templates/projectized.xml"/>
5
</project>
(-)sample.bindingsprovider/manifest.mf (+6 lines)
Line 0 Link Here
1
Manifest-Version: 1.0
2
AutoUpdate-Show-In-Client: true
3
OpenIDE-Module: org.netbeans.modules.sample.bindingsprovider
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/sample/bindingsprovider/Bundle.properties
5
OpenIDE-Module-Specification-Version: 1.0
6
(-)sample.bindingsprovider/nbproject/project.properties (+2 lines)
Line 0 Link Here
1
javac.source=1.7
2
javac.compilerargs=-Xlint -Xlint:-serial
(-)sample.bindingsprovider/nbproject/project.xml (+36 lines)
Line 0 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project xmlns="http://www.netbeans.org/ns/project/1">
3
    <type>org.netbeans.modules.apisupport.project</type>
4
    <configuration>
5
        <data xmlns="http://www.netbeans.org/ns/nb-module-project/3">
6
            <code-name-base>org.netbeans.modules.sample.bindingsprovider</code-name-base>
7
            <module-dependencies>
8
                <dependency>
9
                    <code-name-base>org.netbeans.api.knockout</code-name-base>
10
                    <build-prerequisite/>
11
                    <compile-dependency/>
12
                    <run-dependency>
13
                        <specification-version>1.0</specification-version>
14
                    </run-dependency>
15
                </dependency>
16
                <dependency>
17
                    <code-name-base>org.openide.filesystems</code-name-base>
18
                    <build-prerequisite/>
19
                    <compile-dependency/>
20
                    <run-dependency>
21
                        <specification-version>9.3</specification-version>
22
                    </run-dependency>
23
                </dependency>
24
                <dependency>
25
                    <code-name-base>org.openide.util.lookup</code-name-base>
26
                    <build-prerequisite/>
27
                    <compile-dependency/>
28
                    <run-dependency>
29
                        <specification-version>8.30</specification-version>
30
                    </run-dependency>
31
                </dependency>
32
            </module-dependencies>
33
            <public-packages/>
34
        </data>
35
    </configuration>
36
</project>
(-)sample.bindingsprovider/src/org/netbeans/modules/sample/bindingsprovider/Bundle.properties (+1 lines)
Line 0 Link Here
1
OpenIDE-Module-Name=Knockout Sample Bindings Provider
(-)sample.bindingsprovider/src/org/netbeans/modules/sample/bindingsprovider/SampleBindingsProvider.java (+78 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2014 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2014 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.sample.bindingsprovider;
43
44
import org.netbeans.spi.knockout.Bindings;
45
import org.netbeans.spi.knockout.BindingsProvider;
46
import org.openide.filesystems.FileObject;
47
import org.openide.util.lookup.ServiceProvider;
48
49
/**
50
 *
51
 * @author rsvitanic
52
 */
53
@ServiceProvider(service = BindingsProvider.class)
54
public class SampleBindingsProvider implements BindingsProvider {
55
56
    @Override
57
    public void findBindings(FileObject htmlFile, Response r) {
58
        Bindings tweet = Bindings.create("Tweet").
59
                stringProperty("from_user", false).
60
                intProperty("from_user_id", false);
61
62
        Bindings tweeters = Bindings.create("Tweeters").
63
                stringProperty("name", false).
64
                stringProperty("userNames", true);
65
66
        Bindings twitterClient = Bindings.create("TwitterClient");
67
        twitterClient.
68
                stringProperty("activeTweetersName", false).
69
                stringProperty("activeTweeters", true).
70
                stringProperty("userNameToAdd", false).
71
                booleanProperty("loading", false).
72
                modelProperty("currentTweets", tweet, true).
73
                modelProperty("savedLists", tweeters, true);
74
75
        r.applyBindings(twitterClient);
76
    }
77
78
}

Return to bug 231131