|
1 import Ember from 'ember'; |
|
2 |
|
3 const CC_LICENCE_URL_REGEXP = /http:\/\/creativecommons\.org\/licenses\/([byndsac-]+)\/([\d\.]+)\//; |
|
4 const CC_LICENCE_TEXT = { |
|
5 'by': 'Attribution', |
|
6 'by-nd': 'Attribution - Pas de Modification', |
|
7 'by-sa': 'Attribution - Partage dans les Mêmes Conditions', |
|
8 'by-nc': 'Attribution - Pas d’Utilisation Commerciale', |
|
9 'by-nc-nd': 'Attribution - Pas d\'Utilisation Commerciale - Pas de Modification', |
|
10 'by-nc-sa': 'Attribution - Pas d\'Utilisation Commerciale - Partage dans les Mêmes Conditions' |
|
11 }; |
|
12 |
|
13 export default Ember.Component.extend({ |
|
14 tagName: 'span', |
|
15 code: Ember.computed('matches', function() { |
|
16 return this.get('matches')[1]; |
|
17 }), |
|
18 version: Ember.computed('matches', function() { |
|
19 return this.get('matches')[2]; |
|
20 }), |
|
21 matches: Ember.computed('url', function() { |
|
22 const url = this.get('url'); |
|
23 if(!url) { |
|
24 return [url,'by', '4.0']; |
|
25 } |
|
26 let m = url.match(CC_LICENCE_URL_REGEXP); |
|
27 if(m === null || m.length !== 3) { |
|
28 return [url,'by', '4.0']; |
|
29 } |
|
30 return m; |
|
31 }), |
|
32 text: Ember.computed('code', function() { |
|
33 const code = this.get('code'); |
|
34 return CC_LICENCE_TEXT[code]; |
|
35 }) |
|
36 |
|
37 }); |