Module: Fontcustom::Util
- Included in:
- Generator::Font, Generator::Template, Options, Watcher
- Defined in:
- lib/fontcustom/util.rb
Instance Method Summary collapse
- #check_fontforge ⇒ Object
- #expand_path(path) ⇒ Object
- #overwrite_file(file, content = "") ⇒ Object
- #relative_to_root(path) ⇒ Object
- #say_changed(status, changed) ⇒ Object
- #say_message(status, message, color = :yellow) ⇒ Object
- #symbolize_hash(hash) ⇒ Object
Instance Method Details
#check_fontforge ⇒ Object
6 7 8 9 10 11 |
# File 'lib/fontcustom/util.rb', line 6 def check_fontforge fontforge = `which fontforge` if fontforge == "" || fontforge == "fontforge not found" raise Fontcustom::Error, "Please install fontforge. Visit <http://fontcustom.com> for instructions." end end |
#expand_path(path) ⇒ Object
24 25 26 27 |
# File 'lib/fontcustom/util.rb', line 24 def (path) return path if path[0] == "/" File. File.join(base(:project_root), path) end |
#overwrite_file(file, content = "") ⇒ Object
36 37 38 39 |
# File 'lib/fontcustom/util.rb', line 36 def overwrite_file(file, content = "") File.open(file, "w") { |f| f.write(content) } # say_changed :update, [ file ] end |
#relative_to_root(path) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/fontcustom/util.rb', line 29 def relative_to_root(path) path = path.sub(base(:project_root), "") path = path[1..-1] if path[0] == "/" path = "." if path.empty? path end |
#say_changed(status, changed) ⇒ Object
13 14 15 16 17 |
# File 'lib/fontcustom/util.rb', line 13 def say_changed(status, changed) return if base(:quiet) = changed.map { |file| relative_to_root(file) } @shell.say_status status, .join("\n#{" " * 14}"), :green # magic number end |
#say_message(status, message, color = :yellow) ⇒ Object
19 20 21 22 |
# File 'lib/fontcustom/util.rb', line 19 def (status, , color = :yellow) return if base(:quiet) && status != :error @shell.say_status status, , color end |
#symbolize_hash(hash) ⇒ Object
41 42 43 |
# File 'lib/fontcustom/util.rb', line 41 def symbolize_hash(hash) hash.inject({}) { |memo, (k, v)| memo[k.to_sym] = v; memo } end |