Sha256: 6890a03e52275014643e4e55efa3a9c2de87e8371948628cb442aaebd558827b

Contents?: true

Size: 1.16 KB

Versions: 5

Compression:

Stored size: 1.16 KB

Contents

module Jitai
  require 'jitai/railtie.rb' if defined?(Rails)

  class FontManager
    attr_accessor :moz_path, :ie_path
    
    def initialize(path= "public")
      @moz_path = "#{path}/stylesheets/fonts_moz.css"
      @ie_path = "#{path}/stylesheets/fonts_ie.css"
    end
  end

  class Font
    attr_accessor :name, :path

    def initialize(path)
      @name = path.downcase.split(".")[0]
      @path = path
    end

    def to_css
      moz = "@font-face {font-family:'#{@name}'; src:url('#{name}.ttf');}"
      ie = "@font-face {font-family:'#{@name}'; src:url('#{name}.eot');}"
      manager = Jitai::FontManager.new
      find_font(manager.moz_path, moz)
      find_font(manager.ie_path, ie)
    end

    def find_font(file, search_font)
      File.open(file, "w") if !File.exists?(file) # touch file

      in_file = false
      File.open(file) do |font|
        test = font.gets
        if !test.nil?
          return (in_file = true) if search_font.eql? test.strip
        end
      end

      unless in_file
        File.open(file, "a") do |f|
          f.puts search_font
          puts search_font
          puts "Was added to #{file}"
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
jitai-0.2.20 lib/jitai.rb
jitai-0.2.19 lib/jitai.rb
jitai-0.2.18 lib/jitai.rb
jitai-0.2.17 lib/jitai.rb
jitai-0.2.10 lib/jitai.rb