Class: Compass::Fontcustom::FontImporter
- Inherits:
-
Sass::Importers::Base
- Object
- Sass::Importers::Base
- Compass::Fontcustom::FontImporter
- Defined in:
- lib/compass/fontcustom/font_importer.rb
Overview
The Sass Importer responsible to find svg and eps files and to start the Fontcustom font generator.
Constant Summary collapse
- GLYPH_FILE_REGEX =
Regexp matching uri’s of svg and eps files. Matching group ‘$1` contains the path, `$3` the file name.
%r{((.+/)?([^\*.]+))/(.+?)\.(svg|eps)}
Class Method Summary collapse
-
.content_for_font(uri, name) ⇒ String
Renders the stylesheet for font ‘name` at `uri`.
-
.files(uri) ⇒ Array
Returns an array of font files.
-
.font_name(uri) ⇒ String
Returns only the file name component of ‘uri`.
-
.fonts_path ⇒ String
Returns the fonts path.
-
.glyph_names(uri) ⇒ Array
Returns all glyph names inside the folder at ‘uri`.
-
.path(uri) ⇒ String
Returns only the path component of ‘uri`.
-
.path_and_name(uri) ⇒ Array
Returns an array with two elements.
-
.sass_engine(uri, name, importer, options) ⇒ Sass::Engine
Returns a ‘Sass::Engine`.
-
.sass_options(uri, importer, options) ⇒ Hash
Returns ‘Sass::Engine` options with defaults.
- .search_paths ⇒ Object
-
.template_path ⇒ String
Returns the gems’ internal template path.
Instance Method Summary collapse
-
#eql?(other) ⇒ Boolean
Compares this instance with another object.
-
#find(uri, options) ⇒ Sass::Engine
Resolves incoming uri from an ‘@import “…”` directive.
-
#find_relative(uri, base, options) ⇒ Object
Unused.
-
#hash ⇒ String
Returns the hash of this instance.
-
#key(uri, options = {}) ⇒ Array
This instance’s Compass cache key.
- #mtime(uri, options) ⇒ Object
-
#public_url(*args) ⇒ Object
Unused.
-
#to_s ⇒ String
Returns the string representation of this instance.
Class Method Details
.content_for_font(uri, name) ⇒ String
Renders the stylesheet for font ‘name` at `uri`
98 99 100 101 102 |
# File 'lib/compass/fontcustom/font_importer.rb', line 98 def content_for_font(uri, name) erb = File.read File.join(template_path, 'stylesheet.scss.erb') binder = TemplateData.new(uri: uri, name: name, path: fonts_path, glyph_names: glyph_names(uri)) ERB.new(erb).result(binder.expose_binding) end |
.files(uri) ⇒ Array
Returns an array of font files.
119 120 121 122 123 124 |
# File 'lib/compass/fontcustom/font_importer.rb', line 119 def files(uri) [].tap do |ary| ary.concat Dir[uri] search_paths.each { |p| ary.concat Dir[File.join p, uri] } end end |
.font_name(uri) ⇒ String
Returns only the file name component of ‘uri`.
44 45 46 47 |
# File 'lib/compass/fontcustom/font_importer.rb', line 44 def font_name(uri) _, name = path_and_name(uri) name end |
.fonts_path ⇒ String
Returns the fonts path
106 107 108 |
# File 'lib/compass/fontcustom/font_importer.rb', line 106 def fonts_path Compass.configuration.fonts_dir.to_s end |
.glyph_names(uri) ⇒ Array
Returns all glyph names inside the folder at ‘uri`.
64 65 66 67 68 69 70 71 72 |
# File 'lib/compass/fontcustom/font_importer.rb', line 64 def glyph_names(uri) images = files(uri).sort if images.empty? raise Compass::SpriteException, %Q{No glyph images were found matching "#{uri}" in the images path. Your current images path is: #{folder}} end images.map { |f| File.basename(f)[0..-5] } end |
.path(uri) ⇒ String
Returns only the path component of ‘uri`
52 53 54 55 |
# File 'lib/compass/fontcustom/font_importer.rb', line 52 def path(uri) path, _ = path_and_name(uri) path end |
.path_and_name(uri) ⇒ Array
Returns an array with two elements. First the path, second the file name of the ‘uri`.
33 34 35 36 37 38 39 |
# File 'lib/compass/fontcustom/font_importer.rb', line 33 def path_and_name(uri) if uri =~ GLYPH_FILE_REGEX [$1, $3] else raise Compass::Error, "Invalid glyph image uri" end end |
.sass_engine(uri, name, importer, options) ⇒ Sass::Engine
Returns a ‘Sass::Engine`
89 90 91 92 |
# File 'lib/compass/fontcustom/font_importer.rb', line 89 def sass_engine(uri, name, importer, ) content = content_for_font(uri, name) Sass::Engine.new(content, (uri, importer, )) end |
.sass_options(uri, importer, options) ⇒ Hash
Returns ‘Sass::Engine` options with defaults
79 80 81 |
# File 'lib/compass/fontcustom/font_importer.rb', line 79 def (uri, importer, ) .merge!(:filename => uri.gsub(%r{\*/},"*\\/"), :syntax => :scss, :importer => importer) end |
.search_paths ⇒ Object
57 58 59 |
# File 'lib/compass/fontcustom/font_importer.rb', line 57 def search_paths Compass.configuration.fontcustom_input_paths.to_a end |
.template_path ⇒ String
Returns the gems’ internal template path.
112 113 114 |
# File 'lib/compass/fontcustom/font_importer.rb', line 112 def template_path File.('../templates', __FILE__) end |
Instance Method Details
#eql?(other) ⇒ Boolean
Compares this instance with another object.
164 165 166 |
# File 'lib/compass/fontcustom/font_importer.rb', line 164 def eql?(other) other.class == self.class end |
#find(uri, options) ⇒ Sass::Engine
Resolves incoming uri from an ‘@import “…”` directive.
132 133 134 135 136 137 |
# File 'lib/compass/fontcustom/font_importer.rb', line 132 def find(uri, ) if uri =~ GLYPH_FILE_REGEX return self.class.sass_engine(uri, self.class.font_name(uri), self, ) end nil end |
#find_relative(uri, base, options) ⇒ Object
Unused. Just returns nil.
145 146 147 |
# File 'lib/compass/fontcustom/font_importer.rb', line 145 def find_relative(uri, base, ) nil end |
#hash ⇒ String
Returns the hash of this instance.
157 158 159 |
# File 'lib/compass/fontcustom/font_importer.rb', line 157 def hash self.class.name.hash end |
#key(uri, options = {}) ⇒ Array
This instance’s Compass cache key
178 179 180 |
# File 'lib/compass/fontcustom/font_importer.rb', line 178 def key(uri, ={}) [self.class.name + ":fontcustom:" + File.dirname(File.(uri)), File.basename(uri)] end |
#mtime(uri, options) ⇒ Object
168 169 170 171 172 |
# File 'lib/compass/fontcustom/font_importer.rb', line 168 def mtime(uri, ) self.class.files(uri).inject(Time.at(0)) do |max_time, file| (t = File.mtime(file)) > max_time ? t : max_time end end |
#public_url(*args) ⇒ Object
Unused
140 141 142 |
# File 'lib/compass/fontcustom/font_importer.rb', line 140 def public_url(*args) nil end |
#to_s ⇒ String
Returns the string representation of this instance.
151 152 153 |
# File 'lib/compass/fontcustom/font_importer.rb', line 151 def to_s self.class.name end |