Play framework: how to pass parameters to include - include

I want to include an html file in a view and pass parameters to that include.
Can i pass parameters when using: (?)
#{include 'page.html' /}
Something along the lines of a jsp:include where you can specify which parameters you want to pass.
example: In the same page do something like
<jsp:include page="page.jsp">
<jsp:param name="a" value="aValue"/>
<jsp:param name="b" value="bValue"/>
<jsp:param name="c" value="cVlaue"/>
</jsp:include>
<jsp:include page="page.jsp">
<jsp:param name="a" value="aOtherValue"/>
<jsp:param name="b" value="bOtherValue"/>
</jsp:include>
Thanks.

If you want to pass parameters, then you are better off making a groovy tag, rather than creating an include.
More information can be found on the Play documentation - http://www.playframework.org/documentation/1.2.4/templates#tags
Basically, though, you would do the following
#{mytag param:'data', param2:'data2' /}
Then, in the following file app/views/tags/mytag.html, you would add the following (note the underscores)
Some html, which can access the parameters as ${_param} and ${_param2}

Related

Nokogiri removes closing tags to some nodes I want with a closing tag

Is there a way to have Nokogiri not remove an ending tag to certain nodes. I have the following node, and when I write my xml file with changes I'm losing an ending tag on it:
Before my modifications, it looks like this:
<Catalog name="example" version="3"></Catalog>
After modifications:
<Catalog name="example" version="3"/>
You can use the NO_EMPTY_TAGS option:
doc.to_xml(:save_with => Nokogiri::XML::Node::SaveOptions::NO_EMPTY_TAGS)
or the rather more concise:
doc.to_xml &:no_empty_tags
When using Nokogiri, how do you suppress the insertion of self-closing tags?

JSTL : Enable c:set to accept expression as variable name

I'm trying to modularize my JSTL code. A particular code needs to be called in many places inside a JSP so I've separated it out in a separate INC file. In my JSP, I include the file using <%# include file="snippet.inc" %>. The snippet needs to work on some variables in page context, determined by the caller.
I'm storing the NAME of the relevant variable in a variable called __var which will be used by the snippet. The expectation is that the snippet will read and modify the actual variable in pageScope whose name is passed via __var.
The JSP file:
<c:set var="name1" value="Admin"></c:set>
<c:set var="name2" value="Moderator"></c:set>
<c:set var="__var" value="name1"></c:set>
<%# include file="snippet.inc" %>
${name1}
<c:set var="__var" value="name2"></c:set>
<%# include file="snippet.inc" %>
${name2}
The INC file:
<c:set var="__value" value="${pageScope[__var]}"></c:set>
<c:set var="${pageScope[__var]}"> Hello ${__value} </c:set>
The first line works fine and I can read the value of the variable name. The second line does not work and complains that I can't use expressions as variable names.
How do I go about this issue?
It's things like these that make you realize what a wonderful thing StackOverflow is! Found and modified a solution from https://stackoverflow.com/a/8750411/1101040 to achieve my cause.
<c:set var="__value" value="${pageScope[__var]}"></c:set>
<c:set target="${pageScope}" property="${__var}"> Hello ${__value} </c:set>
All set! :)

xmllint xsd:selector xpath behaviour different from --xpath or --shell

The command:
xmllint myfile.xml --xpath 'MapField2Data[#country="FR"]/*[#active!="false" or not(#active) ]'
works as expected for my xml structure
But trying to use it in an xsd, it fails to compile:
xmllint --loaddtd --noout --noent --xinclude --schema xsd/pnsConf.xsd pnsConf.xml
xsd/pnsConf.xsd:75: element selector: Schemas parser error : Element '{http://www.w3.org/2001/XMLSchema}selector', attribute 'xpath': The XPath expression 'MapField2Data[#country="FR"]/*[#active!="false" or not(#active) ]' could not be compiled.
My xsd has a proper
<xsd:selector xpath='MapField2Data[#country="FR"]/*[#active!="false" or not(#active) ]'/>
Where a simpler xpath like 'MapField2Data/*' works fine in both situations.
This looks like a bug or a missing feature in xmllint or libxml2.
Should I file a bug on the gnome bugzilla for xmllint?
Maybe there is another solution to my problem in the mean time?
I want "active" tags to be unique and ignore non-active tags in a structure such as this one:
<MapField2Data country='FR' >
<raw id='NoUnReadMails' active='true'>
<depend ref='_EndMailNotif'/>
<depend ref='_EndMailSub' />
</raw>
<raw id='NoUnReadMails' active='false'>
<depend ref='_EndMailNotif'/>
<depend ref='_EndMailSub' />
</raw>
<raw id='NoEMails' >
<depend ref='_EndMailNotif'/>
<depend ref='_EndMailSub' />
</raw>
...
Regards,
Emmanuel.
This is not a bug. xsd:selector only allows a restricted set of XPath operations. Your expression uses predicates which are not allowed. Also see this question.

How to convert test report log files into Jenkins Junit XML File format?

I've been assigned a task to do with Ruby, but as I'm new to it I'm searching over the internet for a proper solution to solve it:
I have a list of log files reports in a web page actually divided in passed or failed.
I need to take log files and convert them into a format compatible with Jenkins Junit XML File format.
Everything, the passage from log to XML has to be written in Ruby.
Any ideas?!
I looked all over the internet and found information but still have no clear ideas how to solve this.
Are there any Ruby libraries that make this easier?
Has anyone ever handled anything like this?
You don't show the format you need, and I don't know what Jenkins needs, but creating XML is easy. Unfortunately, what you want will take a book, or several articles, which is beyond the scope of Stack Overflow. Basically though...
You can use a templating system, like ERB where you create templates for your overall XML document, or Nokogiri::Builder can be used to generate XML, or you can do it old school and use simple string interpolation to create your XML.
A syslog file is typically fairly well structured, at least for the first several fields, followed by free-form text which is the output of various commands. A log file from Apache is similar, with columns of text, followed by some free-form, but easily parsable text. There are gems here and there, along with tutorials on how to parse a log, so search around and you'll find something. The idea is you want to break down each line read into text you can assign to an XML node.
Once you have your fields, you can substitute them into the template or have Ruby interpolate the variables into strings, or use Builder to add the text between the tags.
It's not really hard, but is going to take several small tasks to accomplish.
Using string interpolation, if you wanted XML like:
<xml>
<tag1>
<tag2>some text</tag2>
<tag2>some more text</tag2>
</tag1>
</xml>
You could create it like:
var1 = "some text"
var2 = "some more text"
xml = %Q{
<xml>
<tag1>
<tag2>#{var1}</tag2>
<tag2>#{var2}</tag2>
</tag1>
</xml>
}
puts xml
Similarly, if you want to use ERB:
require 'erb'
var1 = "some text"
var2 = "some more text"
template = ERB.new <<-EOF
<xml>
<tag1>
<tag2><%= var1 %></tag2>
<tag2><%= var2 %></tag2>
</tag1>
</xml>
EOF
puts template.result(binding)
Which outputs:
<xml>
<tag1>
<tag2>some text</tag2>
<tag2>some more text</tag2>
</tag1>
</xml>
Or, using Nokogiri::Builder:
require 'nokogiri'
var1 = "some text"
var2 = "some more text"
builder = Nokogiri::XML::Builder.new do |node|
node.xml {
node.tag1 {
[var1, var2].each do |t|
node.tag2(t)
end
}
}
end
puts builder.to_xml
Which outputs:
<?xml version="1.0"?>
<xml>
<tag1>
<tag2>some text</tag2>
<tag2>some more text</tag2>
</tag1>
</xml>
Under this link there is a small explanation that may help
https://pzolee.blogs.balabit.com/2012/11/jenkins-vs-junit-xml-format/
Basically you just use https://wiki.jenkins-ci.org/display/JENKINS/xUnit+Plugin
to import a XML that follows the Junit schema. You can convert XML to Junit format having the schemes.
A good description of the Junit format can be found under: llg.cubic.org/docs/junit/

yard, How to include image to documentation?

I want to include image in yard-genereted documentation, but can't find anywhere how to do this... Does anyone know how to do this?
You can just add <img /> tag to your documentation:
# Blah-blah
#
# <img src=img/1.png />
# #param [String] blah
# #return [String] blah
def foo(bar)
end
Use rdoc-image: links:
# Gets foo.
#
# rdoc-image:img/1.png
def foo(bar)
"foo"
end
is rendered by YARD into
<p>Gets foo.</p>
<p><img src="img/1.png"></p>
The rdoc-images: also works in standalone *.rdoc files.
Depending on your markup format you may have to use another mechanism. For instance, if you use Markdown, the syntax is ![Alt text](/path/to/img.jpg). In RDoc, an img tag should work, but you can check if they have added a special markup syntax for this. Note that RDoc probably (not sure) doesn't like XHTML, you should use with no ending /.

Resources