sphere 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/.gitignore +1 -0
  2. data/README.markdown +84 -0
  3. data/Rakefile +26 -0
  4. data/VERSION +1 -0
  5. data/lib/sphere.rb +32 -0
  6. data/lib/sphere/backends/base.rb +44 -0
  7. data/lib/sphere/backends/closure.rb +29 -0
  8. data/lib/sphere/backends/yui.rb +28 -0
  9. data/lib/sphere/config.rb +55 -0
  10. data/lib/sphere/css_minifier.rb +29 -0
  11. data/lib/sphere/helper.rb +38 -0
  12. data/lib/sphere/package/base.rb +87 -0
  13. data/lib/sphere/package/javascript.rb +17 -0
  14. data/lib/sphere/package/stylesheet.rb +17 -0
  15. data/lib/sphere/packager.rb +48 -0
  16. data/lib/sphere/tasks/commit.rake +22 -0
  17. data/lib/sphere/tasks/compass.rake +19 -0
  18. data/lib/sphere/tasks/sphere.rake +31 -0
  19. data/lib/sphere/tasks/upload.rake +37 -0
  20. data/rails/init.rb +2 -0
  21. data/spec/scenario/config/boot.rb +110 -0
  22. data/spec/scenario/config/database.yml +0 -0
  23. data/spec/scenario/config/environment.rb +5 -0
  24. data/spec/scenario/config/sphere.yml +16 -0
  25. data/spec/scenario/public/javascripts/custom/file_a.js +9 -0
  26. data/spec/scenario/public/javascripts/custom/file_b.js +8 -0
  27. data/spec/scenario/public/javascripts/custom/ignore.js +8 -0
  28. data/spec/scenario/public/javascripts/file.js +8 -0
  29. data/spec/scenario/public/stylesheets/compiled/custom.css +1 -0
  30. data/spec/scenario/public/stylesheets/compiled/print.css +40 -0
  31. data/spec/spec_helper.rb +50 -0
  32. data/spec/sphere/config_spec.rb +27 -0
  33. data/spec/sphere/css_minifier_spec.rb +16 -0
  34. data/spec/sphere/helper_spec.rb +57 -0
  35. data/spec/sphere/package/base_spec.rb +46 -0
  36. data/spec/sphere/package/javascript_spec.rb +19 -0
  37. data/spec/sphere/package/stylesheet_spec.rb +19 -0
  38. data/spec/sphere/packager_spec.rb +44 -0
  39. data/spec/sphere_spec.rb +16 -0
  40. data/sphere.gemspec +90 -0
  41. metadata +112 -0
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe Sphere::Config do
4
+
5
+ it 'should initialize defaults' do
6
+ conf = Sphere::Config.new
7
+ conf.env.should == 'test'
8
+ conf.compress?.should == false
9
+ end
10
+
11
+ it 'should allow to override defaults' do
12
+ conf = Sphere::Config.new.update! do |c|
13
+ c.env = 'production'
14
+ end
15
+ conf.env.should == 'production'
16
+ conf.compress?.should == true
17
+ conf.package?.should == true
18
+ conf.compress = false
19
+ conf.compress?.should == false
20
+ end
21
+
22
+ it 'should parse config file content' do
23
+ Sphere::Config.new.send(:definitions).should be_a(Hash)
24
+ end
25
+
26
+ end
27
+
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe Sphere::CSSMinifier do
4
+
5
+ def css_content
6
+ File.read File.join(File.dirname(__FILE__), '..', 'scenario', 'public', 'stylesheets', 'compiled', 'print.css')
7
+ end
8
+
9
+ it "should minify CSS" do
10
+ minifier = Sphere::CSSMinifier.new(css_content)
11
+ minifier.size.should == 881
12
+ minifier.minify!
13
+ minifier.size.should == 279
14
+ end
15
+
16
+ end
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+
3
+ describe Sphere::Helper do
4
+ class SphereDummyHelper < ActionView::Base
5
+ end
6
+
7
+ def helper
8
+ @helper ||= SphereDummyHelper.new
9
+ end
10
+
11
+ it 'should have method to load javascript packages' do
12
+ helper.should respond_to(:include_javascripts)
13
+ end
14
+
15
+ it 'should have method to load stylesheet packages' do
16
+ helper.should respond_to(:include_stylesheets)
17
+ end
18
+
19
+ describe "in packaging enabled" do
20
+ before do
21
+ Sphere.config.update! {|c| c.package = true }
22
+ end
23
+
24
+ it 'should package JS' do
25
+ helper.include_javascripts(:application).should match(/\<script src=.+assets\/application.js.*/)
26
+ end
27
+
28
+ it 'should package CSS' do
29
+ helper.include_stylesheets(:screen).should match(/\<link href=.+assets\/screen.css.*/)
30
+ end
31
+ end
32
+
33
+ describe "with packaging disabled" do
34
+ before do
35
+ Sphere.config.update! {|c| c.package = false }
36
+ end
37
+
38
+ it 'should package JS' do
39
+ helper.include_javascripts(:application).scan(/script src=\"([^"]+\.js)/).flatten.should == [
40
+ "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js",
41
+ "http://jquery-ui.googlecode.com/svn/tags/latest/ui/minified/jquery.ui.core.min.js",
42
+ "/javascripts/custom/file_a.js",
43
+ "/javascripts/custom/file_b.js",
44
+ "/javascripts/file.js"
45
+ ]
46
+ end
47
+
48
+ it 'should package CSS' do
49
+ helper.include_stylesheets(:screen).scan(/link href=\"([^"]+\.css)/).flatten.should == [
50
+ "http://www.blueprintcss.org/blueprint/src/typography.css",
51
+ "/stylesheets/compiled/custom.css", "/stylesheets/compiled/print.css"
52
+ ]
53
+ end
54
+ end
55
+
56
+ end
57
+
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe Sphere::Package::Base do
4
+
5
+ it 'should have a name' do
6
+ javascripts['application'].name.should == 'application'
7
+ end
8
+
9
+ it 'should have a target file location' do
10
+ javascripts['application'].file.should be_a(Pathname)
11
+ javascripts['application'].file.to_s.should include('/public/assets/application.js')
12
+ end
13
+
14
+ it 'should have source locations' do
15
+ javascripts['application'].should have(5).sources
16
+ javascripts['application'].sources.should == [
17
+ "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js",
18
+ "http://jquery-ui.googlecode.com/svn/tags/latest/ui/minified/jquery.ui.core.min.js",
19
+ "javascripts/custom/file_a.js", "javascripts/custom/file_b.js", "javascripts/file.js"]
20
+ end
21
+
22
+ it 'should separate URLs and files' do
23
+ files = javascripts['application'].source_files.map do |pn|
24
+ pn.to_s.sub(Sphere.config.root.to_s, '')
25
+ end
26
+ files.should == ["/public/javascripts/custom/file_a.js", "/public/javascripts/custom/file_b.js", "/public/javascripts/file.js"]
27
+ javascripts['application'].source_urls.should == [
28
+ "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js",
29
+ "http://jquery-ui.googlecode.com/svn/tags/latest/ui/minified/jquery.ui.core.min.js"
30
+ ]
31
+ end
32
+
33
+ it 'should check if package is out-of-date' do
34
+ javascripts['application'].should be_out_of_date
35
+ end
36
+
37
+ it 'should compile content (without compression)' do
38
+ javascripts['application'].file.exist?.should be(false)
39
+ javascripts['application'].compile
40
+ javascripts['application'].file.exist?.should be(true)
41
+ javascripts['application'].file.size.should == 489
42
+ javascripts['application'].should_not be_out_of_date
43
+ end
44
+
45
+ end
46
+
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe Sphere::Package::Javascript do
4
+
5
+ it 'should have the right extension' do
6
+ Sphere::Package::Javascript.extension.should == 'js'
7
+ end
8
+
9
+ it 'should compile content (with compression)' do
10
+ Sphere.config.compress = true
11
+ javascripts['application'].file.exist?.should be(false)
12
+ javascripts['application'].compile
13
+ javascripts['application'].file.exist?.should be(true)
14
+ javascripts['application'].file.size.should == 279
15
+ javascripts['application'].should_not be_out_of_date
16
+ end
17
+
18
+ end
19
+
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe Sphere::Package::Stylesheet do
4
+
5
+ it 'should have the right extension' do
6
+ Sphere::Package::Stylesheet.extension.should == 'css'
7
+ end
8
+
9
+ it 'should compile content (with compression)' do
10
+ Sphere.config.compress = true
11
+ stylesheets['screen'].file.exist?.should be(false)
12
+ stylesheets['screen'].compile
13
+ stylesheets['screen'].file.exist?.should be(true)
14
+ stylesheets['screen'].file.size.should == 322
15
+ stylesheets['screen'].should_not be_out_of_date
16
+ end
17
+
18
+ end
19
+
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe Sphere::Packager do
4
+
5
+ it 'should create packages from configuration content' do
6
+ Sphere::Packager.instance.send(:javascripts).should have(2).items
7
+ Sphere::Packager.instance.send(:javascripts).values.map(&:name).sort.should == ['application', 'mobile']
8
+ Sphere::Packager.instance.send(:stylesheets).should have(2).items
9
+ Sphere::Packager.instance.send(:stylesheets).values.map(&:name).sort.should == ['print', 'screen']
10
+ end
11
+
12
+ it 'should check if any of the packages is out of date' do
13
+ Sphere::Packager.instance.out_of_date?(:js).should be(true)
14
+ Sphere::Packager.instance.out_of_date?(:css).should be(true)
15
+ Sphere::Packager.instance.out_of_date?(:all).should be(true)
16
+ Sphere::Packager.instance.out_of_date?.should be(true)
17
+ end
18
+
19
+ it 'should package all JS packages' do
20
+ js_files.should have(2).items
21
+ js_files.first.exist?.should be(false)
22
+ js_files.last.exist?.should be(false)
23
+ Sphere::Packager.instance.compile(:js)
24
+ js_files.first.exist?.should be(true)
25
+ js_files.first.size.should == 489
26
+ js_files.last.exist?.should be(true)
27
+ js_files.last.size.should == 167
28
+ Sphere::Packager.instance.out_of_date?(:js).should be(false)
29
+ end
30
+
31
+ it 'should package all CSS packages' do
32
+ css_files.should have(2).items
33
+ css_files.first.exist?.should be(false)
34
+ css_files.last.exist?.should be(false)
35
+ Sphere::Packager.instance.compile(:css)
36
+ css_files.first.exist?.should be(true)
37
+ css_files.first.size.should == 933
38
+ css_files.last.exist?.should be(true)
39
+ css_files.last.size.should == 22
40
+ Sphere::Packager.instance.out_of_date?(:css).should be(false)
41
+ end
42
+
43
+ end
44
+
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe Sphere do
4
+ it 'should initialize the configuration' do
5
+ Sphere.config.should be_a(Sphere::Config)
6
+ Sphere.config.env.should == 'test'
7
+ end
8
+
9
+ it 'should allow to configuration overrides' do
10
+ Sphere.config.update! do |c|
11
+ c.env = 'production'
12
+ end
13
+ Sphere.config.env.should == 'production'
14
+ end
15
+ end
16
+
data/sphere.gemspec ADDED
@@ -0,0 +1,90 @@
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{sphere}
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 = ["Dimitrij Denissenko"]
12
+ s.date = %q{2010-07-13}
13
+ s.description = %q{Built (primarily) to be used with Heroku + AWS/S3}
14
+ s.email = %q{dimitrij@blacksquaremedia.com}
15
+ s.extra_rdoc_files = [
16
+ "README.markdown"
17
+ ]
18
+ s.files = [
19
+ ".gitignore",
20
+ "README.markdown",
21
+ "Rakefile",
22
+ "VERSION",
23
+ "lib/sphere.rb",
24
+ "lib/sphere/backends/base.rb",
25
+ "lib/sphere/backends/closure.rb",
26
+ "lib/sphere/backends/yui.rb",
27
+ "lib/sphere/config.rb",
28
+ "lib/sphere/css_minifier.rb",
29
+ "lib/sphere/helper.rb",
30
+ "lib/sphere/package/base.rb",
31
+ "lib/sphere/package/javascript.rb",
32
+ "lib/sphere/package/stylesheet.rb",
33
+ "lib/sphere/packager.rb",
34
+ "lib/sphere/tasks/commit.rake",
35
+ "lib/sphere/tasks/compass.rake",
36
+ "lib/sphere/tasks/sphere.rake",
37
+ "lib/sphere/tasks/upload.rake",
38
+ "rails/init.rb",
39
+ "spec/scenario/config/boot.rb",
40
+ "spec/scenario/config/database.yml",
41
+ "spec/scenario/config/environment.rb",
42
+ "spec/scenario/config/sphere.yml",
43
+ "spec/scenario/public/assets/.gitignore",
44
+ "spec/scenario/public/javascripts/custom/file_a.js",
45
+ "spec/scenario/public/javascripts/custom/file_b.js",
46
+ "spec/scenario/public/javascripts/custom/ignore.js",
47
+ "spec/scenario/public/javascripts/file.js",
48
+ "spec/scenario/public/stylesheets/compiled/custom.css",
49
+ "spec/scenario/public/stylesheets/compiled/print.css",
50
+ "spec/spec_helper.rb",
51
+ "spec/sphere/config_spec.rb",
52
+ "spec/sphere/css_minifier_spec.rb",
53
+ "spec/sphere/helper_spec.rb",
54
+ "spec/sphere/package/base_spec.rb",
55
+ "spec/sphere/package/javascript_spec.rb",
56
+ "spec/sphere/package/stylesheet_spec.rb",
57
+ "spec/sphere/packager_spec.rb",
58
+ "spec/sphere_spec.rb",
59
+ "sphere.gemspec"
60
+ ]
61
+ s.homepage = %q{http://github.com/dim/sphere}
62
+ s.rdoc_options = ["--charset=UTF-8"]
63
+ s.require_paths = ["lib"]
64
+ s.rubygems_version = %q{1.3.6}
65
+ s.summary = %q{Asset packer and compressor, for Rails}
66
+ s.test_files = [
67
+ "spec/sphere/packager_spec.rb",
68
+ "spec/sphere/helper_spec.rb",
69
+ "spec/sphere/package/javascript_spec.rb",
70
+ "spec/sphere/package/stylesheet_spec.rb",
71
+ "spec/sphere/package/base_spec.rb",
72
+ "spec/sphere/config_spec.rb",
73
+ "spec/sphere/css_minifier_spec.rb",
74
+ "spec/sphere_spec.rb",
75
+ "spec/spec_helper.rb",
76
+ "spec/scenario/config/environment.rb",
77
+ "spec/scenario/config/boot.rb"
78
+ ]
79
+
80
+ if s.respond_to? :specification_version then
81
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
82
+ s.specification_version = 3
83
+
84
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
85
+ else
86
+ end
87
+ else
88
+ end
89
+ end
90
+
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sphere
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
+ - Dimitrij Denissenko
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-07-13 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: Built (primarily) to be used with Heroku + AWS/S3
22
+ email: dimitrij@blacksquaremedia.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files:
28
+ - README.markdown
29
+ files:
30
+ - .gitignore
31
+ - README.markdown
32
+ - Rakefile
33
+ - VERSION
34
+ - lib/sphere.rb
35
+ - lib/sphere/backends/base.rb
36
+ - lib/sphere/backends/closure.rb
37
+ - lib/sphere/backends/yui.rb
38
+ - lib/sphere/config.rb
39
+ - lib/sphere/css_minifier.rb
40
+ - lib/sphere/helper.rb
41
+ - lib/sphere/package/base.rb
42
+ - lib/sphere/package/javascript.rb
43
+ - lib/sphere/package/stylesheet.rb
44
+ - lib/sphere/packager.rb
45
+ - lib/sphere/tasks/commit.rake
46
+ - lib/sphere/tasks/compass.rake
47
+ - lib/sphere/tasks/sphere.rake
48
+ - lib/sphere/tasks/upload.rake
49
+ - rails/init.rb
50
+ - spec/scenario/config/boot.rb
51
+ - spec/scenario/config/database.yml
52
+ - spec/scenario/config/environment.rb
53
+ - spec/scenario/config/sphere.yml
54
+ - spec/scenario/public/assets/.gitignore
55
+ - spec/scenario/public/javascripts/custom/file_a.js
56
+ - spec/scenario/public/javascripts/custom/file_b.js
57
+ - spec/scenario/public/javascripts/custom/ignore.js
58
+ - spec/scenario/public/javascripts/file.js
59
+ - spec/scenario/public/stylesheets/compiled/custom.css
60
+ - spec/scenario/public/stylesheets/compiled/print.css
61
+ - spec/spec_helper.rb
62
+ - spec/sphere/config_spec.rb
63
+ - spec/sphere/css_minifier_spec.rb
64
+ - spec/sphere/helper_spec.rb
65
+ - spec/sphere/package/base_spec.rb
66
+ - spec/sphere/package/javascript_spec.rb
67
+ - spec/sphere/package/stylesheet_spec.rb
68
+ - spec/sphere/packager_spec.rb
69
+ - spec/sphere_spec.rb
70
+ - sphere.gemspec
71
+ has_rdoc: true
72
+ homepage: http://github.com/dim/sphere
73
+ licenses: []
74
+
75
+ post_install_message:
76
+ rdoc_options:
77
+ - --charset=UTF-8
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ segments:
85
+ - 0
86
+ version: "0"
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ segments:
92
+ - 0
93
+ version: "0"
94
+ requirements: []
95
+
96
+ rubyforge_project:
97
+ rubygems_version: 1.3.6
98
+ signing_key:
99
+ specification_version: 3
100
+ summary: Asset packer and compressor, for Rails
101
+ test_files:
102
+ - spec/sphere/packager_spec.rb
103
+ - spec/sphere/helper_spec.rb
104
+ - spec/sphere/package/javascript_spec.rb
105
+ - spec/sphere/package/stylesheet_spec.rb
106
+ - spec/sphere/package/base_spec.rb
107
+ - spec/sphere/config_spec.rb
108
+ - spec/sphere/css_minifier_spec.rb
109
+ - spec/sphere_spec.rb
110
+ - spec/spec_helper.rb
111
+ - spec/scenario/config/environment.rb
112
+ - spec/scenario/config/boot.rb