cytoplasm 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. data/app/assets/javascripts/cytoplasm/cytoplasm.js.erb +13 -6
  2. data/app/controllers/cytoplasm/fonts_controller.rb +310 -85
  3. data/app/views/cytoplasm/fonts/_font_li.html.erb +23 -0
  4. data/app/views/cytoplasm/fonts/index.html.erb +79 -18
  5. data/config/routes.rb +2 -0
  6. data/lib/cytoplasm.rb +23 -0
  7. data/lib/cytoplasm/version.rb +1 -1
  8. data/test/dummy/Gemfile.lock +6 -2
  9. data/test/dummy/app/views/docs/index.html.erb +1 -2
  10. data/test/dummy/app/views/home/index.html.erb +1 -1
  11. data/test/dummy/log/development.log +203643 -0
  12. data/test/dummy/public/fonts/1942-report/1942-webfont.eot +0 -0
  13. data/test/dummy/public/fonts/1942-report/1942-webfont.svg +153 -0
  14. data/test/dummy/public/fonts/1942-report/1942-webfont.ttf +0 -0
  15. data/test/dummy/public/fonts/1942-report/1942-webfont.woff +0 -0
  16. data/test/dummy/public/fonts/1942-report/Freeware License.txt +5 -0
  17. data/test/dummy/public/fonts/1942-report/demo.html +33 -0
  18. data/test/dummy/public/fonts/1942-report/stylesheet.css +16 -0
  19. data/test/dummy/public/fonts/20-db/20db-webfont.eot +0 -0
  20. data/test/dummy/public/fonts/20-db/20db-webfont.svg +174 -0
  21. data/test/dummy/public/fonts/20-db/20db-webfont.ttf +0 -0
  22. data/test/dummy/public/fonts/20-db/20db-webfont.woff +0 -0
  23. data/test/dummy/public/fonts/20-db/Jovanny Lemonad Freeware License.txt +7 -0
  24. data/test/dummy/public/fonts/20-db/demo.html +33 -0
  25. data/test/dummy/public/fonts/20-db/stylesheet.css +16 -0
  26. data/test/dummy/public/fonts/Aaargh/Aaargh-webfont.eot +0 -0
  27. data/test/dummy/public/fonts/Aaargh/Aaargh-webfont.svg +191 -0
  28. data/test/dummy/public/fonts/Aaargh/Aaargh-webfont.ttf +0 -0
  29. data/test/dummy/public/fonts/Aaargh/Aaargh-webfont.woff +0 -0
  30. data/test/dummy/public/fonts/Aaargh/Tup Wanders Font License.txt +9 -0
  31. data/test/dummy/public/fonts/Aaargh/demo.html +33 -0
  32. data/test/dummy/public/fonts/Aaargh/stylesheet.css +31 -0
  33. data/test/dummy/public/fonts/TitilliumText/SIL Open Font License 1.1.txt +91 -0
  34. data/test/dummy/public/fonts/TitilliumText/TitilliumText25L-webfont.eot +0 -0
  35. data/test/dummy/public/fonts/TitilliumText/TitilliumText25L-webfont.svg +247 -0
  36. data/test/dummy/public/fonts/TitilliumText/TitilliumText25L-webfont.ttf +0 -0
  37. data/test/dummy/public/fonts/TitilliumText/TitilliumText25L-webfont.woff +0 -0
  38. data/test/dummy/public/fonts/TitilliumText/TitilliumText25L001-webfont.eot +0 -0
  39. data/test/dummy/public/fonts/TitilliumText/TitilliumText25L001-webfont.svg +247 -0
  40. data/test/dummy/public/fonts/TitilliumText/TitilliumText25L001-webfont.ttf +0 -0
  41. data/test/dummy/public/fonts/TitilliumText/TitilliumText25L001-webfont.woff +0 -0
  42. data/test/dummy/public/fonts/TitilliumText/TitilliumText25L002-webfont.eot +0 -0
  43. data/test/dummy/public/fonts/TitilliumText/TitilliumText25L002-webfont.svg +247 -0
  44. data/test/dummy/public/fonts/TitilliumText/TitilliumText25L002-webfont.ttf +0 -0
  45. data/test/dummy/public/fonts/TitilliumText/TitilliumText25L002-webfont.woff +0 -0
  46. data/test/dummy/public/fonts/TitilliumText/TitilliumText25L003-webfont.eot +0 -0
  47. data/test/dummy/public/fonts/TitilliumText/TitilliumText25L003-webfont.svg +247 -0
  48. data/test/dummy/public/fonts/TitilliumText/TitilliumText25L003-webfont.ttf +0 -0
  49. data/test/dummy/public/fonts/TitilliumText/TitilliumText25L003-webfont.woff +0 -0
  50. data/test/dummy/public/fonts/TitilliumText/TitilliumText25L004-webfont.eot +0 -0
  51. data/test/dummy/public/fonts/TitilliumText/TitilliumText25L004-webfont.svg +247 -0
  52. data/test/dummy/public/fonts/TitilliumText/TitilliumText25L004-webfont.ttf +0 -0
  53. data/test/dummy/public/fonts/TitilliumText/TitilliumText25L004-webfont.woff +0 -0
  54. data/test/dummy/public/fonts/TitilliumText/TitilliumText25L005-webfont.eot +0 -0
  55. data/test/dummy/public/fonts/TitilliumText/TitilliumText25L005-webfont.svg +247 -0
  56. data/test/dummy/public/fonts/TitilliumText/TitilliumText25L005-webfont.ttf +0 -0
  57. data/test/dummy/public/fonts/TitilliumText/TitilliumText25L005-webfont.woff +0 -0
  58. data/test/dummy/public/fonts/TitilliumText/demo.html +58 -0
  59. data/test/dummy/public/fonts/TitilliumText/stylesheet.css +76 -0
  60. data/test/dummy/public/fonts/enabled.yml +7 -0
  61. data/test/dummy/public/fonts/googlewebfonts.yml +2 -2
  62. data/test/dummy/tmp/cache/assets/D03/6B0/sprockets%2Fd3cfc780201b87a3439e35c5236bb71a +0 -0
  63. data/test/dummy/tmp/cache/assets/D0E/7D0/sprockets%2F89200785fe2710582a6c1b8d04ae7fbe +0 -0
  64. data/test/dummy/tmp/cache/assets/D14/170/sprockets%2F40a7b83bb067eea7ce2c8394e1529287 +0 -0
  65. data/test/dummy/tmp/pids/server.pid +1 -0
  66. metadata +105 -4
@@ -17,9 +17,9 @@ var Cytoplasm;
17
17
  var $this = $('#'+v+'_message');
18
18
  if (!$this.is('*')) {
19
19
  $this = $('<p />').addClass('callback_message').attr("id",v+"_message");
20
- if (header.children(':first-child').is('h1')) $this.insertAfter(header.children(':first-child'));
21
- else $this.prependTo(header);
22
- $this.hide();
20
+ //if (header.children(':first-child').is('h1')) $this.insertAfter(header.children(':first-child'));
21
+ //else $this.prependTo(header);
22
+ $this.hide().appendTo(header);
23
23
  }
24
24
  });
25
25
  });
@@ -35,6 +35,7 @@ var Cytoplasm;
35
35
  var vars = {};
36
36
  var ready = false;
37
37
 
38
+ // Gradient manipulation library
38
39
  var parseGradient = function(grad,reverse){
39
40
  // Return untouched if not gradient
40
41
  if (grad.indexOf("gradient")==-1) return grad;
@@ -114,6 +115,7 @@ var Cytoplasm;
114
115
  if ($.inArray(nstr,['aqua','black','blue','fuchsia','gray','grey','green','lime','maroon','navy','olive','purple','red','silver','teal','white','yellow'])>-1) return true;
115
116
  return (nstr.match(/^#([\da-fA-F]{2})([\da-fA-F]{2})([\da-fA-F]{2})/) || nstr.match(/^#([\da-fA-F])([\da-fA-F])([\da-fA-F])/) || nstr.match(/^rgba\(([\d]+),([\d]+),([\d]+),([\d]+|[\d]*.[\d]+)\)/) || nstr.match(/^rgb\(([\d]+),([\d]+),([\d]+)\)/));
116
117
  };
118
+
117
119
  var compileStyles = function(element,styles){
118
120
  output = "";
119
121
  output += element+" { ";
@@ -131,13 +133,14 @@ var Cytoplasm;
131
133
  var methods = {
132
134
  init:function(options){
133
135
  var settings = $.extend(true,{},defaults,options);
136
+ $('body').css("overflow","hidden").children(':not(header)').css("opacity",0);
134
137
 
135
138
  // Fetch latest settings via AJAX
136
139
  $.cytoAjax("/cytoplasm/settings/fetch",{},function(data){
137
140
  conf = data.conf;
138
141
  vars = data.vars;
139
- methods.setStyles.apply(this);
140
142
  $('body').data('cytoplasm',settings);
143
+ methods.setStyles.apply(this);
141
144
  ready = true;
142
145
  });
143
146
  },
@@ -286,8 +289,12 @@ var Cytoplasm;
286
289
  ready:function(callback){
287
290
  var interval = setInterval(function(){
288
291
  if (ready) {
289
- callback.apply();
290
- clearInterval(interval)
292
+ clearInterval(interval);
293
+ var allexceptheader = $('body').children(':not(header)').animate({opacity:1},250,function(){
294
+ $('body').css('overflow-y','scroll');
295
+ $(window).bind('beforeunload',function(){allexceptheader.animate({opacity:0},100);});
296
+ callback.apply();
297
+ });
291
298
  }
292
299
  },10);
293
300
  }
@@ -1,117 +1,342 @@
1
1
  require 'net/http'
2
2
  require 'open-uri'
3
3
  require 'yaml'
4
+ require 'zip/zipfilesystem'
5
+ require 'fileutils'
4
6
 
5
7
  module Cytoplasm
6
8
  class FontsController < ApplicationController
7
9
 
8
- @@fonts = {
9
- "fontsquirrel" => false,
10
- "googlewebfonts" => false,
11
- "imported" => false
12
- }
10
+ @@cache = false
13
11
  @@fontsdir = "public/fonts"
14
12
  @@gwf_file = @@fontsdir + "/googlewebfonts.yml"
13
+ @@enabled_file = @@fontsdir + "/enabled.yml"
15
14
 
16
- def fetch_imported
17
- return @@fonts["imported"] unless @@fonts["imported"] == false
15
+ class << self
16
+ #attr_accessor :fonts
18
17
 
19
- imported = {"fontsquirrel" => {}, "googlewebfonts" => {}}
20
-
21
- # Create @@fontsdir if it doesn't exist
22
- unless File.exists?(@@fontsdir)
23
- Dir.chdir("public")
24
- @@fontsdir = Dir.mkdir("fonts")
25
- Dir.chdir("../")
18
+ def fonts
19
+ @@cache = fetch_fonts() if @@cache == false
20
+ return @fonts
21
+ end
22
+ def fetch_fonts
23
+ @fonts = {"fontsquirrel" => fetch_fs_all(), "googlewebfonts" => fetch_gwf_all(),"imported" => fetch_imported(),"enabled" => fetch_enabled()}
24
+ return @fonts
25
+ end
26
+ def fetch_fs_all
27
+ fs = {}
28
+ fetch_json("http://www.fontsquirrel.com/api/fontlist/all").each do |f|
29
+ fs[f["family_urlname"]] = f
30
+ end
31
+ return fs
32
+ end
33
+ def fetch_gwf_all
34
+ gwf = {}
35
+ fetch_json("https://www.googleapis.com/webfonts/v1/webfonts?key="+Cytoplasm.conf("fontloader.googlewebfonts_apikey"))["items"].each {|f| gwf[f["family"]] = f}
36
+ return gwf
37
+ end
38
+ def fetch_family(dir,fam)
39
+ return fetch_fs_family(fam) if dir=="fontsquirrel"
40
+ return fetch_gwf_family(fam) if dir=="googlewebfonts"
41
+ end
42
+ def fetch_fs_family(family)
43
+ fs = (@@cache==false or @@cache["fontsquirrel"]==false) ? fetch_fs_all() : @@cache["fontsquirrel"]
44
+ return fs[family] unless fs[family].nil?
26
45
  end
46
+ def fetch_fs_familyinfo(family)
47
+ fetch_json("http://www.fontsquirrel.com/api/familyinfo/"+family)
48
+ end
49
+ def fetch_gwf_family(family)
50
+ gwf = (@@cache==false) ? fetch_gwf_all() : @@cache["googlewebfonts"]
51
+ return gwf[family] unless gwf[family].nil?
52
+ end
53
+ def fetch_imported
54
+ imported = {"fontsquirrel" => {}, "googlewebfonts" => {}}
27
55
 
28
- # Create @@gwf_file if it doesn't exist
29
- File.open(@@gwf_file,'w') {|f| f.write("")} unless File.exists?(@@gwf_file)
56
+ # Create @@fontsdir if it doesn't exist
57
+ unless File.exists?(@@fontsdir)
58
+ count = 0
59
+ @@fontsdir.split("/").each do |dir|
60
+ Dir.mkdir(dir) unless File.exists?(dir)
61
+ Dir.chdir(dir)
62
+ count += 1
63
+ end
64
+ while count > 0 do
65
+ Dir.chdir("../")
66
+ count -= 1
67
+ end
68
+ end
69
+
70
+ # Create @@gwf_file and @@enabled_file if it doesn't exist
71
+ File.open(@@gwf_file,'w') {|f| f.write("")} unless File.exists?(@@gwf_file)
72
+ File.open(@@enabled_file,'w') {|f| f.write("")} unless File.exists?(@@enabled_file)
73
+
74
+ # Fetch imported FontSquirrel fonts
75
+ Dir.open(@@fontsdir).each do |f|
76
+ if File.directory?(@@fontsdir+"/"+f) and f!="." and f!=".."
77
+ imported["fontsquirrel"][f] = fetch_fs_family(f)
78
+ imported["fontsquirrel"][f]["familyinfo"] = fetch_fs_familyinfo(f)
79
+ end
80
+ end
81
+
82
+ # Fetch imported GoogleWebFonts fonts
83
+ yaml = fetch_yaml(@@gwf_file)
84
+ yaml["imported"].each {|f| imported["googlewebfonts"][f] = fetch_gwf_family(f)} unless yaml["imported"].nil?
85
+
86
+ return imported
87
+ end
88
+ def fetch_enabled
89
+ enabled = {"fontsquirrel" => {}, "googlewebfonts" => {}}
30
90
 
31
- # Fetch imported FontSquirrel fonts
32
- Dir.open(@@fontsdir).each {|file| imported["fontsquirrel"][file] = fetch_fs_family(file) if File.directory?(file) and file!="." and file!=".."}
91
+ # Attempt to load YAML from @@enabled_file
92
+ yaml = fetch_yaml(@@enabled_file)
93
+
94
+ # Check that FontSquirrel fonts actually exist in @@fontsdir
95
+ notfound = 0
96
+ yaml["fontsquirrel"].each do |fam,variants|
97
+ unless File.exists?(@@fontsdir+"/"+fam)
98
+ yaml["fontsquirrel"].delete(fam)
99
+ notfound += 1
100
+ end
101
+ end
102
+ if notfound>0
103
+ open(@@enabled_file,"w+") {|f| f.write(yaml.to_yaml)}
104
+ return fetch_enabled()
105
+ end
106
+
107
+ # Fetch enabled fonts lists
108
+ ["fontsquirrel","googlewebfonts"].each do |dir|
109
+ unless yaml[dir].nil?
110
+ yaml[dir].each do |fam,variants|
111
+ enabled[dir][fam] = fetch_family(dir,fam)
112
+ end
113
+ end
114
+ end
115
+
116
+ return enabled
117
+ end
118
+ def is_enabled?(dir,fam)
119
+ enabled = (@@cache==false) ? fetch_enabled() : @@cache["enabled"]
120
+ return !enabled[dir][fam].nil?
121
+ end
33
122
 
34
- # Attempt to load YAML from @@gwf_file
35
- begin
36
- c = YAML::load_file(@@gwf_file)
37
- rescue
38
- puts "Failed to parse YAML in #{@@gwf_file}!"
123
+ def import(dir,fam)
124
+ output = {}
125
+ @@cache = fetch_fonts() if @@cache == false
126
+ if dir == "fontsquirrel"
127
+ output["dir"] = @@fontsdir+"/"+fam
128
+ output["url"] = "http://www.fontsquirrel.com/fontfacekit/"+fam
129
+ open(output["url"]) do |f|
130
+ Zip::ZipFile.open(f) do |zipfile|
131
+ zipfile.each do |entry|
132
+ fpath = File.join(output["dir"],entry.to_s)
133
+ FileUtils.mkdir_p(File.dirname(fpath))
134
+ zipfile.extract(entry,fpath){true}
135
+ end
136
+ end
137
+ end
138
+ fix_fs_stylesheet_family_names(fam)
139
+ end
140
+ @@cache["imported"][dir][fam] = fetch_family(dir,fam)
141
+ write_gwf_file() if dir=="googlewebfonts"
142
+ @@cache = fetch_fonts()
143
+ return output;
144
+ end
145
+ def remove(dir,fam)
146
+ output = {}
147
+ @@cache = fetch_fonts() if @@cache == false
148
+ disable(dir,fam) if is_enabled?(dir,fam)
149
+ case dir
150
+ when "fontsquirrel"
151
+ output["dir"] = @@fontsdir+"/"+fam
152
+ FileUtils.rm_rf(output["dir"]) if File.exists?(output["dir"])
153
+ when "googlewebfonts"
154
+ @@cache["imported"]["googlewebfonts"].delete(fam)
155
+ write_gwf_file()
156
+ end
157
+ @@cache = fetch_fonts()
158
+ return output
159
+ end
160
+ def enable(dir,fam)
161
+ output = {}
162
+ @@cache = fetch_fonts() if @@cache == false
163
+ @@cache["enabled"][dir][fam] = fetch_family(dir,fam)
164
+ write_enabled_file()
165
+ @@cache = fetch_fonts()
166
+ return output
167
+ end
168
+ def disable(dir,fam)
169
+ output = {}
170
+ @@cache = fetch_fonts() if @@cache == false
171
+ @@cache["enabled"][dir].delete(fam)
172
+ write_enabled_file()
173
+ @@cache = fetch_fonts()
174
+ return output
39
175
  end
40
176
 
41
- # Fetch imported GoogleWebFonts fonts
42
- c["imported"].each {|f| imported["googlewebfonts"][f] = fetch_gwf_family(f)} unless c["imported"].nil?
177
+ private
178
+ def fetch_json(url)
179
+ return ActiveSupport::JSON.decode(open(url).read)
180
+ end
181
+ def fetch_yaml(file)
182
+ begin
183
+ c = YAML::load_file(file)
184
+ rescue
185
+ puts "Failed to parse YAML in #{file}!"
186
+ end
187
+ return c
188
+ end
189
+ def write_gwf_file
190
+ imported = (@@cache==false) ? fetch_imported()["googlewebfonts"] : @@cache["imported"]["googlewebfonts"]
191
+ open(@@gwf_file,"w+") {|f| f.write({"imported" => imported.keys}.to_yaml)}
192
+ end
193
+ def write_enabled_file
194
+ enabled = (@@cache==false) ? fetch_enabled() : @@cache["enabled"]
195
+ e = {}
196
+ ["fontsquirrel","googlewebfonts"].each do |dir|
197
+ e[dir] = {}
198
+ enabled[dir].keys.each do |fam|
199
+ # Make list of variants to enable
200
+ e[dir][fam] = []
201
+ end
202
+ end
203
+ open(@@enabled_file,"w+") {|f| f.write(e.to_yaml)}
204
+ end
205
+ def fix_fs_stylesheet_family_names(fam)
206
+ sheet = @@fontsdir+"/"+fam+"/stylesheet.css"
207
+ finfo = fetch_fs_familyinfo(fam)
208
+
209
+ # Fetch contents
210
+ lines = File.readlines(sheet)
211
+ lines.each_with_index do |line,index|
212
+ if line.include?("font-family")
213
+ # Parse name
214
+ halves = line.split(":")
215
+ name = halves[1]
216
+ [';','"',"'"].each{|char| name = name.gsub(char,'') if name.include?(char)}
217
+ name = name.strip()
218
+
219
+ # Parse filename
220
+ filename = false
221
+ for i in (index+1)..lines.length
222
+ l = lines[i]
223
+ if l.include?("src: url(")
224
+ filename = l.split("(")[1].split(")")[0]
225
+ ['"',"'"].each{|char| filename = filename.gsub(char,'') if filename.include?(char)}
226
+ filename = filename.split(".")
227
+ ext = filename.pop()
228
+ filename = filename.join(".").strip()
229
+ break
230
+ end
231
+ end
232
+ filename = filename.chomp("-webfont") if filename.include?("-webfont")
233
+
234
+ unless filename == false
235
+
236
+ # Determine corresponding fontface_name from familyinfo
237
+ cname = false
238
+ cindex = false
239
+ if finfo.length == 1 # If there is only one variant, we choose that one
240
+ cindex = 0
241
+ else
242
+ # Search for exact matches among the variants
243
+ finfo.each_with_index do |face,index|
244
+ ffname = face["filename"].split(".")
245
+ ext = ffname.pop()
246
+ ffname = ffname.join(".").strip()
247
+ if ffname == filename
248
+ cindex = index
249
+ break
250
+ end
251
+ end
252
+ # Otherwise, use the Levenshtein algorithm to select the closest match
253
+ if cindex == false
254
+ best = false
255
+ finfo.each_with_index do |face,index|
256
+ ffname = face["filename"].split(".")
257
+ ext = ffname.pop()
258
+ ffname = ffname.join(".").strip()
259
+ lscore = levenshtein(filename,ffname)
260
+ if best==false or lscore <= best
261
+ best = lscore
262
+ cindex = index
263
+ end
264
+ end
265
+ end
266
+ end
267
+
268
+ # Fetch fontface_name from cindex and remove the variant from rotation
269
+ puts "CINDEX: "+cindex.to_s
270
+ cname = finfo[cindex]["fontface_name"]
271
+ finfo.delete(cindex)
272
+ puts "CNAME: " + cname.to_s
273
+
274
+ # Replace if necessary
275
+ lines[index] = halves[0]+": '"+cname+"';\n" if cname != false and name != cname
276
+
277
+ end
278
+ end
279
+ end
280
+
281
+ # Write fixed contents to file
282
+ open(sheet,"w+") {|f| f.write(lines.join())}
283
+ end
284
+
285
+ @@damerau = true
286
+ def levenshtein(s1, s2)
287
+ d = {}
288
+ (0..s1.size).each do |row|
289
+ d[[row, 0]] = row
290
+ end
291
+ (0..s2.size).each do |col|
292
+ d[[0, col]] = col
293
+ end
294
+ (1..s1.size).each do |i|
295
+ (1..s2.size).each do |j|
296
+ cost = 0
297
+ if (s1[i-1] != s2[j-1])
298
+ cost = 1
299
+ end
300
+ d[[i, j]] = [d[[i - 1, j]] + 1,
301
+ d[[i, j - 1]] + 1,
302
+ d[[i - 1, j - 1]] + cost
303
+ ].min
304
+ next unless @@damerau
305
+ if (i > 1 and j > 1 and s1[i-1] == s2[j-2] and s1[i-2] == s2[j-1])
306
+ d[[i, j]] = [d[[i,j]],
307
+ d[[i-2, j-2]] + cost
308
+ ].min
309
+ end
310
+ end
311
+ end
312
+ return d[[s1.size, s2.size]]
313
+ end
43
314
 
44
- @@fonts["imported"] = imported
45
- return @@fonts["imported"]
46
315
  end
47
316
 
48
- def fetch_fs_all
49
- return @@fonts["fontsquirrel"] unless @@fonts["fontsquirrel"] == false
50
- fonts = {}
51
- fetch_json("http://www.fontsquirrel.com/api/fontlist/all").each {|f| fonts[f["family_name"]] = f}
52
- @@fonts["fontsquirrel"] = fonts
53
- return @@fonts["fontsquirrel"]
54
- end
55
- def fetch_gwf_all
56
- return @@fonts["googlewebfonts"] unless @@fonts["googlewebfonts"] == false
57
- gwf = {}
58
- fetch_json("https://www.googleapis.com/webfonts/v1/webfonts?key="+Cytoplasm.conf("fontloader.googlewebfonts_apikey"))["items"].each {|f| gwf[f["family"]] = f}
59
- @@fonts["googlewebfonts"] = gwf
60
- return @@fonts["googlewebfonts"]
61
- end
62
- def fetch_fs_family(family)
63
- fetch_json("http://www.fontsquirrel.com/api/familyinfo/"+family)
64
- end
65
- def fetch_gwf_family(family)
66
- gwf = fetch_gwf_all()
67
- return (!gwf[family].nil?) ? gwf[family] : false;
317
+ def fetch_all
318
+ @@cache = Cytoplasm::FontsController.fetch_fonts() if @@cache == false
319
+ render :text => Cytoplasm::Ajax.success(@@cache)
68
320
  end
69
321
 
70
- def fetch_all
71
- success = {"fontsquirrel" => {}, "googlewebfonts" => {},"imported" => {"fontsquirrel" => {}, "googlewebfonts" => {}}}
72
-
73
- success["fontsquirrel"] = fetch_fs_all()
74
- success["googlewebfonts"] = fetch_gwf_all()
75
- success["imported"] = fetch_imported()
76
-
77
- render :text => Cytoplasm::Ajax.success(success)
322
+ def index
323
+ @@cache = Cytoplasm::FontsController.fetch_fonts() if @@cache == false
324
+ @installed = Cytoplasm::FontsController.fetch_imported()
325
+ @enabled = Cytoplasm::FontsController.fetch_enabled()
78
326
  end
79
327
 
80
328
  def import
81
- puts params
82
- success = {}
83
- case params[:directory]
84
- when "fontsquirrel"
85
- open(@@fontsdir+"/"+params[:family]['family_urlname']+".zip","wb") do |file|
86
- success["url"] = "http://www.fontsquirrel.com/fontfacekit/"+params[:family]['family_urlname']
87
- file << open(success["url"]).read
88
- end
89
-
90
-
91
- when "googlewebfonts"
92
-
93
- end
94
- render :text => Cytoplasm::Ajax.success(success)
329
+ render :text => Cytoplasm::Ajax.success(Cytoplasm::FontsController.import(params[:directory],params[:family]))
95
330
  end
96
-
97
331
  def remove
98
- case params[:directory]
99
- when "fontsquirrel"
100
-
101
- when "googlewebfonts"
102
-
103
- end
104
- render :text => Cytoplasm::Ajax.success()
332
+ render :text => Cytoplasm::Ajax.success(Cytoplasm::FontsController.remove(params[:directory],params[:family]))
105
333
  end
106
-
107
- def index
108
- @installed = fetch_imported()
334
+ def enable
335
+ render :text => Cytoplasm::Ajax.success(Cytoplasm::FontsController.enable(params[:directory],params[:family]))
336
+ end
337
+ def disable
338
+ render :text => Cytoplasm::Ajax.success(Cytoplasm::FontsController.disable(params[:directory],params[:family]))
109
339
  end
110
-
111
- private
112
- def fetch_json(url)
113
- return ActiveSupport::JSON.decode(open(url).read)
114
- end
115
340
 
116
341
  end
117
342
  end