sprockets-export 0.9.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7b57161371802c88947bf586d9dbb07dcdc482b9
4
- data.tar.gz: 00f610fda3e32b792659376d20e921c1a91ccd01
3
+ metadata.gz: f0c9478e9f2c18af7ca58c3408cf613f0839b696
4
+ data.tar.gz: a5f200a57e54820e93ee6b223733dc14c58d8057
5
5
  SHA512:
6
- metadata.gz: 0eae35cd13fe0aa7c79f5971f5773d2945573ba305f04ac8e1c31987ae122ed9f0618da28cfccd1c8ad2449bd6615b58bfdcb70a013ff440bdae12993d292a84
7
- data.tar.gz: 7e5aa9ee09d45fdbadde8086888d24ca6a038c6edb75e3dc3db00a6894668bc05bf329c4f3b1e63b66ee83763049bb61909f53de40acbec5042eeb5ba164d020
6
+ metadata.gz: a66534a884c3464cbd54d478b4a036ce53189c23b48c57faa9f208d63ebdff47d09948a7773056ff16c8caba0995f55b49cec56105566db4470684f44d916ac6
7
+ data.tar.gz: 75a4ab47980c3921c41f941a7fe7f5c823a05a44706c17c78e26ad79b00ab053ce10e6b4eff5fe9a064352e20a051a78372835b5b2ea77ee7ab8ca02694a66de
data/Gemfile CHANGED
@@ -1,2 +1,4 @@
1
1
  source "https://rubygems.org"
2
2
  gemspec
3
+
4
+ gem "rack", "< 2"
@@ -1,7 +1,8 @@
1
1
  require "pathname"
2
2
 
3
+ require "sprockets"
3
4
  require "sprockets/export/version"
4
- require "sprockets/export/namespace"
5
+ require "sprockets/export/store"
5
6
  require "sprockets/export/directive_processor"
6
7
  require "sprockets/export/metadata_injector"
7
8
  require "sprockets/export/bundle_processor"
@@ -1,12 +1,13 @@
1
1
  require "sprockets/export/template"
2
+ require "ostruct"
2
3
 
3
4
  module Sprockets::Export::BundleProcessor
4
5
  extend self
5
6
 
6
- PATTERN = /(.*)\/\* !START EXPORT (.*) \*\/(.*)\/\* !END EXPORT \*\/(.*)/m
7
+ PATTERN = /(.*)\/\* !START EXPORT (\S*)\s*(\S*) \*\/(.*)\/\* !END EXPORT \*\/(.*)/m
7
8
 
8
9
  def call(input)
9
- Sprockets::Export::Namespace.reset
10
+ Sprockets::Export::Store.reset
10
11
  data = input[:data]
11
12
 
12
13
  if data =~ PATTERN
@@ -18,15 +19,22 @@ module Sprockets::Export::BundleProcessor
18
19
 
19
20
  private
20
21
  def extract_template_data(js)
21
- _, head, namespace, export, tail = *js.match(PATTERN)
22
+ _, head, namespace, flags, export, tail = *js.match(PATTERN)
22
23
 
23
24
  { namespace: namespace,
25
+ flags: create_flags(flags),
24
26
  export: format(export),
25
27
  head: format(head),
26
28
  tail: format(tail) }
27
29
  end
28
30
 
29
31
  def format(part)
30
- part.strip.gsub(/\A;$/, "").strip
32
+ part.strip.gsub(/\A\s*;\n*|\n;\s*\z/, "").strip
33
+ end
34
+
35
+ def create_flags(string = "")
36
+ flags = {}
37
+ string.split.each { |flag| flags[flag] = true }
38
+ OpenStruct.new(flags)
31
39
  end
32
40
  end
@@ -1,7 +1,7 @@
1
1
  class Sprockets::DirectiveProcessor
2
- def process_export_directive(namespace)
2
+ def process_export_directive(namespace, *flags)
3
3
  if @content_type == "application/javascript"
4
- Sprockets::Export::Namespace.save(@environment, @filename, namespace)
4
+ Sprockets::Export::Store.set(@environment, @filename, [namespace, flags].flatten.join(" "))
5
5
  process_depend_on_directive "sprockets/export/version.rb"
6
6
  end
7
7
  end
@@ -4,8 +4,8 @@ module Sprockets::Export::MetadataInjector
4
4
  def call(input)
5
5
  data, environment, filename = *input.values_at(:data, :environment, :filename)
6
6
 
7
- if namespace = Sprockets::Export::Namespace.find(environment, filename)
8
- open = "/* !START EXPORT #{namespace} */"
7
+ if metadata = Sprockets::Export::Store.get(environment, filename)
8
+ open = "/* !START EXPORT #{metadata} */"
9
9
  close = "/* !END EXPORT */"
10
10
  data = [open, data.chomp, close].join("\n") + "\n"
11
11
  end
@@ -1,12 +1,12 @@
1
- module Sprockets::Export::Namespace
1
+ module Sprockets::Export::Store
2
2
  extend self
3
3
 
4
- def save(environment, filename, namespace)
4
+ def set(environment, filename, data)
5
5
  mapping[environment] ||= {}
6
- mapping[environment][filename] = namespace
6
+ mapping[environment][filename] = data
7
7
  end
8
8
 
9
- def find(environment, filename)
9
+ def get(environment, filename)
10
10
  if mapping[environment]
11
11
  mapping[environment][filename]
12
12
  end
@@ -1,11 +1,13 @@
1
1
  <%= @head %>
2
2
 
3
3
  (function() {
4
+ var context = <%= @flags.noglobal ? "{}" : "this" %>;
5
+
4
6
  (function() {
5
- <%= indent(@export, 4 )%>
6
- }).call(this);
7
+ <%= indent(@export, 4)%>
8
+ }).call(context);
7
9
 
8
- var <%= @namespace %> = this.<%= @namespace %>;
10
+ var <%= @namespace %> = context.<%= @namespace %>;
9
11
 
10
12
  (function() {
11
13
  <%= indent(@tail, 4) %>
@@ -12,7 +12,7 @@ class Sprockets::Export::Template
12
12
  end
13
13
 
14
14
  def render
15
- ERB.new(self.class.content).result(binding).strip + "\n"
15
+ ERB.new(self.class.content, nil, "-").result(binding).strip + "\n"
16
16
  end
17
17
 
18
18
  private
@@ -1,5 +1,5 @@
1
1
  module Sprockets
2
2
  module Export
3
- VERSION = "0.9.1"
3
+ VERSION = "1.0.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sprockets-export
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Javan Makhmali
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-05-17 00:00:00.000000000 Z
11
+ date: 2016-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sprockets
@@ -85,7 +85,7 @@ files:
85
85
  - lib/sprockets/export/bundle_processor.rb
86
86
  - lib/sprockets/export/directive_processor.rb
87
87
  - lib/sprockets/export/metadata_injector.rb
88
- - lib/sprockets/export/namespace.rb
88
+ - lib/sprockets/export/store.rb
89
89
  - lib/sprockets/export/template.js.erb
90
90
  - lib/sprockets/export/template.rb
91
91
  - lib/sprockets/export/version.rb
@@ -110,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
110
  version: '0'
111
111
  requirements: []
112
112
  rubyforge_project:
113
- rubygems_version: 2.5.1
113
+ rubygems_version: 2.6.6
114
114
  signing_key:
115
115
  specification_version: 4
116
116
  summary: Sprockets Export