nested comments with Clojure in om.next - clojure

Om.Next is an excellent and clean UI library for use with Clojure and Clojurescript and I'm trying to add functionality for commenting to our website.
Essentially: entities have a bid (blurb-id) and now I want to add comments.
My idea is:
entities get a :cid (comment-id) and also they have the attributes :root_bid and :parent_cid
So every comment looks like:
{:cid 676767
:root_bid 5252
:parent_cid 676765
:contents "this is a comment"
:author "this#email.com"
:total-score 70
:number-of-votes 1 }
And that's basically everything I need to be able to store a comment.
So far so good, but now I want to recursively render comments, Fred comments on Jane's blurb, Jesus comments on Fred's comment, Josephine comments on Jesus' comment...
How can I recursively map comments using this datastructure?
I'm stumped so I appreciate any help.

Related

truncate text in django

I have a blog made by django. I want django to be able to read my post content and after django reaches to a specific word which I have already specified for Django, truncate the content.
for example this is a post content :
*Once upon a time, there lived a shepherd boy who was bored watching his flock of sheep on the hill. To amuse himself, he shouted, “Wolf! Wolf! The sheep are being chased by the wolf!” The villagers came running to help the boy and save the sheep. They found nothing and the boy just laughed looking at their angry faces.
[django_Truncate]
“Don’t cry ‘wolf’ when there’s no wolf boy!”, they said angrily and left. The boy just laughed at them.
After a while, he got bored and cried ‘wolf!’ again, fooling the villagers a second time. The angry villagers warned the boy a second time and left. The boy continued watching the flock. After a while, he saw a real wolf and cried loudly, “Wolf! Please help! The wolf is chasing the sheep. Help!”*
I want django to read it and when it reaches to [django_Truncate], truncate it.
so, the paragraph before [django_Truncate] will be displayed and the remainder will not be displayed.
is something like this possible?
You will have to create a custom template filter which takes the value and splits it on your desired string.
If you don't need to change the value to split on you can create it like this:
def split_on_string(value):
return value.split("[django_Truncate")[0]
And then you can use it like this:
{{ mytext|split_on_string }}
If you want the string to split on to be a dynamic value you can adapt this function to take an argument, as is explained at the linked page. The page also explains where to create the custom filter and how to make it usable in a template.

Comment Count API Facebook Restfb Java

I've been programming a lot with restfb, but I'm not able to do a counting of comments, only the comments without the answers, the image can better illustrate.enter image description here
Example post comment facebook
My code
Post post = clienteFacebook.fetchObject(idPostagem,
Post.class,
Parameter.with("fields", "comments.limit(0).summary(true)"),
Parameter.with("filter", "toplevel"));
System.out.println("Comments count: " + post.getCommentsCount());
Out code comments count
But I need to get only actual comments from the publication, in this example 57 comments.
In https://developers.facebook.com/docs/graph-api/reference/v3.2/object/comments I have some references of filter - toplevel but without success.
I also tested with Comment instead of Post but without success.
How can I get 57 posts in a post?
Please try the following code:
Post post = clienteFacebook.fetchObject(idPostagem,
Post.class,Parameter.with("fields", "comments.limit(0).summary(1).filter(toplevel)"));
System.out.println("Comments count: " + post.getCommentsCount());
As you can see the filter is part of the fields parameter. But the strange thing is, toplevel is the default filter if no filter is provided. So maybe it is something different.
Maybe you can get in touch with us (RestFB Team) directly, so we can help a bit more in depth ;)

parameter order for drag( ) in Raphael.js

The drag method in Raphael has three parameters : onmove, onstart , onend.
Most examples in books show examples in that order , like this
drag(onmove, instart, onend)
and then declare them in any order.
Some examples show the parameters in a different order like:
drag(onstart, onmove, onend)
I have't been able to make it work this 2nd way but there are too many examples in books and the web for me to dismiss as just wrong. But is it wrong?
The docs here say...
Element.drag(onmove, onstart, onend, [mcontext], [scontext], [econtext])
And looking in the code here it supports this.
I'm not sure where you've seen the 2nd form you mention, but it looks wrong, and not sure why 'any order' for parameters would make sense. Maybe if you post a link to those examples, it may give further context. But for your own code, I would follow the docs, and then if that doesn't work, post an example jsfiddle or similar of your code for people to look at.

ember.js: how do nested resources correspond to templates?

given this fiddle ( I couldn't make it work, i'm sorry and very frustrated): i don't understand why, when i ask for a book detail, ember is asking not asking my books/book, but my book template. Is that a feature or i'm doing anything wrong?
And, in addition, when i structure my files tree correctly, asking for book detail gives:
-at 1st try: OUTPU: OUTER
-at 2nd try: OUTPUT: Uncaught You can't call renderToBufferIfNeeded on a destroyed view
and i really can't understand why
thank you
First, of all, here is a working version of your fiddle with latest ember.js and ember-data: http://jsfiddle.net/va9gc/
The reason why ember is looking for book template instead of books/book is because you define book as a resource, not as a route. This is explained here: http://emberjs.com/guides/routing/defining-your-routes/#toc_nested-resources

How do I add comment lines to a business rule authored in Business Action Language

I am using JRules to author business rules. I want to add comments to the rules as shown in the very simple example below. I realise there is a documentation section for the rule but that is not what I require
// comments needed here
definitions
set 'an existing customer' to a customer
where the category of 'an existing customer' is "gold"
if
the city of 'an existing customer' is "London"
then
give a 5% discount to 'an existing customer'
else
// and more comments needed here
give a 10% discount to 'an existing customer'
Clearly, using the usual c++ and c# double forwardslash // will not work in the example above, so my question is how are comments added to rules in BAL.
Unfortunately you cannot add comments in rules. The rules are supposed to be self explanatory if the verbalization is good.
But you can use the documentation feature,if you want to document the business justification for each of the rules.
There is a simple workaround:
You can create 2 static virtual methods in your BOM: one commenting the conditions and one for the actions.
In the case of conditions:
Create a static method that takes a parameter String and return a boolean
Verbalize it like this "// {0}" (without quotes)
In the B2X, make it return true
Then, you can comment a condition with //"your_condition" and ...
In the previous example:
if
the city of 'an existing customer' is "London" and
// "blablabla" and
the age of 'an existing customer' is greater than 18
then ...
Since the method returns true, it won't affect the test. It has to be surrounded by "and", not "or".
In the case of actions:
Create a static method that takes a parameter String and return void
Verbalize it like this "// {0}" (without quotes)
In the B2X, add "return;"
Then, you can comment an action with //"your_action" ;
In the previous example:
else
// "and more comments needed here" ;
give a 10% discount to 'an existing customer' ;
You can do it but it means a hell lot of customization. So forget it
And it would be feasible only via browser interface, not Eclipse.
Just because you will be cheating.
How to do it:
Ready?... Steady?...
You need to recreate your own RTS (teamserver) web interface! if it sounds like too much effort then stop reading :)
Using the API, you can retrieve the rules from RTS (database) the there is (as mention in Tito's answer) a documentation attached to any rule.
So you can handle the display of your rule and add the comment accordingly.
Of course you need to find a way to position the comment correctly in the rule Line number could do the trick.
This is for the display...
Ten when you save the rule (by clicking a lovely button that you will have coded to do the actual saving) you need to remove the comments (and know where they are for the next time you want to display the rule) and save both the rule body and the documentation attached.
Sounds crazy? One client done it and I was working on this :) but we didn't modify the rule body. Almost everything but the rule body.
This will take you months, inpependently to the number of people working on it, I'm afraid.
To sum up: Can you do it, yes!
Does the implementation worth the effort? NO WAY!!!
Will this feature be available in the next version? NO! As Tito mentioned a rule should be self-explainatory.
Sorry :(