View Single Post
Old 05-02-2016, 08:03 AM   #1117
davidfor
Grand Sorcerer
davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.
 
Posts: 24,907
Karma: 47303748
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
Quote:
Originally Posted by oren64 View Post
The rating shows in numeral (1,2,3...) in template for the comments, and not like here that the stars is show.

Code:
{pubdate:|<p>Published: |</p>}{rating:|<p>Rating: |</p>}{#pages:|<p>Pages count: |} \ {#words:|Word count: |</p>}{tags:|<p>Tags: |</p>}<hr/>{comments}
FW 3.13.1
That image was produced using the "jacket" style template. That was the only choice with the initial beta of this. The disadvantage of this style was that it is harder to not show anything with no values. This will still work with the latest version, but you need to prefix the template with "jacket:".

With the "plugboard" style template, there doesn't seem to be a way to display the stars directly. I had to write a template function to do it. My template is:

Code:
{comments}{tags:|<p>Tags: |</p>}{rating:rating_as_stars()|<p>Rating: |</p>}{#kobo_last_read:|<p>Last Read: |</p>}{#words:|<p>Word count: |</p>}
The "rating_as_stars()" is defined in the "Template Functions" screen of calibre. On this, you define:

Function: rating_as_stars
Arg count: 1
Documentation: rating_as_stars(x) -- returns x number of stars.
And the code:
Code:
def evaluate(self, formatter, kwargs, mi, locals, r):
	try:
		x = int(r) * '★'
	except:
		x = ''
	return x
And alternative version of this is:

Documentation: rating_as_stars(r) -- returns r number of filled stars followed by 5-r empty stars.
And the code:
Code:
def evaluate(self, formatter, kwargs, mi, locals, r):
	if r:
		try:
			i = int(r)			
		except:
			i = 0
		x = i * unichr(9733) + (5-i) * unichr(9734)
	else:
		x = ''
	return x

I haven't been able to decide which of these I like better.
davidfor is offline   Reply With Quote