Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A question re r18n and haml templates with Sinatra #66

Closed
davesag opened this issue Sep 25, 2010 · 5 comments
Closed

A question re r18n and haml templates with Sinatra #66

davesag opened this issue Sep 25, 2010 · 5 comments

Comments

@davesag
Copy link

davesag commented Sep 25, 2010

I am using r18n in Sinatra
I'd like Sinatra's 'haml' method to automatically look for a template (say called hello.haml) first in views/{locale}/hello.haml and then if it can't fine one specific it will drop back to views/hello.haml

Is there are clean and simple way to do this?

@ai
Copy link

ai commented Sep 26, 2010

Use something link this (it isn’t optimized, but you can understand logic):
def localized_haml(template)
R18n.get.locales.each do |locale|
return haml "#{template}.#{locale}" if File.exists? "view/#{template}.#{locale}.haml"
end
return haml template
end

@rkh
Copy link
Member

rkh commented Sep 26, 2010

you could even override haml and call super in it. or render, if you want it more general.

@davesag
Copy link
Author

davesag commented Sep 27, 2010

I almost have it but it's not quite working.

See Gist of my haml override method

When I load my page in my Sinatra app the

= yield

bit of my layout.haml file just inserts the localised template name and not the results of the template.

@davesag
Copy link
Author

davesag commented Sep 27, 2010

Aha I got it working. Of course I need to pass a the file contents of the template, not the name of the template :-)

@ronnqvist
Copy link

I'd go with:

def localized_haml(template)
return haml :"#{template}.#{r18n.locale.code}" if File.exists? "views/#{template}.#{r18n.locale.code}.haml"
return haml template
end

zzak pushed a commit to zzak/sinatra that referenced this issue Jul 22, 2016
Modify cookie[]= method to support additional options
zzak pushed a commit to zzak/sinatra that referenced this issue Jul 22, 2016
Revert "Merge pull request sinatra#66 from kylewlacy/master"

This reverts commit 1ad87b6, reversing
changes made to 2141511.
zzak pushed a commit to zzak/sinatra that referenced this issue Jul 22, 2016
Modify cookie[]= method to support additional options
zzak pushed a commit to zzak/sinatra that referenced this issue Jul 22, 2016
Revert "Merge pull request sinatra#66 from kylewlacy/master"

This reverts commit 1ad87b6, reversing
changes made to 2141511.
zzak pushed a commit that referenced this issue Aug 12, 2016
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants