Skip to content

Commit

Permalink
Add woff data uri to generated CSS + template helper
Browse files Browse the repository at this point in the history
refs #131
  • Loading branch information
jvatic committed Feb 11, 2014
1 parent fbc2b68 commit c5ffc30
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/fontcustom/generator/template.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require "json"
require "pathname"
require "base64"

module Fontcustom
module Generator
Expand Down Expand Up @@ -36,7 +37,7 @@ def set_relative_paths
css_path = Pathname.new(@options[:output][:css]).realdirpath
preview_path = Pathname.new(@options[:output][:preview]).realdirpath
@font_path = File.join fonts_path.relative_path_from(css_path).to_s, name
@font_path_alt = if @options[:preprocessor_path].nil?
@font_path_alt = if @options[:preprocessor_path].nil?
@font_path
elsif ! @options[:preprocessor_path] || @options[:preprocessor_path].empty?
name
Expand Down Expand Up @@ -129,6 +130,7 @@ def font_face(style = :normal)
font-family: "#{font_name}";
src: #{url}("#{path}.eot");
src: #{url}("#{path}.eot?#iefix") format("embedded-opentype"),
#{url}(#{woff_data_uri}),
#{url}("#{path}.woff") format("woff"),
#{url}("#{path}.ttf") format("truetype"),
#{url}("#{path}.svg##{font_name}") format("svg");
Expand All @@ -144,6 +146,15 @@ def font_face(style = :normal)
}|
end

def woff_data_uri
"data:application/x-font-woff;charset=utf-8;base64,#{woff_base64}"
end

def woff_base64
woff_path = File.join(@options[:output][:fonts], "#{@font_path_alt}.woff")
Base64.encode64(File.read(File.join(woff_path))).gsub("\n", "")
end

def glyph_selectors
output = @glyphs.map do |name, value|
@options[:css_selector].sub("{{glyph}}", name.to_s) + ":before"
Expand Down

0 comments on commit c5ffc30

Please sign in to comment.