Sha256: 3c1aa9127383ad6b6c092f25e52bd367785f815a27cc0bf1fd4ca7809379a1c3

Contents?: true

Size: 1.53 KB

Versions: 1

Compression:

Stored size: 1.53 KB

Contents

require 'rack'
require 'uglifier'
require 'yui/compressor'

class Susanoo::Application

  # This controller is responsible for serving/building assets files
  class Assets < Susanoo::Controller
    def call(env)
      # Environment is a sprockets environment instance
      run environment
    end

    def build(generator, route)
      assets = Sprockets::Environment.new
      assets.append_path File.join(project_root,
                                   'src/assets/javascripts')
      assets.append_path File.join(project_root,
                                   'src/assets/stylesheets')

      func = lambda do |path, filename|
        filename !~ %r~assets~  && !%w[.js .css].include?(File.extname(path))
      end

      precompile = [func, /(?:\/|\\|\A)application\.(css|js)$/]
      assets.each_logical_path(*precompile).each {|path|
        case File.extname(path)
        when '.js'
          dir = 'javascripts'
        when '.css'
          dir = 'stylesheets'
        end
        assets[path].write_to "www/assets/#{dir}/#{path}"
      }

      if File.exist? File.join(project_root,
                               'src/assets/images')
        generator.say_status 'copy', 'src/assets/images'
        `cp #{project_root}/src/assets/images #{project_root}/www/assets/images -r`
      end

      if File.exist? File.join(project_root,
                               'src/assets/fonts')
        generator.say_status 'copy', 'src/assets/fonts'
        `cp #{project_root}/src/assets/fonts #{project_root}/www/assets/fonts -r`
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
susanoo-0.10.0 lib/susanoo/controllers/assets.rb