Rails tabs instead spaces - ruby-on-rails

Is there any way to to setup Rails generating files with tabs instead spaces?
Or maybe is there any way to auto replacing spaces to tabs in gedit?
Cause I really prefered tabs and it's really take some time to replace spaces to tabs in new generated files by Rails.
Thanks in advance!

To do this in gedit, try the Tab Converter plugin.
(Don't think there's a way to do it directly in Rails.)

Unfortunately there isn't a simple way. The generators begin copying a template file into your project and then substitute the various variable names into that template.
The template files that are copied into your project use spaces, so you'd need to monkey patch some filter into the generators; a filter that would regex replace the leading spaces with tabs. Not an ideal solution.

Related

Most efficient way of doing static HTML in multiple languages

So I would need to make static HTML pages in multiple languages and now I'm looking what way it would best to do. HTML of the pages stays same, as does images. Basically only text content changes from localisation to another. Page structure is something like this:
en/
../index.html (main/home page)
../catalogue.html
../video.html
../examples.html
de/
../index.html (main/home page)
../catalogue.html
../video.html
../examples.html
So layout (html, css and images) are same on all pages. Just text content changes. There are about 10 different languages. What tool would you use for the injecting text (from json file?) to each template and automatically building needed folders & files. Grunt + mustache?
This is pretty simple so I don't really want to use any CMS for this. For sass etc I will use Grunt already.
If you are going the grunt way here are some thoughts:
Take a look at grunt-dom-munger, it's designed to manipulate html's using standard selectors. You can replace text, elements, append new ones or remove existing, whatever you need.
If you also need to copy files from here to there after transforming them you may want to use grunt-contrib-copy.
Moreover, do not forget that the Gruntfile is plain javascript so you can write your own custom functions to do whatever manipulations or operations you may need.
Hope this helps you get started...

grails split i18n files (messages.properties)

I would like to split the messages.properties into several files, for example one will contain the validation messages, while the other the text for the FAQ or ToS.
I've been searching and I found this website: http://mrhaki.blogspot.com.es/2011/03/grails-goodness-splitting-i18n-message.html
But it didn't work.
It's possible to accomplish this, or I'm just losing my time?
Thanks in advanced.
Edit: I'm using Grails 2.3.0
In the i18n folder, I've created customValidation.properties and view.properties. Works fine for me. You have to adhere to the conventions which is keep them in the i18n folder and you can't have underscores in the names except to denote locale.
#Gregg, thank you for hint.
By the way, to keep good structure in project, you can also nest i18n files in subdirectories, like this:
grails-app
|--i18n
|--|--en_US
|--|--|--messagesUserProfile_en_US.properties
|--|--|--messagesRegistration_en_US.properties
|--|--|--messagesCommon_en_US.properties
|--|--pl_PL
|--|--|--messagesUserProfile_pl_PL.properties
|--|--|--messagesRegistration_pl_PL.properties
|--|--|--messagesCommon_pl_PL.properties

Can I use url parameters in LESS css?

Intro:
I'm trying out LESS in an asp.net mvc environment.
I use dotless for server side processing (and I wouldn't want to use client side processing especially afer publishing the complete project).
I have to apply a design where there are different color schemes depending on different things (e.g. time of the day).
Less felt very powerful in this case as designing a parameterized css and only changing like 10 variables at the beginning of the file for every theme was really uplifting.
Problem:
But I would need to somehow change the color themes from an outside parameter.
Ideas:
First I thought that an URL parameter like style.less?theme=fuschia would be good, but I found no way to parse something like this.
Then I thought that making a very short blue.less, green.less, orange.less consisting only declared color variables, and including the main.less in every one of them would be a solid solution.
I had no chance to try out the second solution, but I thought this would be a good time to ask for advice on the most robust way of doing this.
The problem again is: I want to control some things in my less file from the outside.
Yes you can (because I implemented that feature for exactly that reason).
Dotless supports parameters from the outside via the querystring parameter.
<link rel="stylesheet" href="style.less?foo=bar" />
Will let you use the following less:
#foo = bar;
The parameter injection code is very simple. it just prepends the variable declarations to your normal less file, so anything that comes as a querystring parameter will follow the above syntax.
The code in question is very simple: https://github.com/dotless/dotless/blob/master/src/dotless.Core/Engine/ParameterDecorator.cs
AFAIK, you cannot pass parameters for dotnetless to use to do the compile.
As a suggestion, why not just call different less files? This would be fairly easy to do by using a Viewbag property.
To make the different less ones, You first create a less file with each set of colors in them. Then you import your base css file. dotnetless will merge the color definations in the parent file with the usages in the base file. So you have something like -
#baseGray: #ddd;
#baseGrayDark: darken(#baseGray, 15%);
#baseGrayLight: lighten(#baseGray, 10%);
#import "baseCss.less";
I just tested this on and MVC3 project and it works.

Not working tab configuration in VIM for Javascript files in Rails project

I am trying to set some tab indent configurations in Vim. Unfortunately I can't get it working.
In my last line I use
u FileType javascript set tabstop=4
in the hope of having the tab width set to 4.
But when I open a .js file and press tab it inserts only 2 spaces. I tried to comment out the other whitespace stuff without success.
Here is also my full vimrc: https://gist.github.com/919909
How do I set the tabs and so on for Javascript files, and why does the above not work?
Update
The problem seems to be somewhere else as when editing new Javascript files it works as expected. It only seems to behave differently on the Javascript files in my Rails project.
How could that be? I have a Rails.vim plugin installed, could that be the cause?
'tabstop' is the number of spaces a tab character in the file counts for. The number of spaces of an indentation level is set with the 'shitfwidth' option, and the number of spaces that a tab counts for when doing edit operations is set with 'softtabstop'. It's a little complicated, but if you set both 'shitfwidth' and 'softtabstop' to the same value, you'll probably get what you want. You can keep 'tabstop' at the default value.
If you are one of those that like spaces all the time and not tabs, you these settings will probably suit you.
The Rails plugin is probably setting some of these leading to the different behavior you're experiencing.
Ok, the root of the problem seems to be in Rails.vim (see https://github.com/tpope/vim-rails/pull/78)
But there is also this easy solution:
autocmd User Rails/**/*.js set tabstop=4

Rails: Hash#to_json - split over multiple lines?

I'm having a slight annoyance with the javascript_I18n plugin, which generates js-friendly versions of the I18n translation tables, so that you can localise your javascript. It all works fine, but it works by calling to_json on each locale's translations hash and outputting the results into a file. When you call to_json on a hash the resulting string is all a single lne, which means you end up with files with an enormous line at the end.
This in turn is stopping git from being able to merge any changes, because the merge works on a line by line basis and can't deal with a single massive line with changes in the middle somewhere. It's not a massive problem because i can always just re-generate the js-friendly translation file with a rake task that comes with the plugin (which replaces the mid-merge file with a brand new one which i can just commit in), but it's just a bit annoying. It occurred to me that if the json was output on different lines, instead of all the same line, then it wouldn't be a problem, and it wouldn't even make the file that much bigger, just inserting two characters (\n) per line.
Before i try and hack the resulting string with a gsub to split it onto seperate lines, is there a nicer way to call to_json on a hash and output the results onto seperate lines? Or a nicer way to solve this problem generally? (i can't find much useful in the documentation for javascript_I18n).
Grateful for any advice - max
Not to answer you question, but to give a suggestion:
It would probably be easier to just ignore all the generated js translation files.
This is because even if you separate the translation into multiple lines, there are still chances of merge conflicts, which you probably already resolved once in your yaml file.
I would set it up this way:
1). gitignore all the js translation files.
2). In ActionController, add a before filter to generate the js files automatically on each load in development mode only.
3). Tweak your deploy.rb file to generate the js files after code update.
No more merge conflicts! (at least for js translation files) :D
Aaron Qian

Resources