How to convert Rails whole application in erb to haml - ruby-on-rails

I have one Rails application and all files are in erb format. Is there any quick way to convert whole application's erb file to haml.. without any conflict.
And also would like to know for the Reverse..
Thanks in advance. :)

For erb-to-haml
You can use from the command line html2haml
html2haml your_erb_file new_haml_file
If you want to convert all your files in one go, look at this article : http://shifteleven.com/articles/2008/06/08/converting-erb-to-haml-snippet
erb2haml gem will do the trick.. have a look to https://github.com/dhl/erb2haml
For haml-to-erb
I recommend you HAML2ERB service . It's really cool and generates valid ERB/HTML code! Tested on big HAML views (over 800 lines of markup) from the real production app. Project active :)
have a look to this also http://makandracards.com/makandra/544-convert-haml-to-erb

Related

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

How to convert layout in LESS to SCSS

I've got a layout coded in LESS and I need to implement it into a Rails application. As Rails straight use SCSS, I would like to use this instead of LESS.
Is there any tool that could do the conversion from LESS to SCSS for me?
Thanks
I could not find any tools for converting except this which seems old & possibly not working.
However the syntax of less & scss is very similar, you could do a quick search and replace to convert variables like #color: #4D926F; to $color: #4D926Fl; & so on
It would require some time, but not as much as you might thing.

Using a database value in a LESS file in Rails

I have installed the less-rails gem as I am keen to use the colour manipulation LESS offers. I need to extract a colour from my database as my themes base colour, and build up from there.
I have the static CSS, and have renamed it styles.css.less to ensure that rails understands the less extension, which it appears to.
The next thing I tried was to also wrap the file as an erb, to hopefully allow ruby string literals to process before being sent to LESS, and eventually outputting as valid CSS (still with me?)
The file is now called style.css.less.erb. While the file simple contains valid CSS, the processing of the document works. As soon as I add a ruby string literal, it fails.
color: #{"#112233"};
In the chrome debugger, nothing after this line is getting processed.
What am I doing wrong, and how should I do what I am trying to do?
As Chowlett says in comments, you should use erb syntax: <%= "#112233" %>
Next step is get that value from db. If this color value is application-wide, probably you are looking for settings in db solution. I use rails-settings-cached gem for that. Your result code will looks like
color: <%= Setting.foo_color %>
If you are using assets on production, don't forget to recompile them after each setting change.
And if it's not a setting but probably something specific to each user then you can't use application-wide css files for that, but you can write inline css in views.

Vim html.erb snippets?? snipMate Need a vim tip

When I'm in an html.erb file, I get no snipMate snippets.
I would like both HTML and Ruby, or just HTML would be fine,
How would I do this?
Would I need to write a set of snippets?
If so, is there a way of pulling in existing snippets without copying them?
Is there a way of telling vim to go into html mode when it sees .html erb?
You can use an autocmd to set the filetype to html when opening a ".html.erb" file. This could have unwanted side effects for plugins that work for ".erb" files.
autocmd BufNewFile,BufRead *.html.erb set filetype=html
You can also load more than one set of snippets by using a dotted filetype:
autocmd BufNewFile,BufRead *.html.erb set filetype=html.eruby
See :help snippet-syntax in the snipMate help for more info.
Snippets are stored in directory called snippets somewhere in your ~/.vim folder.
If you look there, there is usually one file per filetype, there is a c.snippets, a ruby.snippets, so it seems what you have to do is to create an erb.snippets there with what you want.
Eventually you could copy the content of ruby.snippets and html.snippets into your new erb.snippets.
Alternatively you can search on github, some people have posted their own erb.snippets configuration. For example, there is a nice collection there :
https://github.com/scrooloose/snipmate-snippets
The best thing would to try first to open a snippet file and look at the syntax, it is pretty easy to create your own snippet depending on what you use the most.
I am currently on a promoting tour for UltiSnips on StackOverflow. UltiSnips supports extending other file types, your erb.snippets would look like this:
extends html, ruby, rails
snippet temp "A snippet only in Erb"
erb rules ${1}
endsnippet
A conversion script for snipMate snippets is shipped with UltiSnips, so switching is easy.
I used the autocommand method to the set the filetype, but then I got html syntax errors for things like this:
<%= image_tag("logo.png", :alt => "Sample App", :class => "round") %>
The last two angle brackets would be highlighted in red, which drove me bonkers. So, I created a symlink called eruby.snippets that points to html.snippets. That worked like a champ and now I don't have to make changes in two places. I also have an eruby-rails snippet directory for non-html eruby snippets.
This is on a Mac OS X system. Note that an alias won't work. You need to hit the terminal and use the ln command. Not sure about doing this on a Windoze system.
You can assign multiple snippets scopes to a single filetype. (I've found that altering the filetype tends to break some syntax highlighting).
You can check that the filetype for erb files is indeed 'eruby' with:
:set filetype?
If you're using the maintained fork of snipmate, it looks like you'll want both the eruby.snippets and eruby-rails.snippets from the snipmate-snippets repository (owned by honza, but I don't have enough reputation to link to it here) (see the INSTALL section of the snipmate README for proper setup).
If you are using the maintained fork, I believe setting g:snipMate.scope_aliases in your .vimrc with the following will work for your example:
let g:snipMate = {}
let g:snipMate.scope_aliases = {}
let g:snipMate.scope_aliases['eruby'] = 'eruby,eruby-rails'
I've added a pull request to snipmate to have their documentation updated.
Jumping on the UltiSnips bandwagon after trying SnipMate for a while. Like SirVer mentioned, having the html, ruby, etc snippets available within an *.erb file was as simple as adding the extend line to the eruby.snippets file.
With the original snipMate plugin, create a file ~/.vim/ftplugin/erb_snippets.vim and put the following into it:
silent call ExtractSnipsFile(g:snippets_dir . 'html.snippets', &l:filetype)
silent call ExtractSnipsFile(g:snippets_dir . 'ruby.snippets', &l:filetype)

Ruby PDF:Toolkit using pdftotext

I'm converting pdf files in my Ruby project. I'm using the pdf toolkit gem for this.
The documentation shows how you can use pdftotext
pdftotext(file,outfile = nil,&block)
In my project I am converting a PDF file without any arguments and can just do this:
PDF::Toolkit.pdftotext("file.pdf", "file.txt)
If I run it from the command line, I can preserve the layout by passing that param
pdftotext -layout file.pdf
What is the correct syntax to achieve this with PDF::Toolkit?
Thanks!
Figured out how to make it work so I'm answering my own question, but if there's a "proper way" to do this, I'd love to see how to do it.
Put the options in the second argument and the text file will be named file_name.txt
PDF::Toolkit.pdftotext("file_name.pdf","-layout" )

Resources