sprockets-export 0.9.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.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +21 -0
- data/README.md +34 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/sprockets/export.rb +11 -0
- data/lib/sprockets/export/bundle_processor.rb +37 -0
- data/lib/sprockets/export/directive_processor.rb +8 -0
- data/lib/sprockets/export/metadata_injector.rb +15 -0
- data/lib/sprockets/export/namespace.rb +23 -0
- data/lib/sprockets/export/template.js.erb +17 -0
- data/lib/sprockets/export/template.rb +25 -0
- data/lib/sprockets/export/version.rb +5 -0
- data/sprockets-export.gemspec +25 -0
- metadata +102 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 35d273659beb5900a0795a6fb6c50b4386f0ac6f
|
4
|
+
data.tar.gz: 2637f0d67c40fe574f73588f887823468fbaaef2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 37cb5bc48b85b6bca5a886aa38033e2758814b442f186f6ed724de1f77561fb9af830596eb584497312ee5078ba09dd86584777d94f50ff13ea92db6765e7c5b
|
7
|
+
data.tar.gz: 94bcfb8ddfa200a80a2d19daf3ae2bd43e99c4a2dccb5bc7ddfaa8527bdc5bfa83dc9c1256762fb1a9904f02a887609d5a24b0739ef1e091cbf34f4a76dc4055
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Javan Makhmali
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# Sprockets Export
|
2
|
+
|
3
|
+
A [Sprockets directive](https://github.com/rails/sprockets#sprockets-directives) for hassle-free [UMD](https://github.com/umdjs/umd)-style JavaScript module definitions.
|
4
|
+
|
5
|
+
## Using
|
6
|
+
|
7
|
+
``` ruby
|
8
|
+
# Gemfile
|
9
|
+
|
10
|
+
gem 'sprockets', '>= 3.0.0'
|
11
|
+
gem 'sprockets-export'
|
12
|
+
```
|
13
|
+
|
14
|
+
```js
|
15
|
+
/* widget.js */
|
16
|
+
|
17
|
+
//= export Widget
|
18
|
+
//= require_self
|
19
|
+
|
20
|
+
this.Widget = { name: "gizmo" }
|
21
|
+
```
|
22
|
+
|
23
|
+
## Consuming
|
24
|
+
|
25
|
+
```js
|
26
|
+
widget = require("widget")
|
27
|
+
widget.name // gizmo
|
28
|
+
```
|
29
|
+
|
30
|
+
---
|
31
|
+
|
32
|
+
Licensed under the [MIT License](LICENSE.txt)
|
33
|
+
|
34
|
+
© 2016 Javan Makhmali
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "sprockets/export"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require "pathname"
|
2
|
+
|
3
|
+
require "sprockets/export/version"
|
4
|
+
require "sprockets/export/namespace"
|
5
|
+
require "sprockets/export/directive_processor"
|
6
|
+
require "sprockets/export/metadata_injector"
|
7
|
+
require "sprockets/export/bundle_processor"
|
8
|
+
|
9
|
+
Sprockets.append_path Pathname.new(__dir__).join("..")
|
10
|
+
Sprockets.register_postprocessor "application/javascript", Sprockets::Export::MetadataInjector
|
11
|
+
Sprockets.register_bundle_processor "application/javascript", Sprockets::Export::BundleProcessor
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require "sprockets/export/template"
|
2
|
+
|
3
|
+
module Sprockets::Export::BundleProcessor
|
4
|
+
extend self
|
5
|
+
|
6
|
+
PATTERN = /(.*)\/\* !START EXPORT (.*) \*\/(.*)\/\* !END EXPORT \*\/(.*)/m
|
7
|
+
|
8
|
+
def call(input)
|
9
|
+
Sprockets::Export::Namespace.reset
|
10
|
+
data = input[:data]
|
11
|
+
|
12
|
+
if data =~ PATTERN
|
13
|
+
data = Sprockets::Export::Template.new(extract_template_data(data)).render
|
14
|
+
end
|
15
|
+
|
16
|
+
{ data: data }
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
def extract_template_data(js)
|
21
|
+
_, head, namespace, export, tail = *js.match(PATTERN)
|
22
|
+
|
23
|
+
export.strip!
|
24
|
+
body = format_body(head, tail)
|
25
|
+
|
26
|
+
{ namespace: namespace, export: export, body: body }
|
27
|
+
end
|
28
|
+
|
29
|
+
def format_body(head, tail)
|
30
|
+
[head, tail]
|
31
|
+
.reject { |s| s == "" }
|
32
|
+
.map(&:strip)
|
33
|
+
.join("\n")
|
34
|
+
.gsub(/\A;$/, "")
|
35
|
+
.strip
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
class Sprockets::DirectiveProcessor
|
2
|
+
def process_export_directive(namespace)
|
3
|
+
if @content_type == "application/javascript"
|
4
|
+
Sprockets::Export::Namespace.save(@environment, @filename, namespace)
|
5
|
+
process_depend_on_directive "sprockets/export/version.rb"
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Sprockets::Export::MetadataInjector
|
2
|
+
extend self
|
3
|
+
|
4
|
+
def call(input)
|
5
|
+
data, environment, filename = *input.values_at(:data, :environment, :filename)
|
6
|
+
|
7
|
+
if namespace = Sprockets::Export::Namespace.find(environment, filename)
|
8
|
+
open = "/* !START EXPORT #{namespace} */"
|
9
|
+
close = "/* !END EXPORT */"
|
10
|
+
data = [open, data.chomp, close].join("\n") + "\n"
|
11
|
+
end
|
12
|
+
|
13
|
+
{ data: data }
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Sprockets::Export::Namespace
|
2
|
+
extend self
|
3
|
+
|
4
|
+
def save(environment, filename, namespace)
|
5
|
+
mapping[environment] ||= {}
|
6
|
+
mapping[environment][filename] = namespace
|
7
|
+
end
|
8
|
+
|
9
|
+
def find(environment, filename)
|
10
|
+
if mapping[environment]
|
11
|
+
mapping[environment][filename]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def reset
|
16
|
+
@mapping = nil
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
def mapping
|
21
|
+
@mapping ||= {}
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
(function() {
|
2
|
+
(function() {
|
3
|
+
<%= indent(@export, 4 )%>
|
4
|
+
}).call(this);
|
5
|
+
|
6
|
+
var <%= @namespace %> = this.<%= @namespace %>;
|
7
|
+
|
8
|
+
(function() {
|
9
|
+
<%= indent(@body, 4) %>
|
10
|
+
}).call(this);
|
11
|
+
|
12
|
+
if (typeof module === "object" && module.exports) {
|
13
|
+
module.exports = <%= @namespace %>;
|
14
|
+
} else if (typeof define === "function" && define.amd) {
|
15
|
+
define(<%= @namespace %>);
|
16
|
+
}
|
17
|
+
}).call(this);
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "erb"
|
2
|
+
|
3
|
+
class Sprockets::Export::Template
|
4
|
+
CONTENT = Pathname.new(__dir__).join("template.js.erb").read
|
5
|
+
|
6
|
+
def initialize(data = {})
|
7
|
+
data.each do |key, value|
|
8
|
+
instance_variable_set("@#{key}".to_sym, value)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def render
|
13
|
+
ERB.new(CONTENT).result(binding)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
def indent(string, amount)
|
18
|
+
lines = string.lines
|
19
|
+
result = lines.shift
|
20
|
+
lines.each do |line|
|
21
|
+
result << line.gsub(/^(?!$)/, " " * amount)
|
22
|
+
end
|
23
|
+
result
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'sprockets/export/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "sprockets-export"
|
8
|
+
spec.version = Sprockets::Export::VERSION
|
9
|
+
spec.authors = ["Javan Makhmali"]
|
10
|
+
spec.email = ["javan@javan.us"]
|
11
|
+
|
12
|
+
spec.summary = %q{Sprockets Export}
|
13
|
+
spec.description = %q{A Sprockets directive for hassle-free UMD-style JavaScript module definitions.}
|
14
|
+
spec.homepage = "https://github.com/javan/sprockets-export"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "minitest"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sprockets-export
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Javan Makhmali
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-05-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.12'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: A Sprockets directive for hassle-free UMD-style JavaScript module definitions.
|
56
|
+
email:
|
57
|
+
- javan@javan.us
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- bin/console
|
68
|
+
- bin/setup
|
69
|
+
- lib/sprockets/export.rb
|
70
|
+
- lib/sprockets/export/bundle_processor.rb
|
71
|
+
- lib/sprockets/export/directive_processor.rb
|
72
|
+
- lib/sprockets/export/metadata_injector.rb
|
73
|
+
- lib/sprockets/export/namespace.rb
|
74
|
+
- lib/sprockets/export/template.js.erb
|
75
|
+
- lib/sprockets/export/template.rb
|
76
|
+
- lib/sprockets/export/version.rb
|
77
|
+
- sprockets-export.gemspec
|
78
|
+
homepage: https://github.com/javan/sprockets-export
|
79
|
+
licenses:
|
80
|
+
- MIT
|
81
|
+
metadata: {}
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
requirements: []
|
97
|
+
rubyforge_project:
|
98
|
+
rubygems_version: 2.5.1
|
99
|
+
signing_key:
|
100
|
+
specification_version: 4
|
101
|
+
summary: Sprockets Export
|
102
|
+
test_files: []
|