{"action":"created","issue":{"url":"https://api.github.com/repos/asciidoctor/asciidoctor/issues/573","labels_url":"https://api.github.com/repos/asciidoctor/asciidoctor/issues/573/labels{/name}","comments_url":"https://api.github.com/repos/asciidoctor/asciidoctor/issues/573/comments","events_url":"https://api.github.com/repos/asciidoctor/asciidoctor/issues/573/events","html_url":"https://github.com/asciidoctor/asciidoctor/issues/573","id":18269256,"number":573,"title":"Add partial helper for rendering fragments in a backend template","user":{"login":"mojavelinux","id":79351,"avatar_url":"https://avatars.githubusercontent.com/u/79351?v=3","gravatar_id":"","url":"https://api.github.com/users/mojavelinux","html_url":"https://github.com/mojavelinux","followers_url":"https://api.github.com/users/mojavelinux/followers","following_url":"https://api.github.com/users/mojavelinux/following{/other_user}","gists_url":"https://api.github.com/users/mojavelinux/gists{/gist_id}","starred_url":"https://api.github.com/users/mojavelinux/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mojavelinux/subscriptions","organizations_url":"https://api.github.com/users/mojavelinux/orgs","repos_url":"https://api.github.com/users/mojavelinux/repos","events_url":"https://api.github.com/users/mojavelinux/events{/privacy}","received_events_url":"https://api.github.com/users/mojavelinux/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/asciidoctor/asciidoctor/labels/enhancement","name":"enhancement","color":"009800"}],"state":"open","locked":false,"assignee":{"login":"mojavelinux","id":79351,"avatar_url":"https://avatars.githubusercontent.com/u/79351?v=3","gravatar_id":"","url":"https://api.github.com/users/mojavelinux","html_url":"https://github.com/mojavelinux","followers_url":"https://api.github.com/users/mojavelinux/followers","following_url":"https://api.github.com/users/mojavelinux/following{/other_user}","gists_url":"https://api.github.com/users/mojavelinux/gists{/gist_id}","starred_url":"https://api.github.com/users/mojavelinux/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mojavelinux/subscriptions","organizations_url":"https://api.github.com/users/mojavelinux/orgs","repos_url":"https://api.github.com/users/mojavelinux/repos","events_url":"https://api.github.com/users/mojavelinux/events{/privacy}","received_events_url":"https://api.github.com/users/mojavelinux/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/asciidoctor/asciidoctor/milestones/9","html_url":"https://github.com/asciidoctor/asciidoctor/milestones/v1.6.0","labels_url":"https://api.github.com/repos/asciidoctor/asciidoctor/milestones/9/labels","id":349596,"number":9,"title":"v1.6.0","description":"","creator":{"login":"mojavelinux","id":79351,"avatar_url":"https://avatars.githubusercontent.com/u/79351?v=3","gravatar_id":"","url":"https://api.github.com/users/mojavelinux","html_url":"https://github.com/mojavelinux","followers_url":"https://api.github.com/users/mojavelinux/followers","following_url":"https://api.github.com/users/mojavelinux/following{/other_user}","gists_url":"https://api.github.com/users/mojavelinux/gists{/gist_id}","starred_url":"https://api.github.com/users/mojavelinux/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mojavelinux/subscriptions","organizations_url":"https://api.github.com/users/mojavelinux/orgs","repos_url":"https://api.github.com/users/mojavelinux/repos","events_url":"https://api.github.com/users/mojavelinux/events{/privacy}","received_events_url":"https://api.github.com/users/mojavelinux/received_events","type":"User","site_admin":false},"open_issues":134,"closed_issues":0,"state":"open","created_at":"2013-06-06T09:06:40Z","updated_at":"2015-10-19T05:02:26Z","due_on":null,"closed_at":null},"comments":4,"created_at":"2013-08-19T23:08:42Z","updated_at":"2015-10-23T05:45:12Z","closed_at":null,"body":"Add a partial helper method to AbstractNode that delegates to the Renderer to render a template fragment from within a backend template.\r\n\r\nFor example, the `document.html.slim` template could render the header and footer content from partials as follows:\r\n\r\n```\r\n= partial :header\r\nbody id=@id ...\r\n  #header\r\n    - if has_header?\r\n      ...\r\n  #content=content\r\n  = partial :footer\r\n```\r\n\r\nThe partial method would delegate to the Renderer, which would in turn look for the file `_footer.html.slim` in one of the directories that were scanned to locate the templates (i.e., `:template_dirs`). It would then invoke the render method of the template in the context of the current AbstractNode, in this case Document.\r\n\r\nHere's a rough sketch of how these methods might look:\r\n\r\nin AbstractNode\r\n```\r\ndef partial name, opts = {}\r\n  renderer.render_partial name.to_s, self, opts\r\nend\r\n```\r\n\r\nin Renderer\r\n```\r\ndef render_partial name, object, opts = {}\r\n  unless @partials.has_key\r\n    raise \"Couldn't resolve partial for #{name}.\"\r\n  end\r\n\r\n  @partials[name].render(object, opts[:locals] || {})\r\nend\r\n```\r\n\r\nThe `@partials` Hash is built when the template directories are first scanned. Any file found that begins with and underscore would be put into the `@partials` Hash instead of the `@views` Hash.\r\n\r\nThe `opts` argument could allow the rendering to be tuned, such as to set view options for Tilt or to specify a different engine (Haml inside of Slim for instance)."},"comment":{"url":"https://api.github.com/repos/asciidoctor/asciidoctor/issues/comments/150479853","html_url":"https://github.com/asciidoctor/asciidoctor/issues/573#issuecomment-150479853","issue_url":"https://api.github.com/repos/asciidoctor/asciidoctor/issues/573","id":150479853,"user":{"login":"mojavelinux","id":79351,"avatar_url":"https://avatars.githubusercontent.com/u/79351?v=3","gravatar_id":"","url":"https://api.github.com/users/mojavelinux","html_url":"https://github.com/mojavelinux","followers_url":"https://api.github.com/users/mojavelinux/followers","following_url":"https://api.github.com/users/mojavelinux/following{/other_user}","gists_url":"https://api.github.com/users/mojavelinux/gists{/gist_id}","starred_url":"https://api.github.com/users/mojavelinux/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mojavelinux/subscriptions","organizations_url":"https://api.github.com/users/mojavelinux/orgs","repos_url":"https://api.github.com/users/mojavelinux/repos","events_url":"https://api.github.com/users/mojavelinux/events{/privacy}","received_events_url":"https://api.github.com/users/mojavelinux/received_events","type":"User","site_admin":false},"created_at":"2015-10-23T05:45:12Z","updated_at":"2015-10-23T05:45:12Z","body":"With support for this in Slim (our preferred template engine), I'm feeling pretty strongly this is no longer an issue. On top of that, we now recognize and load helpers for Slim, so you could even implement your own include helper if you don't want to use the one from Slim.\r\n\r\nWhere this issue should really go is documenting this capability."}}