Sha256: 6a867e6c21f2540873609df536136947b6b3144677f65fd725cca667e3990706

Contents?: true

Size: 1.4 KB

Versions: 1

Compression:

Stored size: 1.4 KB

Contents

require 'fileutils'
require 'pyro/assets'

# Public: Main script for running Pyro.
#
# Examples
#
#   Pyro.burn('development', true)
module Pyro
  include Pyro::Assets

  # Public: Burn a build of an app.
  #
  # target      - 'development' or 'production' determines compression
  #                and output directory.
  # fast        - Boolean to run the server faster (skips rebuilding resources).
  # working_dir - Path to the app.
  #
  # Examples
  #
  #   Pyro.burn('development', true)
  #
  # Generates a built app.
  def self.burn(target = 'production', fast = false, working_dir = '.')
    @target      = target
    @timestamp   = Time.now.strftime "%Y%m%d%H%M%S"
    @working_dir = working_dir
    @links       = []

    unless File.exists? "#{@working_dir}/index.erb"
      raise 'Can\'t find an index.erb file to burn.'
    end

    if @target == 'development' || @target == 'test'
      @build_dir = "#{@working_dir}/tmp"
    else
      @build_dir = "#{@working_dir}/pkg/#{@timestamp}"
    end

    FileUtils.rm_rf   @build_dir
    FileUtils.mkdir_p @build_dir

    unless fast
      FileUtils.cp_r("#{@working_dir}/resources", @build_dir)
      FileUtils.cp_r("#{@working_dir}/vendor",    @build_dir)
    end

    File.open("#{@build_dir}/index.html", 'w+') do |f|
      f.write( ERB.new(File.read "#{@working_dir}/index.erb").result(binding) )
    end

    compress(@build_dir) if @target == 'production'
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pyro-1.0.0.rc2 lib/pyro.rb