Sha256: e1073d518c0241e59597d65d98e440fc0784203e0e1ee2cc0cf83b0482654432

Contents?: true

Size: 1.56 KB

Versions: 7

Compression:

Stored size: 1.56 KB

Contents

require 'asciidoctor'
require 'yaml'
require 'fileutils'
require 'set'

require_relative 'asciinurse/version'

ENV['ASCIINURSE_USER_DIR'] ||= ('%s/.asciinurse' % ENV['HOME'])

module Asciinurse

  RESOURCE_PRECEDENCE = [
      ENV['ASCIINURSE_USER_DIR'],
      File.expand_path(File.dirname(__FILE__) + '/..')
  ]

  def self.add_custom_path(path)
    RESOURCE_PRECEDENCE.insert 1, path
  end

  def self.find(path)
    result = []
    RESOURCE_PRECEDENCE.each do |basedir|
      result += Dir["#{basedir}/#{path}"]
    end
    result
  end

  def self.find_resource(path)
    find("resources/#{path}").first
  end

  def self.read_resource(path)
    IO.read find_resource(path)
  end

  CONFIG = {}

  def self.config(key)
    result = CONFIG
    key.to_s.split('.').each do |obj|
      result = result[obj]
    end
    result
  end

  # reverse order so custom config can take precedence over built-in config
  find('config/asciinurse.yml').reverse_each do |file|
    CONFIG.merge! YAML::load_file(file)
  end

  TEMP_DIRS = Set::new

  def self.tmp_dir(document)
    basedir = document.attributes['docdir']
    tmpdir = "#{basedir}/tmp"
    FileUtils.mkpath tmpdir unless File.exist? tmpdir
    TEMP_DIRS << tmpdir if document.attributes['backend'] == 'pdf'
    tmpdir
  end

  at_exit do
    TEMP_DIRS.each do |tmpdir|
      FileUtils.rmtree tmpdir
    end
  end

end

require_relative 'asciinurse/extensions/charts/extension'

if File.exist? ENV['ASCIINURSE_USER_DIR']
  custom_script = '%s/asciinurse.rb' % ENV['ASCIINURSE_USER_DIR']
  require custom_script if File.exist? custom_script
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
asciinurse-0.1.7 lib/asciinurse.rb
asciinurse-0.1.6 lib/asciinurse.rb
asciinurse-0.1.5 lib/asciinurse.rb
asciinurse-0.1.4 lib/asciinurse.rb
asciinurse-0.1.3 lib/asciinurse.rb
asciinurse-0.1.2 lib/asciinurse.rb
asciinurse-0.1.1 lib/asciinurse.rb