[openstreetmap-website] Link prefixed Wikidata-tags to wikidata.org (#788)

Tom Hughes notifications at github.com
Thu Jul 24 21:18:51 UTC 2014


> @@ -61,8 +61,17 @@ def format_key(key)
>    def format_value(key, value)
>      if wp = wikipedia_link(key, value)
>        link_to h(wp[:title]), wp[:url], :title => t('browse.tag_details.wikipedia_link', :page => wp[:title])
> -    elsif wdt = wikidata_link(key, value)
> -      link_to h(wdt[:title]), wdt[:url], :title => t('browse.tag_details.wikidata_link', :page => wdt[:title])
> +    elsif wdt = wikidata_links(key, value)
> +      # IMPORTANT: Note that wikidata_links() returns an array of hashes, unlike for example wikipedia_link(),
> +      # which just returns one such hash.
> +      # Thus we have to iterate over it here.
> +      result = ''
> +      for item in wdt
> +        # adding a link to the result-string
> +        result += ';'+link_to(item[:title], item[:url], :title => t('browse.tag_details.wikidata_link', :page => item[:title].strip))
> +      end

I suspect it would make more sense to use `map` to build links and then `join` to merge them into a single string. It would also avoid the need to then remove the extra semicolon.

---
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/788/files#r15373581
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20140724/1a9e2d42/attachment-0001.html>


More information about the rails-dev mailing list