Class: Fontcustom::Util
- Inherits:
-
Object
- Object
- Fontcustom::Util
- Defined in:
- lib/fontcustom/util.rb
Class Method Summary collapse
- .check_fontforge ⇒ Object
- .clear_file(file) ⇒ Object
-
.collect_options(args = {}) ⇒ Object
Converts all options into symbol-accessible hashes Priority: Passed args > config file > default.
- .gem_lib_path ⇒ Object
-
.get_config_path(options) ⇒ Object
passed path > input.
-
.get_template_paths(options) ⇒ Object
Translates shorthand to full path of packages templates, otherwise, it checks input and pwd for the template.
Class 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 first. Visit http://fontcustom.com for more details." end end |
.clear_file(file) ⇒ Object
87 88 89 |
# File 'lib/fontcustom/util.rb', line 87 def clear_file(file) File.open(file, "w") {} end |
.collect_options(args = {}) ⇒ Object
Converts all options into symbol-accessible hashes Priority: Passed args > config file > default
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/fontcustom/util.rb', line 15 def (args = {}) = Fontcustom::DEFAULT_OPTIONS.clone args = args.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo} [:input] = args[:input] if args[:input] [:config] = args[:config] if args[:config] args.delete :config # don't overwrite the return value of #get_config_path [:config] = get_config_path if [:config] config = YAML.load File.open([:config]) if config.is_a? Hash config = config.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo} .merge! config end end .merge! args [:output] ||= File.join([:input], "fontcustom") [:templates] = get_template_paths [:font_name] = [:font_name].strip.downcase.gsub(/\W/, '-') end |
.gem_lib_path ⇒ Object
91 92 93 |
# File 'lib/fontcustom/util.rb', line 91 def gem_lib_path File.(File.join(File.dirname(__FILE__))) end |
.get_config_path(options) ⇒ Object
passed path > input
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/fontcustom/util.rb', line 40 def get_config_path() if [:config] && File.directory?([:config]) && File.exists?(File.join([:config], "fontcustom.yml")) File.join [:config], "fontcustom.yml" elsif [:config] && File.exists?([:config]) [:config] elsif File.exists? File.join([:input], "fontcustom.yml") File.join [:input], "fontcustom.yml" else false end end |
.get_template_paths(options) ⇒ Object
Translates shorthand to full path of packages templates, otherwise, it checks input and pwd for the template.
Could arguably belong in Generator::Template, however, it’s nice to be able to catch template errors before any generator runs.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/fontcustom/util.rb', line 57 def get_template_paths() [:templates] << "css" if [:templates].include?("preview") && ! [:templates].include?("css") [:templates].map do |template| case template when "preview" File.join gem_lib_path, "templates", "fontcustom-preview.html" when "css" File.join gem_lib_path, "templates", "fontcustom.css" when "scss" File.join gem_lib_path, "templates", "_fontcustom.scss" when "bootstrap" File.join gem_lib_path, "templates", "fontcustom-bootstrap.css" when "bootstrap-scss" File.join gem_lib_path, "templates", "_fontcustom-bootstrap.scss" when "bootstrap-ie7" File.join gem_lib_path, "templates", "fontcustom-bootstrap-ie7.css" when "bootstrap-ie7-scss" File.join gem_lib_path, "templates", "_fontcustom-bootstrap-ie7.scss" else if File.exists?(template) template elsif File.exists?(File.join([:input], template)) File.join [:input], template else raise Fontcustom::Error, "We couldn't find your custom template #{template}. Double check and try again?" end end end end |