|
Hi everybody,
The plugin I develop contains a lot of widget that are similar. For each widget, I copy and paste the same methods like getImage, who have a Double in parameter and return the URL of my image, etc... That's not a problem for one or two methods in a few widgets, but I have 7 methods and ... 30 widgets. So it would be lighter if I could declare these static methods once and call them from the widgets. I defined a ruby class with the static methods in a file in the "resources/static" repository but after a lot of tests, I failed to call these methods from a widget. Is anybody already success to embed static ruby methods ? Reagards, Thomas |
|
Hi Thomas.
I defined a ruby class with the static methods in a file in the "resources/static" repository but after a lot of tests, I failed to call these methods from a widget. Indeed this directory is not for code but for static content like images or CSS.
Widgets are implemented with ERB templates only, so it's not possible to share ruby code. But there's maybe a workaround since release 3.0 : you can try use the new extension point "ruby on rails application" to define a new app without any controllers but with only models : src/main/resources/org/sonar/ror/<plugin key>/app/models An empty file init.rb must be added to the directory <plugin key>. The ruby files in the directory models/ should be available in widgets. I hope it works Regards |
|
Hi Simon,
thank you for your answer. Maybe I will try that solution later. Regards, Thomas 2012/6/20 Simon Brandhof <[hidden email]> Hi Thomas. |
|
This post has NOT been accepted by the mailing list yet.
Hi all,
Solution tested and it works but with limitations. If you use ruby method defined by SONAR like methods metric(), format_measure() defined in the ApplicationHelper class for example, you need to import the ApplicationHelper in your Ruby files. But it's not the only problem. For example, if you use the chart() method which have other dependencies with other SONAR ruby class, you need to import all class, even those used by the chart() method. But, when you know this, it's a very good possibility to not have duplication in your ruby code. Regards, David FRANCOIS |
|
In reply to this post by thomas sermier
Think green - keep it on the screen. This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you. |
|
Hi David,
Sorry for the late answer, I'm back from holidays. RoR helpers are only available in views by design. Controllers are not supposed to handle rendering, that's why they can't access helpers. Regards On 21 August 2012 19:31, Francois, David <[hidden email]> wrote:
-- http://sonarsource.com |
| Powered by Nabble | Edit this page |
