Sha256: 118b6428ebf906c9b20fc222a910dc0a0d87b272d7d2b8ccaf84444f2462c031

Contents?: true

Size: 1.28 KB

Versions: 6

Compression:

Stored size: 1.28 KB

Contents

require 'deface'

namespace :deface do
  include Deface::TemplateHelper

  desc "Precompiles overrides into template files"
  task :precompile => [:environment, :clean] do |t, args|
    base_path = Rails.root.join("app/compiled_views")

    # temporarily configures deface env and loads
    # all overrides so we can precompile
    unless Rails.application.config.deface.enabled
      Rails.application.config.deface = Deface::Environment.new
      Rails.application.config.deface.overrides.early_check
      Rails.application.config.deface.overrides.load_all Rails.application
    end

    Rails.application.config.deface.overrides.all.each do |virtual_path,overrides|
      template_path = base_path.join( "#{virtual_path}.html.erb")

      FileUtils.mkdir_p template_path.dirname
      begin
        source = load_template_source(virtual_path.to_s, false, true)
        if source.blank?
          raise "Compiled source was blank for '#{virtual_path}'"
        end
        File.open(template_path, 'w') {|f| f.write source } 
      rescue Exception => e
        puts "Unable to precompile '#{virtual_path}' due to: "
        puts e.message
      end
    end
  end

  desc "Removes all precompiled override templates"
  task :clean do
    FileUtils.rm_rf Rails.root.join("app/compiled_views")
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
deface-1.0.0.rc1 tasks/precompile.rake
deface-0.9.1 tasks/precompile.rake
deface-0.9.0 tasks/precompile.rake
deface-0.8.0 tasks/precompile.rake
deface-0.7.2 tasks/precompile.rake
deface-0.7.1 tasks/precompile.rake