Polymer Elements in Dart Packages -
i have dart package contains 3 extensions of polymer element: tp-element-a, tp-element-b , tp-element-c. each of these elements there html-file containing markup of element , dart file code. tp-element-c contains references tp-element-a , tp-element-b. package structure looks this:
testpolymer pubspec.yaml - packages - asset tp-element-a.html tp-element-b.html tp-element-c.html - lib testpolymer.dart tp-element-a.dart tp-element-b.dart tp-element-c.dart - web index.html
the definitiopn of polymer elements simple:
tp-element-a.html
<polymer-element name="tp-element-a"> <template> <h1>hello element a</h1> </template> <script type="application/dart" src="../lib/tp-element-a.dart"></script> </polymer-element>
tp-element-a.dart
part of testpolymer; @customtag("tp-element-a") class tpelementa extends polymerelement { tpelementa.created() : super.created() {} }
i skip definitions of tp-element-b , tp-element-c. similar. difference tp-element-c uses tp-element-a , tp-element-b within template markup.
the file testpolymer.dart contains definition of library testpolymer:
library testpolymer; import "package:polymer/polymer.dart"; part "tp-element-a.dart"; part "tp-element-b.dart"; part "tp-element-c.dart";
in yaml file decalre dependency polymer package , add polymer transformer:
name: testpolymer description: pub package dependencies: polymer: transformers: - polymer: entry_points: web/index.html
last not least index.html contains link tp-element-c.html , uses element:
<html> <head> <link rel="import" href="../asset/tp-element-c.html"> <script type="application/dart">export 'package:polymer/init.dart';</script> <script src="packages/browser/dart.js"></script> </head> <body> <div id="sample_container_id"> <tp-element-c></tp-element-c> </div> </body> </html>
so far good. when run pub build errors, caused organizing dart files in library:
packages/testpolymer/tp-element-a.dart:1:1: directive not allowed here. part of testpolymer; packages/testpolymer/tp-element-a.dart:4:26: class can't extend malformed type. try correcting malformed type annotation or removing 'extends' clause. class tpelementa extends polymerelement { packages/testpolymer/tp-element-a.dart:3:2: cannot resolve 'customtag'. @customtag("tp-element-a")
so how possible include code polymer elements in libraries?
if don't organize polymer code library, error in tp-element-c.dart, imports (if no library used) tp-element-a.dart , tp-element-b.dart directly:
the imported libraries 'tp-element-a.dart' , 'tp-element-b.dart' should not have same name ''
how can resolve puzzle?
you last error message, if don't have in each dart file unique library uniquename;
definitions. in case names be: tp-element-a, tp-element-b etc.
Comments
Post a Comment