strockets 0.2.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.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.md +35 -0
- data/Rakefile +1 -0
- data/lib/strockets/bundle.rb +13 -0
- data/lib/strockets/config.rb +13 -0
- data/lib/strockets/environment.rb +17 -0
- data/lib/strockets/processor.rb +31 -0
- data/lib/strockets/stitch.js +58 -0
- data/lib/strockets/version.rb +3 -0
- data/lib/strockets.rb +5 -0
- data/strockets.gemspec +25 -0
- metadata +85 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Strockets
|
2
|
+
|
3
|
+
Use Stitch allong with Sprockets
|
4
|
+
|
5
|
+
## Warning
|
6
|
+
This is currently under revision so the gem's API might change
|
7
|
+
|
8
|
+
## Usage
|
9
|
+
|
10
|
+
Just include this gem in your Gemfile
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'sprockets'
|
14
|
+
```
|
15
|
+
|
16
|
+
And all your javascript files will be compiled using Stitch/CommonJS.
|
17
|
+
You can add
|
18
|
+
|
19
|
+
```javascript
|
20
|
+
// no-stitch
|
21
|
+
```
|
22
|
+
|
23
|
+
on any file's first line to prevent it from being stitched.
|
24
|
+
|
25
|
+
Alternatively you can enable the compatibility mode with
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
Sprockets.compatibility_mode!
|
29
|
+
```
|
30
|
+
|
31
|
+
to conditionaly stitch files that have the following header:
|
32
|
+
|
33
|
+
```javascript
|
34
|
+
// stitch
|
35
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Strockets
|
2
|
+
module Environment
|
3
|
+
def self.included(base)
|
4
|
+
base.send :alias_method, :initialize_without_stitch, :initialize
|
5
|
+
base.send :alias_method, :initialize, :initialize_with_stitch
|
6
|
+
end
|
7
|
+
|
8
|
+
def initialize_with_stitch(*args)
|
9
|
+
initialize_without_stitch(*args)
|
10
|
+
|
11
|
+
self.register_bundle_processor 'application/javascript', Bundle
|
12
|
+
self.register_postprocessor 'application/javascript', Processor
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
Sprockets::Environment.send :include, Strockets::Environment
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Strockets
|
2
|
+
class Processor < Tilt::Template
|
3
|
+
self.default_mime_type = 'application/javascript'
|
4
|
+
|
5
|
+
def prepare
|
6
|
+
end
|
7
|
+
|
8
|
+
def evaluate(scope, locals, &block)
|
9
|
+
if stitch? scope
|
10
|
+
"\nrequire.define({'#{ scope.logical_path }': function(exports, require, module) {\n" +
|
11
|
+
indent(data) +
|
12
|
+
"\n}});\n"
|
13
|
+
else
|
14
|
+
data
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
def stitch?(scope)
|
20
|
+
return false if scope.pathname.basename.to_s =~ /\.jst/
|
21
|
+
|
22
|
+
directive = File.open(scope.pathname){|f| f.readline}.downcase.gsub(/[^a-z\-]/,"") rescue nil
|
23
|
+
|
24
|
+
Strockets.compatibility_mode? ? directive == "stitch" : directive != "no-stitch"
|
25
|
+
end
|
26
|
+
|
27
|
+
def indent(string)
|
28
|
+
string.gsub(/$(.)/m, "\\1 ").strip
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
(function(/*! Stitch !*/) {
|
2
|
+
if (!this.require) {
|
3
|
+
|
4
|
+
var modules = {},
|
5
|
+
cache = {},
|
6
|
+
require = function(name, root) {
|
7
|
+
var module = cache[name], path = expand(root, name), fn;
|
8
|
+
if (module) {
|
9
|
+
return module;
|
10
|
+
} else if (fn = modules[path] || modules[path = expand(path, './index')]) {
|
11
|
+
module = {id: name, exports: {}};
|
12
|
+
try {
|
13
|
+
cache[name] = module.exports;
|
14
|
+
|
15
|
+
fn(module.exports, function(name) {
|
16
|
+
return require(name, dirname(path));
|
17
|
+
}, module);
|
18
|
+
|
19
|
+
return cache[name] = module.exports;
|
20
|
+
} catch (err) {
|
21
|
+
delete cache[name];
|
22
|
+
throw err;
|
23
|
+
}
|
24
|
+
} else {
|
25
|
+
throw 'module "' + name + '" not found';
|
26
|
+
}
|
27
|
+
},
|
28
|
+
expand = function(root, name) {
|
29
|
+
var results = [], parts, part;
|
30
|
+
if (/^\.\.?(\/|$)/.test(name)) {
|
31
|
+
parts = [root, name].join('/').split('/');
|
32
|
+
} else {
|
33
|
+
parts = name.split('/');
|
34
|
+
}
|
35
|
+
for (var i = 0, length = parts.length; i < length; i++) {
|
36
|
+
part = parts[i];
|
37
|
+
if (part == '..') {
|
38
|
+
results.pop();
|
39
|
+
} else if (part != '.' && part != '') {
|
40
|
+
results.push(part);
|
41
|
+
}
|
42
|
+
}
|
43
|
+
return results.join('/');
|
44
|
+
},
|
45
|
+
dirname = function(path) {
|
46
|
+
return path.split('/').slice(0, -1).join('/');
|
47
|
+
};
|
48
|
+
|
49
|
+
this.require = function(name) {
|
50
|
+
return require(name, '');
|
51
|
+
}
|
52
|
+
|
53
|
+
this.require.define = function(bundle) {
|
54
|
+
for (var key in bundle)
|
55
|
+
modules[key] = bundle[key];
|
56
|
+
};
|
57
|
+
}
|
58
|
+
}).call(this);
|
data/lib/strockets.rb
ADDED
data/strockets.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "strockets/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "strockets"
|
7
|
+
s.version = Strockets::VERSION
|
8
|
+
s.authors = ["Sebastian Gamboa"]
|
9
|
+
s.email = ["me@sagmor.com"]
|
10
|
+
s.homepage = "https://github.com/sagmor/strockets"
|
11
|
+
s.summary = %q{Make Stitch and Sprockets friends}
|
12
|
+
s.description = %q{Use Stitch allong with Sprockets}
|
13
|
+
|
14
|
+
s.rubyforge_project = "strockets"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
s.add_development_dependency "rake"
|
23
|
+
s.add_runtime_dependency "sprockets", ">=2.0.0"
|
24
|
+
# s.add_runtime_dependency "stitch"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: strockets
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Sebastian Gamboa
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-12-14 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: &70297367288240 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70297367288240
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: sprockets
|
27
|
+
requirement: &70297367287720 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.0.0
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70297367287720
|
36
|
+
description: Use Stitch allong with Sprockets
|
37
|
+
email:
|
38
|
+
- me@sagmor.com
|
39
|
+
executables: []
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files: []
|
42
|
+
files:
|
43
|
+
- .gitignore
|
44
|
+
- Gemfile
|
45
|
+
- README.md
|
46
|
+
- Rakefile
|
47
|
+
- lib/strockets.rb
|
48
|
+
- lib/strockets/bundle.rb
|
49
|
+
- lib/strockets/config.rb
|
50
|
+
- lib/strockets/environment.rb
|
51
|
+
- lib/strockets/processor.rb
|
52
|
+
- lib/strockets/stitch.js
|
53
|
+
- lib/strockets/version.rb
|
54
|
+
- strockets.gemspec
|
55
|
+
homepage: https://github.com/sagmor/strockets
|
56
|
+
licenses: []
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
segments:
|
68
|
+
- 0
|
69
|
+
hash: -2558210479809988184
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
segments:
|
77
|
+
- 0
|
78
|
+
hash: -2558210479809988184
|
79
|
+
requirements: []
|
80
|
+
rubyforge_project: strockets
|
81
|
+
rubygems_version: 1.8.10
|
82
|
+
signing_key:
|
83
|
+
specification_version: 3
|
84
|
+
summary: Make Stitch and Sprockets friends
|
85
|
+
test_files: []
|