Sha256: 4af2bb861db92b63c3bb9a1e746abeecf8077e998f4200496f9a2f9e95aade41

Contents?: true

Size: 1.52 KB

Versions: 4

Compression:

Stored size: 1.52 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)
      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 -rv`
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
susanoo-0.8.0 lib/susanoo/controllers/assets.rb
susanoo-0.7.4 lib/susanoo/controllers/assets.rb
susanoo-0.7.2 lib/susanoo/controllers/assets.rb
susanoo-0.7.1 lib/susanoo/controllers/assets.rb