I am not a Java developer and forced to work with Tapestry 5.3.8.
I am able to use assets like css, images and a fav icon in my web page. I do this by injecting them in my page like this:
#Inject
#Path("context:static/img/logo.png")
private Asset logo;
#Inject
#Path("context:static/img/favicon.ico")
private Asset favIcon;
This works without problems. Although it works, I am not convinced the assets are in the right folder. Should they be placed in folder 'static'?
Now I want to add a Javascript file. This is what I did:
#Import(library = "context:static/js/additional.js")
public class Master {
// ...
}
The file is found, but I runtime i get the following error: "The resource path was not within an aliased path".
From what I understand is that I need to create an alias for the path where my Javscript file is located, but how?
I guess this must be done in method "contributeClasspathAssetAliasManager" in CiAppModule.java. Is this right, and what should I add?
I've never tried to use a context: asset for a javascript file. Tapestry makes classpath assets available under the assets/ alias which is possibly what this error is referring to. See the mention of 'asset fingerprinting' here
A possible souition is:
package foo.bar.components;
#Import(library = "additional.js")
public class Master {
And then have foo/bar/components/additional.js available on the classpath. For maven / gradle this will mean the file lives at src/main/resources/foo/bar/components/additional.js
The problem was in this part:
#Import(library = "context:static/js/additional.js")
When I change it into
#Import(library = {"context:static/js/additional.js"})
it works.
Thanks to Tapestry's error reporting, this was not clear at all. Grrrr.
Related
When I work with angular2 code I often need to see the implementation of a class, let's say the Router class.
If I click on the Router type in my IDE WebStorm, e. g. inside the constructor of another class
export class myClass {
constructor(private router: Router) {}
// ...
}
my IDE takes me to the TypeScript definition file router.d.ts inside my node_modules folder. What I want is it to take me to the original router.ts file with the implementation of the router class, not just its definition.
The original .ts file is not included in the node_modules folder structure when you get angular2 from github via the standard package.json suggested in the Angular2 Quickstart. Currently, I have to look up the original code in the official github repo.
Any ideas how to get the .ts files into my node_modules/#angular folder instead of the .d.ts files?
Sadly, it's not possible since no TS files exist. Even if you add them it still not possible since you import real angular paths which always point to the definition files. On top of that the file structure of the project does not correlate to the structure of the import string literals.
Some background and more information
The NPM package does not include .ts files, this is by design from the angular team. Up until some time ago the .ts files were indeed supplied with the NPM package.
The reasoning for removing them is to disable abuse from users accessing private classes and #internal and private APIs which is public methods/properties in the API that are not supposed to be public but must be so other angular internal classes can use them.
We used to see a lot of code samples out there doing things like import { PromiseCompleter } from 'angular2/src/facade/lang'; (before RC0) but this was changed when the project structure had a big structure refactor in RC0. This abuse was wide and it's bad, very bad... For users and for Angular PR.
The Angular project has a complex and robust build process where all of the API is moved from .ts files into d.ts files using an automated process that limits exposure. (public_api_guard)
The end result is d.ts files only.
It's also not possible to clone the git repo and use it since, again, the file structure is way way different so imports will have to change. Most importantly without the build Angular will, most likely, not work.
A solution using a different approach
However, if you debug your app you notice that you reach actual angular core .ts files in the source view of the console, this is because the NPM package comes with source map files that include the whole TS source code. Nice trick they did there.
This is what I use to dig deep into angular, it works quite great and I get a lot from it.
It's not as nice as Goto Declaration but it something...
IMO it's also easier to understand when you step through code...
I am using a private folder in my Meteor project to store/use static (private) assets (e.g., .json and .js files) which can be loaded using Assets.getText(assetFileName). These are normally deployed on meteor startup from "projectdir\private" to "projectdir.meteor\local\build\programs\server\assets\app".
However, of the three .js files that I have in my private directory, only two are deployed; one of them remains absent. I am trying to use that file in the exact same way (part of a loop that finds and processes all files in a directory), but Meteor simply doesn't deploy the file to the aforementioned directory, as a result of which I am met with a file-does-not-exist error for "platform_b.js".
"platform_a.js" and "platform_c.js" can be found (i.e., are deployed) and all three of them are present in the private folder, but (auto-)deployment fails for "platform_b.js". Deleting the deployment directory and/or rerunning does not seem to solve the issue. Any thoughts? Many thanks in advance.
I have the same problem. You can load the private file in your code like this to force loading the assets.
Assets.getBinary('path/to/file')
In my meteor application. I defined a BaseControllerin base_controller.js:
BaseController = RouteController.extend({
layoutTemplate: 'mainLayout'
});
Then I defined PostController in post_controller.js:
PostController = BaseController.extend({
});
If I put base_controller.js and post_controller.js in same directory, no error founds. But if I put in different directory, such as base_controller.js in controller and post_controller.js in controller/post I will meet exception when running application:
ReferenceError: BaseController is not defined
My question is: how can I divide those javascript file into different directory? I need to do this, because my application will have many controllers so put all controllers into same directory (without any child directory) will make project hard for maintenance.
Thanks :)
You have to understand how Meteor loads your files. See sub-section File Load Order: http://docs.meteor.com/#/full/structuringyourapp
From the docs:
There are several load ordering rules. They are applied sequentially to all applicable files in the application, in the priority given below:
HTML template files are always loaded before everything else
Files beginning with main. are loaded last
Files inside any lib/ directory are loaded next
Files with deeper paths are loaded next
Files are then loaded in alphabetical order of the entire path
If you want your files to be loaded first, put them in lib directory in the root of your project or in any subdirectory.
Your PostController depends on BaseController, so I would put BaseController into lib folder.
If you need to specify exact file load order, you can create a package with desired functionality. You can specify exact file load order only in packages.
If both are in the lib/ directory, I think the answer is from 4 and 5 from the docs:
Files with deeper paths are loaded next
Files are then loaded in alphabetical order of the entire path
So it should be the case that lib/controller/post/PostController would get loaded before lib/controller/BaseController, since its path is deeper.
I think the solution is probably to move them both into lib/controller so that BaseController gets loaded first, since it will be first alphabetically.
Hi I wanted to know the advantage of registering Asset Bundle following the process described in the docs like
Process one
in AppAsset.php
public $js = [
'js/myjsfile.js'
];
then in the view file
adding Namespace like
namespace app\assets;
and then adding the use statement like
use app\assets\AppAsset;
AppAsset::register($this);
Instead of doing all this if I use
Process Two
$this->registerJs('js/myjsfile.js', $this::POS_READY);
it works fine.
So why should I use Process One.
Any advantage and reason for this will be greatly appreciated.
If I follow the process one Do I need to add all the js files in
AppAsset.php individually.
Thanks.
Asset Bundles have some advantages over normal registering. Apart from what #deacs said in his/her answer here are others:
Assets Bundles can publish the file to assets if its not in web accessible directory
Assets Bundle can deal with less files (in case of CSS) as well as compressing the assets.
Makes Code Elegant especially in solving dependencies and hence reusability
All the features that makes bundles shine are found in docs
One of the main reasons for using an Asset Bundle is that your assets' paths will always be correct. Consider:
$this->registerJsFile('js/myjsfile.js', ['position'=>$this::POS_READY]);
will generate something like:
<script src="js/myjsfile.js"></script>
Which works great for non urlManager enabled urls, e.g. http://localhost/yiiproject/index.php?r=user/update&id=8 because your browser looks for the js file at: /yiiproject/js/myjsfile.js
But if you enable urlManager, your url will look like http://localhost/yiiproject/user/update/8, which means your browser will look for your js file at: /yiiproject/user/update/8/js/myjsfile.js.
You could overcome this problem by using:
$this->registerJsFile(Yii::$app->request->baseUrl.'/js/myjsfile.js', ['position'=>$this::POS_READY]);
But the Asset Bundle basicly does that for you.
Using Asset Bundles, you can also get the latest version from 'vendor' folder, so if you need to update some lib you don't need to manually do this since composer already do this.
I'm adding three files for the client in my Meteor package like so:
api.add_files([
'lib/client/newsletter_banner.html',
'lib/client/newsletter_banner.css',
'lib/client/templates.js'
], ['client']);
newsletter_banner.html defines a template which is not available when I load the site. If I look through the sources in Devtools, I can see that the CSS and JS files are available, but the HTML file is not. Why is this? I've confirmed that the filename is correct and even changed it thinking that name might be unavailable to me for whatever reason, but the file is still not included.
Html files are loaded by the templating package, so you need to add it to your package as well:
api.use(['templating', 'spacebars', 'ui'], 'client');