emcee 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/emcee/directive_processor.rb +33 -0
- data/lib/emcee/document.rb +44 -0
- data/lib/emcee/{post_processors → processors}/import_processor.rb +11 -12
- data/lib/emcee/processors/script_processor.rb +32 -0
- data/lib/emcee/processors/stylesheet_processor.rb +32 -0
- data/lib/emcee/railtie.rb +14 -13
- data/lib/emcee/resolver.rb +23 -0
- data/lib/emcee/version.rb +1 -1
- data/test/compressors_test.rb +1 -5
- data/test/document_test.rb +55 -0
- data/test/dummy/app/assets/components/test6.html +2 -1
- data/test/dummy/app/assets/components/test7.html +2 -0
- data/test/dummy/log/test.log +17338 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/458351c9b3b38136f089d00567fa2ab9 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/d4ee6708adf72d1eb87e17c8ac3ae163 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/e0561b1cebd62df57d5d6ac9d2b23033 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/ef2c9664b54fb0d162127bdea23cb7d9 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/f16d30b33e206690649697e498a2f1a8 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/f60c4ca381dbca97bfacc058e847695f +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/f70ad5f62d58f65f05f09c8cc1d3165b +0 -0
- data/test/dummy_app_integration_test.rb +5 -0
- data/test/{post_processors_test.rb → processors_test.rb} +25 -27
- data/test/resolver_test.rb +53 -0
- metadata +22 -10
- data/lib/emcee/post_processors/script_processor.rb +0 -42
- data/lib/emcee/post_processors/stylesheet_processor.rb +0 -42
- data/lib/emcee/pre_processors/directive_processor.rb +0 -35
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
require 'action_controller'
|
3
|
+
require 'coffee-rails'
|
4
|
+
require 'sass'
|
3
5
|
|
4
6
|
class DummyAppIntegrationTest < ActionController::TestCase
|
5
7
|
tests DummyController
|
@@ -35,9 +37,12 @@ class DummyAppIntegrationTest < ActionController::TestCase
|
|
35
37
|
<p>test1</p>
|
36
38
|
<polymer-element name="test6" attributes="source">
|
37
39
|
<template>
|
40
|
+
<p hidden?="{{ hidden }}">hidden</p>
|
38
41
|
<img src="{{ source }}">
|
39
42
|
</template>
|
40
43
|
</polymer-element>
|
44
|
+
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
|
45
|
+
<p>External script</p>
|
41
46
|
EOS
|
42
47
|
end
|
43
48
|
end
|
@@ -1,50 +1,48 @@
|
|
1
1
|
require 'test_helper'
|
2
|
-
require 'emcee/
|
3
|
-
require 'emcee/
|
4
|
-
require 'emcee/
|
2
|
+
require 'emcee/processors/import_processor'
|
3
|
+
require 'emcee/processors/script_processor'
|
4
|
+
require 'emcee/processors/stylesheet_processor'
|
5
|
+
require 'emcee/document'
|
5
6
|
|
6
|
-
|
7
|
-
|
7
|
+
# Create a stub of our asset resolver, so we can test if we're sending the
|
8
|
+
# correct messages to it.
|
9
|
+
class ResolverStub
|
10
|
+
attr_reader :asset_required
|
8
11
|
|
9
|
-
|
10
|
-
# the correct messages to it.
|
11
|
-
class ContextStub
|
12
|
-
attr_reader :assets
|
13
|
-
|
14
|
-
def initialize
|
15
|
-
@assets = []
|
16
|
-
end
|
17
|
-
|
18
|
-
def pathname
|
12
|
+
def directory
|
19
13
|
"/"
|
20
14
|
end
|
21
15
|
|
22
16
|
def require_asset(asset)
|
23
|
-
@
|
17
|
+
@asset_required = true
|
24
18
|
end
|
25
19
|
|
26
|
-
def evaluate(path
|
20
|
+
def evaluate(path)
|
27
21
|
"/* contents */"
|
28
22
|
end
|
23
|
+
|
24
|
+
def should_inline?(path)
|
25
|
+
true
|
26
|
+
end
|
29
27
|
end
|
30
28
|
|
31
|
-
class
|
29
|
+
class ProcessorsTest < ActiveSupport::TestCase
|
32
30
|
setup do
|
33
|
-
@
|
31
|
+
@resolver = ResolverStub.new
|
34
32
|
@body = <<-EOS.strip_heredoc
|
35
33
|
<link rel="import" href="test.html">
|
36
34
|
<link rel="stylesheet" href="test.css">
|
37
35
|
<script src="test.js"></script>
|
38
36
|
<p>test</p>
|
39
37
|
EOS
|
38
|
+
@doc = Emcee::Document.new(@body)
|
40
39
|
end
|
41
40
|
|
42
41
|
test "processing imports should work" do
|
43
|
-
processor = Emcee::
|
44
|
-
processed = processor.process(@
|
42
|
+
processor = Emcee::Processors::ImportProcessor.new(@resolver)
|
43
|
+
processed = processor.process(@doc).to_s
|
45
44
|
|
46
|
-
|
47
|
-
assert_equal "/test.html", @context.assets[0]
|
45
|
+
assert @resolver.asset_required
|
48
46
|
assert_equal processed, <<-EOS.strip_heredoc
|
49
47
|
<link rel="stylesheet" href="test.css">
|
50
48
|
<script src="test.js"></script>
|
@@ -53,8 +51,8 @@ class PostProcessorsTest < ActiveSupport::TestCase
|
|
53
51
|
end
|
54
52
|
|
55
53
|
test "processing stylesheets should work" do
|
56
|
-
processor = Emcee::
|
57
|
-
processed = processor.process(@
|
54
|
+
processor = Emcee::Processors::StylesheetProcessor.new(@resolver)
|
55
|
+
processed = processor.process(@doc).to_s
|
58
56
|
|
59
57
|
assert_equal processed, <<-EOS.strip_heredoc
|
60
58
|
<link rel="import" href="test.html">
|
@@ -65,8 +63,8 @@ class PostProcessorsTest < ActiveSupport::TestCase
|
|
65
63
|
end
|
66
64
|
|
67
65
|
test "processing scripts should work" do
|
68
|
-
processor = Emcee::
|
69
|
-
processed = processor.process(@
|
66
|
+
processor = Emcee::Processors::ScriptProcessor.new(@resolver)
|
67
|
+
processed = processor.process(@doc).to_s
|
70
68
|
|
71
69
|
assert_equal processed, <<-EOS.strip_heredoc
|
72
70
|
<link rel="import" href="test.html">
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'emcee/resolver.rb'
|
3
|
+
|
4
|
+
# Create a stub of Sprocket's Context class, so we can test if we're sending
|
5
|
+
# the correct messages to it.
|
6
|
+
class ContextStub
|
7
|
+
attr_reader :assets
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@assets = []
|
11
|
+
end
|
12
|
+
|
13
|
+
def pathname
|
14
|
+
"/"
|
15
|
+
end
|
16
|
+
|
17
|
+
def require_asset(asset)
|
18
|
+
@assets << asset
|
19
|
+
end
|
20
|
+
|
21
|
+
def evaluate(path, options = {})
|
22
|
+
"/* contents */"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class ResolverTest < ActiveSupport::TestCase
|
27
|
+
setup do
|
28
|
+
@context = ContextStub.new
|
29
|
+
@resolver = Emcee::Resolver.new(@context)
|
30
|
+
end
|
31
|
+
|
32
|
+
test "should have directory" do
|
33
|
+
assert_equal @resolver.directory, "/"
|
34
|
+
end
|
35
|
+
|
36
|
+
test "should require assets" do
|
37
|
+
assert_difference "@context.assets.length" do
|
38
|
+
@resolver.require_asset("/asset1")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
test "should evaluate an asset" do
|
43
|
+
assert_equal @resolver.evaluate("/test"), "/* contents */"
|
44
|
+
end
|
45
|
+
|
46
|
+
test "should indicate if asset should be inlined" do
|
47
|
+
assert @resolver.should_inline?("test.css")
|
48
|
+
assert @resolver.should_inline?("/vendor/assets/test.js")
|
49
|
+
|
50
|
+
assert_not @resolver.should_inline?("//fonts.googleapis.com/css?family=RobotoDraft:regular,bold,italic,thin,light,bolditalic,black,medium&lang=en")
|
51
|
+
assert_not @resolver.should_inline?("//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js")
|
52
|
+
end
|
53
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: emcee
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Huth
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 1.3.9
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: 1.3.9
|
83
83
|
description: Add web components to the Rails asset pipeline
|
84
84
|
email:
|
85
85
|
- andrew@huth.me
|
@@ -91,20 +91,23 @@ files:
|
|
91
91
|
- Rakefile
|
92
92
|
- lib/emcee.rb
|
93
93
|
- lib/emcee/compressors/html_compressor.rb
|
94
|
+
- lib/emcee/directive_processor.rb
|
95
|
+
- lib/emcee/document.rb
|
94
96
|
- lib/emcee/helpers/asset_tag_helper.rb
|
95
97
|
- lib/emcee/helpers/asset_url_helper.rb
|
96
98
|
- lib/emcee/helpers/sprockets_helper.rb
|
97
99
|
- lib/emcee/loose_assets.rb
|
98
|
-
- lib/emcee/
|
99
|
-
- lib/emcee/
|
100
|
-
- lib/emcee/
|
101
|
-
- lib/emcee/pre_processors/directive_processor.rb
|
100
|
+
- lib/emcee/processors/import_processor.rb
|
101
|
+
- lib/emcee/processors/script_processor.rb
|
102
|
+
- lib/emcee/processors/stylesheet_processor.rb
|
102
103
|
- lib/emcee/railtie.rb
|
104
|
+
- lib/emcee/resolver.rb
|
103
105
|
- lib/emcee/version.rb
|
104
106
|
- lib/generators/emcee/install/install_generator.rb
|
105
107
|
- lib/generators/emcee/install/templates/application.html
|
106
108
|
- lib/generators/emcee/install/templates/template.bowerrc
|
107
109
|
- test/compressors_test.rb
|
110
|
+
- test/document_test.rb
|
108
111
|
- test/dummy/README.rdoc
|
109
112
|
- test/dummy/Rakefile
|
110
113
|
- test/dummy/app/assets/components/application.html
|
@@ -116,6 +119,7 @@ files:
|
|
116
119
|
- test/dummy/app/assets/components/test/test3.html
|
117
120
|
- test/dummy/app/assets/components/test1.html
|
118
121
|
- test/dummy/app/assets/components/test6.html
|
122
|
+
- test/dummy/app/assets/components/test7.html
|
119
123
|
- test/dummy/app/assets/javascripts/application.js
|
120
124
|
- test/dummy/app/assets/stylesheets/application.css
|
121
125
|
- test/dummy/app/controllers/application_controller.rb
|
@@ -171,13 +175,16 @@ files:
|
|
171
175
|
- test/dummy/tmp/cache/assets/test/sprockets/ea6d25feb3cd8cc19f7982458443f784
|
172
176
|
- test/dummy/tmp/cache/assets/test/sprockets/ef2c9664b54fb0d162127bdea23cb7d9
|
173
177
|
- test/dummy/tmp/cache/assets/test/sprockets/f16d30b33e206690649697e498a2f1a8
|
178
|
+
- test/dummy/tmp/cache/assets/test/sprockets/f60c4ca381dbca97bfacc058e847695f
|
179
|
+
- test/dummy/tmp/cache/assets/test/sprockets/f70ad5f62d58f65f05f09c8cc1d3165b
|
174
180
|
- test/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655
|
175
181
|
- test/dummy/tmp/cache/assets/test/sprockets/fadf553480495a92d11dade99298bf7e
|
176
182
|
- test/dummy/vendor/assets/components/test4.html
|
177
183
|
- test/dummy/vendor/assets/components/test4.js
|
178
184
|
- test/dummy_app_integration_test.rb
|
179
185
|
- test/helpers_test.rb
|
180
|
-
- test/
|
186
|
+
- test/processors_test.rb
|
187
|
+
- test/resolver_test.rb
|
181
188
|
- test/test_helper.rb
|
182
189
|
homepage: https://github.com/ahuth/emcee
|
183
190
|
licenses:
|
@@ -205,6 +212,7 @@ specification_version: 4
|
|
205
212
|
summary: Add web components to the Rails asset pipeline.
|
206
213
|
test_files:
|
207
214
|
- test/compressors_test.rb
|
215
|
+
- test/document_test.rb
|
208
216
|
- test/dummy/app/assets/components/application.html
|
209
217
|
- test/dummy/app/assets/components/compile/test5.css.scss
|
210
218
|
- test/dummy/app/assets/components/compile/test5.html
|
@@ -214,6 +222,7 @@ test_files:
|
|
214
222
|
- test/dummy/app/assets/components/test/test3.html
|
215
223
|
- test/dummy/app/assets/components/test1.html
|
216
224
|
- test/dummy/app/assets/components/test6.html
|
225
|
+
- test/dummy/app/assets/components/test7.html
|
217
226
|
- test/dummy/app/assets/javascripts/application.js
|
218
227
|
- test/dummy/app/assets/stylesheets/application.css
|
219
228
|
- test/dummy/app/controllers/application_controller.rb
|
@@ -271,12 +280,15 @@ test_files:
|
|
271
280
|
- test/dummy/tmp/cache/assets/test/sprockets/ea6d25feb3cd8cc19f7982458443f784
|
272
281
|
- test/dummy/tmp/cache/assets/test/sprockets/ef2c9664b54fb0d162127bdea23cb7d9
|
273
282
|
- test/dummy/tmp/cache/assets/test/sprockets/f16d30b33e206690649697e498a2f1a8
|
283
|
+
- test/dummy/tmp/cache/assets/test/sprockets/f60c4ca381dbca97bfacc058e847695f
|
284
|
+
- test/dummy/tmp/cache/assets/test/sprockets/f70ad5f62d58f65f05f09c8cc1d3165b
|
274
285
|
- test/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655
|
275
286
|
- test/dummy/tmp/cache/assets/test/sprockets/fadf553480495a92d11dade99298bf7e
|
276
287
|
- test/dummy/vendor/assets/components/test4.html
|
277
288
|
- test/dummy/vendor/assets/components/test4.js
|
278
289
|
- test/dummy_app_integration_test.rb
|
279
290
|
- test/helpers_test.rb
|
280
|
-
- test/
|
291
|
+
- test/processors_test.rb
|
292
|
+
- test/resolver_test.rb
|
281
293
|
- test/test_helper.rb
|
282
294
|
has_rdoc:
|
@@ -1,42 +0,0 @@
|
|
1
|
-
require 'nokogiri'
|
2
|
-
require 'uri'
|
3
|
-
|
4
|
-
module Emcee
|
5
|
-
module PostProcessors
|
6
|
-
# ScriptProcessor scans a document for external script references and inlines
|
7
|
-
# them into the current document.
|
8
|
-
class ScriptProcessor
|
9
|
-
def initialize(context)
|
10
|
-
@context = context
|
11
|
-
@directory = File.dirname(context.pathname)
|
12
|
-
end
|
13
|
-
|
14
|
-
def process(data)
|
15
|
-
doc = Nokogiri::HTML.fragment(data)
|
16
|
-
inline_scripts(doc)
|
17
|
-
URI.unescape(doc.to_s)
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
def inline_scripts(doc)
|
23
|
-
doc.css("script[src]").each do |node|
|
24
|
-
path = absolute_path(node.attribute("src"))
|
25
|
-
content = @context.evaluate(path)
|
26
|
-
script = create_script(doc, content)
|
27
|
-
node.replace(script)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def absolute_path(path)
|
32
|
-
File.absolute_path(path, @directory)
|
33
|
-
end
|
34
|
-
|
35
|
-
def create_script(doc, content)
|
36
|
-
node = Nokogiri::XML::Node.new("script", doc)
|
37
|
-
node.content = content
|
38
|
-
node
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
require 'nokogiri'
|
2
|
-
require 'uri'
|
3
|
-
|
4
|
-
module Emcee
|
5
|
-
module PostProcessors
|
6
|
-
# StylesheetProcessor scans a document for external stylesheet references and
|
7
|
-
# inlines them into the current document.
|
8
|
-
class StylesheetProcessor
|
9
|
-
def initialize(context)
|
10
|
-
@context = context
|
11
|
-
@directory = File.dirname(context.pathname)
|
12
|
-
end
|
13
|
-
|
14
|
-
def process(data)
|
15
|
-
doc = Nokogiri::HTML.fragment(data)
|
16
|
-
inline_styles(doc)
|
17
|
-
URI.unescape(doc.to_s)
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
def inline_styles(doc)
|
23
|
-
doc.css("link[rel='stylesheet']").each do |node|
|
24
|
-
path = absolute_path(node.attribute("href"))
|
25
|
-
content = @context.evaluate(path)
|
26
|
-
style = create_style(doc, content)
|
27
|
-
node.replace(style)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def absolute_path(path)
|
32
|
-
File.absolute_path(path, @directory)
|
33
|
-
end
|
34
|
-
|
35
|
-
def create_style(doc, content)
|
36
|
-
node = Nokogiri::XML::Node.new("style", doc)
|
37
|
-
node.content = content
|
38
|
-
node
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
module Emcee
|
2
|
-
module PreProcessors
|
3
|
-
# The `DirectiveProcessor` is responsible for parsing and evaluating
|
4
|
-
# directive comments in a source file.
|
5
|
-
class DirectiveProcessor < Sprockets::DirectiveProcessor
|
6
|
-
# Matches the entire header/directive block. This is everything from the
|
7
|
-
# top of the file, enclosed in html comments.
|
8
|
-
HEADER_PATTERN = /\A((?m:\s*)(<!--(?m:.*?)-->))+/
|
9
|
-
|
10
|
-
# Implement `render` so that it uses our own header pattern.
|
11
|
-
def render(context, locals)
|
12
|
-
@context = context
|
13
|
-
@pathname = context.pathname
|
14
|
-
@directory = File.dirname(@pathname)
|
15
|
-
|
16
|
-
@header = data[HEADER_PATTERN, 0] || ""
|
17
|
-
@body = $' || data
|
18
|
-
# Ensure body ends in a new line
|
19
|
-
@body += "\n" if @body != "" && @body !~ /\n\Z/m
|
20
|
-
|
21
|
-
@included_pathnames = []
|
22
|
-
|
23
|
-
@result = ""
|
24
|
-
@result.force_encoding(body.encoding)
|
25
|
-
|
26
|
-
@has_written_body = false
|
27
|
-
|
28
|
-
process_directives
|
29
|
-
process_source
|
30
|
-
|
31
|
-
@result
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|