== URB {}[http://travis-ci.org/archan937/urb] {}[https://codeclimate.com/github/archan937/urb] Shorten URLs in your Rack / Rails app. === Installation ==== Using Bundler Add URB in Gemfile as a gem dependency: gem "urb" Run the following in your console to install with Bundler: $ bundle install === Usage ==== Include urb.js Invoke the view helper method urb within your template: Killer App <%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %> <%= javascript_include_tag "application", "data-turbolinks-track" => true %> <%= csrf_meta_tags %> <%= urb %> ==== Add urb.js to the precompiled Rails assets You will need to add urb.js to the additional precompiled assets in the production and staging environment. (e.g. in config/environments/production.rb) # Precompile additional assets. # application.js, application.css, and all non-JS/CSS in app/assets folder are already added. config.assets.precompile += %w(urb.js) ==== Start opening URLs Click on links within your webpage or call the Javascript function URB.open(). URB will automatically shorten the URL when it refers to the application itself and exceeds URB::MAXLENGTH (which is 2000 characters). ==== URL storage The shortened URLs are stored using the {Moneta}[https://github.com/minad/moneta] gem. At default, they will be stored in memory. To store them within a database, configure URB with URB.configure (shortcut: URB) and the arguments will be forwarded to the Moneta constructor: (e.g. in config/initializers/u.rb) URB.config :ActiveRecord, :table => "urls", :connection => {:adapter => "mysql2", :database => "my_awesome_app", :user => "someone", :password => "letmypass"} or probably (e.g. in config/initializers/u.rb) URB :ActiveRecord, :table => "urls", :connection => ActiveRecord::Base.connection.instance_variable_get(:@config) The corresponding migration file should look like: class CreateUrls < ActiveRecord::Migration def change create_table :urls do |t| t.text :k t.text :v t.timestamps end end end You can try this out in the provided demo application. Do not forget to uncomment the last line in {config/initializers/u.rb}[https://github.com/archan937/urb/blob/master/demo/config/initializers/u.rb]. === Console and demo Rails app The URB repository is provided with a console which you can start with script/console. Also, you can run the provided Rails 4 demo application to try out URB in your browser. === Testing Run the following command for testing: $ rake === License Copyright (c) 2014 Paul Engel, released under the MIT license http://gettopup.com – http://github.com/archan937 – http://twitter.com/archan937 – {pm_engel@icloud.com}[mailto:pm_engel@icloud.com] Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.