Sha256: 8e84634d75f88c722c5f37f0a2c16715fbdbf5c612335715cf8969ec831f6976

Contents?: true

Size: 1.17 KB

Versions: 1

Compression:

Stored size: 1.17 KB

Contents

# -*- coding: utf-8 -*-


require 'erb'
require 'pp'


module Xot


  module Rake


    def glob (*patterns)
      paths = []
      patterns.each do |pattern|
        paths.concat Dir.glob(pattern)
      end
      paths
    end

    def erb (str)
      ERB.new(str, nil, "%").result binding
    end

    def compile (path, out)
      open(path) do |input|
        open(out, "w") do |output|
          output.write erb(input.read)
        end
      end
    #rescue
    end

    def params (n, sep = "", &block)
      raise "block not given." unless block
      return "" if n == 0
      (1..n).map(&block).join(sep)
    end

    def convertions (paths, convs)
      raise "empty conversion." if convs.empty?
      paths = paths.map do |path|
        convpath = path
        convs.each do |from, to|
          convpath = convpath.sub(/#{from.gsub('.', '\.')}$/, to)
        end
        [path, convpath]
      end
      Hash[*paths.flatten]
    end

    def env (name, defval = nil)
      Object.const_get(name) rescue ENV[name.to_s] || defval
    end

    def win32? ()
      RUBY_PLATFORM =~ /mswin|ming|cygwin/
    end

    def cocoa? ()
      RUBY_PLATFORM =~ /darwin/
    end


  end# Rake


end# Xot

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
xot-0.1.3 lib/xot/rake/helpers.rb