Sha256: 6f1e3f2681e9415268795f7d388e0601245ae6ae95d044f211693b43c0c3529d

Contents?: true

Size: 1.91 KB

Versions: 7

Compression:

Stored size: 1.91 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
      environment.call env
    end

    def build(generator, options)
      platform = options[:platform]

      Sprockets::Helpers.configure do |config|
        config.prefix      = "/#{platform}_asset/www/assets"
        config.debug       = false
        config.environment = @environment
      end

      @environment.append_path File.join(project_root,
                                   'src/assets/javascripts')
      @environment.append_path File.join(project_root,
                             'src/assets/stylesheets')

      @environment.append_path File.join(project_root,
                                   'src/assets/fonts')


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

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

7 entries across 7 versions & 1 rubygems

Version Path
susanoo-0.13.2 lib/susanoo/controllers/assets.rb
susanoo-0.13.1 lib/susanoo/controllers/assets.rb
susanoo-0.13.0 lib/susanoo/controllers/assets.rb
susanoo-0.12.3 lib/susanoo/controllers/assets.rb
susanoo-0.12.2 lib/susanoo/controllers/assets.rb
susanoo-0.12.1 lib/susanoo/controllers/assets.rb
susanoo-0.12.0 lib/susanoo/controllers/assets.rb