Sha256: 079712409ccd4755e4d793b48c114e72bdb75511535966de12db9bf7376edc95

Contents?: true

Size: 1.37 KB

Versions: 1

Compression:

Stored size: 1.37 KB

Contents

require 'aws/s3'
require 'uglifier'

class SimpleSite
  
  def initialize(options = {})
    @options = options
    @options[:js_files] ||= Dir['_js/*.js']
    @options[:buckets] ||= []
  end
  
  def generate_html
    system "haml -r simple_site/haml_helper.rb _src/index.haml public/index.html"
    puts "Regenerated site!"
  end
  
  def generate_css
    system "sass _sass/style.sass public/css/style.css"
    puts "Regenerated css!"
  end
  
  def generate_js
    system 'mkdir -p _tmp; touch _tmp/js.js; :> _tmp/js.js'
    @options[:js_files].each do |f|
      system "cat _js/#{f} >> _tmp/js.js"
    end
    File.open('public/js/script.js', 'w') {|f| f.write(Uglifier.compile(File.read('_tmp/js.js'))) }
    system 'rm _tmp/js.js'
    puts "Regenerated js!"
  end
  
  def deploy!
    Dir.chdir('public')
    Dir['**/*'].select { |f| File.file?(f) }.each do |file|
      deploy file
    end
  end
  
  def deploy_file!
    Dir.chdir('public')
    ENV['FILES'].select { |f| File.file?(f) }.each do |file|
      deploy file
    end
  end
  
  
  private
    def deploy(file)
      age = 7*24*60*60
      options = {
        :access => :public_read,
        :cache_control => "max-age=#{age}",
        :expires => age.from_now.httpdate
      }
      puts "  --> #{file}"
      @options[:buckets].each do |bucket|
        AWS::S3::S3Object.store(file, open(file), bucket, options)
      end
    end
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
simple_site-0.0.1 lib/simple_site.rb