Sha256: c9f5191e495084bcb79c098c4958bd7e75b98ded0fbd7741ab5f6288590c984f

Contents?: true

Size: 1.42 KB

Versions: 1

Compression:

Stored size: 1.42 KB

Contents

desc 'Compiles all resources'
task :compile   => ['compile:all']

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')[environment]
    [:js, :css, :html].map { |f| get_sources(f, 'www/js') }.flatten.each do |f|
      data.each do |k, v|
        sh "sed -i \"s/'...#{k.upcase}...'/'#{v}'/g\" #{f}"
        # sh "sed -i \"s/'####{k.upcase}###'/#{v}/g\" #{f}" # numbers
      end
    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
    # print "HAML | #{t.source} -> #{t.name} | "
    # sh "haml #{t.source} #{}"
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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