live template like TextMate
hello,
I am trying to convert some snippets from TextMate and I am having some trouble with a controller action. What I would like to have is this:
def create
@model_name = ModelName.new
end
When I type "model_name" I would like RM to fill out the ModelName.
Regards,
Cezar
请先登录再写评论。
I know one way, but you need to take a look on Groovy language =)
1. Create Live template with text
2. Select "Ruby" context checkbox
3. Press "Edit variables" button
4. Now you need to specify expression(function) which will automatically modify MODEL_CLASS variable using MODEL_VAR_NAME value. If you put cursor in "expression" field you will notice several predefined functions. Unfortunately you will not find "to_camel_case" function ( you can submit a request in our bugtracker). But there is one universal function - ability to execute any Groovy script.
5. So you need to specify something like this
First parameter is Groovy script body or path to Groovy script file on disc.
Second and other params will be bind to '''_i''' groovy local variable, i from [1, 2, ..].
The script from my example converts MODEL_VAR_NAME to upper case. If you wan't CamelCase - please write corresponding groovy script by yourself. Sorry =)
6. Also select checkbox "skip if defined" for MODEL_CLASS variable.
can you provide some info on what subset of groovy works inside RM ? I've tried a few methods but none of them seemed to work so I need some docs for the groovy lang, thanks