Git Product home page Git Product logo

Comments (7)

nedtwigg avatar nedtwigg commented on June 26, 2024

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.

jjlauer avatar jjlauer commented on June 26, 2024

from rocker.

nedtwigg avatar nedtwigg commented on June 26, 2024

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.

nedtwigg avatar nedtwigg commented on June 26, 2024

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.

jjlauer avatar jjlauer commented on June 26, 2024

from rocker.

nedtwigg avatar nedtwigg commented on June 26, 2024

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.

jjlauer avatar jjlauer commented on June 26, 2024

from rocker.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.