Importing Node Modules in to Rails - ruby-on-rails

I'm working with Jasmine. I spotted this handy looking library: https://github.com/JamieMason/Jasmine-Matchers and I thought its collection of customer matchers would help me a lot.
Problem is, it's loaded with files common to Node applications, such as JSHint, Grunt, travis.yml etc
The project I'm working on, that would love these matchers, is a Rails application. I've tried dropping them into my assets/javascripts and requiring in application.js, but obviously, life isn't that simple.
What is the correct way to install these files, and integrate them with Jasmine in a Rails context? Is Bower the tool for the job? If so, what's the right procedure to adding JS dependencies/integrating them off the bat?

Author of Jasmine-Matchers here, the only file you need to load into your test environment is this one https://github.com/JamieMason/Jasmine-Matchers/blob/master/dist/jasmine-matchers.js.
The other files are part of the development repo, I'll open an issue to have those excluded from npm/bower packages to save confusion.
You should be able to copy that file to your assets/javascripts directory, then embed it after Jasmine but before your tests.
Please comment if I've missed anything out here.

I was also trying to use Node modules inside my Rails application and the easiest way I found to achieve it was through browserify-rails gem.
The installation is pretty straightforward, just follow the getting started section and everything should be working. :-)

Related

How to deploy angulardart 5.2 properly for production?

on the angulardart official website, I can not find any docs related to production deployment. I prefer command line way, so far I find out I can do webdev build to generate a build/ directory. But there are still some more questions:
I want to clarify what files I should deploy to the production server. I think they should be favicon.ico, index.html, main.dart.js, styles.css 4 files, right?
Why does it generate .build.manifest, .packages, packages/? two files and one directory which contains many directories and files. They are just confusing me. This is for production. Why do I ever want to have those files? Should I write a deploy script to simply auto-remove them?
It seems the generated main.dart.js is a minimized js file. But why are there many useless newlines in it? How to get rid of those useless newlines properly by using angulardart way? I can do that with gulp, but I don't want to use gulp if dart can handle this.
How to minimize html and css files properly by using angulardart way? for example, index.html and styles.css. Again, I can do that with gulp, but I don't want to use gulp if dart can handle this.
Thank you very much for your help.
Here you can find some of official doc :
https://webdev.dartlang.org/angular/guide/deployment

How can I change the default path to the `rails` script in my project, or remove that dependency?

In another question (Why does the Rails command force a help message for the new command?), I found that Rails needs the rails script to be in the script folder, in the root of my project, in order for it to be properly detected as an existing Rails projects, and allow me to use the various rails commands other then new.
I did this because I felt that the more popular moniker for including executable content in a repository to highlight available use cases is by using the name scripts. At least the pluralism in English should be appreciated!
Is there anyway to change which folder the main Rails executable looks for the project-included one?
I actually think it's a bit silly to include this rails executable in the project, and can be redundant. Maybe it's for customization, but I feel that could better be done in the configuration, environment, other .rb files. So also, could this just be removed somehow, and still have a functioning project through varied use of the main rails command.

Grunt and Rails

I'm working on using a Grunt workflow to manage my assets in my Rails app rather than Sprockets.
So far, I have my apps JS and CSS both being concatenated and minified into public/assets/javascripts/application.js and public/assets/stylesheets/application.css respectively.
And also have my Bower components JS and CSS being concatenated and minified into public/assets/javascripts/vendor.js and public/assets/stylesheets/vendor.css respectively.
Fonts and Images from Bower components are then copied into public/assets/(images|fonts).
This is all well and good but now I need the references to fonts/images within those files to be updated to reflect their new location.
I have looked at cssmin and yes it rewrites file references but I cannot get the file path to change depending upon the type of file being referenced.
Any ideas on how I can do this?
Also, I ahve been reading about Grunt plugins which can read your view files and use those to minify and concatenate files and update the and tags in the views for you.
Surely I can't do that in a Rails app? Is there a way I can deal with this in Rails?
This other StackOverflow post may be of help:
Integrate Grunt into Rails asset pipeline
The accepted answer recommends using the Half Pipe gem.
The second answer linked to a blog post about a Do-It Yourself solution: Goodbye, Sprockets! A Grunt-based Rails Asset Pipeline.
I haven't used either solution, but they are worth a try.

Using CodeKit 2 with Wordpress/Bootstrap via Bower

This may be a really dumb question but I've been searching the interwebs and haven't really found much helpful information. I have CodeKit 2 and I want to use Wordpress and Bootstrap in a project. I've never used Bower before but it looks really cool and I thought I'd give it a shot with CodeKit. I installed Wordpress, JQuery, and Bootstrap through the assets tab in my project and they installed into bower_components. In the video from Bryan Jones showing off Bower, he says not to move anything out of that folder or CodeKit won't see it as an asset anymore.
So my question is: how do I go about building my project from here? Obviously I don't want to have to run from the bower_components folder to do everything. In the Bower docs it says the easiest way is to just statically link the components you want. But I don't really understand how that would work with Wordpress and it seems like there'd be a better way to do it with CodeKit.
Thanks for the help!
There is no need to use Bower to manage wordpress, since wordpress can update itself very easily.
I think the best approach to building a WP site with Codekit is described in this tutorial: Use CodeKit 2.0 for Local WordPress Development.
Basically:
setup wordpress locally, any way you like, and use MAMP or AMPPS to serve the site.
drag your theme folder into Codekit - the theme is the project.
In the Browser Refreshing section of your project settings, use the external server option. Paste in the local URL for your new WP site.
Here's an article with some details.
Basically you just need to install bootstrap.less and variables.less in your /less folder, and then point your #import commands to your /bower_components folder. While you technically are running things out of /bower_components, after it's set up, you'll never know the difference.
The most useful thing about having wordpress connected to Bower is that you can just get the files downloaded quickly without having to grab the latest zip.
It makes sense to move the wordpress files to the top level, or where ever you are used to putting them.

Why is there Rails.rb files all over the place?

Was digging around my Rails applications and noticed that there are rails.rb files all over the place. In my ruby gems directories like:
...gems\devise-2.0.4\lib\devise\rails.rb
...gems\cucumber-rails-1.3.0\lib\cucumber\rails.rb
...gems\railties-3.2.3\lib\rails.rb
I am assuming that there are executed whenever you issue some command like "rails xxx". So all these extra rails.rb files combine with the original rails.rb file to essentially make one big rails.rb file. Essentially, when we type in "rails xxx" it goes thru all them all?
Just looking for some confirmation PLUS a little more knowledge about this. Thanks.
The best way to understand what these rails.rb files are doing, is to read the source code.
ralties
devise
cucumber-rails
As you can see, in any library the file assumes a different scope. The common behaviour is that the file rails.rb normally contains the code required to initialize the library when loaded from a Rails project.
BTW, this has nothing to do with the script/rails command and there is no "big rails.rb" file.
The files are not generated but are simply source files of these libraries you are using.
In this case they are probably rails-related classes that either extend Rails in some way or modify it or make the library interact with Rails.
Rails is a very common framework in Ruby land so most if not all libraries will have some sort of integration with Rails.
By no means are all of those loaded when you run rails XXX but rather when your application loads these libraries their rails.rb files may be executed to provide some sort of integration with Rails.

Resources