look_down that checks (inside HTML) content - perl

With HTML::TreeBuilder, using command $root->look_down(_tag => 'a') I get first anchor.
(1) How can I find last anchor?
Additionally, how can I check for inside content of the tag, to check if it does or does not contain some string inside of it? So for example,
(2) how can I find an anchor that contains "Hallo" or "hallo" in inside HTML?
(3) how can I find an anchor that DOES NOT contain "Hallo" or "hallo" in inside HTML?

The look_down() function returns a list of all <a> tags found, so simply access to last element of it using an index, like:
my $last_a_tag = ($root->look_down(_tag => 'a'))[-1]
To search into its text, use content_list() function, that returns a list with all child text elements. Then use a map() function to check if it contains or not any text, like:
map { m/[Hh]allo/ } $last_a_tag->content_list;

Related

Get elements of list beginning with specific letter

I have a list of words allWords and I am trying to create a new list from allWords containing only those words that begin with a specific letter currLetter. Looking at the docs, collection.map() seems like a great choice. However the statement below won't compile since .starts(with: ) returns a boolean.
targetWords = allWords.map { $0.starts(with: currLetter) }
Can anyone point me in the right direction?
While not described in the documentation of collection type instance methods, the solution is to use filter() instead of map():
targetWords = allWords.filter { $0.starts(with: currLetter) }

How can I replace custom tags with strings from an xlf file in TYPO3

I'm trying to use the TYPO3 tags function to get strings from an xlf file. If I hard code the reference to the string I want, it returns successfully, but I need to know how to get it to return the appropriate string based on the tag content.
For example, this works:
HTML:
<var>myVar</var>
Typoscript:
lib.parseFunc_myExt{
tags {
var = TEXT
var{
value = {LLL:path/to/locallang.xlf:var.myVar}
insertData = 1
}
}
}
I need a method to take the content of the <var> tag and use it in place of myVar in the value.

D3 invalid character in element

I'm getting a response in JSON format, which contains an _id that is stored as an ObjectID in Mongodb on the server side. However, I change it into a String, and it still won't let me add it. Is it because it has numbers? I need the element to be identifiable by the id, so if I can't append this way, is there any other way I can reference the element by the id?
var group = d3.select("#containerthing");
var id = response._id.toString();
console.log(id);
//5802bc044f6313c1097de4a2
var responseNode = group.append(id).attr("fill","black").attr("x", 15).attr("y", 15).attr("width", 190).attr("height", 90);
//InvalidCharacterError: String contains an invalid character
I believe that I understand your problem.
D3's .append():
If the specified type is a string, appends a new element of this type (tag name) as the last child of each selected element, or the next following sibling in the update selection if this is an enter selection. [...] This function should return an element to be appended. (The function typically creates a new element, but it may instead return an existing element.
Why .append() work fine if you pass 'foo'? Because D3 append a custom tag element. If you see in your console I'am sure that you will see <foo>...</foo>
Why .append() work wrong if you pass '5802bc044f6313c1097de4a2'? A custom tag element can't start with a number. You don't use _id, you should try to find another pattern for identify your element.
I hope that helps
The reason was that you can't start elements with numbers. I had to do:
var responseNode = group.append("n"+id).attr("fill","black").attr("x", 15).attr("y", 15).attr("width", 190).attr("height", 90);
to get it to work.

How to fetch value from custom multifield component?

I have created a multifield custom widget having two fields with names ./urlLink and ./urlText.
Now i m trying to fetch the values from widget into the component's jsp with following code
String property = properties.get("./urlLink",String[].class);
for(String value: property ) {
out.print(value);
}
out.print(property);
But i am not able to get its value instead i m getting error.
If you're getting a property and it contains a string value, you need to use the method getString() - that way when you have the property, you can set the string to the value by doing something like this:
Property property = properties.get("./urlLink",String.class);
String value = property.getString();
Just a side note, if your return is supposed to be a string array, your type that you're putting the values in should be a string array.
String[] value
Check out the documentation on day.com for Properties and getting the values inside them.
Looks like a typo: you don't prefix a property name with .\ when accessing it.
My guess is you got a NullPointerException, right? That's because there's no ./urlLink property in the value map (properties). You should check against that anyway (so that it's not thrown on a fresh page with no content).
If that doesn't help -- double check that you have the properties in the content (call your page with .xml or .infinite.json extensions, and then double check if you can read them as plain strings (you should be able to -- CRX does some magic, smart type conversions).
It's good to register custom xtype as :
// registering the custom widget with the name dualfield
CQ.Ext.reg("dualfield", CQ.Ext.form.DualField);
Then u can easily fetch the value as :
String[] data = properties.get("multi",String[].class);
Here multi is the name of widget having multifield as xtype

How to access element and elementId from within didInsertElement

Using Ember.CollectionView I want to access and manipulate the DOM element which is being inserted by each child view. The issue I have is that I don’t know how to get a reference to the element from within didInsertElement. Here is the jsFiddle -- the summery of coffeescript is below:
window.App = Ember.Application.create()
window.App.initialize()
App.Item = Em.View.extend
didInsertElement: () ->
console.log ">>> element is: ", this.element
App.items = Em.ArrayController.create()
App.items.set('content',[
Em.Object.create({title:"AN", id:"item-one"}),
Em.Object.create({title:"Epic", id:"item-two"}),
Em.Object.create({title:"View", id:"item-three"})
])
App.EpicView = Ember.CollectionView.extend
classNames: ['epic-view']
contentBinding: 'App.items'
itemViewClass: 'App.Item'
this.element is undefined. I have also tried calling element and that is undefined as well. According to the docs, there is an element property available inside the view, but I don’t know how to access it, and I am not sure if it is available from within didInsertElement or not.
How can I get the id of the DOM element that was just inserted into the view? Ideally, I would like not having to search for it in the DOM since the view should already be aware of what it is inserting into the DOM.
ps: I am using Ember 1.0pre
Use get('element') or get('elementId') to access properties in Ember