Skip to content

Instantly share code, notes, and snippets.

@bittner
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bittner/9929210 to your computer and use it in GitHub Desktop.
Save bittner/9929210 to your computer and use it in GitHub Desktop.
Bootstrap-Sass JavaScript generation (combine + minify) using vanilla Compass
# Copyright 2014 Peter Bittner <django@bittner.it>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
system('uglifyjs --version')
unless $?.exitstatus == 0
puts "ERROR: UglifyJS v2 not found. Please install it using \`sudo npm install -g uglify-js'"
puts "See https://github.com/mishoo/UglifyJS2 for more information."
exit 1
end
unless defined? javascripts_dir
puts "ERROR: No 'javascripts_dir' defined. You should run this file with Compass (e.g. compass compile)."
puts "Usage: Place this file (javascript.rb) to your Compass project's folder, right" \
" next to config.rb. Then add the following lines at the end of your config.rb file:"
puts " # JavaScript generation"
puts ' javascripts_before = "jquery.js another_file_before_bs.js ..."'
puts ' javascripts_after = "file_after_bs.js another_file_after_bs.js ..."'
puts " eval(File.open(File.join(File.dirname(__FILE__), 'javascript.rb')).read)"
exit 1
end
# TODO
#. Find/compute: $(gemdir)/gems/$(bootstrap-sass-*)/vendor/assets/javascripts/bootstrap/
#. Detect/use: all .js files listed in bootstrap.js (javascripts_bootstrap = "affix dropdown scrollspy ...")
#. Run/execute: system("uglifyjs -o scripts.js #{javascripts_before} #{javascripts_bootstrap} #{javascripts_after}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment