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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# 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')
  @environment.append_path File.join(project_root,
                               'src/assets/sounds')

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

  unless Susanoo::Project.debug
    @environment.js_compressor  = :uglify
    @environment.css_compressor = :scss
  end

  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

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

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

  if File.exist? File.join(project_root,
                           'src/assets/videos')
    generator.say_status 'copy', 'src/assets/videos'
    `cp #{project_root}/src/assets/videos #{project_root}/www/assets/videos -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