Localized partials in Middleman - ruby

In Middleman, is it possible to localize partials? I haven't been able to find any documentation for this. But I'm working on long pieces with complex markup, and it may be necessary to adjust the templates themselves for localization. I'd like to be able to narrow these sections down to partials so that I don't have to fall back on maintaining entirely separate templates when this happens. Is there a place I can put partials such that the partial command will look up a partial as partial_name.language.html.erb?
It might also be possible to dynamically construct partials argument if it's possible to tell what language I'm in within the ERb. So I could do something like <%= partial "my_piece/partials/#{current_lang}/tricky_section" %>, but I don't know if something like current_lang exists.

On the issue tracker, I found documentation of how I can use the second option I can do <%= partial "partials/my_piece/#{lang}/tricky_section" %>, or directly embed logic that otherwise keys off of lang.

Related

a rails partial but used by multiple views

I have a piece of code that I would like to have show up on several areas... from two different views. Which is to say handled by two different controllers (all the data comes from a helper though) what is the best way to break this up, should these partials be rendered then as lay outs? Though they use the twitter bootstrap modal and I have had huge issues getting those to show correctly when called from a layout (most the reason why I have to break up this code into a partial, one that comes from one index.erb.html and another that comes from a partial of its own _document_header.erb.html good time to ask, can you stuff one partial within another...
so just trying to get some pointers. This code is really common to two views.
(and is not always needing to be rendered or displayed)...so want to do this the best way.
You can reference a partial that is anywhere in your views folder.
It's common to make a "shared" folder in your views and reference the partial like: <%= render 'shared/my_partial' %>

HTML in public folder with hooks

I have an HTML file (index.html) in the public folder.
These HTML has some "hooks" in it.
Like:
<div>{client_ssnumber}</div>
<div>{client_company}</div>
I have to retrieve this file and complete the information in the hooks using data obtained in a controller´s method, then display in the screen.
What is the rails way to do it?
You can't do this (without terrible terrible hacking), it's hard coded to look for public files before checking the router.
Anyway, Your client is wrong. Tell them to use "<%= ... %>" instead of "{ ... }" and move it into a view (you should move it into the view, so it's where you want it to be, then just tell them what the name of the file is).
There is no sensible reason to make up your own templating language. It will be buggier and slower, and it will add a lot of time to get the product out the door. Plus you'll then have to maintain that code. This is a solved problem, use ERB. If they really like that syntax, use Mustache which is pretty similar, and is an existing templating language.
If you can't get them to do this, you have much bigger problems than how to render this page.
Put them in a view, on app/views/ and use a template engine like erb or haml. You can then assign variables in a controller and use them in your view.

How to render partials from unrelated controllers in one view....almost Amazon style

How can we render many partials from different controllers into one view?
The local variables of each partial are calculated separately in different and independent controllers.
What I really have to make things more specific, is a home layout, and in that layout that has dynamic content, there's a partial that only handles site wide news announcements, and these are independently updated.
I know a quick hack such like:
render :partial => '/news', :locals=> {#news = News.last}
but I want something more "correct". Like I've been reading about :templates rendering but i'm not sure how it works exactly in Rails 3.1.
Any help would be highly appreciated!
2.2.3 Rendering an Action’s Template from Another Controller
What if you want to render a template from an entirely different controller from the one that contains the action code? You can also do that with render, which accepts the full path (relative to app/views) of the template to render. For example, if you’re running code in an AdminProductsController that lives in app/controllers/admin, you can render the results of an action to a template in app/views/products this way:
render 'products/show'
Rails knows that this view belongs to a different controller because of the embedded slash character in the string. If you want to be explicit, you can use the :template option (which was required on Rails 2.2 and earlier):
render :template => 'products/show'
Sources: http://guides.rubyonrails.org/layouts_and_rendering.html#using-content_for
Should have read in more details.

Merge items in nanoc

I have been trying to use nanoc for generating a static website. I need to organize a complex arrangement pages I want to keep my content DRY.
How does the concept of includes or merges work within the nanoc system? I have read the docs but I can't seem to find what I want.
For example: how can I take two partial content items and merge them together into a new content item.
In staticmatic you can do some like the following inside your page.
= partial('partials/shared/navigation')
How would a similar convention work within nanoc?
nanoc’s author here.
In nanoc, partials are layouts. So, you could have layouts/partials/shared/navigation.html and then render that partial like this:
= render '/partials/shared/navigation'
For that to work, enable the Rendering helper first, by including it somewhere in the lib/ dir (e.g. lib/helpers.rb):
include Nanoc3::Helpers::Rendering
For more information, check out the layouts as partials section of the manual.
Hope this helps!

ERB Ruby Templates -- Online Editor

I am aware of quite a few different JavaScript based online text editors for WYSISYG html editing, however I am trying to find something similar for ERB Ruby templates. Essentially it would be just like the other editors, however it would not garble or encode the <%= foo.to_s %> type code blocks.
Is there anything out there which will be capable of this? I am willing to try and modify and existing JS editor if there is nothing already, so any suggestions as to which one is the nicest to work with would be much appreciated.
Thanks
Amar
You can use the ProtectedSource configuration option in CKeditor for this purpose:
FCKConfig.ProtectedSource.Add( /<%[\s\S]*?%>/g ) ;

Resources