Spring Boot .mustache file extension - spring-mvc

I'm working on a spring boot application and adding a small configuration web page using Mustache templates using this article as an example. I have it working fine when all of my mustache template files have the extension .html, but the problem is that I don't get any IDE support. IntelliJ IDEA has a plugin for mustache, but the extension has to be .mustache. When I change the file extensions, though, I end up with a 404 error.
I've seen in the official example that they are using .mustache, so I know it's possible. I couldn't find anything in that project to indicate that a setting was changed to enable this. The only major difference is that I am using Kotlin instead of Java, but I don't see why that would have any effect on the mustache file extensions.
What am I missing? Thanks!

According to Spring Boot documentation (for v1.5.6, for v2.0.0.M3) you can easily configure the extension of Mustache template files by setting the following property:
spring.mustache.suffix=.mustache # Suffix to apply to template names.
In v1.5.x the default was .html but in v2.0.0 they switched to .mustache. (release notes)
Also you can configure IntelliJ IDEA to handle *.html files with the Handlebars/Mustache plugin by registering *.html pattern in Settings > Editor > File types > Handlebars/Mustache.

This isn't an answer in place of ones already given. Really it should be a comment, but I can't upload a screenshot in a comment.
It's worth noting that (at least in my IDE), I had to install the mustache plugin (not noted in the kotlin spring tutorial I'm following), and once installed, there is not a context menu selection for a new mustache file type:
But, if you pick the generic File and name it whatever.mustache, the editor will apply the mustache language tool to it.
Seems very "yeah, duh", but it threw me for a bit b/c everything in intellij so far feels so specific, I thought the fact that I wasn't seeing it as an option meant I was missing something :| .

Nevermind. I just realized that it is a 2.0.0 branch of spring boot and the 1.5.x branch still has it as .html.

Related

Can't add a breakpoint to Twig files in VS Code

I am trying to debug a Twig template in my Drupal 9 site. I am using VSCode as my IDE and using Xdebug for debugging. I have setup/configured the installation based on the instructions outlined here -
https://www.drupal.org/docs/develop/development-tools/configuring-visual-studio-code
I am able to set breakpoints in PHP files (step thru and watch variables successfully) however I just can't seem to do the same for Twig template files (just so I can see what variables I have access to in that template). What I mean by when I say I am unable to add the breakpoint is that clicking on the gutters of a Twig file within VSCode does not result in addition of any breakpoint.
I'd like to take advantage of Xdebug instead of using debugging functions like breakpoint() and dump() offered by the Devel and Twig_xdebug modules within Drupal. I am pretty sure I am doing something wrong or have missed a step but I can't seem to figure out what it is.
Some more details on my env:
a local Drupal 9 setup on a Mac OS that uses PHP 7.4 and nginx as its webserver.
Xdebug (v3.1.1) is installed and enabled (verified via phpinfo() output)
VSCode (1.63.0) installed with all of the supporting Drupal and PHP extensions outlined in the above article (specifically php-debug) have been installed.
I am using the default launch configuration to Run my debug session in VSCode.
I'd appreciate any pointers on what I am doing wrong and/or what I can try. Also, I hope I provided enough info on my use case.
Twig compiles the template files into PHP files. You need to set breakpoints in these Twig generated PHP files in order to debug them.
On this page, I also see that there is caching involved, which you will need to disable. That documentation seems to be quite comprehensive.
Came here looking for an answer to this very question.
You may be interested to know that there are a couple of ways to achieve this. You can either use a built-in feature of the devel.module (see: https://www.drupal.org/node/2788089) or there is also a contrib module called twig_xdebug, which lives here: https://www.drupal.org/project/twig_xdebug
I think the mechanism behind both of these is probably very similar, to be honest. The latter of those links provides further links to several guides on the subject matter. HTH! :)

KSS Installtion and Setup

Can someone outline some step by step instructions on how to set KSS up on my local computer?
I've been reading a lot of articles and none of them show a working demo. And they also assume I'm a ruby expert.
I'm expecting to see an html page and some sort of auto-generated documentation page.
I've installed and used gems before but I am by no means an expert. So assume I'm a total noob.
Assume I have the following folder structure:
C:Projects/MySite
index.html
sass
css
js
I did this:
gem install kss
I get confused here though:
styleguide = Kss::Parser.new("#{RACK_ROOT}public/stylesheets")
KSS doesn't have a native outputer. The example that confused you should be run in an Ruby interpretive shell (irb for example, which is installed by default with ruby).
So, go to your command line, type irb, and then type that line into the resulting shell, replacing "#{RACK_ROOT}public/stylesheets" with "C:/Projects/MySite/css"
If you want a nice navigable web page, see the example Sinatra app.

How to validate HTML/CSS files with grunt.js?

This is a noob question.
I would like to use grunt.js as a build tool for my web project. Can use grunt.js to validate my HTML/CSS files? Do you have an example of such a grunt.js file?
There is another plugin that seems to be updated more often and does not require java. grunt-html-validation. It has a number of options and has been working great for me. You can install and use it like this:
npm install grunt-html-validation --save-dev
Then put something like this in the initconfig of your Gruntfile.js
and this in appropriate places in your Gruntfile.js
grunt.loadNpmTasks('grunt-html-validation');
grunt.registerTask("default", ["validation"]);
There is also a number of useful options including the ability to relax errors based on a regular expression (could be useful for AngularJS for example) and the ability to save a report.
You can use the grunt plugin grunt-html. Beware, you will need Java on your computer to use it. It works well for me.
As of now there seem to be two popular HTML validation plugins:
grunt-html-validation
grunt-html
grunt-html-validation uses the W3C Markup Validation Service and grunt-html uses a local copy of the java-based The Nu HTML Checker.
They both work well and have very similar options so it comes down to whether you want to wait for an external service call or wait for a local java app.

Customizing newly created projects in Aptana

I need to define a model for newly created projects in Aptana.
Basically, I want, anytime, when I create a new project, it adds some defined directories/files (not existing files, but new ones) to this project.
I'm not even sure it's possible.
Aptana doesn't appear to support that.
Maybe you can just create a small external sript to do it for you? Not the ideal solution, but better then none.
This might be a longshot, but it is worth mentioning. Since Aptana is based on Eclipse, you might be able to see how Eclipse would handle custom project templates. It appears that the easiest way to go about this is to actually create an Eclipse plugin that has a Template Wizard. IBM has a nice guide on how to use PDE to create a Custom Template. I am not sure if you will be able use PDE from within Aptana (you might be able to), otherwise, you might need to download a stock version of Eclipse, create the Plugin, then install it in Aptana.
Aptana is based on eclipse, so you could use a combination of Maven Archetypes and the Maven eclipse plugin to achieve this really easily.
Download and install maven
Create a basic maven project using the quickstart archetype, Archetypes are project templates used to rubber stamp new project structures. The quickstart is a very basic project template
mvn archetype:generate
generate the eclipse project files using the eclipse plugin. This will create the standard
mvn eclipse:eclipse
tweak the pom until and re-run step 3 until you're satisfied with the layout etc. You'll no doubt have to add configuration the eclipse plugin to add the correct build spec and project nature. If you open an existing .project file it will contain the values you need. you can see here how to add them.
once the project is set up to your liking you can create your own archetype out of it and use this to rubber stamp new projects in the future.
mvn:archetype:create-from-project
now you can run the generate again and can select your archetype from the list. If its not there, you may need to run this first to update the list of archetypes
mvn archetype:crawl
Open Source your archetype for others to use ;)
It's very simple in Studio 3. Try the following: http://wiki.appcelerator.org/display/tis/Creating+a+new+template#Creatinganewtemplate-Creatinganewprojecttemplate
Basically you create a .zip file of the project content, and then write a few lines of Ruby code to reference it.
Aptana uses (as I'm sure you know) its own 'new rails' project that gives you a variety of options.
I don't think it's beyond Will (the RadRails maintainer) to add a simple text field to that Wizard that would allow you to enter a command-line option parameter. He's always been very responsive with my previous bug and feature requests.
If you want to give that a try, and that works, then I would HIGHLY and STRONGLY recommend that you look into one of the new Rails features 'templates' in which you could make a generic template, then call it through the new input box. We use templates at my current job and they save us about 4 hours of work on each project. They are very easy to use...def...definitely.
If you can't wait for the input box, then you could always write the template then call it from within the command line (see
http://m.onkey.org/2008/12/4/rails-templates
for info about templates)
Unless RadRails three is light-years ahead of the latest release, though, you'll be missing out on a lot of very handy advantages of using a more community-supported solution such as VIM or TextMate. (I switched to VIM from RadRails about 4 months ago and have never looked back).
Eclipse has a Plugin Development Environment. If I'm not mistaken, you can also create project templates with it. Please try: http://www.ibm.com/developerworks/library/os-eclipse-pde/

Liferay: how to avoid rebuilding/redeploying CSS files

if you're familiar with Liferay you'll know that when you make an itsy-bitsy change to a css file you shall rebuild the theme and redeploy it.
As for redeploying I made a symlink (mind you I'm on Windows: for the curious creating a symlink on Vista is just a matter of issuing mklink /d dir1 dir2).
But what about rebuilding the stuff with maven? I'd rather skip that step. Basically what it does is combyining and packing all CSS in one everything_packed.css. Is there a sort of config variable to tell liferay just to include the raw files and skip redeployment alltogether?
Thanks
Guys I found the solution myself.
You should have a file called portal-ext.properties file in
$TOMCAT_DIR/webapps/ROOT/WEB-INFO/classes
Or more specifically for my win setup in
C:\liferay\webapps\ROOT\WEB-INF\classes
The file would hold the value
theme.css.fast.load=false
This will prevent liferay to be looking for the everything_packed.css and so you're free to modify your stuff without rebuilding and CTRL-R to refresh the page and see the changes.
Just for completeness, as this question is somewhat old and the problem already solved: There's a lot more along these lines, e.g. javascript, layouts etc. that can be used uncached. This is documented in either the Liferay Wiki (as Developler Mode) or the Development Guide, available from the documentation site (though currently it's not there for the last version - if it's still not there when you're reading it, look for it (PDF) in the older versions.
It's advisable to use these settings only in development, not in production, as putting all css and javascript in as few files as possible results in a huge performance impact.
to include all those settings, just can also just add the following line into your portal-ext.properties file:
include-and-override=portal-developer.properties
this will include all the developer specific settings, and when you want to remove them, you can just comment out this line.
you can edit the css files of your theme from Webapps{your theme}\css
And can see the changes directly.
You can edit almost every file which doesn't require compilation.like .jsp files but not .java files

Resources