This package is a community effort to bring support for Polymer 2 and latest HTML standards to Dart (DDC).
It features :
polymer 2.0.0
(web components 1.0)ES6
output codeimd
(require js implementation using html imports)bower
Polymerize
works on every platforms where DDC
runs that's MacOS and Linux for now.
The upcoming version of pub
will support DDC
build and polymerize
will support it too thus extending the platform where you can use it.
Polymerize
uses DDC
and Polymer-2
, this means that it will only work on modern browsers. So far only chrome
and firefox
have been tested but Safari
should work too along with latest IE11 builds.
Eventually some "transpiling" support can be added along with some optimizing post processing (like vulcanize or similar) could be added to the build chain to broaden the compatibility range.
** UPDATE ** : after moving to ** PUB+DDC ** there's something broken with firefox , will fix soon. But I wanted to publish this release quickly after 1.24 was officially released.
In order to build a project with polymerize you have to add the following transformer and dev dependencies to your pubspec:
dev_dependencies:
- polymerize: ^0.9.0
transformers:
- polymerize:
entry-point: web/index.dart
The entry point is the main dart file. Your html file should look as this:
<html>
<head>
<script src="bower_components/webcomponentsjs/webcomponents-loader.js"></script>
<script type="application/dart" src="index.dart"></script>
<script src="polymerize_require/start.js"></script>
</head>
...
</html>
See the demo todo project for more details.
pub build --web-compiler dartdevc
(or add the necessary entries in the pubspec as well) ** DISCLAIMER ** : When using dartdevc
for production build you will loose al the optimizations that dart2js
normally makes to your code. This means that you will have bigger fat code even if modular and loaded only on demand.
A sample project illustrating how to build polymer-2
components using polymerize
can be found here :
See the README for more information.
This is a sample component definition:
import 'package:polymer_element/polymer_element.dart';
import 'package:my_component/other_component.dart';
@PolymerRegister('my-tag',template:'my-tag.html')
abstract class MyTag extends PolymerElement {
int count = 0; // <- no need to annotate this !!!
onClickIt(Event ev,details) { // <- NO need to annotate this!!!!
count = count + 1; // <- no need to call `set` API , magical setter in action here
}
@Observe('count')
void countChanged(val) {
print("Count has changed : ${count}");
}
MyTag() { // <- Use a simple constructor for created callback !!!
print("HELLO THERE !")
}
factory MyTag.tag() => Element.tag('my-tag'); // <- If you want to create it programmatically use this
connectedCallback() {
super.connectedCallback(); // <- super MUST BE CALLED if you override this callback (needed by webcomponents v1) !!!!
}
}
The Html template is just the usual dom-module
template without any JS code. The import dependencies will generate the appropriate html imports so there is no need to add them to
the template.
The index.html
should preload imd
, webcomponents
polyfill and polymer.html
(see the demo).
To import a bower component and use it in your project simply create a stub (that can created automatically, see below) for it and use the @BowerImport
annotation along with @PolymerRegister
with native=true
, for instance:
@PolymerRegister('paper-button',native:true)
@BowerImport(ref:'PolymerElements/paper-button#2.0-preview',import:"paper-button/paper-button.html",name:'paper-button')
abstract class PaperButton extends PolymerElement implements imp0.PaperButtonBehavior {
/**
* If true, the button should be styled with a shadow.
*/
external bool get raised;
external set raised(bool value);
}
During the build phase polymerize
will check any @BowerImport
annotation on classes of dependencies, generate a bower.json
file (using resolutions
if you need to override something) and then
runs bower install
.
You can also automatically generate a stub from the HTML polymer
component using polymerize generate_wrapper
, for instance:
pub run polymerize:polymerize generate-wrapper --component-refs comps.yaml --dest-path out -p polymer_elements --bower-needs-map Polymer.IronFormElementBehavior=package:polymer_elements/iron_form_element_behavior.dart
(You have to add polymerize
as a dev dependency of your project).
The generator uses a yaml file describing the components to analyze passed through the component-refs
options (see gen/comps.yam
in this repo for an example).
The project polymerize_elements is an example of wrappers generated using this tool for the polymer-elements
components.
After complilation everything will be found in the bazel output folder (bazel-bin
), ready to be used.
Builder
for build
(use polymerizeBuilder()
to generate a builder for polymerize)skip-generate: true
to skip generation polymer_elements
and html5
toobower_resolutions.yaml
optional ovverride for polymerize init
.packages
(dart 1.20)paper_dialog.dart
)polymerize
web
assets (not only index.html
)amd
is actually fully supported)You can install the package from the command line:
$ pub global activate polymerize
The package has the following executables:
$ polymerize
Add this to your package's pubspec.yaml file:
dependencies:
polymerize: ^0.9.8
You can install packages from the command line:
with pub:
$ pub get
Alternatively, your editor might support pub get
.
Check the docs for your editor to learn more.
Now in your Dart code, you can use:
import 'package:polymerize/polymerize.dart';
Version | Uploaded | Documentation | Archive |
---|---|---|---|
0.9.8 | Nov 16, 2017 |
|
|
0.9.7 | Oct 31, 2017 |
|
|
0.9.6 | Sep 10, 2017 |
|
|
0.9.5 | Jul 24, 2017 |
|
|
0.9.4 | Jun 30, 2017 |
|
|
0.9.3 | Jun 23, 2017 |
|
|
0.9.2 | Jun 22, 2017 |
|
|
0.9.1+1 | Jun 18, 2017 |
|
|
0.9.1 | Jun 18, 2017 |
|
|
0.9.0+1 | Jun 13, 2017 |
|
|
Popularity:
Describes how popular the package is relative to other packages.
[more]
|
28
|
Health:
Code health derived from static analysis.
[more]
|
--
|
Maintenance:
Reflects how tidy and up-to-date the package is.
[more]
|
--
|
Overall:
Weighted score of the above.
[more]
|
14
|
The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.
Support Dart 2 in pubspec.yaml
.
The SDK constraint in pubspec.yaml
doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see https://www.dartlang.org/dart-2#migration.
Make sure dartdoc
successfully runs on your package's source files. (-10 points)
Dependencies were not resolved.
Package | Constraint | Resolved | Available |
---|---|---|---|
Direct dependencies | |||
Dart SDK | >=1.8.0 <2.0.0 |