swiss_knife 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.
Files changed (47) hide show
  1. data/Gemfile +9 -0
  2. data/Gemfile.lock +102 -0
  3. data/README.rdoc +183 -0
  4. data/Rakefile +26 -0
  5. data/lib/swiss_knife/action_controller.rb +43 -0
  6. data/lib/swiss_knife/assets.rb +81 -0
  7. data/lib/swiss_knife/dispatcher_js.rb +14 -0
  8. data/lib/swiss_knife/helpers.rb +178 -0
  9. data/lib/swiss_knife/i18n_js.rb +14 -0
  10. data/lib/swiss_knife/jquery.rb +14 -0
  11. data/lib/swiss_knife/jquery_ujs.rb +14 -0
  12. data/lib/swiss_knife/jsmin.rb +205 -0
  13. data/lib/swiss_knife/modernizr.rb +14 -0
  14. data/lib/swiss_knife/railtie.rb +19 -0
  15. data/lib/swiss_knife/rake_tasks.rb +31 -0
  16. data/lib/swiss_knife/rspec/have_tag.rb +115 -0
  17. data/lib/swiss_knife/rspec.rb +3 -0
  18. data/lib/swiss_knife/support/remote_file.rb +11 -0
  19. data/lib/swiss_knife/version.rb +8 -0
  20. data/lib/swiss_knife.rb +12 -0
  21. data/spec/controllers/application_controller_spec.rb +52 -0
  22. data/spec/helpers/helpers_spec.rb +314 -0
  23. data/spec/resources/assets/javascripts/application.js +1 -0
  24. data/spec/resources/assets/javascripts/jquery.js +1 -0
  25. data/spec/resources/assets/javascripts/rails.js +1 -0
  26. data/spec/resources/assets/stylesheets/main.css +1 -0
  27. data/spec/resources/assets/stylesheets/reset.css +1 -0
  28. data/spec/resources/assets/stylesheets/shared.css +1 -0
  29. data/spec/resources/assets.yml +16 -0
  30. data/spec/resources/stylesheets/_shared.less +1 -0
  31. data/spec/resources/stylesheets/main.less +3 -0
  32. data/spec/resources/stylesheets/reset.css +1 -0
  33. data/spec/resources/stylesheets/ui/tab.css +1 -0
  34. data/spec/resources/stylesheets/ui/window.less +1 -0
  35. data/spec/spec_helper.rb +25 -0
  36. data/spec/support/app/controllers/application_controller.rb +2 -0
  37. data/spec/support/config/boot.rb +20 -0
  38. data/spec/support/config/locales/en.yml +7 -0
  39. data/spec/support/log/test.log +8 -0
  40. data/spec/support/rspec/remote_file_shared.rb +21 -0
  41. data/spec/swiss_knife/assets_spec.rb +73 -0
  42. data/spec/swiss_knife/dispatcher_js_spec.rb +8 -0
  43. data/spec/swiss_knife/i18n_js_spec.rb +8 -0
  44. data/spec/swiss_knife/jquery_spec.rb +8 -0
  45. data/spec/swiss_knife/jquery_ujs_spec.rb +8 -0
  46. data/spec/swiss_knife/modernizr_spec.rb +8 -0
  47. metadata +149 -0
@@ -0,0 +1 @@
1
+ var name = "application";
@@ -0,0 +1 @@
1
+ var name = "jquery";
@@ -0,0 +1 @@
1
+ var name = "rails";
@@ -0,0 +1 @@
1
+ name: main
@@ -0,0 +1 @@
1
+ name: reset
@@ -0,0 +1 @@
1
+ name: shared
@@ -0,0 +1,16 @@
1
+ javascripts:
2
+ base:
3
+ - jquery
4
+ - rails
5
+ - application
6
+ libs:
7
+ - jquery
8
+ - rails
9
+
10
+ stylesheets:
11
+ base:
12
+ - reset
13
+ - main
14
+ shared:
15
+ - reset
16
+ - shared
@@ -0,0 +1 @@
1
+ @background: #fff;
@@ -0,0 +1,3 @@
1
+ @import "_shared";
2
+
3
+ * { background: @background; }
@@ -0,0 +1 @@
1
+ * { margin: 0; padding: 0; }
@@ -0,0 +1 @@
1
+ .tab { background: #f90; }
@@ -0,0 +1 @@
1
+ #window { background: #fff; }
@@ -0,0 +1,25 @@
1
+ ENV["RAILS_ENV"] = "test"
2
+ require "rails"
3
+ require "swiss_knife"
4
+ require File.dirname(__FILE__) + "/support/config/boot"
5
+ require "rspec/rails"
6
+ require "swiss_knife/rspec"
7
+
8
+ # Load support files
9
+ Dir[File.dirname(__FILE__) + "/support/rspec/**/*.rb"].each {|file| require file}
10
+
11
+ # Restore default configuration
12
+ RSpec.configure do |config|
13
+ remove_file = proc do |file|
14
+ File.unlink(file)
15
+ end
16
+
17
+ remote_static_files = proc do
18
+ Dir[Rails.root.join("public/javascripts/*.js")].each(&remove_file)
19
+ Dir[Rails.root.join("public/stylesheets/*.css")].each(&remove_file)
20
+ Dir[File.dirname(__FILE__) + "/resources/**/*_packaged.**"].each(&remove_file)
21
+ end
22
+
23
+ config.before(&remote_static_files)
24
+ config.after(&remote_static_files)
25
+ end
@@ -0,0 +1,2 @@
1
+ class ApplicationController < ActionController::Base
2
+ end
@@ -0,0 +1,20 @@
1
+ ENV["BUNDLE_GEMFILE"] = File.expand_path(File.dirname(__FILE__) + "/../../../Gemfile")
2
+ require "bundler"
3
+ Bundler.setup
4
+
5
+ # require "active_record/railtie"
6
+ require "action_controller/railtie"
7
+ require "action_mailer/railtie"
8
+ require "active_resource/railtie"
9
+ require "rails/test_unit/railtie"
10
+
11
+ Bundler.require(:default)
12
+
13
+ module SwissKnife
14
+ class Application < Rails::Application
15
+ config.root = File.dirname(__FILE__) + "/.."
16
+ config.active_support.deprecation = :log
17
+ end
18
+ end
19
+
20
+ SwissKnife::Application.initialize!
@@ -0,0 +1,7 @@
1
+ en:
2
+ titles:
3
+ products:
4
+ index: "All products"
5
+ new: "Add a new product"
6
+ edit: "Editing %{name}"
7
+ destroy: "Remove %{name}"
@@ -0,0 +1,8 @@
1
+ Processing by StubResourcesController#index as HTML
2
+ Completed in 15ms
3
+ Processing by StubResourcesController#index as HTML
4
+ Completed in 14ms
5
+ Processing by StubResourcesController#index as HTML
6
+ Completed in 50ms
7
+ Processing by StubResourcesController#index as HTML
8
+ Completed in 20ms
@@ -0,0 +1,21 @@
1
+ shared_examples_for "remote file" do
2
+ let(:directory) { Rails.root.join("public") }
3
+ let(:file_path) { directory.join(file) }
4
+
5
+ it "should update file" do
6
+ mock = mock(:read => "FILE CONTENT")
7
+ subject.should_receive(:open).with(url).and_return(mock)
8
+ subject.update
9
+
10
+ File.read(file_path).should == "FILE CONTENT"
11
+ end
12
+
13
+ it "should overwrite previous file" do
14
+ File.open(file_path, "w+") << "OLD CONTENT"
15
+ mock = mock(:read => "UPDATED CONTENT")
16
+ subject.should_receive(:open).with(url).and_return(mock)
17
+ subject.update
18
+
19
+ File.read(file_path).should == "UPDATED CONTENT"
20
+ end
21
+ end
@@ -0,0 +1,73 @@
1
+ require "spec_helper"
2
+
3
+ describe SwissKnife::Assets do
4
+ let!(:public_dir) { Pathname(File.dirname(__FILE__) + "/../resources/assets") }
5
+ let!(:config) { YAML.load_file(File.dirname(__FILE__) + "/../resources/assets.yml") }
6
+
7
+ before do
8
+ YAML.stub :load_file => config
9
+ end
10
+
11
+ it "should load config file" do
12
+ YAML.should_receive(:load_file).once.and_return(config)
13
+ SwissKnife::Assets.instance_variable_set "@config", nil
14
+ 2.times { SwissKnife::Assets.config }
15
+ end
16
+
17
+ it "should return public dir" do
18
+ SwissKnife::Assets.public_dir.should == ::Rails.root.join("public")
19
+ end
20
+
21
+ context "export" do
22
+ before do
23
+ SwissKnife::Assets.stub :public_dir => public_dir
24
+ end
25
+
26
+ it "should generate javascript bundles" do
27
+ SwissKnife::Assets.export(:javascripts)
28
+
29
+ File.should be_file(public_dir.join("javascripts", "base_packaged.js"))
30
+ File.should be_file(public_dir.join("javascripts", "libs_packaged.js"))
31
+ end
32
+
33
+ it "should ignore missing javascript section" do
34
+ YAML.stub :load_file => {}
35
+
36
+ expect { SwissKnife::Assets.export(:javascripts) }.to_not raise_error
37
+ end
38
+
39
+ it "should ignore missing stylesheet section" do
40
+ YAML.stub :load_file => {}
41
+
42
+ expect { SwissKnife::Assets.export(:stylesheets) }.to_not raise_error
43
+ end
44
+
45
+ it "should merge javascript files in the right order" do
46
+ SwissKnife::Assets::export(:javascripts)
47
+ source = File.read(public_dir.join("javascripts", "base_packaged.js"))
48
+ matches = source.scan(/name = "(.*?)"/x).to_a.flatten
49
+
50
+ matches[0].should == "jquery"
51
+ matches[1].should == "rails"
52
+ matches[2].should == "application"
53
+ matches[3].should be_nil
54
+ end
55
+
56
+ it "should merge stylesheet files in the right order" do
57
+ SwissKnife::Assets::export(:stylesheets)
58
+ source = File.read(public_dir.join("stylesheets", "base_packaged.css"))
59
+ matches = source.scan(/name: (.*?)$/).to_a.flatten
60
+
61
+ matches[0].should == "reset"
62
+ matches[1].should == "main"
63
+ matches[2].should be_nil
64
+ end
65
+
66
+ it "should generate stylesheet bundles" do
67
+ SwissKnife::Assets.export(:stylesheets)
68
+
69
+ File.should be_file(public_dir.join("stylesheets", "base_packaged.css"))
70
+ File.should be_file(public_dir.join("stylesheets", "shared_packaged.css"))
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,8 @@
1
+ require "spec_helper"
2
+
3
+ describe SwissKnife::DispatcherJs do
4
+ let(:url) { "http://github.com/fnando/dispatcher-js/raw/master/dispatcher.js" }
5
+ let(:file) { "javascripts/dispatcher.js" }
6
+
7
+ it_behaves_like "remote file"
8
+ end
@@ -0,0 +1,8 @@
1
+ require "spec_helper"
2
+
3
+ describe SwissKnife::I18nJs do
4
+ let(:url) { "http://github.com/fnando/i18n-js/raw/master/source/i18n.js" }
5
+ let(:file) { "javascripts/i18n.js" }
6
+
7
+ it_behaves_like "remote file"
8
+ end
@@ -0,0 +1,8 @@
1
+ require "spec_helper"
2
+
3
+ describe SwissKnife::Jquery do
4
+ let(:url) { "http://code.jquery.com/jquery-latest.min.js" }
5
+ let(:file) { "javascripts/jquery.js" }
6
+
7
+ it_behaves_like "remote file"
8
+ end
@@ -0,0 +1,8 @@
1
+ require "spec_helper"
2
+
3
+ describe SwissKnife::JqueryUjs do
4
+ let(:url) { "http://github.com/rails/jquery-ujs/raw/master/src/rails.js" }
5
+ let(:file) { "javascripts/rails.js" }
6
+
7
+ it_behaves_like "remote file"
8
+ end
@@ -0,0 +1,8 @@
1
+ require "spec_helper"
2
+
3
+ describe SwissKnife::Modernizr do
4
+ let(:url) { "http://github.com/Modernizr/Modernizr/raw/master/modernizr.js" }
5
+ let(:file) { "javascripts/modernizr.js" }
6
+
7
+ it_behaves_like "remote file"
8
+ end
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: swiss_knife
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
+ - Nando Vieira
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-10-11 00:00:00 -03:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rails
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 3
30
+ - 0
31
+ - 0
32
+ version: 3.0.0
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: rspec
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ segments:
44
+ - 2
45
+ - 0
46
+ - 0
47
+ version: 2.0.0
48
+ type: :development
49
+ version_requirements: *id002
50
+ description: Several helpers for Rails 3
51
+ email: fnando.vieira@gmail.com
52
+ executables: []
53
+
54
+ extensions: []
55
+
56
+ extra_rdoc_files:
57
+ - README.rdoc
58
+ files:
59
+ - Gemfile
60
+ - Gemfile.lock
61
+ - README.rdoc
62
+ - Rakefile
63
+ - lib/swiss_knife.rb
64
+ - lib/swiss_knife/action_controller.rb
65
+ - lib/swiss_knife/assets.rb
66
+ - lib/swiss_knife/dispatcher_js.rb
67
+ - lib/swiss_knife/helpers.rb
68
+ - lib/swiss_knife/i18n_js.rb
69
+ - lib/swiss_knife/jquery.rb
70
+ - lib/swiss_knife/jquery_ujs.rb
71
+ - lib/swiss_knife/jsmin.rb
72
+ - lib/swiss_knife/modernizr.rb
73
+ - lib/swiss_knife/railtie.rb
74
+ - lib/swiss_knife/rake_tasks.rb
75
+ - lib/swiss_knife/rspec.rb
76
+ - lib/swiss_knife/rspec/have_tag.rb
77
+ - lib/swiss_knife/support/remote_file.rb
78
+ - lib/swiss_knife/version.rb
79
+ - spec/controllers/application_controller_spec.rb
80
+ - spec/helpers/helpers_spec.rb
81
+ - spec/resources/assets.yml
82
+ - spec/resources/assets/javascripts/application.js
83
+ - spec/resources/assets/javascripts/jquery.js
84
+ - spec/resources/assets/javascripts/rails.js
85
+ - spec/resources/assets/stylesheets/main.css
86
+ - spec/resources/assets/stylesheets/reset.css
87
+ - spec/resources/assets/stylesheets/shared.css
88
+ - spec/resources/stylesheets/_shared.less
89
+ - spec/resources/stylesheets/main.less
90
+ - spec/resources/stylesheets/reset.css
91
+ - spec/resources/stylesheets/ui/tab.css
92
+ - spec/resources/stylesheets/ui/window.less
93
+ - spec/spec_helper.rb
94
+ - spec/support/app/controllers/application_controller.rb
95
+ - spec/support/config/boot.rb
96
+ - spec/support/config/locales/en.yml
97
+ - spec/support/log/test.log
98
+ - spec/support/rspec/remote_file_shared.rb
99
+ - spec/swiss_knife/assets_spec.rb
100
+ - spec/swiss_knife/dispatcher_js_spec.rb
101
+ - spec/swiss_knife/i18n_js_spec.rb
102
+ - spec/swiss_knife/jquery_spec.rb
103
+ - spec/swiss_knife/jquery_ujs_spec.rb
104
+ - spec/swiss_knife/modernizr_spec.rb
105
+ has_rdoc: true
106
+ homepage: http://github.com/fnando/swiss_knife
107
+ licenses: []
108
+
109
+ post_install_message:
110
+ rdoc_options:
111
+ - --charset=UTF-8
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ segments:
120
+ - 0
121
+ version: "0"
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ segments:
128
+ - 0
129
+ version: "0"
130
+ requirements: []
131
+
132
+ rubyforge_project:
133
+ rubygems_version: 1.3.7
134
+ signing_key:
135
+ specification_version: 3
136
+ summary: Several helpers for Rails 3
137
+ test_files:
138
+ - spec/controllers/application_controller_spec.rb
139
+ - spec/helpers/helpers_spec.rb
140
+ - spec/spec_helper.rb
141
+ - spec/support/app/controllers/application_controller.rb
142
+ - spec/support/config/boot.rb
143
+ - spec/support/rspec/remote_file_shared.rb
144
+ - spec/swiss_knife/assets_spec.rb
145
+ - spec/swiss_knife/dispatcher_js_spec.rb
146
+ - spec/swiss_knife/i18n_js_spec.rb
147
+ - spec/swiss_knife/jquery_spec.rb
148
+ - spec/swiss_knife/jquery_ujs_spec.rb
149
+ - spec/swiss_knife/modernizr_spec.rb