diff --git a/README.md b/README.md index a9de14a..43f86bc 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,46 @@ -# Cdnjs::Rails +# [cdnjs](http://cdnjs.com) helpers for Rails apps -TODO: Write a gem description +This gem adds view helpers to Ruby on Rails applications that embed javascripts +and stylesheets directly from [cdnjs](http://cdnjs.com) ## Installation Add this line to your application's Gemfile: - - gem 'cdnjs-rails' +```ruby +gem 'cdnjs-rails' +``` And then execute: - - $ bundle - -Or install it yourself as: - - $ gem install cdnjs-rails +``` +$ bundle +``` ## Usage -TODO: Write usage instructions here +From view files +``` + + + Hello World! + <%= stylesheet_cdnjs_tag 'normalize' %> + + + <%= yield %> + <%= javascript_cdnjs_tag 'jquery', version: '2.0.3', protocol: 'https' %> + + +``` + +From anywhere in the app +```ruby +CdnjsRails.package_url('chosen', v: '0.9.10', proto: 'http') +``` + +## Options + +`version` (aliases: `ver`, `v`): package version, latest by default + +`protocol` (alias: `proto`): url protocol, relative by default ## Contributing diff --git a/Rakefile b/Rakefile index ac65e4a..9891e30 100644 --- a/Rakefile +++ b/Rakefile @@ -22,10 +22,10 @@ namespace :cdnjs do } end.inject(:merge) - # Format JSON for better diffs and smaller patches + # Pretty format JSON for better diffs and smaller patches json = MultiJson.dump(data, :pretty => true) - File.open(file_path, 'wb') do |file| + File.open file_path, 'wb' do |file| file.write json file.close end diff --git a/lib/cdnjs_rails/view_helpers.rb b/lib/cdnjs_rails/view_helpers.rb index 57de9bc..c9829a7 100644 --- a/lib/cdnjs_rails/view_helpers.rb +++ b/lib/cdnjs_rails/view_helpers.rb @@ -1,11 +1,11 @@ module CdnjsRails module ViewHelpers - def javascript_cdnjs_tag name, version = nil - javascript_include_tag CdnjsRails.package_url(name, version) + def javascript_cdnjs_tag name, options = {} + javascript_include_tag CdnjsRails.package_url(name, options) end - def stylesheet_cdnjs_tag name, version = nil - stylesheet_include_tag CdnjsRails.package_url(name, version) + def stylesheet_cdnjs_tag name, options = {} + stylesheet_include_tag CdnjsRails.package_url(name, options) end end end