How to find the path a Ruby Gem is installed at (i.e. Gem.lib_path c.f. Gem.bin_path)
The problem with the checked answer is that you must "require" the rubygem or it won't work. Often this is undesireable because if you're working with an executable gem, you don't want to "require" it or you'll get a bunch of warnings.
This is a universal solution for executables and libs:
spec = Gem::Specification.find_by_name("cucumber")
gem_root = spec.gem_dir
gem_lib = gem_root + "/lib"
If you want to get really technical, there isn't just one lib directory. The gemspec has a "require_paths" array of all the directorys to search (added to $LOAD_PATH). So, if you want an array of the require_paths, use this:
gem_lib = gem_root + "/" + spec.require_paths[0]
No need for bundler.
Using Twitter Bootstrap for SASS without Rails or Compass
And now I want a script that does:
I'm not sure why you need this script at all. Cause if you can run the script you also can install sass and run sass css/application.scss css/application.css
. You can install all bootstrap's file in your site
folder by running bower install bootstrap-sass
and then run the sass
command with --load-path
option which should point to your bower_components
folder. You can also copy / or link the required javascripts and font from the bower_components
folder.
Or consider to use Gulp or Grunt to set up your build chain.
But you can use Sass programmatically indeed.
Process css/application.scss with SASS and outputs css/application.css.
Your script.rb should look something like that shown below:
/usr/bin/env ruby
require 'sass'
require 'bootstrap-sass'
sass_engine = Sass::Engine.for_file('css/application.scss',{
:style => :compact,
:syntax => :scss
})
output = sass_engine.render
File.open("css/application.css", 'w+') {|f| f.write(output) }
Notice that you also should have to integrate the autoprefixer.
Put the Bootstrap JavaScript I need into a single file in js/
After installing the bootstrap-sass gem you can read the javascript files from the gem (see: How to find the path a Ruby Gem is installed at (i.e. Gem.lib_path c.f. Gem.bin_path)).
So the get the content of the affix plugin you can use:
file = File.new(Gem::Specification.find_by_name("bootstrap-sass").gem_dir + "/assets/javascripts/bootstrap/affix.js", "r")
You you can read the required script, concatenate their content, minify and copy
If I'm using Bootstrap's icons, put the glyphicons fonts in fonts/.
As above, copy them from Gem::Specification.find_by_name("bootstrap-sass").gem_dir + "/assets/fonts
Related Topics
How to Emit Comments in a Yaml Document Using Psych
Preferred Way to Private Messages Modeling in Rails 3
Is It Idiomatic Ruby to Add an Assert( ) Method to Ruby's Kernel Class
How to Convert an Array of Strings into a Comma-Separated String
What Is the Meaning of "H" in "<%=H [ ...] %>"
Check If a Hash's Keys Include All of a Set of Keys
Force Bundle Install to Use Https:// Instead of Git:// for Github-Based Gems
How to Find the Path a Ruby Gem Is Installed at (I.E. Gem.Lib_Path C.F. Gem.Bin_Path)
What Does the "Yield" Keyword Do in Ruby
How to Unit-Test a JSON Controller
Undefined Method '>' for Nil:Nilclass <Nomethoderror>
Mongo - Ruby Connection Problem