Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Propose to remove the template extension restriction for ".rocker.html" #128

Open
iceant opened this issue Jan 7, 2020 · 4 comments
Open

Comments

@iceant
Copy link

iceant commented Jan 7, 2020

I am using rocker as a generic engine for rendering .html, .js files, and generate dynamic sql.
for example, I have a file with path "static/js/app/app.main.js", I want to keep the extension as it is, so we can benefit the IDE features to coding easily.
I have modified the implementation of rocker to generate a source file with path "static/js/app/app_dot_main_dot_js.java" in "generated-sources" directory.

Is it possible to modify the code base to support this feature?

attach the code I modified.
diff.txt

@jjlauer
Copy link
Member

jjlauer commented Jan 7, 2020

@iceant I'm open to ideas on allowing additional file extensions or conventions. For example, allowing '.js' in the build process to be processed by Rocker. However, the replacing of dots and spaces with "dot" and "space" feels a bit hacky. Could you just rename "app.main.js" to "app_main.js"? Not sure I understand why not being able to rename the file is a huge deal.

@iceant
Copy link
Author

iceant commented Jan 8, 2020

@jjlauer thanks, the reason we want to name the java file for 'app.js' like 'app_dot_js.java' is because we defined a web fragment as a combination of .html + .css + .js, for example, we have a web fragment called 'timeline', it has this file structure: common/timeline.html, common/timeline.css, common/timeline.js. base on rocker's strategy, the .html, .css and .js will be compiled as the same unit 'timeline.java' that could be an issue. To add 'dot' is the design strategy to avoid this issue.

RockerBootstrap is good design, we can provide a new implementation of it to use different 'path to class' resolve strategy. But the compiler is the issue to stop us to use different strategy. It's better to remove the restriction for temlate file with '.html' or '.raw' extension. Even better to have a new interface called 'TemplateResolver' wich has 'public String templateNameToClassName(String templateName)', 'public ContentType templateNameToContentType(String templateName)', 'public String templatePathToClassName(String templatePath)' methods. These interfaces that can be used in DefaultRockerBootstrap, TemplateParser and TemplateModel. The user can provide different implementation for it.

@xenoterracide
Copy link

xenoterracide commented Nov 28, 2020

hmm... looking at possibly using rocker for project scaffolding, including .java files, though I find intellij at least is not so good once you put other syntax in there.

yeah

java.lang.IllegalArgumentException: Invalid template extension '.scaf/templates/TestApplication.java.raw'. Expecting something like 'views/app/index.rocker.html')

@xenoterracide
Copy link

xenoterracide commented Nov 28, 2020

oh, man, this extension parsing is just a terrible experience

java.lang.IllegalArgumentException: Invalid template extension '.scaf/templates/TestApplication_java.rocker.html'. Expecting something like 'views/app/index.rocker.html')

I'm going to move on to a different templating system, performance doesn't concern me, I was just hoping for the static typing, without a massive "we only do html" experience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants