Class: Susanoo::Application::Assets

Inherits:
Controller show all
Defined in:
lib/susanoo/controllers/assets.rb

Overview

This controller is responsible for serving/building assets files

Instance Attribute Summary

Attributes inherited from Controller

#debug, #environment, #project_root

Instance Method Summary collapse

Methods inherited from Controller

#initialize, #static_compile?

Constructor Details

This class inherits a constructor from Susanoo::Controller

Instance Method Details

#build(generator, options) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/susanoo/controllers/assets.rb', line 14

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

#call(env) ⇒ Object



9
10
11
12
# File 'lib/susanoo/controllers/assets.rb', line 9

def call(env)
  # Environment is a sprockets environment instance
  environment.call env
end