embarista 1.1.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 +1 -0
- data/.rspec +1 -0
- data/Gemfile +10 -0
- data/LICENSE +22 -0
- data/README.md +1 -0
- data/Rakefile +9 -0
- data/embarista.gemspec +27 -0
- data/lib/embarista/filters/erb_filter.rb +28 -0
- data/lib/embarista/filters/precompile_handlebars_filter.rb +104 -0
- data/lib/embarista/filters/rewrite_minispade_requires_filter.rb +32 -0
- data/lib/embarista/filters/strip_ember_asserts_filter.rb +13 -0
- data/lib/embarista/filters.rb +10 -0
- data/lib/embarista/helpers.rb +57 -0
- data/lib/embarista/javascript_pipeline.rb +33 -0
- data/lib/embarista/server.rb +160 -0
- data/lib/embarista/version.rb +3 -0
- data/lib/embarista.rb +12 -0
- data/spec/erb_filter_spec.rb +45 -0
- data/spec/helpers_spec.rb +13 -0
- data/spec/precompile_handlebars_filter_spec.rb +51 -0
- data/spec/rewrite_minispade_requires_filter_spec.rb +55 -0
- data/spec/spec_helper.rb +45 -0
- data/spec/strip_ember_asserts_filter_spec.rb +55 -0
- data/vendor/ember.js +21051 -0
- data/vendor/handlebars.js +1920 -0
- metadata +183 -0
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Embarista::Filters::RewriteMinispadeRequiresFilter do
|
4
|
+
MemoryFileWrapper = Rake::Pipeline::SpecHelpers::MemoryFileWrapper
|
5
|
+
|
6
|
+
let(:file_wrapper_class) { MemoryFileWrapper }
|
7
|
+
|
8
|
+
let(:input_js) {
|
9
|
+
<<-JS
|
10
|
+
require('baz');
|
11
|
+
require('../baz');
|
12
|
+
require('./baz');
|
13
|
+
require('./bar/baz');
|
14
|
+
JS
|
15
|
+
}
|
16
|
+
|
17
|
+
let(:input_files) {
|
18
|
+
[
|
19
|
+
MemoryFileWrapper.new("/path/to/input", "foo/bar.js", "UTF-8", input_js)
|
20
|
+
]
|
21
|
+
}
|
22
|
+
|
23
|
+
let(:output_root) { '/path/to/output' }
|
24
|
+
|
25
|
+
let(:options) {
|
26
|
+
nil
|
27
|
+
}
|
28
|
+
|
29
|
+
let(:rake_application) {
|
30
|
+
Rake::Application.new
|
31
|
+
}
|
32
|
+
|
33
|
+
let(:subject) {
|
34
|
+
filter = described_class.new(options)
|
35
|
+
filter.file_wrapper_class = file_wrapper_class
|
36
|
+
filter.input_files = input_files
|
37
|
+
filter.output_root = output_root
|
38
|
+
filter.rake_application = rake_application
|
39
|
+
filter
|
40
|
+
}
|
41
|
+
|
42
|
+
it "rewrites require to be relative to input" do
|
43
|
+
tasks = subject.generate_rake_tasks
|
44
|
+
tasks.each(&:invoke)
|
45
|
+
|
46
|
+
file = MemoryFileWrapper.files["/path/to/output/foo/bar.js"]
|
47
|
+
file.body.should eq(<<-JS)
|
48
|
+
minispade.require('baz');
|
49
|
+
minispade.require('baz');
|
50
|
+
minispade.require('foo/baz');
|
51
|
+
minispade.require('foo/bar/baz');
|
52
|
+
JS
|
53
|
+
file.encoding.should eq('UTF-8')
|
54
|
+
end
|
55
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'pry'
|
2
|
+
require 'embarista'
|
3
|
+
|
4
|
+
class Rake::Pipeline
|
5
|
+
module SpecHelpers
|
6
|
+
|
7
|
+
class MemoryFileWrapper < Struct.new(:root, :path, :encoding, :body)
|
8
|
+
@@files = {}
|
9
|
+
@@data = {}
|
10
|
+
|
11
|
+
def self.files
|
12
|
+
@@files
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.data
|
16
|
+
@@data
|
17
|
+
end
|
18
|
+
|
19
|
+
def with_encoding(new_encoding)
|
20
|
+
self.class.new(root, path, new_encoding, body)
|
21
|
+
end
|
22
|
+
|
23
|
+
def fullpath
|
24
|
+
File.join(root, path)
|
25
|
+
end
|
26
|
+
|
27
|
+
def create
|
28
|
+
@@files[fullpath] = self
|
29
|
+
self.body = ""
|
30
|
+
yield
|
31
|
+
end
|
32
|
+
|
33
|
+
def read
|
34
|
+
body || @@data[fullpath] || ""
|
35
|
+
end
|
36
|
+
|
37
|
+
def write(contents)
|
38
|
+
self.body << contents
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
RSpec.configure do |config|
|
45
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Embarista::Filters::StripEmberAssertsFilter do
|
4
|
+
MemoryFileWrapper = Rake::Pipeline::SpecHelpers::MemoryFileWrapper
|
5
|
+
|
6
|
+
let(:file_wrapper_class) { MemoryFileWrapper }
|
7
|
+
|
8
|
+
let(:input_js) {
|
9
|
+
<<-JS
|
10
|
+
function foo() {
|
11
|
+
Ember.warn('do not foo');
|
12
|
+
Ember.assert('assert something', Ember.something);
|
13
|
+
Ember.deprecate('foo is deprecated');
|
14
|
+
Ember.deprecateFunc('foo is deprecated', Ember.foo);
|
15
|
+
}
|
16
|
+
JS
|
17
|
+
}
|
18
|
+
|
19
|
+
let(:input_files) {
|
20
|
+
[
|
21
|
+
MemoryFileWrapper.new("/path/to/input", "foo/bar.js", "UTF-8", input_js)
|
22
|
+
]
|
23
|
+
}
|
24
|
+
|
25
|
+
let(:output_root) { '/path/to/output' }
|
26
|
+
|
27
|
+
let(:rake_application) {
|
28
|
+
Rake::Application.new
|
29
|
+
}
|
30
|
+
|
31
|
+
let(:subject) {
|
32
|
+
filter = described_class.new
|
33
|
+
filter.file_wrapper_class = file_wrapper_class
|
34
|
+
filter.input_files = input_files
|
35
|
+
filter.output_root = output_root
|
36
|
+
filter.rake_application = rake_application
|
37
|
+
filter
|
38
|
+
}
|
39
|
+
|
40
|
+
it "should strip Ember asserts, warnings and deprecations" do
|
41
|
+
tasks = subject.generate_rake_tasks
|
42
|
+
tasks.each(&:invoke)
|
43
|
+
|
44
|
+
file = MemoryFileWrapper.files["/path/to/output/foo/bar.js"]
|
45
|
+
file.body.should eq(<<-JS)
|
46
|
+
function foo() {
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
}
|
52
|
+
JS
|
53
|
+
file.encoding.should eq('UTF-8')
|
54
|
+
end
|
55
|
+
end
|