Add a basic sky-element custom element

After this CL, you can use <sky-element> to describe custom elements. The
current iteration is very basic and is hardcoded to "example", but its a start.

This CL renames the |init| function to |_init| to prevent importers from
calling it directly. Also, we now pass the <script> element to |_init| to give
some context.

R=ojan@chromium.org, eseidel@chromium.org

Review URL: https://codereview.chromium.org/950493003
This commit is contained in:
Adam Barth
2015-02-20 21:45:36 -08:00
parent 7c79bbf6bc
commit 8b94fd7798
4 changed files with 44 additions and 3 deletions

View File

@@ -0,0 +1,25 @@
<!--
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-->
<import src="/sky/framework/sky-element.sky" />
<sky-element>
<template>
<style>
div {
height: 50px;
width: 50px;
background-color: green;
}
</style>
<div>Hi</div>
</template>
<script>
@Tagname('example')
class ExampleElement extends SkyElement {
}
_init(script) => register(script, ExampleElement);
</script>
</sky-element>

View File

@@ -0,0 +1,16 @@
<!--
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-->
<sky>
<import src="example-element.sky" />
<style>
example {
border: 1px solid blue;
width: 100px;
height: 100px;
}
</style>
<example />
</sky>

View File

@@ -2,7 +2,7 @@
<script>
final String one = 'one';
bool oneInit = false;
void init() {
void _init(_) {
oneInit = true;
}
final conflict = 'one';
@@ -10,7 +10,7 @@ final conflict = 'one';
<script>
final String two = 'two';
bool twoInit = false;
void init() {
void _init(_) {
twoInit = true;
}
final conflict = 'two';

View File

@@ -6,7 +6,7 @@ class TestClass extends base.BaseClass {
bool didInit = false;
void init() {
void _init(_) {
didInit = (new TestClass() != null);
}
</script>