jquery_corpus 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,23 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
22
+ tmp
23
+ public
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Tse-Ching Ho
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,41 @@
1
+ = jquery_corpus
2
+
3
+ Manage jQuery and it's plugins for Rails 3 applications.
4
+
5
+ Rails and jQuery are both awesome framework for web developers. It's annoying to setup the groundwork manually, we require some handy scripts and rails 3 generators will help this quit easier. This gem will collect useful and popular jqeury plugins and provide a reliable way to manage it via rails 3 generator.
6
+
7
+ == Requirements
8
+
9
+ * Rubygem >= 1.3.6
10
+ * Rails >= 3.0.0.beta
11
+
12
+ == Installation
13
+
14
+ Edit your Gemfile, and add:
15
+
16
+ gem 'jquery_corpus'
17
+
18
+ Use bundler to install:
19
+
20
+ bundle install
21
+
22
+ == Usage
23
+
24
+ You can use `rails generate` to check the available generators under "jquery" namespace, and use them like:
25
+
26
+ rails generate jquery:ui 1.8rc3
27
+ rails generate jquery:colorbox
28
+
29
+ == Note on Patches/Pull Requests
30
+
31
+ * Fork the project.
32
+ * Make your feature addition or bug fix.
33
+ * Add tests for it. This is important so I don't break it in a
34
+ future version unintentionally.
35
+ * Commit, do not mess with rakefile, version, or history.
36
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
37
+ * Send me a pull request. Bonus points for topic branches.
38
+
39
+ == Copyright
40
+
41
+ Copyright (c) 2010 Tse-Ching Ho. See LICENSE for details.
@@ -0,0 +1,60 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "jquery_corpus"
8
+ gem.summary = %Q{Manage jQuery and it's plugins for Rails 3 applications.}
9
+ gem.description = %Q{This gem will collect useful and popular jqeury plugins and provide a reliable way to manage it via rails 3 generator.}
10
+ gem.email = "tsechingho@gmail.com"
11
+ gem.homepage = "http://github.com/tsechingho/jquery_corpus"
12
+ gem.authors = ["Tse-Ching Ho"]
13
+ #gem.add_dependency "rubygem", ">= 1.3.6"
14
+ #gem.add_dependency "rails", ">= 3.0.0.beta"
15
+ gem.add_development_dependency "rspec", ">= 2.0.0.beta.3"
16
+ gem.add_development_dependency "cucumber", ">= 0.6.3"
17
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
18
+ end
19
+ Jeweler::GemcutterTasks.new
20
+ rescue LoadError
21
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
22
+ end
23
+
24
+ begin
25
+ require 'rspec/core/rake_task'
26
+ Rspec::Core::RakeTask.new(:spec)
27
+ Rspec::Core::RakeTask.new(:rcov) do |spec|
28
+ spec.rcov = true
29
+ end
30
+ task :spec => :check_dependencies
31
+ rescue LoadError
32
+ task :spec do
33
+ abort "Rspec is not available. In order to run specs, you must: [sudo] gem install Rspec"
34
+ end
35
+ end
36
+
37
+ begin
38
+ require 'cucumber/rake/task'
39
+ Cucumber::Rake::Task.new(:features)
40
+ task :features => :check_dependencies
41
+ rescue LoadError
42
+ task :features do
43
+ abort "Cucumber is not available. In order to run features, you must: [sudo] gem install cucumber"
44
+ end
45
+ end
46
+
47
+ task :default => :spec
48
+
49
+ begin
50
+ require 'rake/rdoctask'
51
+ Rake::RDocTask.new do |rdoc|
52
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
53
+ rdoc.rdoc_dir = 'rdoc'
54
+ rdoc.title = "jquery_corpus #{version}"
55
+ rdoc.rdoc_files.include('README*')
56
+ rdoc.rdoc_files.include('lib/**/*.rb')
57
+ end
58
+ rescue Exception
59
+ puts "Rake is not available. In order to run rdoc, you must: [sudo] gem install rake"
60
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,9 @@
1
+ Feature: something something
2
+ In order to something something
3
+ A user something something
4
+ something something something
5
+
6
+ Scenario: something something
7
+ Given inspiration
8
+ When I create a sweet new gem
9
+ Then everyone should see how awesome I am
@@ -0,0 +1,4 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
2
+ require 'jquery_corpus'
3
+
4
+ require 'spec/expectations'
@@ -0,0 +1,72 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{jquery_corpus}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Tse-Ching Ho"]
12
+ s.date = %q{2010-03-10}
13
+ s.description = %q{This gem will collect useful and popular jqeury plugins and provide a reliable way to manage it via rails 3 generator.}
14
+ s.email = %q{tsechingho@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "features/jquery_corpus.feature",
27
+ "features/step_definitions/jquery_corpus_steps.rb",
28
+ "features/support/env.rb",
29
+ "jquery_corpus.gemspec",
30
+ "lib/generators/jquery.rb",
31
+ "lib/generators/jquery/colorbox/USAGE",
32
+ "lib/generators/jquery/colorbox/colorbox_generator.rb",
33
+ "lib/generators/jquery/ui/USAGE",
34
+ "lib/generators/jquery/ui/templates/application.html.erb",
35
+ "lib/generators/jquery/ui/templates/jquery.rb",
36
+ "lib/generators/jquery/ui/ui_generator.rb",
37
+ "lib/jquery_corpus.rb",
38
+ "spec/generators/colorbox_generator_spec.rb",
39
+ "spec/generators/ui_generator_spec.rb",
40
+ "spec/jquery_corpus_spec.rb",
41
+ "spec/spec.opts",
42
+ "spec/spec_helper.rb"
43
+ ]
44
+ s.homepage = %q{http://github.com/tsechingho/jquery_corpus}
45
+ s.rdoc_options = ["--charset=UTF-8"]
46
+ s.require_paths = ["lib"]
47
+ s.rubygems_version = %q{1.3.6}
48
+ s.summary = %q{Manage jQuery and it's plugins for Rails 3 applications.}
49
+ s.test_files = [
50
+ "spec/generators/colorbox_generator_spec.rb",
51
+ "spec/generators/ui_generator_spec.rb",
52
+ "spec/jquery_corpus_spec.rb",
53
+ "spec/spec_helper.rb"
54
+ ]
55
+
56
+ if s.respond_to? :specification_version then
57
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
58
+ s.specification_version = 3
59
+
60
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
61
+ s.add_development_dependency(%q<rspec>, [">= 2.0.0.beta.3"])
62
+ s.add_development_dependency(%q<cucumber>, [">= 0.6.3"])
63
+ else
64
+ s.add_dependency(%q<rspec>, [">= 2.0.0.beta.3"])
65
+ s.add_dependency(%q<cucumber>, [">= 0.6.3"])
66
+ end
67
+ else
68
+ s.add_dependency(%q<rspec>, [">= 2.0.0.beta.3"])
69
+ s.add_dependency(%q<cucumber>, [">= 0.6.3"])
70
+ end
71
+ end
72
+
@@ -0,0 +1,39 @@
1
+ require 'rails/generators/named_base'
2
+
3
+ module Jquery
4
+ module Generators
5
+ class Base < Rails::Generators::Base
6
+ def self.source_root
7
+ @_jquery_source_root ||= begin
8
+ if base_name && generator_name
9
+ File.expand_path(File.join(base_name, generator_name, 'templates'), File.dirname(__FILE__))
10
+ end
11
+ end
12
+ end
13
+
14
+ protected
15
+
16
+ def self.banner
17
+ "rails generate #{namespace} #{self.arguments.map{ |a| a.usage }.join(' ')} [options]"
18
+ end
19
+
20
+ def readme(file_name)
21
+ file_path = File.expand_path(file_name, self.class.source_root)
22
+ say File.exist?(file_path) ? File.read(file_path) : nil
23
+ end
24
+
25
+ # always relative to current path (Rails.root)
26
+ def app_tmp_path
27
+ 'tmp/jquery'
28
+ end
29
+
30
+ def app_root_path
31
+ defined?(Rails) && Rails.respond_to?(:root) ? Rails.root : Dir.pwd
32
+ end
33
+
34
+ def expand_app_path(file)
35
+ File.expand_path(file, app_root_path)
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,18 @@
1
+ Description:
2
+ Install colorbox directly from internet (http://colorpowered.com/colorbox).
3
+ Or You could provide local zip file with --zip option like:
4
+
5
+ --zip=./colorbox.zip
6
+ --zip=/Users/foo/colorbox.zip
7
+ --zip=~/colorbox.zip
8
+
9
+ Please note that this zip file will NOT be deleted after installation.
10
+
11
+ ColorBox: A light-weight, customizable lightbox plugin for jQuery 1.3 and 1.4
12
+
13
+ Example:
14
+ rails generate jquery:colorbox
15
+
16
+ This will create:
17
+ public/javascripts/jquery.colorbox.js
18
+
@@ -0,0 +1,49 @@
1
+ require 'generators/jquery'
2
+
3
+ module Jquery
4
+ module Generators
5
+ class ColorboxGenerator < Base
6
+ class_option :zip, :desc => 'The absolute path of zip file'
7
+ class_option :clean, :default => false, :desc => "Clean up tmp directory"
8
+
9
+ def fetch_colorbox_files
10
+ empty_directory app_tmp_path
11
+ inside(app_tmp_path) do
12
+ get "#{download_path}/#{zip_file}", zip_file unless File.exists? zip_file
13
+ run "unzip #{zip_file} -d .", :verbose => false
14
+ end
15
+ end
16
+
17
+ def copy_javascript_files
18
+ Dir.glob("#{unzip_path}/colorbox/jquery.*-min.js").each do |js_file|
19
+ source_file = expand_app_path(js_file) # jquery.colorbox-min.js
20
+ copy_file source_file, 'public/javascripts/jquery.colorbox.js'
21
+ end
22
+ end
23
+
24
+ def delete_tmp_files
25
+ in_root do
26
+ if options[:clean]
27
+ run "rm -rf #{app_tmp_path}", :verbose => false
28
+ else
29
+ run "rm -rf #{unzip_path}", :verbose => false
30
+ end
31
+ end
32
+ end
33
+
34
+ protected
35
+
36
+ def download_path
37
+ "http://colorpowered.com/colorbox"
38
+ end
39
+
40
+ def zip_file
41
+ options[:zip] || "colorbox.zip"
42
+ end
43
+
44
+ def unzip_path
45
+ "#{app_tmp_path}/colorbox"
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,35 @@
1
+ Description:
2
+ Install jquery-ui directly from internet (http://jqueryui.com/download).
3
+ Or You could provide customized jquery-ui zip file downloaded from
4
+ http://jqueryui.com/download with --zip option like:
5
+
6
+ --zip=./jquery-ui-version.custom.zip
7
+ --zip=/Users/foo/custom.zip
8
+ --zip=~/custom.zip
9
+
10
+ Please note that this zip file will NOT be deleted after installation.
11
+
12
+ Example:
13
+ rails generate jquery:ui 1.8rc3
14
+
15
+ This will create:
16
+ app/views/layouts/application.html.erb
17
+ config/initializers/jquery.rb
18
+ public/javascripts/jquery.js
19
+ public/javascripts/jquery-ui.js
20
+ public/javascripts/rails.js
21
+ public/stylesheets/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png
22
+ public/stylesheets/smoothness/images/ui-bg_flat_75_ffffff_40x100.png
23
+ public/stylesheets/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png
24
+ public/stylesheets/smoothness/images/ui-bg_glass_65_ffffff_1x400.png
25
+ public/stylesheets/smoothness/images/ui-bg_glass_75_dadada_1x400.png
26
+ public/stylesheets/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png
27
+ public/stylesheets/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png
28
+ public/stylesheets/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png
29
+ public/stylesheets/smoothness/images/ui-icons_222222_256x240.png
30
+ public/stylesheets/smoothness/images/ui-icons_2e83ff_256x240.png
31
+ public/stylesheets/smoothness/images/ui-icons_454545_256x240.png
32
+ public/stylesheets/smoothness/images/ui-icons_888888_256x240.png
33
+ public/stylesheets/smoothness/images/ui-icons_cd0a0a_256x240.png
34
+ public/stylesheets/smoothness/jquery-ui.css
35
+
@@ -0,0 +1,28 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title><%= Rails.application.class.name.split('::').first %>: <%= controller.action_name %></title>
5
+ <%= stylesheet_link_tag 'scaffold', 'smoothness/jquery-ui' %>
6
+ <%= csrf_meta_tag %>
7
+ </head>
8
+ <body>
9
+
10
+ <p class="notice"><%= notice %></p>
11
+
12
+ <%- flash.each do |name, msg| -%>
13
+ <%= content_tag :div, msg, :id => "flash_#{name}" if msg.is_a?(String) %>
14
+ <%- end if flash -%>
15
+
16
+ <% if user_signed_in? -%>
17
+ <div id="user_login_box" style="float:right">
18
+ <%= current_user.email %> |
19
+ <%= link_to 'My info', edit_user_registration_path %> |
20
+ <%= link_to 'Sign out', destroy_user_session_path %>
21
+ </div>
22
+ <% end -%>
23
+
24
+ <%= yield %>
25
+
26
+ <%= javascript_include_tag :defaults %>
27
+ </body>
28
+ </html>
@@ -0,0 +1,9 @@
1
+ # Switch the javascript_include_tag :defaults to use jquery instead of
2
+ # the default prototype helpers.
3
+ if ActionView::Helpers::AssetTagHelper.const_defined?(:JAVASCRIPT_DEFAULT_SOURCES)
4
+ ActionView::Helpers::AssetTagHelper.send(:remove_const, "JAVASCRIPT_DEFAULT_SOURCES")
5
+ end
6
+ ActionView::Helpers::AssetTagHelper::JAVASCRIPT_DEFAULT_SOURCES = [
7
+ 'jquery', 'jquery-ui', 'rails'
8
+ ]
9
+ ActionView::Helpers::AssetTagHelper::reset_javascript_include_default
@@ -0,0 +1,89 @@
1
+ require 'generators/jquery'
2
+
3
+ module Jquery
4
+ module Generators
5
+ class UiGenerator < Base
6
+ argument :version, :type => :string
7
+ class_option :zip, :desc => 'The absolute path of zip file'
8
+ class_option :clean, :default => false, :desc => "Clean up tmp directory"
9
+
10
+ def fetch_jquery_ui_files
11
+ empty_directory app_tmp_path
12
+ inside(app_tmp_path) do
13
+ get "#{download_path}/#{zip_file}", zip_file unless File.exists? zip_file
14
+ run "unzip #{zip_file} -d #{unzip_folder}", :verbose => false
15
+ end
16
+ end
17
+
18
+ def fetch_rails_jquery_ujs_file
19
+ get 'http://github.com/rails/jquery-ujs/raw/master/src/rails.js', 'public/javascripts/rails.js'
20
+ end
21
+
22
+ # http://code.google.com/apis/ajaxlibs/documentation/
23
+ def copy_javascript_files
24
+ Dir.glob("#{unzip_path}/js/jquery-*.min.js").each do |js_file|
25
+ source_file = expand_app_path(js_file)
26
+ if js_file =~ /-ui-.+\.custom/ # jquery-ui-VERSION.custom.js
27
+ copy_file source_file, 'public/javascripts/jquery-ui.js'
28
+ else # jquery-VERSION.js
29
+ copy_file source_file, 'public/javascripts/jquery.js'
30
+ end
31
+ end
32
+ end
33
+
34
+ def copy_stylesheet_files
35
+ Dir.glob("#{unzip_path}/css/**/*").each do |css_file|
36
+ source_file = expand_app_path(css_file)
37
+ target_file = css_file.sub("#{unzip_path}/css", 'public/stylesheets')
38
+ if File.directory? source_file
39
+ empty_directory target_file
40
+ elsif source_file =~ /\.png$/ # images/*.png
41
+ copy_file source_file, target_file
42
+ elsif source_file =~ /\.css$/ # jquery-ui-VERSION.custom.css
43
+ copy_file source_file, target_file.sub(/-ui-.+\.css$/, '-ui.css')
44
+ end
45
+ end
46
+ end
47
+
48
+ def create_initializer_file
49
+ copy_file 'jquery.rb', 'config/initializers/jquery.rb'
50
+ end
51
+
52
+ def create_application_layout_file
53
+ copy_file 'application.html.erb', 'app/views/layouts/application.html.erb'
54
+ end
55
+
56
+ def delete_tmp_files
57
+ in_root do
58
+ if options[:clean]
59
+ run "rm -rf #{app_tmp_path}", :verbose => false
60
+ else
61
+ run "rm -rf #{unzip_path}", :verbose => false
62
+ end
63
+ end
64
+ end
65
+
66
+ def show_readme
67
+ readme 'README'
68
+ end
69
+
70
+ protected
71
+
72
+ def download_path
73
+ "http://jqueryui.com/download"
74
+ end
75
+
76
+ def zip_file
77
+ options[:zip] || "jquery-ui-#{version}.custom.zip"
78
+ end
79
+
80
+ def unzip_folder
81
+ "ui"
82
+ end
83
+
84
+ def unzip_path
85
+ "#{app_tmp_path}/#{unzip_folder}"
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,5 @@
1
+ module JqueryCorpus
2
+ def self.version
3
+ '0.0.0'
4
+ end
5
+ end
@@ -0,0 +1,84 @@
1
+ #require File.expand_path('../../spec_helper', __FILE__)
2
+ require 'spec_helper'
3
+ require 'generators/jquery/colorbox/colorbox_generator'
4
+
5
+ describe Jquery::Generators::ColorboxGenerator do
6
+ before do
7
+ @destination = File.join('tmp', 'test_app')
8
+ @source = Jquery::Generators::ColorboxGenerator.source_root
9
+ @generator = Jquery::Generators::ColorboxGenerator.new(
10
+ [], {}, {:destination_root => @destination}
11
+ )
12
+ @app_tmp_path = "tmp/jquery"
13
+ @unzip_path = "#{@app_tmp_path}/colorbox"
14
+ end
15
+
16
+ after do
17
+ FileUtils.rm_rf(@destination)
18
+ end
19
+
20
+ it "fetch colorbox files from remote" do
21
+ zip_file = "colorbox.zip"
22
+ download_path = "http://colorpowered.com/colorbox"
23
+ @generator.options[:zip].should be_nil
24
+ @generator.should_receive(:empty_directory).with(@app_tmp_path).and_return(true)
25
+ File.should_receive(:exists?).with(zip_file).and_return(false)
26
+ @generator.should_receive(:get).with("#{download_path}/#{zip_file}", zip_file).and_return(true)
27
+ @generator.should_receive(:run).with("unzip #{zip_file} -d .", :verbose => false).and_return(true)
28
+ @generator.fetch_colorbox_files
29
+ end
30
+
31
+ it "fetch colorbox files from local" do
32
+ zip_file = "my_colorbox.zip"
33
+ @generator = Jquery::Generators::ColorboxGenerator.new(
34
+ [], {:zip => zip_file}, {:destination_root => @destination}
35
+ )
36
+ @generator.options[:zip].should_not be_nil
37
+ @generator.options[:zip].should == zip_file
38
+ @generator.should_receive(:empty_directory).with(@app_tmp_path).and_return(true)
39
+ # @generator.stub!(:empty_directory).with(@app_tmp_path).and_return(true)
40
+ File.should_receive(:exists?).with(zip_file).and_return(true)
41
+ @generator.should_not_receive(:get)
42
+ @generator.should_receive(:run).with("unzip #{zip_file} -d .", :verbose => false).and_return(true)
43
+ @generator.invoke :fetch_colorbox_files
44
+ end
45
+
46
+ it "copy javascript files" do
47
+ glob_string = "#{@unzip_path}/colorbox/jquery.*-min.js"
48
+ source_files = ["#{@unzip_path}/colorbox/jquery.colorbox-min.js"]
49
+ target_files = ['public/javascripts/jquery.colorbox.js']
50
+ Dir.should_receive(:glob).with(glob_string).and_return(source_files)
51
+ @generator.should_receive(:expand_app_path).with(source_files[0]).and_return(source_files[0])
52
+ @generator.should_receive(:copy_file).with(source_files[0], target_files[0]).and_return(true)
53
+ @generator.copy_javascript_files
54
+ end
55
+
56
+ it "delete tmp files without zip file" do
57
+ @generator.options[:clean].should be_nil
58
+ @generator.should_receive(:run).with("rm -rf #{@unzip_path}", :verbose => false)
59
+ @generator.delete_tmp_files
60
+ end
61
+
62
+ it "delete tmp files with zip file" do
63
+ @generator = Jquery::Generators::ColorboxGenerator.new(
64
+ [], {:clean => true}, {:destination_root => @destination}
65
+ )
66
+ @generator.options[:clean].should_not be_nil
67
+ @generator.options[:clean].should be_true
68
+ @generator.should_receive(:run).with("rm -rf #{@app_tmp_path}", :verbose => false)
69
+ @generator.delete_tmp_files
70
+ end
71
+
72
+ it "should go through all tasks" do
73
+ @generator.should_receive(:fetch_colorbox_files).and_return(true)
74
+ @generator.should_receive(:copy_javascript_files).and_return(true)
75
+ @generator.should_receive(:delete_tmp_files).and_return(true)
76
+ @generator.invoke
77
+ end
78
+
79
+ it "do real work" do
80
+ # Jquery::Generators::ColorboxGenerator.start('', :destination_root => @destination)
81
+ # File.directory?(File.join(@app_tmp_path)).should be_true
82
+ # File.exist?(File.join(@app_tmp_path, 'colorbox.zip')).should be_true
83
+ end
84
+ end
@@ -0,0 +1,151 @@
1
+ #require File.expand_path('../../spec_helper', __FILE__)
2
+ require 'spec_helper'
3
+ require 'generators/jquery/ui/ui_generator'
4
+
5
+ describe Jquery::Generators::UiGenerator do
6
+ before do
7
+ @destination = File.join('tmp', 'test_app')
8
+ @source = Jquery::Generators::UiGenerator.source_root
9
+ @generator = Jquery::Generators::UiGenerator.new(
10
+ ["1.8rc3"], {}, {:destination_root => @destination}
11
+ )
12
+ @app_tmp_path = "tmp/jquery"
13
+ @unzip_folder = "ui"
14
+ @unzip_path = "#{@app_tmp_path}/#{@unzip_folder}"
15
+ end
16
+
17
+ after do
18
+ FileUtils.rm_rf(@destination)
19
+ end
20
+
21
+ it "fetch jquery-ui files from remote" do
22
+ @generator.version.should == '1.8rc3'
23
+ @generator.options[:zip].should be_nil
24
+ zip_file = "jquery-ui-#{@generator.version}.custom.zip"
25
+ download_path = "http://jqueryui.com/download"
26
+ @generator.should_receive(:empty_directory).with(@app_tmp_path).and_return(true)
27
+ File.should_receive(:exists?).with(zip_file).and_return(false)
28
+ @generator.should_receive(:get).with("#{download_path}/#{zip_file}", zip_file).and_return(true)
29
+ @generator.should_receive(:run).with("unzip #{zip_file} -d #{@unzip_folder}", :verbose => false).and_return(true)
30
+ @generator.fetch_jquery_ui_files
31
+ end
32
+
33
+ it "fetch jquery-ui files from local" do
34
+ zip_file = 'my_jquery_ui.zip'
35
+ @generator = Jquery::Generators::UiGenerator.new(
36
+ ["1.8rc3"], {:zip => zip_file}, {:destination_root => @destination}
37
+ )
38
+ @generator.version.should == '1.8rc3'
39
+ @generator.options[:zip].should_not be_nil
40
+ @generator.options[:zip].should == zip_file
41
+ @generator.should_receive(:empty_directory).with(@app_tmp_path).and_return(true)
42
+ File.should_receive(:exists?).with(zip_file).and_return(true)
43
+ @generator.should_not_receive(:get)
44
+ @generator.should_receive(:run).with("unzip #{zip_file} -d #{@unzip_folder}", :verbose => false).and_return(true)
45
+ @generator.invoke :fetch_jquery_ui_files
46
+ end
47
+
48
+ it "fetch rails jquery-ujs file" do
49
+ url = 'http://github.com/rails/jquery-ujs/raw/master/src/rails.js'
50
+ @generator.should_receive(:get).with(url, 'public/javascripts/rails.js').and_return(true)
51
+ @generator.fetch_rails_jquery_ujs_file
52
+ end
53
+
54
+ it "copy javascript files" do
55
+ @generator.version.should == '1.8rc3'
56
+ glob_string = "#{@unzip_path}/js/jquery-*.min.js"
57
+ source_files = [
58
+ "#{@unzip_path}/js/jquery-ui-#{@generator.version}.custom.js",
59
+ "#{@unzip_path}/js/jquery-#{@generator.version}.js"
60
+ ]
61
+ target_files = [
62
+ 'public/javascripts/jquery-ui.js',
63
+ 'public/javascripts/jquery.js'
64
+ ]
65
+ Dir.should_receive(:glob).with(glob_string).and_return(source_files)
66
+ @generator.should_receive(:expand_app_path).with(source_files[0]).and_return(source_files[0])
67
+ @generator.should_receive(:copy_file).with(source_files[0], target_files[0]).and_return(true)
68
+ @generator.should_receive(:expand_app_path).with(source_files[1]).and_return(source_files[1])
69
+ @generator.should_receive(:copy_file).with(source_files[1], target_files[1]).and_return(true)
70
+ @generator.copy_javascript_files
71
+ end
72
+
73
+ it "copy stylesheet files" do
74
+ @generator.version.should == '1.8rc3'
75
+ glob_string = "#{@unzip_path}/css/**/*"
76
+ source_files = [
77
+ "#{@unzip_path}/css/smoothness",
78
+ "#{@unzip_path}/css/smoothness/images",
79
+ "#{@unzip_path}/css/smoothness/jquery-ui-#{@generator.version}.custom.css",
80
+ "#{@unzip_path}/css/smoothness/images/ui-bg.png",
81
+ "#{@unzip_path}/css/smoothness/images/ui-icons.png"
82
+ ]
83
+ target_files = [
84
+ "public/stylesheets/smoothness",
85
+ "public/stylesheets/smoothness/images",
86
+ "public/stylesheets/smoothness/jquery-ui.css",
87
+ "public/stylesheets/smoothness/images/ui-bg.png",
88
+ "public/stylesheets/smoothness/images/ui-icons.png"
89
+ ]
90
+ Dir.should_receive(:glob).with(glob_string).and_return(source_files)
91
+ @generator.should_receive(:expand_app_path).with(source_files[0]).and_return(source_files[0])
92
+ File.should_receive(:directory?).with(source_files[0]).and_return(true)
93
+ @generator.should_receive(:empty_directory).with(target_files[0]).and_return(true)
94
+ @generator.should_receive(:expand_app_path).with(source_files[1]).and_return(source_files[1])
95
+ File.should_receive(:directory?).with(source_files[1]).and_return(true)
96
+ @generator.should_receive(:empty_directory).with(target_files[1]).and_return(true)
97
+ @generator.should_receive(:expand_app_path).with(source_files[2]).and_return(source_files[2])
98
+ File.should_receive(:directory?).with(source_files[2]).and_return(false)
99
+ @generator.should_receive(:copy_file).with(source_files[2], target_files[2]).and_return(true)
100
+ @generator.should_receive(:expand_app_path).with(source_files[3]).and_return(source_files[3])
101
+ File.should_receive(:directory?).with(source_files[3]).and_return(false)
102
+ @generator.should_receive(:copy_file).with(source_files[3], target_files[3]).and_return(true)
103
+ @generator.should_receive(:expand_app_path).with(source_files[4]).and_return(source_files[4])
104
+ File.should_receive(:directory?).with(source_files[4]).and_return(false)
105
+ @generator.should_receive(:copy_file).with(source_files[4], target_files[4]).and_return(true)
106
+ @generator.copy_stylesheet_files
107
+ end
108
+
109
+ it "create initializer file" do
110
+ @generator.should_receive(:copy_file).with('jquery.rb', 'config/initializers/jquery.rb').and_return(true)
111
+ @generator.create_initializer_file
112
+ end
113
+
114
+ it "create application layout file" do
115
+ @generator.should_receive(:copy_file).with('application.html.erb', 'app/views/layouts/application.html.erb').and_return(true)
116
+ @generator.create_application_layout_file
117
+ end
118
+
119
+ it "delete tmp files without zip file" do
120
+ @generator.options[:clean].should be_nil
121
+ @generator.should_receive(:run).with("rm -rf #{@unzip_path}", :verbose => false)
122
+ @generator.delete_tmp_files
123
+ end
124
+
125
+ it "delete tmp files with zip file" do
126
+ @generator = Jquery::Generators::UiGenerator.new(
127
+ ["1.8rc3"], {:clean => true}, {:destination_root => @destination}
128
+ )
129
+ @generator.options[:clean].should_not be_nil
130
+ @generator.options[:clean].should be_true
131
+ @generator.should_receive(:run).with("rm -rf #{@app_tmp_path}", :verbose => false)
132
+ @generator.delete_tmp_files
133
+ end
134
+
135
+ it "show_readme" do
136
+ @generator.should_receive(:readme).with('README')
137
+ @generator.show_readme
138
+ end
139
+
140
+ it "should go through all tasks" do
141
+ @generator.should_receive(:fetch_jquery_ui_files).and_return(true)
142
+ @generator.should_receive(:fetch_rails_jquery_ujs_file).and_return(true)
143
+ @generator.should_receive(:copy_javascript_files).and_return(true)
144
+ @generator.should_receive(:copy_stylesheet_files).and_return(true)
145
+ @generator.should_receive(:create_initializer_file).and_return(true)
146
+ @generator.should_receive(:create_application_layout_file).and_return(true)
147
+ @generator.should_receive(:delete_tmp_files).and_return(true)
148
+ @generator.should_receive(:show_readme).and_return(true)
149
+ @generator.invoke
150
+ end
151
+ end
@@ -0,0 +1,10 @@
1
+ #require File.expand_path('../spec_helper', __FILE__)
2
+ require 'spec_helper'
3
+
4
+ describe "JqueryCorpus" do
5
+ it "has version string" do
6
+ version = '0.1.2.beta'
7
+ JqueryCorpus.should_receive(:version).and_return(version)
8
+ JqueryCorpus::version.should == version
9
+ end
10
+ end
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,14 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
3
+ require 'rubygems'
4
+ require 'rspec'
5
+ require 'rspec/autorun'
6
+
7
+ require 'rails/generators'
8
+ require 'jquery_corpus'
9
+
10
+ Rspec.configure do |config|
11
+ config.mock_framework = :rspec
12
+ #config.include Rspec::Matchers
13
+ #config.mock_with :rspec
14
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jquery_corpus
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Tse-Ching Ho
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-03-10 00:00:00 +08:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 2
29
+ - 0
30
+ - 0
31
+ - beta
32
+ - 3
33
+ version: 2.0.0.beta.3
34
+ type: :development
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: cucumber
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ segments:
44
+ - 0
45
+ - 6
46
+ - 3
47
+ version: 0.6.3
48
+ type: :development
49
+ version_requirements: *id002
50
+ description: This gem will collect useful and popular jqeury plugins and provide a reliable way to manage it via rails 3 generator.
51
+ email: tsechingho@gmail.com
52
+ executables: []
53
+
54
+ extensions: []
55
+
56
+ extra_rdoc_files:
57
+ - LICENSE
58
+ - README.rdoc
59
+ files:
60
+ - .document
61
+ - .gitignore
62
+ - LICENSE
63
+ - README.rdoc
64
+ - Rakefile
65
+ - VERSION
66
+ - features/jquery_corpus.feature
67
+ - features/step_definitions/jquery_corpus_steps.rb
68
+ - features/support/env.rb
69
+ - jquery_corpus.gemspec
70
+ - lib/generators/jquery.rb
71
+ - lib/generators/jquery/colorbox/USAGE
72
+ - lib/generators/jquery/colorbox/colorbox_generator.rb
73
+ - lib/generators/jquery/ui/USAGE
74
+ - lib/generators/jquery/ui/templates/application.html.erb
75
+ - lib/generators/jquery/ui/templates/jquery.rb
76
+ - lib/generators/jquery/ui/ui_generator.rb
77
+ - lib/jquery_corpus.rb
78
+ - spec/generators/colorbox_generator_spec.rb
79
+ - spec/generators/ui_generator_spec.rb
80
+ - spec/jquery_corpus_spec.rb
81
+ - spec/spec.opts
82
+ - spec/spec_helper.rb
83
+ has_rdoc: true
84
+ homepage: http://github.com/tsechingho/jquery_corpus
85
+ licenses: []
86
+
87
+ post_install_message:
88
+ rdoc_options:
89
+ - --charset=UTF-8
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ segments:
97
+ - 0
98
+ version: "0"
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ segments:
104
+ - 0
105
+ version: "0"
106
+ requirements: []
107
+
108
+ rubyforge_project:
109
+ rubygems_version: 1.3.6
110
+ signing_key:
111
+ specification_version: 3
112
+ summary: Manage jQuery and it's plugins for Rails 3 applications.
113
+ test_files:
114
+ - spec/generators/colorbox_generator_spec.rb
115
+ - spec/generators/ui_generator_spec.rb
116
+ - spec/jquery_corpus_spec.rb
117
+ - spec/spec_helper.rb