Sha256: 04e4b3d7a41a650c0a9921b5c676254b0c90c3a44a3bd0aa56988c12fdbe7a92

Contents?: true

Size: 1.62 KB

Versions: 1

Compression:

Stored size: 1.62 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)
      case val = (ENV[name.to_s] || Object.const_get(name) rescue defval)
      when /^\d+$/ then val.to_i
      when 'true'  then true
      when 'false' then false
      else val
      end
    end

    def header (mod)
      puts "-- #{mod.to_s.capitalize} " + "-" * 50
    end

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

    def mswin? ()
      RUBY_PLATFORM =~ /mswin/
    end

    def ming? ()
      RUBY_PLATFORM =~ /ming/
    end

    def cygwin? ()
      RUBY_PLATFORM =~ /cygwin/
    end

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

    def clang? ()
      RbConfig::CONFIG['CXX'] =~ /clang/
    end


  end# Rake


end# Xot

Version data entries

1 entries across 1 versions & 1 rubygems

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