Sha256: 34d246b645952021c7901afa3ade3bfea2dd1f6ca707e2d69237e5185ba1d7fb

Contents?: true

Size: 1.62 KB

Versions: 1

Compression:

Stored size: 1.62 KB

Contents

desc 'Compiles all resources'
task :compile => [:greet, 'compile:all', :report]
desc 'Compiles all resources with ENV=production'
task :release => [:set_release, :compile]

task :set_release do
  @env = 'production'
end

class Erbs < OpenStruct
  def render(template)
    ERB.new(template).result(binding)
  end
end


namespace :compile do
  task :all   => [:js, :css, :html, :vars]

  desc 'Compiles Coffee -> JS'
  task :js => get_sources(:coffee).ext('.js')

  desc 'Compiles SASS -> CSS'
  task :css => get_sources(:sass).ext('.css')

  desc 'Compiles HAML -> HTML'
  task :html => get_sources(:haml).ext('.html')

  desc 'Postcompile ENV variables'
  task :vars do
    data = YAML.load_file('config/app.yml')[env]
    # STDOUT.puts 'ERB.new(config/app.yml).render on www/'
    [:js, :css, :html].map { |f| get_sources(f, 'www') }.flatten.each do |file|
      out = Erbs.new(data).render(File.read(file))
      File.open(file, 'w') { |f| f << out  }
    end
  end

  rule '.js' => '.coffee' do |t|
    output = File.dirname(t.source).gsub(/app\//, 'www/')
    # print "CoffeeScript | " # #{t.source} -> #{output}"
    sh "coffee --no-header -b -o #{output} #{t.source}"
  end

  rule '.css' => '.sass' do |t|
    # print "SASS | #{t.source} -> #{t.name} | "
    sh "sass #{t.source} #{t.name.gsub(/app\//, 'www/')}"
  end

  rule '.html' => '.haml' do |t|
    next if t.name =~ /layout/
    template = Tilt.new(t.source)
    # => #<Tilt::HAMLTemplate @file="path/to/file.haml" ...>
    File.open(t.name.gsub(/app\//, 'www/'), 'w') do |f|
      f.puts layout.render { template.render }
    end
    STDOUT.puts "haml #{t.source} -> #{t.name}"
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cordova-rake-0.0.7 lib/tasks/application.rake