Skip to content

Commit

Permalink
Active template virtual path (#13)
Browse files Browse the repository at this point in the history
* Revert "Remove virtual_path_of_template. (#12)"

This reverts commit 55ace47.

* Expose method to all templates

After the revert, we'd like to rename the method and make it accessible to all
templates. The reasoning behind this is because superglue was using @virtual_path
on the html templates, which seemed like a private variable, with this change we
expose the active_template_virtual_path to everyone so we don't have to use private
instance vars elsewhere.
  • Loading branch information
jho406 committed Dec 10, 2023
1 parent 315f1ad commit 919b0bc
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/props_template/layout_patch.rb
@@ -1,6 +1,12 @@
module Props
module LayoutPatch
def render_template(view, template, layout_name, locals)
unless view.respond_to? :active_template_virtual_path
view.instance_eval <<~RUBY, __FILE__, __LINE__ + 1
def active_template_virtual_path; "#{template.virtual_path}";end
RUBY
end

if template.respond_to?(:handler) && template.handler == Props::Handler && layout_name
prepend_formats(template.format)
render_props_template(view, template, layout_name, locals)
Expand All @@ -11,6 +17,7 @@ def render_template(view, template, layout_name, locals)

def render_props_template(view, template, path, locals)
layout = resolve_layout(path, locals.keys, [formats.first])

body = if layout
layout.render(view, locals) do |json|
template.render(view, locals)
Expand Down

0 comments on commit 919b0bc

Please sign in to comment.