I'm currently working on a project which contains a number of components (polymer elements). All said and done, I'll probably be looking at around 10+ components for the application. At the moment, following Pub's Package Layout Conventions each .html and associated .dart file is in the web/ directory.
It would be nice to have them in lib/src/ of my application and only have the main files in web/ however at the moment <link ref="import" href="package:my_app/src/my_component.html"> will not work (See Issue 12867).
Are there currently any conventions in use to handle multiple (private) components for an app? Should I create a web/src/ directory to load imports/source files relative to the web/ directory? Would it even make sense to keep Polymer Element .html files in lib/src/ (assuming it was supported) as they're not pure dart files as traditionally recommended/expected in a pub package layout?
As far as I understand, package: works only for external components (dependencies declared in pubspec.yaml), and the default path is the packages folder (created by pub install). See the getting started section here: Dart Pub
I keep components in their own folders under the web directory so web/component1, web/component2 and so on and I use relative links to import across components. Not sure if this is the best practice but it works.
Related
I have a Latex project that is including multiple PDFs. These PDFs are added in the final document through the includepdf tag when the project is compiled over Overleaf. My question is can Latex automatically generate a ToC from included PDFs, i.e., can it automatically read the \section \subsection tags from the included files and automatically generate it? Or maybe this is only possible if I included the separate project or sources into the final solution and compile that.
Your help is so welcome!
Including a rendered pdf file in your project would make you limited in accessing details of those documents. You will then only be able to select specific pages or add some content on specific places of those files (e.g. your own page numbers).
Since you have access to those projects, best is to nest those raw tex files under your current project using one (or a combination) of the following methods:
Input command: \input{foo.tex}: in this case the input file mustn't be a separate project (no \begindocument and \enddocument in it)
Include command: \include{foo.tex}: very similar to input command but a bit limited about nested includes.
import package: very similar to input and include commands but allows nested imports and also accepts a different logic for path resolution on its input (i.e. it accepts relative path to the file from where it is called).
subfiles package: In this case the subfile can have its own document body and is able to be rendered separately. The subfiles would use the preambles of your main project.
standalone package: Similar to subfiles but the main project would use the preambles of your subfiles in this case.
Overleaf nicely allows you to add files from another project which is the best choice when the other file is still being developed in a separate project. In this case, the file remains under control of the other project.
For further info, here is a very nice guide on how to write modular documents in latex and here is a brief tutorial on subfiles and standalone.
I am writing a Dart package, and I would like to have a resources directory that Pub includes with the package. I want this directory to be accessible relative to the root file of the package. Is there a standard way of doing this with Pub?
Thanks!
In general only files within lib/** can be used from other packages, therefore this is where you should put them.
Your question doesn't contain a lot of information what kind of package your want to create and what kind of resources you want to ship with the package or how the resources are supposed to be used by the user of the package. There are a few open bugs about other ways to make resources available to running applications.
Assets are available within the lib folder.
Create a folder under lib called assets, i.e. /lib/assets
Then link it in pubspec.yaml:
assets:
- assets/something.jpeg
I am trying to understand Dart's recommended project structure and not seeing the "forest through the trees".
So, if my project is intended to be a reusable library, say, a logging framework of some sort, then if I understand the above link correctly, I want all of my development to be under a lib and lib/src directory.
But what if I am building a web app? Where do my Dart source files go? Under packages? Specifically:
Where do I place Dart source files for a web app (not a lib)?
Are my web app's "packages" just directories that are logically organized similar to Java packages?
Does Dart recommend a 1-class-per-file convention for its source code?
1)
your_app_package/web
your_app_package/web/src/xxx
static content like jpg, css go to
* your_app_package/asset
2) the packages directory is maintained automatically. You configure in the file pubspec.yaml which 3rd party libraries you want to use and then call pub get or pub upgrade and the packages directory is updated automatically (the Darteditor does this automatically when you update pubspec.yaml).
3) not that I know of.
I had some problems putting additional classed in the code file of a Polymer element though. But I guess this is just a temporary limitation of Polymer.
If I'm just getting started authoring and managing my client source code using dart within a PHP or Rails project (similar to haxe or coffeescript), what convention(s) should be used for project structure?
Does any of this change if I say I'm mainly going to be transpiling my code to JavaScrpt?
Dart package layout conventions:
http://pub.dartlang.org/doc/package-layout.html
The more relevant parts for a client side dart application:
http://pub.dartlang.org/doc/package-layout.html#public-libraries
http://pub.dartlang.org/doc/package-layout.html#implementation-files
http://pub.dartlang.org/doc/package-layout.html#web-files
Long story short, put your dart libraries in the lib/ folder. The Dart scripts in here define what other packages (including your web/) can import and use. Entry points--scripts with main()--cannot go in the lib folder.
Files in lib/ can me imported with import "package:project_name/file_name.dart".
Internal libraries that should only be imported and used inside of the package should be put in lib/src/.
You use part/part of in dart code to create libraries, how does the HTML templates in WebComponents fit into this? How do I make the HTML templates part of the library? Also when i use <link rel> to import the relevant component, what do I reference?
I have this problem where I wrote a web componet A, so I have A.dart and A.html, I would like to package A into a library. If I reference A.html using a link rel anywhere the compiler will not package it into the library and instead treat it as a separate file.
Is each dart application a separate package or can I create multiple packages inside of a dart application project in dart-editor? The reason why I ask is because I want to separate my application into components
/web
/components
A.html
A.dart
index.html
index.dart
where everything under /components get put into a package that can be imported by index.html
There is a distinction between a Dart library and a Dart package. A library contains only Dart code, while a package contains Dart libraries as well as their relevant assets. library foo; part of foo; are only relevant in a code context. So long as your assets are in the same package directory as your Dart code (i.e. the directory that has pubspec.yaml at the top level) they are part of the same package.
You can import assets from packages by specifying the package path:
<link rel="import" href="package:foo/a.html">
Where foo is a package in your web/packages directory.