Symlinked templates

33 views
Skip to first unread message

Cory Gwin

unread,
Aug 30, 2017, 9:21:44 AM8/30/17
to Ruby on Rails: Core
Hello,

I am exploring a possible feature for an app I am working on. Ideally we would like to be able to symlink templates so we can use them in multiple paths easily, partials are not really a good option for our use case. I have written a custom template resolver built on top of ActionView::PathResolver to accomplish this. I was speaking with eileencodes about this feature and trying to explore the idea of Rails having native support for this, she said I should start a discussion here.

What do people think? I would love to have this natively supported and would be more than happy to work on a PR.

Thanks,
Cory

Gabriel Sobrinho

unread,
Aug 31, 2017, 7:44:45 AM8/31/17
to Ruby on Rails: Core
Why aren't partials a good option?

Cory Gwin

unread,
Aug 31, 2017, 8:48:29 AM8/31/17
to Ruby on Rails: Core
We are using Rails to serve static templates from a Git repo. We have template writers who are writing Ditta style templates that are single sourced. What this means is that they write a template that may be used in various versions of documentation which will live at different urls, ie /v2/template or /v3/template. The source templates live in a /content folder, to simplify their site structuring we are considering having the site live in a separate folder holding its own directory structure with content templates symlinked so they can be in multiple locations inside the site's structure. I have written a controller and associated prepend view path rule and route to know how to resolve the correct template from that structure.

While partials could work, from a template writing perspective it adds a fair amount of overhead, also symlinks are well understood and a first class citizen of most file systems.

Cory Gwin

unread,
Aug 31, 2017, 9:22:56 AM8/31/17
to Ruby on Rails: Core
I also think partials will be problematic because we don't want the templates themselves to be in the look up path for Rails.

Andrew Kaspick

unread,
Aug 31, 2017, 10:04:27 AM8/31/17
to Ruby on Rails: Core
Sounds like some pretty specific requirements for what you need which is a good candidate for an external gem.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

Gabriel Sobrinho

unread,
Aug 31, 2017, 10:10:14 AM8/31/17
to rubyonra...@googlegroups.com
I'm thinking that you may use a app helper for that.

Let's say that you are using erb, you may have something like that:

app/views/
  shared/
    _foo.html.erb
    _bar.html.erb
  v1/
    some.html.erb
  v2/
    some.html.erb

You can implement a simple helper like that:

<%= shared 'foo' %>

And use something like that:

def shared(template, *options)
  # You may have business rules here to discover the path.
  render "shared/#{template}", *options
end


You aren't probably using ERB but you have similar ways to accomplish the same helper feature in almost all of them.

That is not enough?


I'm not against symlink functionality (I'm not even in the core xD), I'm just trying to understand your requirement here.

You received this message because you are subscribed to a topic in the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/rubyonrails-core/5oNEFAMLvT8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to rubyonrails-co...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
signature.asc

Cory Gwin

unread,
Aug 31, 2017, 2:09:55 PM8/31/17
to Ruby on Rails: Core
As I understand it, in order to use a partial like being suggested here, the file has to be in the look up path. This would mean that even under this approach templates would resolve in ways that I do not intend, since render uses the view path to find its template candidates. 
 
I have built something similar to this, but I have to handle a lot of what Rails handles out of the box. :(
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsub...@googlegroups.com.

To post to this group, send email to rubyonra...@googlegroups.com.
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to a topic in the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/rubyonrails-core/5oNEFAMLvT8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to rubyonrails-core+unsub...@googlegroups.com.

Cory Gwin

unread,
Aug 31, 2017, 2:12:00 PM8/31/17
to Ruby on Rails: Core
Yeah it is rather specific, although it is fairly trivial to implement. There is a file bin read in the template renderer, basically all that needs to happen is that you check if it is a symlink before that and resolve the symlink before reading the file. My reason for bringing it to the core group is that symlinks are a pretty standard feature of the file system so I sort of expected them to just be followed.


On Thursday, August 31, 2017 at 10:04:27 AM UTC-4, Andrew Kaspick wrote:
Sounds like some pretty specific requirements for what you need which is a good candidate for an external gem.
On Thu, Aug 31, 2017 at 10:22 AM, Cory Gwin <gwin...@gmail.com> wrote:
I also think partials will be problematic because we don't want the templates themselves to be in the look up path for Rails.


On Wednesday, August 30, 2017 at 9:21:44 AM UTC-4, Cory Gwin wrote:
Hello,

I am exploring a possible feature for an app I am working on. Ideally we would like to be able to symlink templates so we can use them in multiple paths easily, partials are not really a good option for our use case. I have written a custom template resolver built on top of ActionView::PathResolver to accomplish this. I was speaking with eileencodes about this feature and trying to explore the idea of Rails having native support for this, she said I should start a discussion here.

What do people think? I would love to have this natively supported and would be more than happy to work on a PR.

Thanks,
Cory

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-co...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages