I'm working on a Java SonarQube plugin, but am still new to the API and making plugins in general.
I've downloaded the Example SonarQube Plugin (from https://github.com/SonarSource/sonar-examples) and have been playing around with it to try get the hang of it.
For a start, I'm trying to simply show the number of Lines of Code of a selected program. In the html.erb part, I have just added some "Hello World" text as seen below:
<div> Hello World </div>
I already added the metrics option so I think I'm just missing something small.
#WidgetProperty(key = "Metric",
type = WidgetPropertyType.METRIC,
description = "Select a metric (at least one is necessary).",
optional = false )
Essentially, I just want to click the Lines of Code metric in the widget options and display its output.
Any ideas? Thank you very much in advance!
The way to solve the issue is as follows:
Assuming your "Metric" input is as in the question above, the following code in the html.erb file should do the trick in displaying the value of the selected metric.
<h3 align="center"><%= widget_properties['Metric'].description -%></h3>
<%= format_measure(widget_properties['Metric'].key, :url => url_for_drilldown(widget_properties['Metric'].key)) -%>
Hope this helps anyone with the same problem.
Related
I've been attempting to find a solution to this problem for about the last 12 hours and simply have to admit defeat and ask the question...
I am currently working on a project which involves added a start rating feature to a product.
the_number = number_with_precision(product.no_of_stars, :precision => 0) gives me the average star rating for the product. I can display the number (eg 4) on the index.html.erb page but cannot for the life of me get it to render a star jpg for for each number (instead of the number).
I am aware of the difference between <%= and <% etc however because this is my first post, I'm unable to copy and past the code I've used :-(
SO... the_number (for example) would give me 4, however the following loop construct within my index.html.erb file keeps throwing an error reading
undefined methodtimes for "4":ActiveSupport::SafeBuffer`
the_number.times do
img src="my-image.jpg" alt=""
end
I understand the snippet above is not wrapped in the correct tags, but as explained before, it will not allow me too. Please assume that the 1st and 3rd line are wrapped in ruby tags without the '=' and the image is wrapped in the relevant html img tag. You can also assume that the rating 'system' works correctly.
Any help would be greatly appreciated :-)
Thanks
the_number.to_i.times do
img src="my-image.jpg" alt=""
end
would <%= ... Integer(expression resulting in 4) %> work for you?
to this you can append times and continue with the loop
such as
Integer(the_number).times do
img src="my-image.jpg" alt=""
end
Try casting the_number to an integer:
the_number.to_i
Then you should be able to call times on it.
I've been watching some Railscast episodes and it looks like he's using Sublime Text as his editor. How does he create new <% %> tags? I can tell he's using a shortcut but can't figure out what it is. Any help would be appreciated.
I really don't know what the "<% %> tags" are, but I imagine the presenter is using the ERB Insert and Toggle Commands add-on. The animated GIF on the project's description page shows such things being used.
I used a plugin to create A QR Code from a plugin which says to use the below code in ruby page
<%= javascript_include_tag :defaults %>
<%= qrcode('http://www.facebook.com/', 2, 3, 'my-qrcode') %>
I was expecting an image file , instead i got a table with lots of values in it. I tried a different ways to find a QRCode image generator and the only one seems to give an image is google charts, which i find not that interesting, I used them like
<%= image_tag("http://chart.apis.google.com/chart?cht=qr&chl=#{'http://www.facebook.com/'}&chs=120x120&choe=UTF-8", :size => "120x120")%>
Does anyone knows any other useful plugin that gives me the following output
I need to see a QR code for a link (where the parameters of the link
changes)
When i click on a link below it, it should be able to download the
QRCode image.
Take a look into rqrcode. It seems to do what you want.
There is an old example app here
I have the following issue. I have a google map (using YM4r + Geokit) within Ruby on Rails, anyhow, i basically have an array of markers which are populated in the following manner
#shops.each do
|sto|
markers << GMarker.new (....)
end
They are definitely being stored fine as under 10 markers they are displayed just fine. The problem arises when there are more than 10 markers on the same page,
Further code related to displaying if this may help:
#map.overlay_global_init(GMarkerGroup.new(true, markers), "sto_markers")
in the html.erb file:
<%= GMap.header %>
<%= javascript_include_tag("markerGroup") %>
<%= #map.to_html%>
<%= #map.div(:width => 700, :height => 500)%>
Only 10 markers are displayed on screen instead of the correct amount in the markers array.
Has anyone ever encountered this issue please? i'm really at a loss on how to overcome this please
Hmm, I have never used these plugins (I prefer to work directly with the API, much easier :)), so this is just random thinking.
Have you looked in the source of the rendered HTML? In there you should have a Javascript Object or Array with all your markers defined. If all of them do show up there, then it is easier to pinpoint if the problem is on the Javascript or the Rails side. (That is what <%= #map.to_html%> should do unless I'm completely off).
Update:
After some looking into the plugin, I can't really tell what the error can be, however since it do put out everything in clear Javascript in the file, it would probably help a lot if you can post the rendered HTML source. I believe that you will find the solution by looking there.
I had come experience with PHP a time ago and now I'm learning to use Ruby on Rails. But one simple question bothered me in both these languages, so I think I can cross-post it to both tags.
As you know, one of the concepts there is that one can embed PHP or Ruby code into web page template. Then these statements are executed and result of its execution is inserted in certain places of the page, marked with "brackets" <%= ... %>.
Or... wait. We program Ruby/PHP, but not HTML. Maybe we should treat template as Ruby/PHP code, into which sometimes HTML markup is inserted? So the process is treated like that HTML are inserted into ruby code into the "brackets" %> ... <%.
These are two different approaches:
HTML page is the primary entity, and it is affected by code execution; or
code is the primary entity, and it is executed, while HTML snippets are inserted in certain places.
This philosophy leads to different possibilities in coding conventions: result of code execution influences the page If we adhere the first insight, then the code would look like this:
<p>
<% (1..10).foreach do |i| %>
Iteration number <strong><%= i %></strong>. <br/>
<% end %>
</p>
But if we stick to the second alternative, the code would be formatted like this:
<%
%><p><%
(1..10).foreach do |i|
%>Iteration number <strong><%
%><%= i %><%
%></strong>. <br/><%
end
%>
How should the concept of templates be construed? What concepts do you, way more experienced Web developers, account for the coding convention?
If this is in your View layer (and it should be), then the HTML is the primary entity. It's the most pertinent part of that layer -- marking up your data to display in meaningful ways to the user.
Even aside from that, your second example is nearly unreadable. I see what you're doing, but it took me a minute to wrap my brain around it. I've also never, ever seen View-layer code like your second example (and I would make it one of my priorities to change it wherever I saw it if it was in a project I was working on).
To be more concise: you're putting the emphasis on the wrong thing. In my opinion, readability trumps just about everything else. The coding style that produces the most readable code is therefore the most superior (ceteris paribus and YMMV, of course).
Maybe you should look into Haml? I don't know if there's a php equivalent, but as far as Rails goes, it's somewhere in between the two schemes. It's not quite code centric. But when used right, all the raw html is prepared programatically.
In short everything is considered text to be directly outputted, unless prefixed with either a %, - or =. Which translate to html-tag, ruby code that doesn't output. Ruby code that does output. Haml then uses whitespacing to nest things properly, much like python does. Raw html outputs untouched but using % to specify a tag handles closing tags.
Sample:
#outer-div
- #items.each do |i|
%span.item
= i
%br
Outputs
<div id="outer-div">
<span class="item">
item
</span>
<br>
</div>
See the haml tutorial for more information.
To answer the central question. The bulk of any page is going to be HTML or raw text. We reduce the bulk of that text with includes and helpers, but it's still there. If there were a truly code centered approach my use of it would depend on the ratio of program logic to html. Personally I'd rather go with the html centered approach.
If you are interested in a code-oriented view, this is something you might try implementing as a pure Ruby DSL:
tag :p, :class => 'iterations-container' do
(1..10).each do |i|
text "Iteration number "
tag :strong { text i }
text "."
tag :br
end
end
Or perhaps instead of tag :p do ... end, you may favor tag.p do ... end.
I recommend doing only very simple logic in your template files. That way designers who can edit HTML can easily edit even those files to alter the layout if need be.