rack-tipi 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Binary file
@@ -0,0 +1,9 @@
1
+ *.gem
2
+ .bundle
3
+ .DS_Store
4
+ .sass-cache
5
+ .gist_cache
6
+ _cache
7
+ Gemfile.lock
8
+ pkg/*
9
+ tmp/*
@@ -0,0 +1 @@
1
+ 1.9.3-p0
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gemspec
File without changes
@@ -0,0 +1,21 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'pathname'
3
+
4
+ task :default => [ :tests ]
5
+
6
+ desc 'Run all tests in path specified (defaults to tests). Tell Rake to start at a specific path with `rake tests[\'tests/rack/assets\']`'
7
+ task :tests, :path do |t, args|
8
+ args.with_defaults(:path => 'tests')
9
+
10
+ run_recursively = lambda do |dir|
11
+ Pathname.new(dir).expand_path.children.each do |dir_or_test|
12
+ if dir_or_test.directory?
13
+ run_recursively.call dir_or_test
14
+ elsif dir_or_test.to_s.end_with? '_test.rb'
15
+ require_relative dir_or_test
16
+ end
17
+ end
18
+ end
19
+
20
+ run_recursively.call args[:path]
21
+ end
@@ -0,0 +1 @@
1
+ require 'rack/tipi'
@@ -0,0 +1 @@
1
+ require 'rack/tipi/assets'
@@ -0,0 +1,31 @@
1
+ require 'rack/mime'
2
+
3
+ module Rack
4
+ module Tipi
5
+ class Asset
6
+ attr_reader :namespace, :path
7
+
8
+ def initialize(namespace, path, route)
9
+ @namespace = namespace
10
+ @path = Pathname.new(path).expand_path
11
+ @route = route.sub(/\//, '')
12
+ end
13
+
14
+ def ==(other)
15
+ route == other.route if other.respond_to? :route
16
+ end
17
+
18
+ def content
19
+ path.read
20
+ end
21
+
22
+ def mime_type
23
+ Rack::Mime.mime_type(path.extname)
24
+ end
25
+
26
+ def route
27
+ "/#{namespace}/#{@route}"
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,35 @@
1
+ require 'rack/tipi/asset'
2
+
3
+ module Rack
4
+ module Tipi
5
+ class Assets
6
+ attr_reader :app, :tipi_root
7
+
8
+ def initialize(app, options)
9
+ @app = app
10
+ @tipi_root = options[:tipi_root]
11
+ end
12
+
13
+ def call(env)
14
+ asset = self.class.resources.detect do |a|
15
+ "#{tipi_root}#{a.route}" == env['REQUEST_PATH']
16
+ end
17
+
18
+ if asset
19
+ [ 200, { 'Content-Type' => asset.mime_type }, [ asset.content ] ]
20
+ else
21
+ app.call(env)
22
+ end
23
+ end
24
+
25
+ def self.resources
26
+ @resources || []
27
+ end
28
+
29
+ def self.register(namespace, path, route)
30
+ asset = Asset.new(namespace, path, route)
31
+ (@resources ||= []) << asset unless resources.include? asset
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,17 @@
1
+ module Rack
2
+ module Tipi
3
+ module Version
4
+ MAJOR = 0
5
+ MINOR = 1
6
+ PATCH = 0
7
+
8
+ def self.to_s
9
+ [
10
+ MAJOR,
11
+ MINOR,
12
+ PATCH
13
+ ].join('.')
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require File.expand_path('../lib/rack/tipi/version', __FILE__)
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'rack-tipi'
7
+ s.version = Rack::Tipi::Version.to_s
8
+ s.authors = ['Raving Genius']
9
+ s.email = ['rg+code@ravinggenius.com']
10
+ s.summary = 'Include and depend on third-party JS (and CSS) libraries'
11
+ s.license = 'MIT'
12
+
13
+ s.rubyforge_project = 'rack-tipi'
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,feature}{,s}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
18
+ s.require_paths = ['lib']
19
+
20
+ s.signing_key = '/home/thomas/Code/___/certificates/gem-private_key.pem'
21
+ s.cert_chain = [
22
+ '/home/thomas/Code/___/certificates/gem-public_cert.pem'
23
+ ]
24
+
25
+ s.add_development_dependency 'minitest'
26
+ s.add_development_dependency 'ruby-debug19'
27
+
28
+ s.add_runtime_dependency 'bundler'
29
+ s.add_runtime_dependency 'rack'
30
+ end
@@ -0,0 +1,44 @@
1
+ require_relative '../../test_helper'
2
+
3
+ require 'pathname'
4
+ require 'rack/tipi/asset'
5
+
6
+ class AssetTest < TestHelper
7
+ def setup
8
+ @dir = File.join(File.dirname(__FILE__), '../../test_files')
9
+ @asset_css = Rack::Tipi::Asset.new(:woot, File.join(@dir, '/stylesheet.css'), '/stylesheet.css')
10
+ @asset_js = Rack::Tipi::Asset.new(:woot, File.join(@dir, 'javascript.js'), 'javascript.js')
11
+ end
12
+
13
+ def test_equalequal
14
+ assert_operator @asset_css, :==, Rack::Tipi::Asset.new(:woot, File.join(@dir, '/stylesheet.css'), '/stylesheet.css')
15
+ assert_operator @asset_js, :==, Rack::Tipi::Asset.new(:woot, File.join(@dir, 'javascript.js'), 'javascript.js')
16
+ assert_operator @asset_js, :!=, nil
17
+ end
18
+
19
+ def test_content
20
+ assert_equal "/* sample CSS file */\n", @asset_css.content
21
+ assert_equal "// sample JavaScript file\n", @asset_js.content
22
+ end
23
+
24
+ def test_mime_type
25
+ assert_equal 'text/css', @asset_css.mime_type
26
+ assert_equal 'application/javascript', @asset_js.mime_type
27
+ end
28
+
29
+ def test_namespace
30
+ assert_equal :woot, @asset_css.namespace
31
+ assert_equal :woot, @asset_js.namespace
32
+ end
33
+
34
+ def test_path
35
+ root = Pathname.new(__FILE__) + '..' + '..' + '..' + 'test_files'
36
+ assert_equal (root + 'stylesheet.css'), @asset_css.path
37
+ assert_equal (root + 'javascript.js'), @asset_js.path
38
+ end
39
+
40
+ def test_route
41
+ assert_equal '/woot/stylesheet.css', @asset_css.route
42
+ assert_equal '/woot/javascript.js', @asset_js.route
43
+ end
44
+ end
@@ -0,0 +1,55 @@
1
+ require_relative '../../test_helper'
2
+
3
+ require 'pathname'
4
+ require 'rack/tipi/assets'
5
+
6
+ class AssetsTest < TestHelper
7
+ def setup
8
+ @asset_root = Pathname.new(__FILE__) + '..' + '..' + '..' + 'test_files'
9
+ @app = lambda { |env| [ 200, { 'Content-Type' => 'text/plain' }, ['testing...'] ] }
10
+ @assets = Rack::Tipi::Assets.new(@app, :tipi_root => '/assets')
11
+ end
12
+
13
+ def teardown
14
+ Rack::Tipi::Assets.instance_variable_set('@resources', []) if Rack::Tipi::Assets.resources.count > 0
15
+ end
16
+
17
+ def add_script
18
+ Rack::Tipi::Assets.register(:woot, (@asset_root + 'javascript.js'), 'javascript.js')
19
+ end
20
+
21
+ def add_style
22
+ Rack::Tipi::Assets.register(:woot, (@asset_root + 'stylesheet.css'), 'stylesheet.css')
23
+ end
24
+
25
+ def test_call
26
+ add_script
27
+ add_style
28
+
29
+ assert_equal ['testing...'], @assets.call('REQUEST_PATH' => '/').last
30
+ assert_equal ["/* sample CSS file */\n"], @assets.call('REQUEST_PATH' => '/assets/woot/stylesheet.css').last
31
+ assert_equal ["// sample JavaScript file\n"], @assets.call('REQUEST_PATH' => '/assets/woot/javascript.js').last
32
+ end
33
+
34
+ def test_resouces
35
+ assert_equal 0, Rack::Tipi::Assets.resources.count
36
+
37
+ add_script
38
+ add_style
39
+
40
+ assert_equal 2, Rack::Tipi::Assets.resources.count
41
+ end
42
+
43
+ def test_register
44
+ assert_equal 0, Rack::Tipi::Assets.resources.count
45
+
46
+ Rack::Tipi::Assets.register(:woot, (@asset_root + 'javascript.js'), 'javascript.js')
47
+ assert_equal 1, Rack::Tipi::Assets.resources.count
48
+
49
+ Rack::Tipi::Assets.register(:woot, (@asset_root + 'javascript.js'), 'javascript.js')
50
+ assert_equal 1, Rack::Tipi::Assets.resources.count
51
+
52
+ Rack::Tipi::Assets.register(:woot, (@asset_root + 'stylesheet.css'), 'stylesheet.css')
53
+ assert_equal 2, Rack::Tipi::Assets.resources.count
54
+ end
55
+ end
@@ -0,0 +1 @@
1
+ // sample JavaScript file
@@ -0,0 +1 @@
1
+ /* sample CSS file */
@@ -0,0 +1,7 @@
1
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib'))
2
+
3
+ require 'minitest/autorun'
4
+ #require 'ruby-debug' # http://blog.wyeworks.com/2011/11/1/ruby-1-9-3-and-ruby-debug
5
+
6
+ class TestHelper < MiniTest::Unit::TestCase
7
+ end
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-tipi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Raving Genius
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain:
12
+ - ! '-----BEGIN CERTIFICATE-----
13
+
14
+ MIIDPjCCAiagAwIBAgIBADANBgkqhkiG9w0BAQUFADBFMRAwDgYDVQQDDAdyZ19j
15
+
16
+ b2RlMRwwGgYKCZImiZPyLGQBGRYMcmF2aW5nZ2VuaXVzMRMwEQYKCZImiZPyLGQB
17
+
18
+ GRYDY29tMB4XDTExMDEzMTAyMzI1MloXDTEyMDEzMTAyMzI1MlowRTEQMA4GA1UE
19
+
20
+ AwwHcmdfY29kZTEcMBoGCgmSJomT8ixkARkWDHJhdmluZ2dlbml1czETMBEGCgmS
21
+
22
+ JomT8ixkARkWA2NvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMBt
23
+
24
+ UkaBJrNx3C6klKOoWtCEL+t+jZEdov0FU7Oos0jYceQ04u5SXYYm/t6mw4L5WvEQ
25
+
26
+ NoDaUGFQ3VS9gIKMuosMUIAOsw8pUGA4OeSkIDaj8Z1QgjYiXJTNYia1Vt0cbeOa
27
+
28
+ OCUVzDOgFb/GT3RDV3ZaOuuTCVTTeid8IwbPNseu/n5paS8HEHTla8D7L5bHFta7
29
+
30
+ p2RuKD09dvLYIwm+zrrMGHf1qN8ASq2EV9G8xwQVCXX8fPbnW62GSvbnRqoao7Mh
31
+
32
+ SQDY5GJlC/16gMMpoMdkaqVojXUeo+hQZzliVcJvqg0QjhcYxCGlyCgtTdCEWL+y
33
+
34
+ fA2XoEEHM5t8g1JWzMkCAwEAAaM5MDcwCQYDVR0TBAIwADAdBgNVHQ4EFgQU5tcW
35
+
36
+ zeGngxI/7uKRz8ZLkubhDn0wCwYDVR0PBAQDAgSwMA0GCSqGSIb3DQEBBQUAA4IB
37
+
38
+ AQCLyf/Qko0uooWPFEgkot/W4pcpkXnyYpH+5FfBN36XQcpkD6Ky5J6Wjej6ZqfA
39
+
40
+ umvfF/CK03N3S52axZLHNEunJn19NVJ871RNMViMjJH5qzp8CJcNksdVctcwztwD
41
+
42
+ /0mmYu+vTfvJ4DIg5Q7vvTdS3WriewDc3APaa3la93ZRIEwbQjJASoS0EEAr1pw0
43
+
44
+ WKoA5gx4BqPJHT0QH4LE0MQoE4XB8I/Y3xs5OUwItZL1xWpiUixKpDIqB5zKtN0m
45
+
46
+ EtSgImjQmbN559J/qAn31487zcviSWdGfNkLGT/rfVaLd6lg1VVgA5k5tG6roxiJ
47
+
48
+ CvvfejGH+Hi4YXI1pPhLJj8g
49
+
50
+ -----END CERTIFICATE-----
51
+
52
+ '
53
+ date: 2011-11-15 00:00:00.000000000 Z
54
+ dependencies:
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: &11871900 !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: *11871900
66
+ - !ruby/object:Gem::Dependency
67
+ name: ruby-debug19
68
+ requirement: &11871480 !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ type: :development
75
+ prerelease: false
76
+ version_requirements: *11871480
77
+ - !ruby/object:Gem::Dependency
78
+ name: bundler
79
+ requirement: &11871060 !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ type: :runtime
86
+ prerelease: false
87
+ version_requirements: *11871060
88
+ - !ruby/object:Gem::Dependency
89
+ name: rack
90
+ requirement: &11870640 !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :runtime
97
+ prerelease: false
98
+ version_requirements: *11870640
99
+ description:
100
+ email:
101
+ - rg+code@ravinggenius.com
102
+ executables: []
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - .gitignore
107
+ - .rbenv-version
108
+ - Gemfile
109
+ - README.markdown
110
+ - Rakefile
111
+ - lib/rack-tipi.rb
112
+ - lib/rack/tipi.rb
113
+ - lib/rack/tipi/asset.rb
114
+ - lib/rack/tipi/assets.rb
115
+ - lib/rack/tipi/version.rb
116
+ - rack-tipi.gemspec
117
+ - tests/rack/tipi/asset_test.rb
118
+ - tests/rack/tipi/assets_test.rb
119
+ - tests/test_files/javascript.js
120
+ - tests/test_files/stylesheet.css
121
+ - tests/test_helper.rb
122
+ homepage:
123
+ licenses:
124
+ - MIT
125
+ post_install_message:
126
+ rdoc_options: []
127
+ require_paths:
128
+ - lib
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - ! '>='
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ none: false
137
+ requirements:
138
+ - - ! '>='
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ requirements: []
142
+ rubyforge_project: rack-tipi
143
+ rubygems_version: 1.8.11
144
+ signing_key:
145
+ specification_version: 3
146
+ summary: Include and depend on third-party JS (and CSS) libraries
147
+ test_files: []
Binary file