{"action":"created","issue":{"url":"https://api.github.com/repos/pippo-java/pippo/issues/260","repository_url":"https://api.github.com/repos/pippo-java/pippo","labels_url":"https://api.github.com/repos/pippo-java/pippo/issues/260/labels{/name}","comments_url":"https://api.github.com/repos/pippo-java/pippo/issues/260/comments","events_url":"https://api.github.com/repos/pippo-java/pippo/issues/260/events","html_url":"https://github.com/pippo-java/pippo/issues/260","id":142109735,"node_id":"MDU6SXNzdWUxNDIxMDk3MzU=","number":260,"title":"Add route method helper in templates","user":{"login":"decebals","id":1248311,"node_id":"MDQ6VXNlcjEyNDgzMTE=","avatar_url":"https://avatars3.githubusercontent.com/u/1248311?v=4","gravatar_id":"","url":"https://api.github.com/users/decebals","html_url":"https://github.com/decebals","followers_url":"https://api.github.com/users/decebals/followers","following_url":"https://api.github.com/users/decebals/following{/other_user}","gists_url":"https://api.github.com/users/decebals/gists{/gist_id}","starred_url":"https://api.github.com/users/decebals/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/decebals/subscriptions","organizations_url":"https://api.github.com/users/decebals/orgs","repos_url":"https://api.github.com/users/decebals/repos","events_url":"https://api.github.com/users/decebals/events{/privacy}","received_events_url":"https://api.github.com/users/decebals/received_events","type":"User","site_admin":false},"labels":[{"id":143173724,"node_id":"MDU6TGFiZWwxNDMxNzM3MjQ=","url":"https://api.github.com/repos/pippo-java/pippo/labels/enhancement","name":"enhancement","color":"84b6eb","default":true},{"id":839220423,"node_id":"MDU6TGFiZWw4MzkyMjA0MjM=","url":"https://api.github.com/repos/pippo-java/pippo/labels/proposal","name":"proposal","color":"fbca04","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":14,"created_at":"2016-03-19T23:04:46Z","updated_at":"2018-10-27T18:10:56Z","closed_at":null,"author_association":"MEMBER","body":"In my applications based on Pippo I feel that I'm missing a `route(<template_name>, paramId_1:paramValue_1, ...)` method in my html templates.\nFor example, in [companies.peb](https://github.com/decebals/matilda/blob/master/src/main/resources/templates/admin/views/companies.peb) file I have something like:\n\n```\n<a href=\"{{ appPath }}/admin/companies/{{ company.id }}\">{{ i18n('edit') }}</a>\n```\n\nand I wish something like (pseudo code):\n\n```\n<a href=\"{{ route(\"admin.companies.edit\", \"id\":company.id) }}\">{{ i18n('edit') }}</a>\n```\n\nand in `.java` file (I will don't use route group for simplicity):\n\n```\nGET(\"/admin/customers/{id}, ...).named(\"admin.companies.edit\");\n```\n"},"comment":{"url":"https://api.github.com/repos/pippo-java/pippo/issues/comments/433643029","html_url":"https://github.com/pippo-java/pippo/issues/260#issuecomment-433643029","issue_url":"https://api.github.com/repos/pippo-java/pippo/issues/260","id":433643029,"node_id":"MDEyOklzc3VlQ29tbWVudDQzMzY0MzAyOQ==","user":{"login":"decebals","id":1248311,"node_id":"MDQ6VXNlcjEyNDgzMTE=","avatar_url":"https://avatars3.githubusercontent.com/u/1248311?v=4","gravatar_id":"","url":"https://api.github.com/users/decebals","html_url":"https://github.com/decebals","followers_url":"https://api.github.com/users/decebals/followers","following_url":"https://api.github.com/users/decebals/following{/other_user}","gists_url":"https://api.github.com/users/decebals/gists{/gist_id}","starred_url":"https://api.github.com/users/decebals/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/decebals/subscriptions","organizations_url":"https://api.github.com/users/decebals/orgs","repos_url":"https://api.github.com/users/decebals/repos","events_url":"https://api.github.com/users/decebals/events{/privacy}","received_events_url":"https://api.github.com/users/decebals/received_events","type":"User","site_admin":false},"created_at":"2018-10-27T18:10:56Z","updated_at":"2018-10-27T18:10:56Z","author_association":"MEMBER","body":"I implemented this feature in Pebble template engine (I use this template engine in my projects).\r\nThe implementation is not complete (need to add more defense code - deal with route not found) but is complete functional.\r\n\r\nHow to use:\r\n- define a route with a name\r\n```java\r\nGET(\"/quote\", routeContext -> {\r\n    ParameterValue symbol = routeContext.getParameter(\"symbol\");\r\n    if (symbol.isEmpty()) {\r\n        routeContext.getResponse().badRequest().send(\"Specify a symbol as parameter\");\r\n    } else {\r\n        Stock stock = dataStore.select(Stock.class).where(Stock.SYMBOL.eq(symbol.toString())).get().first();\r\n        List<Quote> quotes = dataStore.select(Quote.class).where(Quote.SYMBOL.eq(stock.symbol)).get().toList();\r\n\r\n        Map<String, Object> model = new HashMap<>();\r\n        model.put(\"stock\", stock);\r\n        model.put(\"quotes\", quotes);\r\n\r\n        routeContext.render(\"quote\", model);\r\n     }\r\n}).named(\"quote\");\r\n```\r\n- reference the route defined above using `route` method\r\n```html\r\n<a href=\"{{ route('quote', {'symbol': stock.symbol }) }}\">{{ stock.symbol }}</a>\r\n```\r\n\r\nI want to say that I consider this feature very nice. The html template is more clear and short :smile: ."}}
{"actor":{"display_login":"decebals"}}