Grails 3 with Fields plugin - show fields like numbers and dates in certain format - grails-3.0.9

A Book domain object has a publicationYear field. In the show view it shows as 2,011 or 1,999 or whatever. It should display as 2011. It used to be a simple g:fomatNumber to get things right.
According to the Fields documentation at http://grails-fields-plugin.github.io/grails-fields/guide/customizingFieldRendering.html one should create a directory grails-app/views/controllerName/actionName/propertyName/ and put a _wrapper.gsp template in it. They don't say what should be in that file. I've tried various things and it looks as if it is just ignored. The year is still 2,013 or whatever.
This will mainly be needed to display dates in various ways - mostly day or minute precision. In this case I want to get rid of the comma.
Any idea how to do this? I'm using Grails 3.0.9 and Scaffolding 3.1.3 because anything newer does not install templates and if one hand installs them, ignores them.

If I understood you correctly the publicationYear property is of type Date?
In this case you can use the tag
g:formatDate
to display it.
So if you only need the year:
g:formatDate format="yyyy" date="${publicationYear}"
See: Grails 3.0.9 formatDate Hope it helps

Related

Use category name in Sitefinity blog URL

I followed the instructions here on establishing a new provider and generating custom URLs, and it works as expected. There doesn't seem to be a clear reference for what parameters can be utilized in the settings as the example given is very basic.
I want to use the category name of the post in the URL. I tried:
/[Category]/[UrlName]
but what I got in the frontend was:
http://localhost:60327/my-page/Telerik.OpenAccess.TrackedList%601[System.Guid]/my-post-name
I also tried
/[Category.Title]/[UrlName]
which just threw errors.
Anyone know how to do this, or better yet, a good reference for the parameters?
I don't think this is possible since the Category property is actually a collection (TrackedList).
In theory you would need one of the collection items, let's say the first one, and your URL expression would be /[Category[0].Title]/[UrlName], but this is currently not supported by the expression parser.
Also, the idea of making the URL dependent on a complex (related) field is not a good idea. If someone deletes that category, they will break all your blog post URLs.
I would suggest you to create a custom text field for the blog post item (ex: CategoryUrl) and then you should be able to set the URL format to /[CategoryUrl]/[UrlName]. Make sure CategoryUrl field is required.

How to add custom field type on KeystoneJS 0.4?

I'm currently building an app for TV/Radio program guide and schedule using keystonejs. I need time input field (hour and minute) for it to work. By default keystonejs doesn't give me an option of time field. Only Date and Datetime are available, none of which are suitable for my use case. Keystonejs documentation doesn't really do the job for >0.4. Although, I can spare its sparse documentation since it's still in beta phase
How to create a new Field type which is usable in production app on keystonejs 0.4.3-beta without directly modifying keystonejs node_modules package?
The one that I found on keystonejs wiki (credit card field type), is to create custom field for development only. And it doesn't even translate to admin UI.
Is it possible to add plugin (such as npm clock-input) to use it as field input on keystonejs admin UI?
I'm still thinking of the best way to integrate schedule system in keystonejs admin UI. For now, I'm thinking of creating a List which contains program name, description, days of the week, and time. In this case, some TV program are supposed to be able to have multiple days, and on specific days of the week it has different time (for example: program A being aired from Monday-Thursday on 4PM, and Friday on 7PM).
I think the way I'm currently planning to implement on is a bit messy. Any suggestion of the good way to do this?
note:
I figure #1 out, although I'm still learning on how it actually works.
I ended up using keystone-custom-fieldtypes npm packages to export my custom input field to keystonejs module without manually touching the file (I use igorrafael fork which works for keystonejs >0.4. Since the original package only works for keystonejs 0.3). You can find it here : https://github.com/igorrafael/keystone-custom-fieldtypes.
I managed to duplicate one of the default field type. So currently I have my custom field type boilerplate. Still need to modify a lot of things though.

How to batch rename Tumblr tags?

I have tagged over 700 blog posts with tags containing hyphens, and these tags suddenly stopped working in 2011, because Tumblr decided (without any notice) to forbid hyphens in tags (I guess hyphens are blocked now, because spaces in tags (which are allowed) get changed to hyphens.). Unfortunately, Tumblr is not willing to globally rename all tags containg hyphens (although these tags are of no use anymore → 404).
Now I want to rename my tags myself.
I tried to do it with the "Mass Post Editor" (tumblr.com/mega-editor), but it's not possible to select posts by tag. I'd have to manually select post after post and look if a certain tag was used, and if so, delete it and add a new one instead. This would be a huge job (700 tagged posts, but more than 1000 in total).
So I thought that the Tumblr API might help me. I'm no programmer, but I'd be willing to dig into it, if I could get some help here as a starting point.
I think I need the following process:
select all posts that are tagged with x (= a tag containing hyphens)
tag all these posts with y (= a tag without hyphens)
delete the tag x on all these posts
I'd start this process for every affected tag manually.
I see that the method (or whatever you call it) /post knows the request parameter tag:
Limits the response to posts with the specified tag
(I guess I can only hope that this works for tags containing hyphens, too.)
After that I'd need a way to add and remove tags from that result set. /post/edit doesn't say anything about tags. Did I miss something? Isn't it possible to add/remove tags with the API?
Have you an idea how I could "easily" rename my tags?
Is it possible with the API? Could you give me a starting point, tip etc. how I could manage to do it?
I don't know if this might be helpful, but I noticed that the search function is still able to find posts "tagged" with tags that contain hyphens.
Example: let's say I have the tag foo-bar. It is linked with /tagged/foo-bar (→ 404). I can find the posts with /search/foo-bar (but this is of course not ideal because it might also find posts that contain (in the body text) words similar/equal to the tag name).
I tried to encode the hyphen (/tagged/foo%2Dbar), but no luck.
just for the record, because this is a popular google search: i've done it! you can use it at http://dev.goose.im/tags/.
i used a combo of PHP and jquery, basing my jquery off of a previous tumblr api script i wrote a year or two ago, and used this tumblr php oauth script for the authentication. if anyone wants me to put up the source code, i'd be happy to.
If you aren't a programmer, how much is your time is worth to you? As they say, time is money. Not only do you have to figure out how to use the API, but choose a language and learn to write in it. That's no small task. You could higher a freelancer for $50 for an hour worth of work.
To answer your question, yes it is possible to do this with the API. It mentions "These parameters are used for /post, /post/edit and /post/reblog methods." and tags is mentioned as a string of comma separated words.
What you want to do is get a listing of every single blog post using the /posts method. You'll want to look at the "Request" section to figure out the criteria to pass to this URL. You want it to be as general as possible to get a complete listing of all your posts.
After you get a listing of posts you'll want to iterate over it and modify the tags parameter provided in the response for each post. You'll want to use the id paramater along with /post/edit, which again takes tags as a string.
The simplest language you can use for this task is PHP. You'll want to look at the curl extension to make your requests. You'll want to read up on arrays as you'll be using them a lot. You'll also need to look at explode, implode, str_replace (for the dashes), and foreach for iterating over the result.
When you do this I would highly recommend you use break at the end of your foreach loop so it only affects one post at first. Testing it first will be important, as you don't want to accidentally erase your tags/posts. print and var_dump are good ways to help you debug the code. xdebug is a nice extension that allows you to step through the code line by line as it runs. Netbeans is an IDE that has good xdebug support.
There's also a nice page here to get you started with PHP. You'll need to install PHP on your machine. You don't need to install a web server - for this PHP-CLI (command line) sapi is good enough.

Flickr API - Photos Search, excluding tags: Am I doing this wrong?

So, I'm trying to pull all photos of a specific user's account via the flickr.photos.search method, but I want to exclude photos with a particular tag. The related documentation page states that "You can exclude results that match a term by prepending it with a - character." ... Well, I tried implementing that option but what get in return is only one photo (even though there are several photos with the tag in question) and that result remains the same whether that specific photo has the tag in question or not AND whether or not I use the "-" option to exclude that tag rather than include it. I also tried the text method with the same exact result. Here's my REST call:
http://api.flickr.com/services/rest/?&method=flickr.photos.search&api_key='.$api_key.'&user_id='.$user_id.'&tag_mode=any&tags=-blog&extras=url_o,url_t&format=json
And here is the page where I'm trying to get this all working:
http://corazonbrew.com/temp/
Anyone know what is going on here?
It seems the answer in the Flickr discussion board I linked to earlier is proving true. In order to use the exclusion option, there has to also be at least one other, non-excluded tag. Well, that is just not good enough for me.
A couple of friends tell me this is a longstanding bug that will not be fixed anytime soon, if ever. But those friends also kindly reminded me of my n00bishness- this whole time I thought I needed to affect the feed to get the desired output. I totally was not realizing I could just use some good ol' PHP if statements to weed out what I don't want.

Jalopy to format return/throw statements

I would like Jalopy to format my return and throw statements such that they look like a method call since they are:
return(true);
throw(new IllegalArgumentException("You can't do that, what we you thinking?"));
I have the rest of the code formatted exactly the way I want so this is the icing on the cake.
Also as an aside, I work on a project with a few team members and each have our own preference for looking at code, has anyone setup Jalopy in conjuction with a successful build as well as checkout?
So, when I checkout code, it gets formatted to my liking, and then each time I get a successful build, it gets formatted according to the Java/Sun Standard and then checked in?
Walter
I would like Jalopy to format my return and throw statements such that they look like a method call
I didn't find anything about this in Jalopy's Manual and think this would require extending Jalopy.
(...) when I checkout code, it gets formatted to my liking, and then each time I get a successful build, it gets formatted according to the Java/Sun Standard and then checked in?
If you are using subversion, maybe you could use a client-side hook on checkout and a pre-commit hook on commit.
The commercial Jalopy supports this.
Here are the links for the corresponding user's guide sections:
Insert throws parentheses