Inside a grails application, I need to upload a file under web-app/js, add a prefix, and put it in S3. I'm having trouble figuring out how to read the js file in a way that will work in development (/web-app/js) and production (/js). I'm doing this from inside a domain object.
In your controllers, you can call :
def jsFolder = grailsAttributes.getApplicationContext().getResource("js/").getFile()
and then proceed with jsFolder.
To determine the base directory of a running Grails application, use
String dir = applicationContent.getResource("/").getFile()
Getting the js path from a service is a little bit tricky:
You need to implement the ApplicationContextAware interface like this :
class MyService implements ApplicationContextAware {
ApplicationContext applicationContext
However, calling this code from a domain class is not a good idea (see this thread for some explanations) and I am not even sure if it's possible except from getting paths from manual configurations
Hope it helps.
Related
I'm using a simple method that reads a location and does some stuff;
public void readMyFile(loc file) {
M3 model = createM3FromEclipseFile(file);
println(model);
// do some stuff;
}
The method fails to read a specific location file;
|plugin://rascal_eclipse/src/org/rascalmpl/eclipse/library/lang/java/jdt/m3/Core.rsc|(1019,261,<33,0>,<38,77>): IO("Could not find|project://hsqldb/doc/verbatim/src/org/hsqldb/server/WebServer.java|")
However, this file is present on my disk. All other locations from the hsqldb project or other projects I've used it with, work without any issue. Only this specific file throws an exception.
I can also use createM3FromEclipseProject to read all files in a project. This works without any issues for the hsqldb project. However, in my workflow I prefer to read an individual file via createM3FromEclipseFile.
Is there a difference between createM3FromEclipseFile and createM3FromEclipseProject concerning the info it reads of an individual file?
I can confirm the behavior of createM3FromEclipseFile of the original question; however createM3FromFile works as expected.
I am new to prestashop and developing a module to change behaviour of checkout process. As i am new, i am first overriding IndexController.php file in my module directory to just test the overriding mechanism in prestashop. The directory structure, i have followed, to override controller file as:
modules/my_modules/override/controllers/front/IndexController.php
Below is the code of above file:
class IndexController extends IndexControllerCore{
public function __construct() {
parent::__construct();
d('You are overriding index file');
}
}
In above code, i have just created an construct and print a test string with die. But nothing is happening on the home page on front end. I have also tried with override another controller file, but i have got same result.
I have searched many things on google, but nothing got. Please anyone tell me, what i am doing wrong in this? if the logic is correct, then why overriding is not working here?
Waiting for solution.
Like #rsanchez said. You need to reinstall the module everytime you change your module's overrides. Prestashop will not automatically check for new changes or new overrides without it.
I'm trying to customize the HTML markup of the excellent FilterPane grails plugin, however I'm having some difficulty. FilterPane provides a bunch of tags for rendering the search/filter form, and I would like to override these in my application.
I had thought that I could simply copy the _tagName.gsps that I wanted to override from
plugins/filterpane-2.0.1.1/grails-app/views/filterpane
into
grails-app/views/filterpane
and modify them, however it looks like Grails never checks whether the application is overriding the views of a plugin, if the render method is called with a plugin name property specified.
org.codehaus.groovy.grails.web.pages.GroovyPagesTemplateRenderer.findAndCacheTemplate contains the following code in a private method:
...
GroovyPageScriptSource scriptSource;
if (pluginName == null) {
scriptSource = groovyPageLocator.findTemplateInBinding(templatePath, pageScope);
} else {
scriptSource = groovyPageLocator.findTemplateInBinding(pluginName, templatePath, pageScope);
}
...
so when a non-null pluginName is specified, we just grab the plugin's view and never check whether the application is overriding it.
I thought a simple way to get around this problem would be to just override GrailsConventionGroovyPageLocator.findTemplateInBinding, or some other similar method in GrailsConventionGroovyPageLocator, however it doesn't appear to be possible to do this from within a Grails application either!
I created a simple class overriding GrailsConventionGroovyPageLocator, replacing the findTemplateInBinding method with one that checks the application's view directory before checking that of the plugin. I then modified resources.groovy, adding a doWithSpring closure to replace the beanClass property of the default groovyPageLocator:
def doWithSpring = {
def pageLocator = delegate.getBeanDefinition("groovyPageLocator")
pageLocator.beanClass = MyConventionGroovyPageLocator
}
However this doesn't seem to be called when my application starts up.
I'm really at a loss here. I'd expected this to be straightforward, but it's turned into a bit of a can of worms. Does anyone have any suggestions? All I want to do is override the views provided by a plugin...
You can modify the plugin source, instead of changing the location of the template.
The location is: user_home\.grails\version\projects\project\plugins\plugin-name
I am not a grails expert, but in order to override plugin views you should recreate them in your main projects views folder. For example, I changed the /auth/login.gsp from Spring Security Plugin by simply creating the same thing in my /project/views/auth/login.gsp. If you make changes into the plugin files itself you could potentially lose them if you uninstall the plugin.
In order to change a view in a template of a plugin, perform the command
grails install-templates
source
This will copy the templates of the plugins to your project which you then can customize. What this does with for example the scaffolding plugin, is copy files to src/templates/scaffolding (note, not grails-app/templates/scaffolding). Therefore, in your case, I would try copying the files to src/views/filterpane
I'm currently mapping my ZF1 applications to ZF2 and was wondering if there is a similar function like $this->view->getScriptPath() from ZF1 in ZF2? I spend already my half day, but didn't find a good solution. It would also be fine to get at least the basePath of the Module or the template folder of the Module.
Based on the follow-up questions, what you are really looking for is the path to a given template file. This is actually relatively easy, assuming you're using the default PhpRenderer: you grab the resolver, and resolve the path.
If you're inside a view script already, the following should work:
$path = $this->resolver($templateName);
If you're elsewhere, you need access to either the PhpRenderer, or the ViewResolver. If you have access to the service manager, pull the ViewResolver service, and call resolve() on it:
$resolver = $services->get('ViewResolver');
$path = $resolver->resolve($templateName);
This is superior to knowing where the module lives, as the developer may have chosen to override the template within the application; the resolver will know where even the new location is.
What is the best way to put custom library or helper methods in symfony?
I am using doctrine with my project. One place I consider to put is under project_root/lib/vendor/MyClasses/
But if I want to create a class or helper function which will use some core symfony/doctrine methods and return a result then how to do that and where should I put it?
I want it to call from different modules to avoid code duplication.
As for the custom library part of the question, you might probably want to put your external library into the lib/vendor folder. Since symfony doesn't automatically load everything that's in there, you'll have to tell its autoloader to do so.
You can either extend your config/ProjectConfiguration.class.php (as described here) or (and this is the much simpler and cleaner way) you add them to your config/autoload.yml (you might have to create this one).
For the latter option, this is a great place to start looking at.
It seems to be a duplicate question.
As asked in symfony's 1.2 "Definitive Guide" docs :
Helper functions (regular PHP functions returning HTML code) should be saved in a file called FooBarHelper.php, where FooBar is the name of the helper group. Store the file in the apps/myapp/lib/helper/ directory (or in any helper/ directory created under one of the lib/ folders of your project) so it can be found automatically by the use_helper('FooBar') helper for inclusion.
So, if you want to create custom helper FooBar for foo() function, create file lib/helper/FooBarHelper.php :
function foo() {echo "foo!"; }
to use it in your template:
use_helper('FooBar')
....
foo(); //outs "foo!"