I just want to know how to include frameworks like angularjs, polymer js, bootstrap.... Into rails app without adding corresponding gems. Reason is the gems that are available are changing and some of them are given up. So instead of gem I want to download the library files given by the vendor directly. How to add them into rails app?
You can download the framework source files/folders, add them to your vendor folder and require those. Thats essentially what those gems do. If you're looking for a more advanced approach you can look into setting up a package manager like gulp and use the direct npm packages
Related
I'm working on a specific project where I have to write a SDK (kind of gem) on top of openid_connect gem. Currently my code consists of single file (but I'm also going to write some tests for it) and sample app which shows the use of SDK. Problem is that I cannot ship SDK as a rubygem as it has to be pushed to the same git repository as sample app. Client is going to use only SDK. SDK is a single class with methods in it.
My current approach is to write SDK in RubyOnRails /lib folder (but SDK has to work with other ruby frameworks as well) and let client download the SDK located inside sample app's lib folder.
1)Should my code go inside lib or vendor directory? Or there is some better approach?
2)How this code can be included in ruby app? Installed as a gem or included by require...
3)Can the tests go in the same folder as SDK (not in rails /test folder)?
1) It sounds like this code is not at all dependent on Rails. As such, do not create a Rails project for it. That would be adding ceremony and dependency that are unnecessary.
2) There is nothing wrong with having sample files in a gem's git repo. You can put them in a directory named samples or examples, for example.
3) To create a conventional gem directory structure, use bundle:
bundle gem my_gem_name
4) Your tests should go in a directory named test if they are Minitest, or spec if they are RSpec.
In Ruby on Rails, which is better for CSS and Javascript dependencies?
To install them as Gem or as Bower dependency? Such as jQuery and or Bootstrap?
It is better to install CSS frameworks like Bootstrap as a Gem. Here is my favorite Bootstrap installation guide: https://launchschool.com/blog/integrating-rails-and-bootstrap-part-1
jQuery is already included in the default Rails setup.
This is very much a personal preference. There are schools of thought that go both ways.
I haven't looked in a long time, but oftentimes the gems are usually behind the current release of front-end libraries.
UI portability is greater if you keep the frontend/backend logic completely separate. If you wanted to switch to another backend tomorrow, how long would it take?
Using gems is faster, and you have a single tool (bundler) to handle the depedencies.
I have avoided providing my personal preference in favor of a neutral post.
AS my opinion ....
rather than gem/bower, you should download files and integrate to project
like for bootstrap download bootstrap files
I have a project of Rails 4 integrated with bootstrap.
I use less-rails-bootstrap gem in order to integrate it.
I wonder what is the best way to integrate bootstrap into rails without using less (os sass). I assume I can simply download the css and js files as explained in the bootstrap site, but I wonder if i might have problems with it.
Yes, if you don't want to customize Bootstrap styles, you can simply download it from bootstrap site and put it under vendor folder.
And you won't have problems, since Rails will precompile the files (js/css/img) under vendor folder.
Make sure to read this answer if you add fonts too.
To include Angular in rails, I can think of three basic methods:
Use gem 'angularjs-rails' (which no one seems to do).
Download Angular, add it to /vendor and manually include it.
Use Bower to require it and then manually include.
I suppose the advantage of Bower is just the dependency model but apart from that, why would I pick any one of these over any of the other options?
A good approach is to use Rails Assets.
From their website:
Rails Assets is the frictionless proxy between Bundler and Bower.
It automatically converts the packaged components into gems that are
easily droppable into your asset pipeline and stay up to date.
I want to use googlecharts in my rails App, and I decided use it directly without using wrapper library.
Currently I download jsapi file from https://www.google.com/jsapi and rename it to jsapi.js, then move the file to vendor/javascripts/google/jsqpi.js.
Then require the file in application.js.
Now I can use the library I want only to know if this is a right way to use the third party library in rails.
Is there better way than this way?
That is perfectly acceptable. vendor/assets/javascripts is the correct location for third-party javascript files.
Sometimes you can find gems that include third-party javascript libraries and integrate them into the asset pipeline for you (e.g. jquery-ui-rails gem). This is nice because it makes you not responsible for handling the actual files and is easier on your version control software (a single line in your Gemfile vs entire files). You can also update the files with bundler. However, this tends to only be practical for really popular libraries. Sometimes you can find gems for the javascript library you are looking for, but the gem hasn't been updated in ages. Of course, you could always roll your own gem that includes the libraries you want.
Have you taken a look at googlecharts gem
its full of examples