creative_commons_rails 0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,252 @@
1
+ ---
2
+ es:
3
+ license_notice: Este obra está bajo una %{license_title}.
4
+ license_title: Licencia Creative Commons %{license_type}
5
+ license_type_by: Atribución %{version} %{jurisdiction}
6
+ license_type_by_sa: Atribución-CompartirIgual %{version} %{jurisdiction}
7
+ license_type_by_nd: Atribución-SinDerivadas %{version} %{jurisdiction}
8
+ license_type_by_nc: Atribución-NoComercial %{version} %{jurisdiction}
9
+ license_type_by_nc_sa: Atribución-NoComercial-CompartirIgual %{version} %{jurisdiction}
10
+ license_type_by_nc_nd: Atribución-NoComercial-SinDerivadas %{version} %{jurisdiction}
11
+ es_ES:
12
+ license_notice: Este obra está bajo una %{license_title}.
13
+ license_title: licencia de Creative Commons %{license_type}
14
+ license_type_by: Reconocimiento %{version} %{jurisdiction}
15
+ license_type_by_sa: Reconocimiento-CompartirIgual %{version} %{jurisdiction}
16
+ license_type_by_nd: Reconocimiento-SinObraDerivada %{version} %{jurisdiction}
17
+ license_type_by_nc: Reconocimiento-NoComercial %{version} %{jurisdiction}
18
+ license_type_by_nc_sa: Reconocimiento-NoComercial-CompartirIgual %{version} %{jurisdiction}
19
+ license_type_by_nc_nd: Reconocimiento-NoComercial-SinObraDerivada %{version} %{jurisdiction}
20
+ ca:
21
+ license_notice: Aquesta obra està subjecta a una llicència de %{license_title}
22
+ license_title: ! '%{license_type} de Creative Commons'
23
+ license_type_by: Reconeixement %{version} %{jurisdiction}
24
+ license_type_by_sa: Reconeixement-CompartirIgual %{version} %{jurisdiction}
25
+ license_type_by_nd: Reconeixement-SenseObraDerivada %{version} %{jurisdiction}
26
+ license_type_by_nc: Reconeixement-NoComercial %{version} %{jurisdiction}
27
+ license_type_by_nc_sa: Reconeixement-NoComercial-CompartirIgual %{version} %{jurisdiction}
28
+ license_type_by_nc_nd: Reconeixement-NoComercial-SenseObraDerivada %{version} %{jurisdiction}
29
+ de:
30
+ license_notice: Dieses Werk bzw. Inhalt steht unter einer %{license_title}.
31
+ license_title: Creative Commons %{license_type} Lizenz
32
+ license_type_by: Namensnennung %{version} %{jurisdiction}
33
+ license_type_by_sa: Namensnennung - Weitergabe unter gleichen Bedingungen %{version}
34
+ %{jurisdiction}
35
+ license_type_by_nd: Namensnennung-Keine Bearbeitung %{version} %{jurisdiction}
36
+ license_type_by_nc: Namensnennung-Nicht-kommerziell %{version} %{jurisdiction}
37
+ license_type_by_nc_sa: Namensnennung - Nicht-kommerziell - Weitergabe unter gleichen
38
+ Bedingungen %{version} %{jurisdiction}
39
+ license_type_by_nc_nd: Namensnennung-NichtKommerziell-KeineBearbeitung %{version}
40
+ %{jurisdiction}
41
+ en:
42
+ license_notice: This work is licensed under a %{license_title}.
43
+ license_title: Creative Commons %{license_type} License
44
+ license_type_by: Attribution %{version} %{jurisdiction}
45
+ license_type_by_sa: Attribution-ShareAlike %{version} %{jurisdiction}
46
+ license_type_by_nd: Attribution-NoDerivs %{version} %{jurisdiction}
47
+ license_type_by_nc: Attribution-NonCommercial %{version} %{jurisdiction}
48
+ license_type_by_nc_sa: Attribution-NonCommercial-ShareAlike %{version} %{jurisdiction}
49
+ license_type_by_nc_nd: Attribution-NonCommercial-NoDerivs %{version} %{jurisdiction}
50
+ eo:
51
+ license_notice: Ĉi tiu verko estas disponebla laŭ la permesilo %{license_title}.
52
+ license_title: Krea Komunaĵo %{license_type}
53
+ license_type_by: Atribuite %{version} %{jurisdiction}
54
+ license_type_by_sa: Atribuite-Samkondiĉe %{version} %{jurisdiction}
55
+ license_type_by_nd: Atribuite-Nemodifite %{version} %{jurisdiction}
56
+ license_type_by_nc: Atribuite-Nekomerce %{version} %{jurisdiction}
57
+ license_type_by_nc_sa: Atribuite-Nekomerce-Samkondiĉe %{version} %{jurisdiction}
58
+ license_type_by_nc_nd: Atribuite-Nekomerce-Nemodifite %{version} %{jurisdiction}
59
+ fr:
60
+ license_notice: Ce(tte) œuvre est mise à disposition selon les termes de la %{license_title}.
61
+ license_title: Licence Creative Commons %{license_type}
62
+ license_type_by: Attribution %{version} %{jurisdiction}
63
+ license_type_by_sa: Attribution - Partage dans les Mêmes Conditions %{version}
64
+ %{jurisdiction}
65
+ license_type_by_nd: Attribution - Pas de Modification %{version} %{jurisdiction}
66
+ license_type_by_nc: Attribution - Pas d’Utilisation Commerciale %{version} %{jurisdiction}
67
+ license_type_by_nc_sa: Attribution - Pas d’Utilisation Commerciale - Partage dans
68
+ les Mêmes Conditions %{version} %{jurisdiction}
69
+ license_type_by_nc_nd: Attribution - Pas d’Utilisation Commerciale - Pas de Modification
70
+ %{version} %{jurisdiction}
71
+ hr:
72
+ license_notice: Ovo djelo je dano na korištenje pod licencom %{license_title}.
73
+ license_title: Creative Commons %{license_type}
74
+ license_type_by: Imenovanje %{version} %{jurisdiction}
75
+ license_type_by_sa: Imenovanje-Dijeli pod istim uvjetima %{version} %{jurisdiction}
76
+ license_type_by_nd: Imenovanje-Bez prerada %{version} %{jurisdiction}
77
+ license_type_by_nc: Imenovanje-Nekomercijalno %{version} %{jurisdiction}
78
+ license_type_by_nc_sa: Imenovanje-Nekomercijalno-Dijeli pod istim uvjetima %{version}
79
+ %{jurisdiction}
80
+ license_type_by_nc_nd: Imenovanje-Nekomercijalno-Bez prerada %{version} %{jurisdiction}
81
+ id:
82
+ license_notice: ciptaan disebarluaskan di bawah %{license_title}.
83
+ license_title: Lisensi Creative Commons %{license_type}
84
+ license_type_by: Atribusi %{version} %{jurisdiction}
85
+ license_type_by_sa: Atribusi-BerbagiSerupa %{version} %{jurisdiction}
86
+ license_type_by_nd: Atribusi-TanpaTurunan %{version} %{jurisdiction}
87
+ license_type_by_nc: Attribusi-NonKomersial %{version} %{jurisdiction}
88
+ license_type_by_nc_sa: Atribusi-NonKomersial-BerbagiSerupa %{version} %{jurisdiction}
89
+ license_type_by_nc_nd: Atribusi-NonKomersial-TanpaTurunan %{version} %{jurisdiction}
90
+ it:
91
+ license_notice: Quest'opera è distribuita con Licenza %{license_title}.
92
+ license_title: Creative Commons %{license_type}
93
+ license_type_by: Attribuzione %{version} %{jurisdiction}
94
+ license_type_by_sa: Attribuzione - Condividi allo stesso modo %{version} %{jurisdiction}
95
+ license_type_by_nd: Attribuzione - Non opere derivate %{version} %{jurisdiction}
96
+ license_type_by_nc: Attribuzione - Non commerciale %{version} %{jurisdiction}
97
+ license_type_by_nc_sa: Attribuzione - Non commerciale - Condividi allo stesso modo
98
+ %{version} %{jurisdiction}
99
+ license_type_by_nc_nd: Attribuzione - Non commerciale - Non opere derivate %{version}
100
+ %{jurisdiction}
101
+ hu:
102
+ license_notice: Ez a Mű a %{license_title}.
103
+ license_title: Creative Commons %{license_type} Licenc feltételeinek megfelelően
104
+ szabadon felhasználható
105
+ license_type_by: Nevezd meg! %{version} %{jurisdiction}
106
+ license_type_by_sa: Nevezd meg! - Így add tovább! %{version} %{jurisdiction}
107
+ license_type_by_nd: Nevezd meg! - Ne változtasd! %{version} %{jurisdiction}
108
+ license_type_by_nc: Nevezd meg! - Ne add el! %{version} %{jurisdiction}
109
+ license_type_by_nc_sa: Nevezd meg! - Ne add el! - Így add tovább! %{version} %{jurisdiction}
110
+ license_type_by_nc_nd: Nevezd meg! - Ne add el! - Ne változtasd! %{version} %{jurisdiction}
111
+ nl:
112
+ license_notice: Dit werk is gelicenseerd onder een %{license_title}
113
+ license_title: Creative Commons %{license_type} licentie
114
+ license_type_by: Naamsvermelding %{version} %{jurisdiction}
115
+ license_type_by_sa: Naamsvermelding-GelijkDelen %{version} %{jurisdiction}
116
+ license_type_by_nd: Naamsvermelding-GeenAfgeleideWerken %{version} %{jurisdiction}
117
+ license_type_by_nc: Naamsvermelding-NietCommercieel %{version} %{jurisdiction}
118
+ license_type_by_nc_sa: Naamsvermelding-NietCommercieel-GelijkDelen %{version} %{jurisdiction}
119
+ license_type_by_nc_nd: Naamsvermelding-NietCommercieel-GeenAfgeleideWerken %{version}
120
+ %{jurisdiction}
121
+ "no":
122
+ license_notice: Dette verk er lisensieret under en %{license_title}.
123
+ license_title: Creative Commons %{license_type} lisens
124
+ license_type_by: Navngivelse %{version} %{jurisdiction}
125
+ license_type_by_sa: Navngivelse-DelPåSammeVilkår %{version} %{jurisdiction}
126
+ license_type_by_nd: Navngivelse-IngenBearbeidelse %{version} %{jurisdiction}
127
+ license_type_by_nc: Navngivelse-Ikkekommersiell %{version} %{jurisdiction}
128
+ license_type_by_nc_sa: Navngivelse-Ikkekommersiell-DelPåSammeVilkår %{version}
129
+ %{jurisdiction}
130
+ license_type_by_nc_nd: Navngivelse-Ikkekommersiell-IngenBearbeidelse %{version}
131
+ %{jurisdiction}
132
+ pl:
133
+ license_notice: Ten utwór jest dostępny na %{license_title}.
134
+ license_title: licencji Creative Commons %{license_type}
135
+ license_type_by: Uznanie autorstwa %{version} %{jurisdiction}
136
+ license_type_by_sa: Uznanie autorstwa-Na tych samych warunkach %{version} %{jurisdiction}
137
+ license_type_by_nd: Uznanie autorstwa-Bez utworów zależnych %{version} %{jurisdiction}
138
+ license_type_by_nc: Uznanie autorstwa-Użycie niekomercyjne %{version} %{jurisdiction}
139
+ license_type_by_nc_sa: Uznanie autorstwa-Użycie niekomercyjne-Na tych samych warunkach
140
+ %{version} %{jurisdiction}
141
+ license_type_by_nc_nd: Uznanie autorstwa-Użycie niekomercyjne-Bez utworów zależnych
142
+ %{version} %{jurisdiction}
143
+ pt:
144
+ license_notice: Este trabalho foi licenciado com uma Licença %{license_title}.
145
+ license_title: Creative Commons - %{license_type}
146
+ license_type_by: Atribuição %{version} %{jurisdiction}
147
+ license_type_by_sa: Atribuição-CompartilhaIgual %{version} %{jurisdiction}
148
+ license_type_by_nd: Atribuição-SemDerivados %{version} %{jurisdiction}
149
+ license_type_by_nc: Atribuição-NãoComercial %{version} %{jurisdiction}
150
+ license_type_by_nc_sa: Atribuição-NãoComercial-CompartilhaIgual %{version} %{jurisdiction}
151
+ license_type_by_nc_nd: Atribuição-NãoComercial-SemDerivados %{version} %{jurisdiction}
152
+ pt_BR:
153
+ license_notice: Este obra foi licenciado sob uma Licença %{license_title}.
154
+ license_title: Creative Commons %{license_type}
155
+ license_type_by: Atribuição %{version} %{jurisdiction}
156
+ license_type_by_sa: Atribuição-CompartilhaIgual %{version} %{jurisdiction}
157
+ license_type_by_nd: Atribuição-SemDerivados %{version} %{jurisdiction}
158
+ license_type_by_nc: Atribuição-NãoComercial %{version} %{jurisdiction}
159
+ license_type_by_nc_sa: Atribuição-NãoComercial-CompartilhaIgual %{version} %{jurisdiction}
160
+ license_type_by_nc_nd: Atribuição-NãoComercial-SemDerivados %{version} %{jurisdiction}
161
+ fi:
162
+ license_notice: Tämän teos teoksen käyttöoikeutta koskee %{license_title}.
163
+ license_title: Creative Commons %{license_type} -lisenssi
164
+ license_type_by: Nimeä %{version} %{jurisdiction}
165
+ license_type_by_sa: Nimeä-JaaSamoin %{version} %{jurisdiction}
166
+ license_type_by_nd: Nimeä-Ei muutoksia %{version} %{jurisdiction}
167
+ license_type_by_nc: Nimeä-Epäkaupallinen %{version} %{jurisdiction}
168
+ license_type_by_nc_sa: Nimeä-Epäkaupallinen-JaaSamoin %{version} %{jurisdiction}
169
+ license_type_by_nc_nd: Nimeä-Ei muutoksia-Epäkaupallinen %{version} %{jurisdiction}
170
+ sv:
171
+ license_notice: Detta verk är licensierat under en %{license_title}.
172
+ license_title: Creative Commons %{license_type} Licens
173
+ license_type_by: Erkännande %{version} %{jurisdiction}
174
+ license_type_by_sa: Erkännande-DelaLika %{version} %{jurisdiction}
175
+ license_type_by_nd: Erkännande-IngaBearbetningar %{version} %{jurisdiction}
176
+ license_type_by_nc: Erkännande-IckeKommersiell %{version} %{jurisdiction}
177
+ license_type_by_nc_sa: Erkännande-IckeKommersiell-DelaLika %{version} %{jurisdiction}
178
+ license_type_by_nc_nd: Erkännande-Ickekommersiell-IngaBearbetningar %{version}
179
+ %{jurisdiction}
180
+ is:
181
+ license_notice: Þetta verk er gefið út með %{license_title}.
182
+ license_title: Creative Commons %{license_type} afnotaleyfi
183
+ license_type_by: Vísun til höfundar %{version} %{jurisdiction}
184
+ license_type_by_sa: Tilvísun-DeilaEins %{version} %{jurisdiction}
185
+ license_type_by_nd: Tilvísun-EnginAfleidd %{version} %{jurisdiction}
186
+ license_type_by_nc: Tilvísun-EkkiÁgóðaskyni %{version} %{jurisdiction}
187
+ license_type_by_nc_sa: Tilvísun-EkkiÁgóðaskyni-DeilaEins %{version} %{jurisdiction}
188
+ license_type_by_nc_nd: Tilvísun-EkkiÁgóðaskyni-EnginAfleidd %{version} %{jurisdiction}
189
+ el:
190
+ license_notice: Αυτό το εργασία χορηγείται με άδεια %{license_title}.
191
+ license_title: ! 'Creative Commons %{license_type} '
192
+ license_type_by: Αναφορά Δημιουργού %{version} %{jurisdiction}
193
+ license_type_by_sa: Αναφορά Δημιουργού - Παρόμοια Διανομή %{version} %{jurisdiction}
194
+ license_type_by_nd: Αναφορά Δημιουργού-Όχι Παράγωγα Έργα %{version} %{jurisdiction}
195
+ license_type_by_nc: Αναφορά Δημιουργού-Μη Εμπορική Χρήση %{version} %{jurisdiction}
196
+ license_type_by_nc_sa: Αναφορά Δημιουργού - Μη Εμπορική Χρήση - Παρόμοια Διανομή
197
+ %{version} %{jurisdiction}
198
+ license_type_by_nc_nd: Αναφορά Δημιουργού-Μη Εμπορική Χρήση-Όχι Παράγωγα Έργα %{version}
199
+ %{jurisdiction}
200
+ ru:
201
+ license_notice: Это произведение доступно по %{license_title}.
202
+ license_title: лицензии Creative Commons %{license_type}
203
+ license_type_by: «Attribution» («Атрибуция») %{version} %{jurisdiction}
204
+ license_type_by_sa: «Attribution-ShareAlike» («Атрибуция — На тех же условиях»)
205
+ %{version} %{jurisdiction}
206
+ license_type_by_nd: «Attribution-NoDerivs» («Атрибуция — Без производных произведений»)
207
+ %{version} %{jurisdiction}
208
+ license_type_by_nc: «Attribution-NonCommercial» («Атрибуция — Некоммерческое использование»)
209
+ %{version} %{jurisdiction}
210
+ license_type_by_nc_sa: «Attribution-NonCommercial-ShareAlike» («Атрибуция — Некоммерческое
211
+ использование — На тех же условиях») %{version} %{jurisdiction}
212
+ license_type_by_nc_nd: «Attribution-NonCommercial-NoDerivs» («Атрибуция — Некоммерческое
213
+ использование — Без производных произведений») %{version} %{jurisdiction}
214
+ uk:
215
+ license_notice: Цей твір ліцензовано за %{license_title}.
216
+ license_title: ліцензією Creative Commons %{license_type}
217
+ license_type_by: Із зазначенням авторства %{version} %{jurisdiction}
218
+ license_type_by_sa: Із зазначенням автора - Розповсюдження на тих самих умовах
219
+ %{version} %{jurisdiction}
220
+ license_type_by_nd: Із зазначенням авторства - Без похідних творів %{version} %{jurisdiction}
221
+ license_type_by_nc: Із зазначенням авторства - Некомерційна %{version} %{jurisdiction}
222
+ license_type_by_nc_sa: Із зазначенням авторства - Некомерційна - Розповсюдження
223
+ на тих самих умовах %{version} %{jurisdiction}
224
+ license_type_by_nc_nd: Із зазначенням авторства - Некомерційна - Без похідних творів
225
+ %{version} %{jurisdiction}
226
+ zh:
227
+ license_notice: 本作品采用%{license_title}进行许可。
228
+ license_title: 知识共享%{license_type}许可协议
229
+ license_type_by: 署名 %{version} %{jurisdiction}
230
+ license_type_by_sa: 署名-相同方式共享 %{version} %{jurisdiction}
231
+ license_type_by_nd: 署名-禁止演绎 %{version} %{jurisdiction}
232
+ license_type_by_nc: 署名-非商业性使用 %{version} %{jurisdiction}
233
+ license_type_by_nc_sa: 署名-非商业性使用-相同方式共享 %{version} %{jurisdiction}
234
+ license_type_by_nc_nd: 署名-非商业性使用-禁止演绎 %{version} %{jurisdiction}
235
+ zh_TW:
236
+ license_notice: 本著作係採用%{license_title}授權.
237
+ license_title: 創用 CC %{license_type} 授權條款
238
+ license_type_by: 姓名標示 %{version} %{jurisdiction}
239
+ license_type_by_sa: 姓名標示-相同方式分享 %{version} %{jurisdiction}
240
+ license_type_by_nd: 姓名標示-禁止改作 %{version} %{jurisdiction}
241
+ license_type_by_nc: 姓名標示-非商業性 %{version} %{jurisdiction}
242
+ license_type_by_nc_sa: 姓名標示-非商業性-相同方式分享 %{version} %{jurisdiction}
243
+ license_type_by_nc_nd: 姓名標示-非商業性-禁止改作 %{version} %{jurisdiction}
244
+ ko:
245
+ license_notice: 이 저작물은 %{license_title}에 따라 이용할 수 있습니다.
246
+ license_title: 크리에이티브 커먼즈 %{license_type} 라이선스
247
+ license_type_by: 저작자표시 %{version} %{jurisdiction}
248
+ license_type_by_sa: 저작자표시-동일조건변경허락 %{version} %{jurisdiction}
249
+ license_type_by_nd: 저작자표시-변경금지 %{version} %{jurisdiction}
250
+ license_type_by_nc: 저작자표시-비영리 %{version} %{jurisdiction}
251
+ license_type_by_nc_sa: 저작자표시-비영리-동일조건변경허락 %{version} %{jurisdiction}
252
+ license_type_by_nc_nd: 저작자표시-비영리-변경금지 %{version} %{jurisdiction}
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'creative_commons_rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "creative_commons_rails"
8
+ spec.version = CreativeCommonsRails::VERSION
9
+ spec.authors = ["Kent Mewhort"]
10
+ spec.email = ["kent@openissues.ca"]
11
+ spec.description = %q{Render internationalized Creative Commons license notices in your views}
12
+ spec.summary = %q{Easy rendering of Creative Commons license notices}
13
+ spec.homepage = "http://github.com/kmewhort/creative_commons_rails"
14
+ spec.license = "BSD"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "mechanize"
24
+ spec.add_runtime_dependency "rails"
25
+ spec.add_runtime_dependency "i18n"
26
+ end
@@ -0,0 +1,7 @@
1
+ require "creative_commons_rails/version"
2
+ require "creative_commons_rails/license_info"
3
+ require "creative_commons_rails/action_view_helpers"
4
+ require "creative_commons_rails/railtie"
5
+
6
+ module CreativeCommonsRails
7
+ end
@@ -0,0 +1,35 @@
1
+ require 'i18n'
2
+
3
+ module CreativeCommonsRails
4
+ module ActionViewHelpers
5
+
6
+ # generates an image/link to the desired CC license
7
+ def cc_license_tags(type, options = {})
8
+ # merge options with defaults and convert to correct data types
9
+ options = default_options.merge(options)
10
+ options[:version] = "%.1f" % options[:version]
11
+ options[:jurisdiction] = options[:jurisdiction].to_sym
12
+ options[:size] = options[:size].to_sym
13
+
14
+ # get license data (exception raised if not found)
15
+ l = LicenseInfo.find({type: type}.merge(options))
16
+
17
+ html = ""
18
+ html << link_to(l.deed_url, rel: 'license') do
19
+ image_tag(l.icon_url(options[:size]), alt: l.translated_title, style: "border-width:0")
20
+ end
21
+ html << "<br />"
22
+ html << I18n.t(:license_notice, license_title: link_to(l.translated_title, l.deed_url, rel: 'license'))
23
+ html.html_safe
24
+ end
25
+
26
+ private
27
+ def default_options
28
+ {
29
+ version: '3.0',
30
+ jurisdiction: :unported,
31
+ size: :normal
32
+ }
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,49 @@
1
+ require 'i18n'
2
+
3
+ module CreativeCommonsRails
4
+ class LicenseInfo
5
+ attr_accessor :type, :jurisdiction, :version
6
+
7
+ # ensure the license exists in the license index
8
+ def self.find(attributes = {})
9
+ index = license_index
10
+ [:jurisdiction, :version, :type].each do |key|
11
+ raise "You must specify the #{attr} to find a licence" if attributes[key].nil?
12
+ index = index[attributes[key].to_s]
13
+ raise "Unknown license #{key}: #{attributes[key]}" if index.nil? || !index
14
+ end
15
+
16
+ LicenseInfo.new(attributes[:type],attributes[:jurisdiction],attributes[:version])
17
+ end
18
+
19
+ def initialize(type, jurisdiction, version)
20
+ @type, @jurisdiction, @version = type, jurisdiction, version
21
+ end
22
+
23
+ def deed_url
24
+ "http://creativecommons.org/licenses/#{type}/#{version}/#{jurisdiction}/deed.#{language}"
25
+ end
26
+
27
+ def icon_url(size = :normal)
28
+ "http://i.creativecommons.org/l/#{type}/#{version}/#{size == :compact ? '80x15' : '88x31'}.png"
29
+ end
30
+
31
+ def translated_title
32
+ I18n.t :license_title, license_type: translated_type
33
+ end
34
+
35
+ def translated_type
36
+ I18n.t "license_type_#{type}", version: version, jurisdiction: I18n.t(jurisdiction)
37
+ end
38
+
39
+ def language
40
+ I18n.locale
41
+ end
42
+
43
+ private
44
+ def self.license_index
45
+ gem_root = Gem::Specification.find_by_name("creative_commons_rails").gem_dir
46
+ @index ||= YAML.load_file("#{gem_root}/config/license_list.yaml")
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,14 @@
1
+ module CreativeCommonsRails
2
+ class Railtie < Rails::Railtie
3
+ # load the action view helpers and i18n dictionary files
4
+ initializer "creative_commons_rails" do
5
+ ActionView::Base.send :include, CreativeCommonsRails::ActionViewHelpers
6
+ I18n.load_path += Dir.glob( File.dirname(__FILE__) + "/../../config/locales/*.{rb,yml}" )
7
+ end
8
+
9
+ # load the rake task to re-retrieve the data on available licenses
10
+ rake_tasks do
11
+ load File.join(File.dirname(__FILE__),'tasks/retrieve_data.rake')
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ module CreativeCommonsRails
2
+ VERSION = "0.9"
3
+ end
@@ -0,0 +1,122 @@
1
+ namespace :cc_retrieve_data do
2
+ desc 'Populate license_list.yaml with an index of all available CC licenses by jurisdiction'
3
+ task :license_index do |t, args|
4
+ require 'mechanize'
5
+ require 'yaml'
6
+ require 'open-uri'
7
+
8
+ # pull the list of jurisdictions from the CC license chooser page
9
+ agent = Mechanize.new { |a| a.user_agent_alias = 'Mac Safari' }
10
+ jurisdictions = agent.get('http://creativecommons.org/choose/').search('#field_jurisdiction option').map do |o|
11
+ o['value']
12
+ end.compact
13
+
14
+ # ping for the deed page of each possible combination of jurisdiction, version and type
15
+ license_index = {}
16
+ jurisdictions.each do |jurisdiction|
17
+ license_index[jurisdiction] = {}
18
+ ["1.0","2.0","2.5","3.0","4.0"].each do |version|
19
+ license_index[jurisdiction][version] = {}
20
+ [:by,:by_sa,:by_nd,:by_nc,:by_nc_sa,:by_nc_nd].each do |type|
21
+ deed_url = "http://creativecommons.org/licenses/#{type.to_s.gsub('_','-')}/#{version}/#{jurisdiction}"
22
+ license_index[jurisdiction][version][type] = false
23
+ begin
24
+ ping_result = open(deed_url)
25
+ if ping_result.status[0] == "200"
26
+ license_index[jurisdiction][version][type.to_s] = true
27
+ end
28
+ rescue OpenURI::HTTPError => ex
29
+ # not found
30
+ end
31
+ sleep(1) # rate limit to avoid hammering creativecommons.org
32
+ end
33
+ end
34
+ end
35
+ license_index['unported'] = license_index[""]
36
+ license_index.delete("")
37
+
38
+ File.open('config/license_list.yaml', 'w') {|f| YAML::dump(license_index, f) }
39
+ end
40
+
41
+ desc 'Populate I18n localizations with translations from the CC License Chooser'
42
+ task :localization do |t, args|
43
+ require 'mechanize'
44
+ require 'yaml'
45
+ require 'open-uri'
46
+ require 'json'
47
+
48
+ notice_localization = {}
49
+ jurisdiction_localization = {}
50
+ agent = Mechanize.new { |a| a.user_agent_alias = 'Mac Safari' }
51
+
52
+ # for each available language
53
+ agent.get('http://creativecommons.org/choose/').search('#other_stuff .licensebox a').each do |a|
54
+ chooser_page = agent.get(a['href'])
55
+ lang = a['hreflang'].to_sym
56
+
57
+ # for each license type
58
+ [:by,:by_sa,:by_nd,:by_nc,:by_nc_sa,:by_nc_nd].each_with_index do |type, i|
59
+ # get the license notice info directly from the License Chooser API
60
+ uri = URI.parse('http://creativecommons.org/choose/xhr_api')
61
+ params = case type
62
+ when :by
63
+ {
64
+ "field_commercial" => 'y',
65
+ "field_derivatives" => 'y'
66
+ }
67
+ when :by_sa
68
+ {
69
+ "field_commercial" => 'y',
70
+ "field_derivatives" => 'sa'
71
+ }
72
+ when :by_nd
73
+ {
74
+ "field_commercial" => 'y',
75
+ "field_derivatives" => 'n'
76
+ }
77
+ when :by_nc
78
+ {
79
+ "field_commercial" => 'n',
80
+ "field_derivatives" => 'y'
81
+ }
82
+ when :by_nc_sa
83
+ {
84
+ "field_commercial" => 'n',
85
+ "field_derivatives" => 'sa'
86
+ }
87
+ when :by_nc_nd
88
+ {
89
+ "field_commercial" => 'n',
90
+ "field_derivatives" => 'n'
91
+ }
92
+ end
93
+
94
+ params["lang"] = lang
95
+ uri.query = URI.encode_www_form( params )
96
+ result = JSON.parse(uri.open.read)
97
+
98
+ if i == 0
99
+ html = Nokogiri::HTML(result['license_html'])
100
+ title = html.css('a:last-child').text
101
+ notice_localization[lang.to_s] = {
102
+ 'license_notice' => html.text.sub(title, "\%\{license_title\}"),
103
+ 'license_title' => title.sub(result['license_title'], "\%\{license_type\}"),
104
+ }
105
+ end
106
+ notice_localization[lang.to_s]["license_type_#{type.to_s}"] =
107
+ result['license_title'].sub(/3\.0.*/, "\%\{version\} \%\{jurisdiction\}")
108
+
109
+ sleep(1) # rate limit to avoid hammering creativecommons.org
110
+ end
111
+
112
+ # get the translations of jurisdiction names (eg. "Canada", "United States", etc.)
113
+ jurisdiction_localization[lang.to_s] = {}
114
+ chooser_page.search('#field_jurisdiction option').each do |o|
115
+ jurisdiction_key = o['value'].empty? ? 'unported' : o['value']
116
+ jurisdiction_localization[lang.to_s][jurisdiction_key.to_s] = o.text.strip
117
+ end
118
+ end
119
+ File.open('config/locales/cc_license_notices.yml', 'w') {|f| YAML.dump(notice_localization,f) }
120
+ File.open('config/locales/cc_license_jurisdictions.yml', 'w') {|f| YAML.dump(jurisdiction_localization,f) }
121
+ end
122
+ end