Sha256: 5c386212aac625b6517fa40f3e1def132162da723f68639f63cfa117be7512d8

Contents?: true

Size: 1.59 KB

Versions: 3

Compression:

Stored size: 1.59 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. 'production' also outputs to /public.
  # 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|
      rendered = ERB.new(File.read("#{@working_dir}/index.erb"), nil, '-')
      f.write rendered.result(binding)
    end

    if @target == 'production'
      compress(@build_dir)
      FileUtils.rm_rf "#{@working_dir}/public"
      FileUtils.cp_r(@build_dir, "#{@working_dir}/public")
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pyro-1.0.0.rc5 lib/pyro.rb
pyro-1.0.0.rc4 lib/pyro.rb
pyro-1.0.0.rc3 lib/pyro.rb