Unknown strange syntax - search-engine

So recently I have been playing around with yacy the p2p search engine. I came across this strange syntax in their html pages looks like some type of include, am not sure exactly what it does (or what language it is). here's the code.
#(num-results)#
::
<p>No Results.</p>
::
<p>No Results. (length of search words must be at least 1 character)</p>
::
<div id="results"></div>
<div class="progress">
<div class="progress-bar progress-bar-info" id="progressbar" role="progressbar" style="width:0%;">
<span style="position:absolute;display:block;text-align:left;width:100%;color:black;"> <strong id="offset">#[offset]#</strong>-<strong id="itemscount">#[itemscount]#</strong> of <strong id="totalcount">#[totalcount]#</strong> #(globalresults)#::; (<strong id="localResourceSize">#[localResourceSize]#</strong> local, <strong id="remoteResourceSize">#[remoteResourceSize]#</strong> remote), <strong id="remoteIndexCount">#[remoteIndexCount]#</strong> from <strong id="remotePeerCount">#[remotePeerCount]#</strong> remote YaCy peers.#(/globalresults)#</span>
</div>
</div>
What does the #(somename)# and #[somename]# syntax do? please help.

Absolutely nothing. but you could parse it with javascript and replace it with values.
Its no official language. its their own implementation to manipulate html output.
Which can be done server side or client side. They kinda make up the rules and you can decide by styling where the values should appear.
In my example I replace #[itemscount]# by an arbitrary 10
str = '<span style="position:absolute;display:block;text-align:left;width:100%;color:black;"> <strong id="offset">#[offset]#</strong>-<strong id="itemscount">#[itemscount]#</strong> of <strong id="totalcount">#[totalcount]#</strong> #(globalresults)#::; (<strong id="localResourceSize">#[localResourceSize]#</strong> local, <strong id="remoteResourceSize">#[remoteResourceSize]#</strong> remote), <strong id="remoteIndexCount">#[remoteIndexCount]#</strong> from <strong id="remotePeerCount">#[remotePeerCount]#</strong> remote YaCy peers.#(/globalresults)#</span>';
document.getElementById('container').innerHTML = str.replace('#[itemscount]#',"10");
<div id="container"></div>

Related

th:with what is the difference between the two examples

<p th:with="firstName1='James1'">
<p>Upper</p><p th:text="${firstName1}"></p>
</p>
<p th:with="df='today'">
Today is: <span th:text="${df}">13 February 2011</span>
Could you tell me what is the difference between the two code sections. They seem identical for me. But there is some difference as the results differ.
Alright, I've never encountered this before... but it looks like Thymeleaf is enforcing the rule that Any <p> (or other block-level element) will implicitly close any open <p>. This works, for example:
<div th:with="firstName1='James1'">
<p>Upper</p>
<p th:text="${firstName1}"></p>
</div>
<p th:with="df='today'">
Today is: <span th:text="${df}">13 February 2011</span>
</p>
In your example, the firstName1 variable is out of scope because the parser is treating your HTML like this (so firstName1 is considered null):
<p th:with="firstName1='James1'"></p>
<p>Upper</p>
<p th:text="${firstName1}"></p>

Setting Data-Parent and HREF dynamically in a for-loop

Previously to create Accordion controls I used to use this piece of code:
<div class="panel-group" id="accordionMessagesSetup">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordionMessagesSetup" href="#collapseMessagesSetup">
<span class="glyphicon glyphicon-chevron-up"></span>
Message Setup
</a>
</h4>
</div>
<div id="collapseMessagesSetup" class="panel-collapse collapse in">
<div>
<p style="background-color: red"> Someting ELSE in here</p>
<p style="background-color: red"> Someting ELSE2 in here</p>
</div>
</div>
</div>
</div>
or as seen here: Bootplay Live Demo
Now I still want to use my example but in this page I have a for-each loop so I need to create these at run-time.
The items I need to put variables there in order for this to work are
id="accordionMessagesSetup"
data-parent="#accordionMessagesSetup"
href="#collapseMessagesSetup"
id="collapseMessagesSetup"
How can I initialize those in a for-each loop a mode using Razor?
Imagine you have whatever property you like to do it in the model.
The biggest issue you are/will likely run into is Razor parsing. When you try to use a Razor variable in the middle of some bit of text, often Razor cannot determine where the variable name ends. For example, if you were to do something like:
<div id="accordion#Model.IdMessageSetup">
Razor thinks it needs to look for a property on the model named IdMessageSetup, when actually, you just wanted Id. The easiest way to fix this is to wrap the variable in paranthesis:
<div id="accordion#(Model.Id)MessageSetup">
Now, it's clear which part is the variable. As far as adding the # sign goes, I'm not really sure what the confusion is there. You just put it where it needs to go:
<a href="#collapse#(Model.Id)MessagesSetup">
Nothing special required.

How to extract article content from a website/blog

I'm trying to write a generic function for extracting article text from blog posts and websites.
A few simplified examples I'd like to be able to process:
Random website:
...
<div class="readAreaBox" id="readAreaBox">
<h1 itemprop="headline">title</h1>
<div class="chapter_update_time">time</div>
<div class="p" id="chapterContent">article text</div>
</div>
...
Wordpress:
<div id="main" class="site-main">
<div id="primary" class="site-content" role="main">
<div id="content" class="site-content" role="main">
<article id="post-1234" class="post-1234 post type-post">
<div class="entry-meta clear">..</div>
<h1 class="entry-title">title</h1>
<div class="entry-content clear">
article content
<div id="jp-post-flair" class="sharedaddy">sharing links</div>
</div>
</article>
</div>
</div>
</div>
Blogspot:
<div id="content">
...
<div class="main" id="main">
<div class="post hentry">
<h3 class="post-title">title</h3>
<div class="post-header">...</div>
<div class="post-body">article content</div>
<div class="post-footer">...</div>
</div>
</div>
</div>
What I came up with (doc is a Nokogiri::HTML::Document):
def fetch_content
html = ''
['#content', '#main', 'article', '.post-body', '.entry-content', '#chapterContent'].each do |css|
candidate = doc.css(css).to_html
html = [html, candidate].select(&:present?).sort_by(&:length).first
end
self.content = html
end
It works relatively well for the examples I tested with but it still leaves some sharing and navigation links plus it won't work if a page uses more cryptic class names.
Is there a better way to do this?
There is a gem called pismo that implements a couple of algorithms that attempts to extract article content.
There is a java library boilerpipe which you can interface from JRuby which extract textual content of a webpage.
Use rapar this gives the facility to write domain specific parser like wordpress.com, blogspot.com etc
You could also use a free article extraction API, for example:
diffbot.com
embed.ly
textracto.com
Some of them work quite good, and as I know there are all easy to integrate with Ruby.

Best way to convert an ASP.NET MVC view to Angular

I'm redesigning an existing ASP.net mvc page, which displays multiple client objects on a single page.
The reason why, is so the page can save all the clients/edits on a single click.
However as I wrote this 18 months ago it feels like their should be a better way to do it, as I have to use a FormBinder to map\save the objects, which is not pretty.
For example, I've started to use bootstrap tabs, each tab is a client and contains the details
<ul class="nav nav-tabs">
#foreach (var client in Model.Clients)
{
<li><a data-target="##client.ClientId" data-toggle="tab" href="##client.ClientId"><i class="fa fa-star"></i> #client.Name</a></li>
}
</ul>
<div class="tab-content">
#foreach (var client in Model.Clients)
{
<div class="tab-pane" id="#client.ClientId">
<div class="form-horizontal" role="form">
<div class="form-group">
<label for="#client.Name" class="col-sm-2 control-label">Name:</label>
<div class="col-sm-10">
#Html.TextBoxFor(model => client.Name, new { #class = "form-control", tabindex = "1"})
</div>
</div>
</div>
</div>
}
</div>
Is their a better, easier way to do this?
Ideally I don't want to use a form binder as well?
Thoughts? Examples?
I will say that as far as load time goes, Angular is going to help you a lot here. In your example, you will be loading the html for all of those tags once for each client. Angular would only load it once as a template, and duplicate the html on the client.
The angular equivalent would be something like this...
<div class="tab-content" ng-controller='ClientCtrl">
<div class="tab-pane">
<div class="form-horizontal" role="form">
<div class="form-group" ng-repeat="client in clients">
<label for="clientName" class="col-sm-2 control-label">Name:</label>
<div class="col-sm-10">
<input name='clientName' type='text' class='form-control' tabindex='1'>{{client.Name}}</input>
</div>
</div>
</div>
</div>
</div>
Granted, you'd have to do some work to implement the controller, but it's easy enough to do.
The benefits are that the scope is handling all of your ID's, so there is no need to keep track of any of that yourself. In some ways Angular is a difficult transition to learn, but once you do, it makes managing the code SO much easier.

Need to move node inside another using Nokogiri, then iterate through the node's contents in view

Thanks for reading. Super frustrated (and maybe missing something fundamental, I've never been great with Nokogiri)
In short - I have a source:
<div class="schedule-page">
<h3>Sunday, September 1, 2013</h3>
<table class="views-table cols-1 schedule-table">
<div class="game">Game 1</div>
<div class="game">Game 2</div>
</table>
<h3>Sunday, September 7, 2013</h3>
<table class="views-table cols-1 schedule-table">
<div class="game">Game 1</div>
<div class="game">Game 2</div>
<div class="game">Game 3</div>
</table>
<!--and so forth.... -->
</div>
I am able to iterate through the source, grab each day and X number of games, and create the container for each day and fields for each game.
<% #schedule_array.each do |a_game| %> #
<div class="game-info">
<div class="date"><%= #the_date %></div>
<div class="single-game"> # this pulls info for each game, works fine.
<div class="game-home"><%= a_game.css('.field-home-team').text %></div>
<div class="game-score"><%= a_game.css('.field-score').text %></div>
<div class="game-away"><%= a_game.css('.field-away-team').text %></div>
<div class="game-time"><%= a_game.css('.field-game-date-start-time').text %</div>
</div>
</div>
<%end%>
But I really don't know how to retrieve the original date (h3) from the source and parse it in such a way so that I can use it as shown above.
I've tried a dozen variations of the example shown under Moving Nodes, here:
http://nokogiri.org/tutorials/modifying_an_html_xml_document.html
But nothing's working. Can anyone tell me the correct way to handle this? My method is gibberish and I'm not sure it's helpful to put it up.
I assume #schedule_array is coming from something like #schedule_array = Nokogiri::HTML( html_contents).css('.schedule-table').
In which case, you need to traverse back to the parent and go back to it's previous sibling and get the value:
game_date = a_game.parent.previous_element.text
So in your particular case, that line can be:
<div class="date"><%= a_game.parent.previous_element.text %></div>

Resources