How to convert layout in LESS to SCSS - ruby-on-rails

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.

Related

Create custom ruby text transformations in Rubymine

I thought this would be something built in and easy to do in Rubymine but I haven't been able to find any references to it let alone possible answers. Maybe I am phrasing my searches all wrong? I want to create a simple ruby script that I can use to transform text in Rubymine. I have to do a lot of snake_case to titleize transformations in my writing of some rails forms. I wish I could highlight some text and right click -> Titleize and have it happen, but Rubymine only does upcase/downcase or snake_case/camelCase conversions. It seems like I should be able to write a simple script like:
require 'active_support'
gets some_string
some_string.titleize
and assign it to a menu item. Any ideas? Right now I open the terminal panel in Rubymine where I have rails c running and copy/paste -> .titleize -> copy/paste.
I don't believe there is a way to do this right now using ruby. The use of RubyMine macros is quite limited, think you could take a look to some simple plugin like CamelCase take it apart and see what they are doing, but that would force you to use Java I guess.
However if you are interested only in the specific case of
snake_case > Snakecase
For that you could install the CamelCase and record a macro and assign it to a any shortcut you like , the macro itself would do this
ALT+SHIFT+U > SnakeCase
CTRL+SHIFT+U > snakecase
ALT+SHIFT+U > Snakecase
Hope that helps.

How to convert Rails whole application in erb to haml

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

SublimeText 2 Ruby formatting

Has anyone found a good Ruby/Rails formatter? There is BeautifyRuby, but it gets strings written like Q%[] wrong because it aligns everything to the [] and it messes everything up.
Essentially it looks like this from a function auto formatted by beautifyruby:
%x[#{cat_command} &]
%x[#{join_command} &]
return newintroname
end
Does anyone have an idea how to fix this?
The current version of beautifyRuby actually solves this problem.
I recommend you to use RuboCop to find all the issues/suggestions/alternatives/good practices in Ruby. It is also available as a Sublime Text plugin.
Ruby Good Practices: https://github.com/bbatsov/ruby-style-guide

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.

Emacs: Using a major-mode's font-locking only for mmm-mode

I've got MMM-mode set up to edit .html.erb files, but indentation does not work in the ruby sections, and all the different electric behaviours of ruby-mode do the wrong thing. I've changed this sub-mode from ruby-moode to fundamental-mode, and it works much better.
I want to still use ruby-mode's font-locking though, is this possible/easy? Any hints on where to start.
Elisp is comfortable to me, but I don't have too much time right now to dig too deeply myself. Hopefully someone will have a snippet?
I see you haven't yet found an answer. Dunno whether it will be better for this, but you might consider using MuMaMo instead of MMM.
To answer the question, you would define a major mode deriving from fundamental-mode, and in its body just copy the font-lock-related lines from the ruby-mode definition body, the ones setting font-lock- variables and also syntax-propertize-function. Naturally , you need to (require 'ruby-mode) somewhere.
But for .html.erb files I can now recommend using mmm-erb, which was not available when this question was asked.

Resources