Sha256: 7ac03e9c4ff8597a421ef6241fb5684d3663d6c0a5e8f801ae9183ae6fb00530

Contents?: true

Size: 1.22 KB

Versions: 8

Compression:

Stored size: 1.22 KB

Contents

require 'net/http'
require 'open-uri'

module Cytoplasm
	class FontsController < ApplicationController
		
		def fetch_imported
			imported = {}
			fontsdir = "public/fonts"
			
			# Find fonts directory, create one if it doesn't exist
			if File.exists?(fontsdir)
				fontsdir = Dir.open(fontsdir)
			else
				Dir.chdir("public")
				fontsdir = Dir.mkdir("fonts")
				Dir.chdir("../")
			end
			
			fontsdir.each do |file|
				imported[file] = fetch_fs_family(file) if File.directory?(file) and file!="." and file!=".."
			end
			return imported
		end
		
		def fetch_fs_family(font)
			return fetch_json("http://www.fontsquirrel.com/api/familyinfo/"+font)
		end
		
		def fetch_all
			success = {"fontsquirrel" => {}, "googlewebfonts" => {},"imported" => {}}
			
			success["fontsquirrel"] = fetch_json("http://www.fontsquirrel.com/api/fontlist/all")
			fetch_json("https://www.googleapis.com/webfonts/v1/webfonts?key="+Cytoplasm.conf("fontloader.googlewebfonts_apikey"))["items"].each {|f| success["googlewebfonts"][f["family"]] = f}
			success["imported"] = fetch_imported()
			
			render :text => Cytoplasm::Ajax.success(success)
		end
		
		private
			def fetch_json(url)
				return ActiveSupport::JSON.decode(open(url).read)
			end
		
	end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
cytoplasm-0.1.3 app/controllers/cytoplasm/fonts_controller.rb
cytoplasm-0.1.2 app/controllers/cytoplasm/fonts_controller.rb
cytoplasm-0.1.1 app/controllers/cytoplasm/fonts_controller.rb
cytoplasm-0.1.0 app/controllers/cytoplasm/fonts_controller.rb
cytoplasm-0.0.9.3 app/controllers/cytoplasm/fonts_controller.rb
cytoplasm-0.0.9.2 app/controllers/cytoplasm/fonts_controller.rb
cytoplasm-0.0.9.1 app/controllers/cytoplasm/fonts_controller.rb
cytoplasm-0.0.9 app/controllers/cytoplasm/fonts_controller.rb