Comments (7)
Along the same lines, named arguments for templates would allow for default arguments. Most of my templates don't need custom CSS or JS, but some do. It would be great if those values of my main.rocker.html
could default to empty.
from rocker.
from rocker.
Thanks, great to know about the builder option! Rocker supports positional arguments with compile-time checking @navbar.template(false)
, or a builder with limited compile-time checking @(new navbar().isDiscourse(false))
. The user has a choice - you can have readable arguments, or compile-time validation that you passed all the arguments, but you can't have both.
It's not trivial, but I think there's a third option, which is for the Rocker compiler to automatically transform @navbar.template(isDiscourse: false)
into @navbar.template(false)
.
If I have a template like this: @args (String item, int qty)
then I could call it like this @cart.template(item: "Cheese", qty: 3)
or like this @cart.template(qty: 3, item: 'Cheese')
, and Rocker would turn both of them into @navbar.template("Cheese", 3)
. But if I did @cart.template(item: "Cheese")
or @cart.template(qty: 3)
then the Rocker compiler yells at me because I didn't supply all the arguments. Now the user doesn't need to make a choice - the arguments are easy to read, and you can be sure that you supplied all the required arguments.
The Java compiler still does all of the type-checking (making sure it's a String or int), but Rocker has to take care of putting the arguments in the right place, and making sure that every required argument was passed.
Obviously this wouldn't be a minor feature, but it also seems like it wouldn't be monumental.
If Rocker was capable of this much, it could then be extended further to this: @args (String item, int qty = 1)
. Now qty is an optional argument that defaults to 1 if it wasn't specified explicitly.
None of this would need changes in the .java
files that Rocker generates, it would just need the Rocker compiler itself to get a teensy bit smarter. It would need a List<String> args
for every template so that it could reorder the arguments and make sure they're all there, and a Map<String, String>
for the default arguments so that it could supply missing values where appropriate.
from rocker.
I've got a flight coming up, I cloned the source to see if I could do some tinkering and see how hard an implementation would be.
cmd> mvn -pl rocker-test-java8 surefire:test
... zillion errors because code wasn't generated ...
cmd> mvn test
... fails on rocker-gradle-plugin, it seems the gradle dep is not present
I'm a maven moron and gradle evangelist. Is there a quickstart for how to run the tests and/or setup a dev environment?
from rocker.
from rocker.
Thanks for the -am -pl
tip, that works and is all I need to tinker. The gradle project still fails for me, but I don't need it. Just FYI:
cmd> mvn -v
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T08:41:47-08:00)
Maven home: /usr/local/Cellar/maven/3.3.9/libexec
Java version: 1.8.0_111, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.12.6", arch: "x86_64", family: "mac"
cmd> mvn test
....
Running com.fizzed.rocker.gradle.RockerGradlePluginTest
Tests run: 5, Failures: 5, Errors: 0, Skipped: 0, Time elapsed: 0.015 sec <<< FAILURE!
com.fizzed.rocker.gradle.RockerGradlePluginTest.testJavaFileIsCreatedInOutputDirectory() Time elapsed: 0.006 sec <<< FAILURE!
java.lang.Error: Unresolved compilation problems:
Test cannot be resolved to a type
Project cannot be resolved to a type
ProjectBuilder cannot be resolved
The method assertTrue(boolean) is undefined for the type RockerGradlePluginTest
(lots more like it)
from rocker.
from rocker.
Related Issues (20)
- Using template in RockerBody does not produce expected result HOT 1
- rocker-compiler.conf is in incorrect folder HOT 1
- Centralized conditional RockerContent rendering ? HOT 2
- Document required template extensions
- GraalVM compatibility HOT 4
- Warnings in Gradle Plugin (@Input annotation used on property of type 'File') HOT 6
- call java function in template HOT 1
- rocker-maven-plugin templateDirectory
- With block invalid: multiple equals symbols found for assignment String href = "/abc?x=y"
- [Doc] it's unclear how to instantiate Rocker
- Loading templates from classpath / jar ? HOT 1
- Parentheses right after variable HOT 2
- Compile time include postprocessor
- support Java 11 HOT 1
- Github latest release points to outdated release.
- Unable to get hot-reload working with tomcat server HOT 3
- Question about formatting
- Generation crashes with NPE if a non-normal file is present in the template directory HOT 1
- Global default null value rendering to avoid NPEs
- it's abandoned? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rocker.