Version 1
[yaffs-website] / vendor / twbs / bootstrap-sass / tasks / converter / js_conversion.rb
1 class Converter
2   module JsConversion
3     def process_javascript_assets
4       log_status 'Processing javascripts...'
5       save_to = @save_to[:js]
6       contents = {}
7       read_files('js', bootstrap_js_files).each do |name, file|
8         contents[name] = file
9         save_file("#{save_to}/#{name}", file)
10       end
11       log_processed "#{bootstrap_js_files * ' '}"
12
13       log_status 'Updating javascript manifest'
14       manifest = ''
15       bootstrap_js_files.each do |name|
16         name = name.gsub(/\.js$/, '')
17         manifest << "//= require ./bootstrap/#{name}\n"
18       end
19       dist_js = read_files('dist/js', %w(bootstrap.js bootstrap.min.js))
20       {
21           'assets/javascripts/bootstrap-sprockets.js' => manifest,
22           'assets/javascripts/bootstrap.js'           => dist_js['bootstrap.js'],
23           'assets/javascripts/bootstrap.min.js'       => dist_js['bootstrap.min.js'],
24       }.each do |path, content|
25         save_file path, content
26         log_processed path
27       end
28     end
29
30     def bootstrap_js_files
31       @bootstrap_js_files ||= begin
32         files = get_paths_by_type('js', /\.js$/).reject { |path| path =~ %r(^tests/) }
33         files.sort_by { |f|
34           case f
35             # tooltip depends on popover and must be loaded earlier
36             when /tooltip/ then
37               1
38             when /popover/ then
39               2
40             else
41               0
42           end
43         }
44       end
45     end
46   end
47 end