Sha256: a99532663f46018b84faed005b86663ab1c5921753ab29e7988bebc496711509

Contents?: true

Size: 1.26 KB

Versions: 1

Compression:

Stored size: 1.26 KB

Contents

##
# Needs access to @shell and an Options instance 
# (@opts in thor, @cli_options or self in Options)
module Fontcustom
  module Util
    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

    def say_changed(status, changed)
      return unless base(:verbose)
      message = changed.map { |file| relative_to_root(file) }
      @shell.say_status status, message.join(" ")
    end

    def say_message(status, message)
      return unless base(:verbose)
      @shell.say_status status, message
    end

    def relative_to_root(path)
      path = path.sub(base(:project_root), "")
      path = path[1..-1] if path[0] == "/"
      path
    end

    def overwrite_file(file, content = "")
      File.open(file, "w") { |f| f.write(content) }
      say_changed :update, [ file ]
    end

    private

    def base(sym)
      # Generators have @opts
      if @opts
        @opts.send sym

      # Options (before merge) uses @cli_options
      elsif @cli_options
        @cli_options[sym]

      # Options (after merge) has its own methods
      else
        send sym
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fontcustom-1.1.0.pre2 lib/fontcustom/util.rb