[ckan-dev] MS Access icon for the resources

Knud Möller knud at datalysator.com
Tue Apr 24 12:56:56 UTC 2018


Hi Alessandro,

I’m not sure if there maybe is an easier way, but here is how I thinks it
basically works. Note that you’ll have to write your own CKAN plugin [1] to
do it.

- When you add a new resource in CKAN, the string entered in the “Format”
field will later be used in the “data-format” attribute when this resource
is rendered e.g. in the /templates/package/snippets/resource_item.html
template:

<span class="format-label" property="dc:format" data-format="{{
res.format.lower() or 'data' }}”> … </span>

- This template renders e.g. like this for a particular resource from our
site:

<span class="format-label" property="dc:format"
data-format="gtfs">GTFS</span>

- Now you ‘only’ need a CSS rule that replaces the “GTFS” string with the
icon you want:

.format-label[data-format=gtfs] {
  background: url("/url/to/your/icon") no-repeat 0 0;
}

- The way this is handled for the standard icons included in CKAN core,
there is one image which contains all icons in /public/base/i
ages/sprite-resource-icons.png, and the rules for the different resource
formats just moves the background position. E.g.:

/* generic rule for all icons */
.format-label {
  background: url("../../../base/images/sprite-resource-icons.png")
no-repeat 0 0;
}

/* specific rule for a particular resource format */
.format-label[data-format=rdf] {
  background-position: -32px -62px;
}
.format-label[data-format=pdf] {
  background-position: -64px -62px;
}
.format-label[data-format=xls] {
  background-position: -160px -62px;
}

(I have shortened the rules, look in /public/base/css for the full versions)

Hope this helps!

Cheers,
Knud


[1] http://docs.ckan.org/en/ckan-2.7.3/extensions/index.html

On 23 April 2018 at 11:36:29, alessandro.dalla-benetta at ext.ec.europa.eu (
alessandro.dalla-benetta at ext.ec.europa.eu) wrote:

Hi all,
in the default ckan icon set for the resources is missing the file format
MS Access.
How it's possible to extend the icon set with this format in CKAN ?

Cheers,

Alessandro Dalla Benetta.
_______________________________________________
ckan-dev mailing list
ckan-dev at lists.okfn.org
https://lists.okfn.org/mailman/listinfo/ckan-dev
Unsubscribe: https://lists.okfn.org/mailman/options/ckan-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.okfn.org/pipermail/ckan-dev/attachments/20180424/15b71ec2/attachment-0003.html>


More information about the ckan-dev mailing list