How do I browse the source code for a gem in Rails3 with RVM (linux & gedit) - ruby-on-rails-3

I am running rails3 in Ubuntu and using gedit for coding. I am using RVM. To look at the gem source code I tried: bundle open jquery-rails
That doesn't work since I hadn't setup an editor. After setting gedit as the editor it still doesn't work because gedit can't be passed directories. I guess it only works with files. Too bad :(.
nathan.f77's answer to this question ( Lookup Gem or Plugin code packaged in a Rails3 application ) seems promising, but I wasn't able to follow his instructions. They lacked sufficient detail for me.
What is a very easy way to browse the source files for gems that I am using in my rails3 app?

bundle show jquery-rails should tell you where the gem source lives on your filesystem. Then open the file that you want.

CubaLibre's response got me half-way there. The other piece of the puzzle I was able to get from Ask Ubuntu.
Here are the steps to browse gem code in gedit using Ubuntu.
a. From the command line run:
gnome-open $(bundle show [gem-name])
b. This will open up the gem directory in nautilus. From there just double click on file you'd like to see and it will open up in gedit.

Assuming you have a default editor set in your terminal, on MacOS you can do something like this example (atom is my editor, but should work with sublime or textmate, vim, etc.):
atom $(bundle show name_of_gem)

Related

Use Haml files in Redmine plugin

I am creating a Redmine plugin and would like to use Haml for the view templates. There is an existing plugin which has Haml views (ekanban) and it does not contain any special code to get Haml working other then having you add require 'haml' to your main application's Gemfile.
So here is what happens -- the templating system loads the .html.haml file correctly but renders the HAML markup (like it was rendering ERB).
I've tried to insert the require 'haml' at various intervals to no avail. I've even tried manually trying to activate Haml.init_rails(...) as suggested in this SO question. I've tried inserting that in a few places, tried it in a Rails.configuration.to_prepare block in the plugins' init.rb file. I've tried telling the Gemfile to not require 'haml' and attempting to do it during plugin load to no avail. What gives?
The view template had Textile in it and I did not notice because the markup for <h2> is similar (h2. vs. %h2). Including gem 'haml_rails' in the plugin's Gemfile is sufficient with no extra code.
Read carefully Installation instruction for this gem :)
Add "gem 'haml'" to your #{RAILS_ROOT}/Gemfile
I can't agree with this strategy: plugin can't change Redmine core! Any Redmine plugin can have own gems (defined in own Gemfile) - so I think you can create Gemfile in your plugin, run bundle install from the Redmine root and I believe you will manage to use Haml

ShopifyAPI method list

I went trough the the shopifyApi documentation and it's explaining how to communicate with the API via post/put/get http verbs.
I am coding in Ruby and I was wondering where I could find a list of all the methods available (like product.add_metafield(params)).
I checked the gem server and didn't find any RDOC available for the api.
Thank you
Here is a neat trick. At your command-line try gem which shopify_api. That will list out the current version you are using for your current Ruby. Of course with RVM or RBEnv these vary wildly.
Copy and paste the result to your clipboard. An example from my CLI is:
/Users/fuzzy/.rvm/gems/ruby-1.9.3-p194/gems/shopify_api-3.0.1/lib/shopify_api.rb
You only need this part...
/Users/fuzzy/.rvm/gems/ruby-1.9.3-p194/gems/shopify_api-3.0.1/lib
With that in your clipboard, type subl or mate or vim or whatever your text editor is and paste in that path. You'll then have the gem at your disposal. If you navigate to the shopify_api/resources folder you'll see the product.rb file, showing off some methods you can use. You can see how most resources work this way. Learning Active Resource can also go a long way to showing off how the API gem provides functionality.
You can hack the gem once you get past this stage of exploration. You can re-open the modules and classes and add your own methods. Pretty neat stuff.
The command line interface based on Thor is also in there, and worth a good look. That is one of the coolest aspects of the gem in my opinion. see shopify_api/cli.rb

How to use WKhtmltopdf Library without using executable

In ruby on rails project.
I am using PDFKit gem for generating pdf reports
PDFKit uses wkhtmltopdf executable which is to be installed on the machine .
And next step to give the path of the executable .
I dont want to use the executable file .because if i use it how to deploy it on server .
the server will need to install it on its local and give the path.
Is it possible to use only library????
The executable is used to wrap the underlying Qt app, so it's technically possible to wrap the library in a gem (using ffi or some other similar lib) but I never heard anybody doing it.
I'm myself bundling the executable with my Rails app, to ship both at once when I deploy (even on Heroku).
To do the same, you can put the binary file in directory (you can call it bin), and configure PDFKit to get the executable where it's at using PDFKit.configure in an initializer for instance (you might wanna check the README).

how to include third party gems like 'spree' in Vendor folder

I am using gem 'spree'. when i install it, it gets installed inside the particular bundler. (I am using rvm).
Problem:
I want to modify the gem according to my needs, so its better if its located inside the Vendor folder of my current project.
Should i do something like copy paste?
You could do this by giving the path to the gem.
It would be something like this gem 'spree' -> /vendor/

Unpack refinery gems in rails project

I tried rake gem:unpack but I get task not found. I would like to have refinery gems in my /vendor directory to be able to see the never ending views and partials and may be modify them.
I'm still learning how to do things the "Rails way", but I feel your need to have the files in a directory that's easy to see. One command I found that will dump in vendor in the local project is bundle install --deployment. You'll need to run this after initially doing a bundle install.
run bundle package
more here: http://gembundler.com/bundle_package.html