chosen_assets 1.1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'http://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in chosen-rails.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (C) 2011-2014 by Tse-Ching Ho, Jonathan Rochkind
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,96 @@
1
+ # Chosen for rails asset pipeline
2
+
3
+ [Chosen](https://github.com/harvesthq/chosen) is a library for making long, unwieldy select boxes more user friendly.
4
+
5
+ The `chosen_assets` gem integrates the `Chosen` with the Rails asset pipeline.
6
+
7
+ **This is a fork of [chosen-rails](https://github.com/tsechingho/chosen-rails)**, this gem, `chosen_assets`, gets
8
+ already compiled .js and .css from the original chosen Github release (via the github api),
9
+ and thus has no dependencies on compass (or sass or coffeescript), it just gives you the already
10
+ compiled source.
11
+
12
+ ## Usage
13
+
14
+ ### Install chosen-rails gem
15
+
16
+ Include `chosen-rails` in Gemefile
17
+
18
+ gem 'chosen_assets'
19
+
20
+ Then run `bundle install`
21
+
22
+ ### Include chosen javascript assets
23
+
24
+ Add to your `app/assets/javascripts/application.js` if use with jQuery
25
+
26
+ //= require chosen.jquery
27
+
28
+ Or with Prototype
29
+
30
+ //= require chosen.prototype
31
+
32
+ ### Include chosen stylesheet assets
33
+
34
+ Add to your `app/assets/stylesheets/application.css`
35
+
36
+ *= require chosen
37
+
38
+ ### Enable chosen javascript by specific css class
39
+
40
+ Add to one coffee script file, like `scaffold.js.coffee`
41
+
42
+ $ ->
43
+ # enable chosen js
44
+ $('.chosen-select').chosen
45
+ allow_single_deselect: true
46
+ no_results_text: 'No results matched'
47
+ width: '200px'
48
+
49
+ Notice: `width` option is required since `Chosen 0.9.15`.
50
+
51
+ And this file must be included in `application.js`
52
+
53
+ //= require chosen.jquery
54
+ //= require scaffold
55
+
56
+ Also add the class to your form field
57
+
58
+ <%= f.select :author,
59
+ User.all.map { |u| [u.name, u.id] },
60
+ { include_blank: true },
61
+ { class: 'chosen-select' }
62
+ %>
63
+
64
+ If you use simple form as form builder
65
+
66
+ <%= f.association :author,
67
+ collection: User.all,
68
+ include_blank: true,
69
+ input_html: { class: 'chosen-select' }
70
+ %>
71
+
72
+
73
+ ## Gem maintenance
74
+
75
+ ### Update chosen source in `chosen-rails` gem with `Rake` commands.
76
+
77
+ Update origin chosen source files.
78
+
79
+ rake update-chosen
80
+
81
+ That will look for the latest release from chosen's github, download the
82
+ release zip, and copy assets into source. For css files, it also replaces
83
+ any url() references to use rails-sass asset-url().
84
+
85
+ If chosen is out of date, feel free to do this and make a pull request!
86
+
87
+ Versioning for `chosen_assets` tracks chosen version -- `chosen_assets 1.1.0.0`
88
+ uses chosen `1.1.0`, and is the first `chosen_assets` release of that chosen version.
89
+
90
+ ### Publish gem.
91
+
92
+ rake release
93
+
94
+ ## License
95
+
96
+ use MIT license.
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env rake
2
+ require 'bundler/gem_tasks'
3
+ require File.expand_path('../lib/chosen_assets/source_fetcher', __FILE__)
4
+
5
+ desc "Update with Chosen Library release files from github"
6
+ task 'update-chosen', 'github_repo', 'tag_name' do |task, args|
7
+ ChosenAssets::SourceFetcher.new(args['github_repo'], args['tag_name']).fetch
8
+
9
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/chosen_assets/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ['Jonathan Rochkind', 'Tse-Ching Ho']
6
+ gem.email = ['rochkind@jhu.edu']
7
+ gem.description = %q{Chosen is a javascript library of select box enhancer for jQuery and Protoype. This gem integrates Chosen with Rails asset pipeline for easy of use.}
8
+ gem.summary = %q{Integrate Chosen javascript library with Rails asset pipeline}
9
+ gem.homepage = 'https://github.com/jrochkind/chosen_assets'
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = 'chosen_assets'
15
+ gem.require_paths = ['lib']
16
+ gem.version = ChosenAssets::VERSION
17
+
18
+ gem.add_dependency 'railties', '>= 3.0'
19
+
20
+ gem.add_development_dependency 'bundler', '>= 1.0'
21
+ gem.add_development_dependency 'rails', '>= 3.0'
22
+ gem.add_development_dependency 'thor', '>= 0.14'
23
+ end
@@ -0,0 +1,11 @@
1
+ module ChosenAssets
2
+ class Engine < ::Rails::Engine
3
+ config.assets.precompile += %w(
4
+ chosen-sprite*.png
5
+ )
6
+
7
+ rake_tasks do
8
+ load 'chosen-rails/tasks.rake'
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ module ChosenAssets
2
+ class Engine3 < ::Rails::Engine
3
+ initializer 'chosen.assets.precompile' do |app|
4
+ app.config.assets.precompile += %w(
5
+ chosen-sprite*.png
6
+ )
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,4 @@
1
+ module ChosenAssets
2
+ class Railtie < ::Rails::Railtie
3
+ end
4
+ end
@@ -0,0 +1,68 @@
1
+ require 'thor'
2
+ require 'json'
3
+ require 'open-uri'
4
+
5
+ require 'rubygems/package'
6
+ require 'zlib'
7
+
8
+ class ChosenAssets::SourceFetcher
9
+ GithubRepo = 'harvesthq/chosen'
10
+
11
+ def initialize(github_repo, tag_name = nil)
12
+ @github_repo = github_repo || GithubRepo
13
+ @tag_name = tag_name
14
+ end
15
+
16
+ #desc 'fetch source files', 'fetch source files from GitHub'
17
+ def fetch
18
+ releases_data = JSON.load( open("https://api.github.com/repos/#{@github_repo}/releases") )
19
+ release = if @tag_name.nil?
20
+ releases_data.first
21
+ else
22
+ releases_data.find {|hash| hash["tag_name"] == @tag_name}
23
+ end
24
+
25
+ # We assume there's only one asset, and we want it
26
+ asset = release['assets'].first
27
+ asset_name = asset['name']
28
+
29
+ local_zip_path = "tmp/#{asset_name}"
30
+
31
+ open(local_zip_path, "wb") do |file|
32
+ # Need to send Accept application/octet-stream to github to get the binary
33
+ # http://developer.github.com/v3/repos/releases/#get-a-single-release-asset
34
+ file << open(asset['url'], "Accept" => "application/octet-stream").read
35
+ end
36
+
37
+ # We're just gonna shell out to the 'unzip' command, OSX and unix prob
38
+ # has it, good enough.
39
+ local_source_path = "tmp/#{asset_name.chomp(File.extname(asset_name))}.scss"
40
+ system("unzip", local_zip_path, "-d", local_source_path)
41
+
42
+ # Copy all the files over
43
+
44
+
45
+ Dir.glob("#{local_source_path}/*.css").each do |source|
46
+ dest = "vendor/assets/stylesheets/#{File.basename source}.scss"
47
+ puts "copy to #{dest}"
48
+ FileUtils.copy source, dest
49
+
50
+ # replace url() with asset-pipeline-aware scss asset-url()
51
+ content = File.read(dest)
52
+ content.gsub!(/ url\(([^)]+)\)/, ' asset-url(\\1, image)')
53
+ File.open(dest, 'wb') { |file| file.write(content) }
54
+ end
55
+
56
+ Dir.glob("#{local_source_path}/*.js").each do |source|
57
+ puts "copy to vendor/assets/javascripts/#{File.basename source}"
58
+ FileUtils.copy source, "vendor/assets/javascripts/#{File.basename source}"
59
+ end
60
+
61
+ Dir.glob("#{local_source_path}/*.{png,gif,jpg,jpeg}").each do |source|
62
+ puts "copy to vendor/assets/images/#{File.basename source}"
63
+ FileUtils.copy source, "vendor/assets/images/#{File.basename source}"
64
+ end
65
+
66
+
67
+ end
68
+ end
@@ -0,0 +1,11 @@
1
+ require 'fileutils'
2
+
3
+ desc 'Create nondigest versions of all chosen digest assets'
4
+ task 'assets:precompile' do
5
+ fingerprint = /\-[0-9a-f]{32}\./
6
+ Dir['public/assets/chosen-*'].each do |file|
7
+ next unless file =~ fingerprint
8
+ nondigest = file.sub fingerprint, '.'
9
+ FileUtils.cp file, nondigest, verbose: true
10
+ end
11
+ end
@@ -0,0 +1,4 @@
1
+ module ChosenAssets
2
+ VERSION = '1.1.0.0'
3
+ CHOSEN_VERSION = '1.1.0'
4
+ end
@@ -0,0 +1,13 @@
1
+ require 'chosen_assets/version'
2
+
3
+ module ChosenAssets
4
+ end
5
+
6
+ case ::Rails.version.to_s
7
+ when /^4/
8
+ require 'chosen_assets/engine'
9
+ when /^3\.[12]/
10
+ require 'chosen_assets/engine3'
11
+ when /^3\.[0]/
12
+ require 'chosen_assets/railtie'
13
+ end