embork 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +22 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +29 -0
  6. data/Rakefile +5 -0
  7. data/TODO.md +16 -0
  8. data/bin/embork +63 -0
  9. data/blueprint/Borkfile +42 -0
  10. data/blueprint/Gemfile +13 -0
  11. data/blueprint/README.md +25 -0
  12. data/blueprint/app/app.js +11 -0
  13. data/blueprint/app/components/.gitkeep +0 -0
  14. data/blueprint/app/controllers/.gitkeep +0 -0
  15. data/blueprint/app/helpers/.gitkeep +0 -0
  16. data/blueprint/app/index.html.erb +18 -0
  17. data/blueprint/app/initializers/.gitkeep +0 -0
  18. data/blueprint/app/mixins/.gitkeep +0 -0
  19. data/blueprint/app/models/.gitkeep +0 -0
  20. data/blueprint/app/router.js +8 -0
  21. data/blueprint/app/routes/.gitkeep +0 -0
  22. data/blueprint/app/routes/index.js +1 -0
  23. data/blueprint/app/styles/.gitkeep +0 -0
  24. data/blueprint/app/styles/app.scss +3 -0
  25. data/blueprint/app/templates/.gitkeep +0 -0
  26. data/blueprint/app/templates/application.hbs +3 -0
  27. data/blueprint/app/templates/components/.gitkeep +0 -0
  28. data/blueprint/app/utils/.gitkeep +0 -0
  29. data/blueprint/app/views/.gitkeep +0 -0
  30. data/blueprint/bower.json +16 -0
  31. data/blueprint/bowerrc +3 -0
  32. data/blueprint/config/development/application.css +0 -0
  33. data/blueprint/config/development/application.js +12 -0
  34. data/blueprint/config/production/application.css +0 -0
  35. data/blueprint/config/production/application.js +12 -0
  36. data/blueprint/dotfiles +3 -0
  37. data/blueprint/erbfiles +5 -0
  38. data/blueprint/gitignore +17 -0
  39. data/blueprint/jshintrc +40 -0
  40. data/blueprint/package.json +15 -0
  41. data/blueprint/static/.gitkeep +0 -0
  42. data/blueprint/tests/.jshintrc +71 -0
  43. data/blueprint/tests/helpers/resolver.js +7 -0
  44. data/blueprint/tests/helpers/start-app.js +29 -0
  45. data/blueprint/tests/index.html +44 -0
  46. data/blueprint/tests/test-helper.js +6 -0
  47. data/blueprint/tests/test-loader.js +8 -0
  48. data/blueprint/tests/unit/.gitkeep +0 -0
  49. data/embork.gemspec +41 -0
  50. data/lib/embork.rb +23 -0
  51. data/lib/embork/borkfile.rb +148 -0
  52. data/lib/embork/build_versions.rb +21 -0
  53. data/lib/embork/builder.rb +156 -0
  54. data/lib/embork/environment.rb +90 -0
  55. data/lib/embork/forwarder.rb +23 -0
  56. data/lib/embork/generator.rb +184 -0
  57. data/lib/embork/logger.rb +40 -0
  58. data/lib/embork/pushstate.rb +16 -0
  59. data/lib/embork/server.rb +80 -0
  60. data/lib/embork/sprockets.rb +6 -0
  61. data/lib/embork/sprockets/ember_handlebars_compiler.rb +75 -0
  62. data/lib/embork/sprockets/es6_module_transpiler.rb +120 -0
  63. data/lib/embork/sprockets/frameworks.rb +34 -0
  64. data/lib/embork/sprockets/helpers.rb +45 -0
  65. data/lib/embork/sprockets/support/es6-module-transpiler.js +7190 -0
  66. data/lib/embork/sprockets/support/node_runner.js +22 -0
  67. data/lib/embork/version.rb +3 -0
  68. data/lib/string/strip.rb +27 -0
  69. data/spec/embork/borkfile/Borkfile.empty +0 -0
  70. data/spec/embork/borkfile/Borkfile.full +32 -0
  71. data/spec/embork/borkfile/Borkfile.rack +5 -0
  72. data/spec/embork/borkfile/Borkfile.relative +3 -0
  73. data/spec/embork/borkfile_spec.rb +119 -0
  74. data/spec/embork/builder/Borkfile +20 -0
  75. data/spec/embork/builder/app/index.html.erb +9 -0
  76. data/spec/embork/builder/config/production/application.css +0 -0
  77. data/spec/embork/builder/config/production/application.js +0 -0
  78. data/spec/embork/builder/config/production/deeply/nested/asset.js +0 -0
  79. data/spec/embork/builder/static/images/image.png +0 -0
  80. data/spec/embork/builder_spec.rb +95 -0
  81. data/spec/embork/environment_spec.rb +78 -0
  82. data/spec/embork/generator_spec.rb +84 -0
  83. data/spec/embork/server/example_app/Borkfile +1 -0
  84. data/spec/embork/server/example_app/app/app.js.erb +3 -0
  85. data/spec/embork/server/example_app/app/css/main.sass +3 -0
  86. data/spec/embork/server/example_app/app/index.html +9 -0
  87. data/spec/embork/server/example_app/build/development/application-12345.js +14 -0
  88. data/spec/embork/server/example_app/build/development/index.html +9 -0
  89. data/spec/embork/server/example_app/components/some/component.js +6 -0
  90. data/spec/embork/server/example_app/config/development/application.css +4 -0
  91. data/spec/embork/server/example_app/config/development/application.js +2 -0
  92. data/spec/embork/server/example_app/config/production/application.css +4 -0
  93. data/spec/embork/server/example_app/config/production/application.js +4 -0
  94. data/spec/embork/server/example_app/static/fonts/.gitkeep +0 -0
  95. data/spec/embork/server/example_app/static/images/.gitkeep +0 -0
  96. data/spec/embork/server/example_app/static/images/image.png +0 -0
  97. data/spec/embork/server/specimen.css +7 -0
  98. data/spec/embork/server/specimen.js +14 -0
  99. data/spec/embork/server_spec.rb +152 -0
  100. data/spec/embork/sprockets/ember_handlebars_compiler/amd_template.js +26 -0
  101. data/spec/embork/sprockets/ember_handlebars_compiler/cjs_template.js +24 -0
  102. data/spec/embork/sprockets/ember_handlebars_compiler/global_handlebars_template.js +17 -0
  103. data/spec/embork/sprockets/ember_handlebars_compiler/global_hbs_template.js +17 -0
  104. data/spec/embork/sprockets/ember_handlebars_compiler/my/hbs/template.hbs +5 -0
  105. data/spec/embork/sprockets/ember_handlebars_compiler/my_handlebars_template.js.handlebars +5 -0
  106. data/spec/embork/sprockets/ember_handlebars_compiler/my_hbs_template.js.hbs +5 -0
  107. data/spec/embork/sprockets/ember_handlebars_compiler/transformed_template.js +26 -0
  108. data/spec/embork/sprockets/ember_handlebars_compiler_spec.rb +82 -0
  109. data/spec/embork/sprockets/es6_module_transpiler/app/my/transformed/module.js +13 -0
  110. data/spec/embork/sprockets/es6_module_transpiler/app/my_fancy_module.js +13 -0
  111. data/spec/embork/sprockets/es6_module_transpiler/compiled_amd.js +20 -0
  112. data/spec/embork/sprockets/es6_module_transpiler/compiled_cjs.js +20 -0
  113. data/spec/embork/sprockets/es6_module_transpiler/component.js +1 -0
  114. data/spec/embork/sprockets/es6_module_transpiler/components/some_component.js +1 -0
  115. data/spec/embork/sprockets/es6_module_transpiler/config/application.js +1 -0
  116. data/spec/embork/sprockets/es6_module_transpiler/manifest.js +20 -0
  117. data/spec/embork/sprockets/es6_module_transpiler/namespaced.js +20 -0
  118. data/spec/embork/sprockets/es6_module_transpiler/transformed.js +20 -0
  119. data/spec/embork/sprockets/es6_module_transpiler_spec.rb +97 -0
  120. data/spec/spec_helper.rb +13 -0
  121. metadata +468 -0
@@ -0,0 +1 @@
1
+ # vim: set ft=ruby:
@@ -0,0 +1,3 @@
1
+ import SomeComponent from 'my-app/some_component';
2
+
3
+ export default Ember.Application.create("<%= Embork.env %>");
@@ -0,0 +1,3 @@
1
+ html
2
+ font-family: "Arial", "sans-serif"
3
+
@@ -0,0 +1,9 @@
1
+ <!DOCTYPE>
2
+ <html>
3
+ <head>
4
+ <script src="application.js" ></script>
5
+ <link href="application.css" type="text/css" media="all">
6
+ </head>
7
+ <body>
8
+ </body>
9
+ </html>
@@ -0,0 +1,14 @@
1
+ define("some/component",
2
+ ["exports"],
3
+ function(__exports__) {
4
+ "use strict";
5
+ __exports__["default"] = function SomeComponentFunction(){ alert('Woohoo'); };
6
+ });
7
+ define("app",
8
+ ["my-app/some_component","exports"],
9
+ function(__dependency1__, __exports__) {
10
+ "use strict";
11
+ var SomeComponent = __dependency1__["default"];
12
+
13
+ __exports__["default"] = Ember.Application.create("development");
14
+ });
@@ -0,0 +1,9 @@
1
+ <!DOCTYPE>
2
+ <html>
3
+ <head>
4
+ <script src="application.js" ></script>
5
+ <link href="application.css" type="text/css" media="all">
6
+ </head>
7
+ <body>
8
+ </body>
9
+ </html>
@@ -0,0 +1,6 @@
1
+ define("some/component",
2
+ ["exports"],
3
+ function(__exports__) {
4
+ "use strict";
5
+ __exports__["default"] = function SomeComponentFunction(){ alert('Woohoo'); };
6
+ });
@@ -0,0 +1,4 @@
1
+ /*
2
+ *= require css/main
3
+ */
4
+
@@ -0,0 +1,2 @@
1
+ //= require some/component
2
+ //= require_tree ../../app
@@ -0,0 +1,4 @@
1
+ /*
2
+ *= require_tree ../app/css
3
+ */
4
+
@@ -0,0 +1,4 @@
1
+ //= require some/component
2
+ //= require_tree ../../app
3
+ //
4
+
@@ -0,0 +1,7 @@
1
+ html {
2
+ font-family: "Arial", "sans-serif"; }
3
+ /*
4
+
5
+ */
6
+
7
+
@@ -0,0 +1,14 @@
1
+ define("some/component",
2
+ ["exports"],
3
+ function(__exports__) {
4
+ "use strict";
5
+ __exports__["default"] = function SomeComponentFunction(){ alert('Woohoo'); };
6
+ });
7
+ define("app",
8
+ ["my-app/some_component","exports"],
9
+ function(__dependency1__, __exports__) {
10
+ "use strict";
11
+ var SomeComponent = __dependency1__["default"];
12
+
13
+ __exports__["default"] = Ember.Application.create("development");
14
+ });
@@ -0,0 +1,152 @@
1
+ require 'spec_helper'
2
+ require 'embork/server'
3
+
4
+ require 'base64'
5
+
6
+ project_root = File.expand_path '../server/example_app', __FILE__
7
+ borkfile_path = File.expand_path 'Borkfile', project_root
8
+ index_specimen = File.read File.expand_path('app/index.html', project_root)
9
+
10
+ image_path = File.expand_path 'static/images/image.png', project_root
11
+ image_data = IO.binread(image_path)
12
+
13
+ class MyRackBackend
14
+ attr_reader :app
15
+ def initialize(app = nil, options = {})
16
+ @app = app
17
+ end
18
+
19
+ def call(env)
20
+ body = %{You visited '%s'.} % [ env['PATH_INFO'] ]
21
+ status = 200
22
+ headers = Hash.new
23
+ [ status, headers, body ]
24
+ end
25
+ end
26
+
27
+ js_specimen = nil
28
+ File.open(File.expand_path('../server/specimen.js', __FILE__), 'r:UTF-8') { |f| js_specimen = f.read.strip }
29
+
30
+ css_specimen = nil
31
+ File.open(File.expand_path('../server/specimen.css', __FILE__), 'r:UTF-8') { |f| css_specimen = f.read.strip }
32
+
33
+ describe 'Embork::Server' do
34
+
35
+ before(:each) { FileUtils.rm_rf File.join(project_root, '.cache') }
36
+ let(:borkfile) { Embork::Borkfile.new borkfile_path }
37
+
38
+ context 'pushState backed' do
39
+
40
+ let(:server) { Embork::Server.new borkfile }
41
+ let(:app) { server.app }
42
+
43
+ it 'serves out compiled js' do
44
+ get '/application.js'
45
+ expect(last_response).to be_ok
46
+ expect(last_response.body.strip).to eq(js_specimen)
47
+ end
48
+
49
+ it 'serves out compiled css' do
50
+ get '/application.css'
51
+ expect(last_response).to be_ok
52
+ expect(last_response.body.strip).to eq(css_specimen)
53
+ end
54
+
55
+ it 'serves out static files' do
56
+ get '/images/image.png'
57
+ expect(last_response).to be_ok
58
+ expect(last_response.body).to eq(image_data)
59
+ end
60
+
61
+ it 'responds with index.html at the root path' do
62
+ get '/'
63
+ expect(last_response).to be_ok
64
+ expect(last_response.body).to eq(index_specimen)
65
+ end
66
+
67
+ it 'responds with index.html for arbitrary paths' do
68
+ get '/foo/bar'
69
+ expect(last_response).to be_ok
70
+ expect(last_response.body).to eq(index_specimen)
71
+ end
72
+
73
+ end
74
+
75
+ context 'rack backed' do
76
+ let(:rack_backed_borkfile) { b = borkfile.dup; b.instance_eval { @backend = MyRackBackend }; b }
77
+ let(:server) { Embork::Server.new rack_backed_borkfile }
78
+ let(:app) { server.app }
79
+
80
+ it 'serves out the index using the rack app' do
81
+ get '/'
82
+ expect(last_response).to be_ok
83
+ expect(last_response.body).to eq(%{You visited '/'.})
84
+ end
85
+
86
+ it 'serves out arbitrary paths using rack' do
87
+ get '/foo/bar'
88
+ expect(last_response).to be_ok
89
+ expect(last_response.body).to eq(%{You visited '/foo/bar'.})
90
+ end
91
+
92
+ it 'continues to serve out sprockets assets' do
93
+ get '/application.css'
94
+ expect(last_response).to be_ok
95
+ expect(last_response.body.strip).to eq(css_specimen)
96
+ end
97
+ end
98
+
99
+ context 'bundled assets' do
100
+ let(:server) { Embork::Server.new borkfile, :bundle_version => '12345' }
101
+ let(:app) { server.app }
102
+
103
+ it 'serves out bundled assets' do
104
+ get '/application-12345.js'
105
+ expect(last_response).to be_ok
106
+ expect(last_response.body.strip).to eq(js_specimen)
107
+ end
108
+
109
+ it 'serves out the index' do
110
+ get '/index.html'
111
+ expect(last_response).to be_ok
112
+ expect(last_response.body).to eq(index_specimen)
113
+ end
114
+
115
+ it 'serves out the index for the root path' do
116
+ get '/'
117
+ expect(last_response).to be_ok
118
+ expect(last_response.body).to eq(index_specimen)
119
+ end
120
+
121
+ it 'servers out the index for arbitrary paths' do
122
+ get '/foo/bar'
123
+ expect(last_response).to be_ok
124
+ expect(last_response.body).to eq(index_specimen)
125
+ end
126
+ end
127
+
128
+ context 'bundled assets and rack backend' do
129
+ let(:rack_backed_borkfile) { b = borkfile.dup; b.instance_eval { @backend = MyRackBackend }; b }
130
+ let(:server) { Embork::Server.new rack_backed_borkfile, :bundle_version => '12345' }
131
+ let(:app) { server.app }
132
+
133
+ it 'serves out bundled assets' do
134
+ get '/application-12345.js'
135
+ expect(last_response).to be_ok
136
+ expect(last_response.body.strip).to eq(js_specimen)
137
+ end
138
+
139
+ it 'serves out the index using the rack app' do
140
+ get '/'
141
+ expect(last_response).to be_ok
142
+ expect(last_response.body).to eq(%{You visited '/'.})
143
+ end
144
+
145
+ it 'serves out arbitrary paths using rack' do
146
+ get '/foo/bar'
147
+ expect(last_response).to be_ok
148
+ expect(last_response.body).to eq(%{You visited '/foo/bar'.})
149
+ end
150
+
151
+ end
152
+ end
@@ -0,0 +1,26 @@
1
+ define("my-package/my_hbs_template",
2
+ ["exports"],
3
+ function(__exports__) {
4
+
5
+ "use strict";
6
+ var template = Ember.Handlebars.template(function anonymous(Handlebars,depth0,helpers,partials,data) {
7
+ this.compilerInfo = [4,'>= 1.0.0'];
8
+ helpers = this.merge(helpers, Ember.Handlebars.helpers); data = data || {};
9
+ var buffer = '', stack1, escapeExpression=this.escapeExpression;
10
+
11
+
12
+ data.buffer.push("<p>\n Hello ");
13
+ stack1 = helpers._triageMustache.call(depth0, "name", {hash:{},hashTypes:{},hashContexts:{},contexts:[depth0],types:["ID"],data:data});
14
+ if(stack1 || stack1 === 0) { data.buffer.push(stack1); }
15
+ data.buffer.push(", here is a horrible picure:\n <br />\n <img ");
16
+ data.buffer.push(escapeExpression(helpers['bind-attr'].call(depth0, {hash:{
17
+ 'src': ("horriblePictureUrl")
18
+ },hashTypes:{'src': "ID"},hashContexts:{'src': depth0},contexts:[],types:[],data:data})));
19
+ data.buffer.push(" />\n</p>\n");
20
+ return buffer;
21
+
22
+ });
23
+
24
+ __exports__["default"] = template;
25
+
26
+ });
@@ -0,0 +1,24 @@
1
+ window.require.define({"my-package/my_hbs_template": function(exports, require, module) {
2
+
3
+ "use strict";
4
+ var template = Ember.Handlebars.template(function anonymous(Handlebars,depth0,helpers,partials,data) {
5
+ this.compilerInfo = [4,'>= 1.0.0'];
6
+ helpers = this.merge(helpers, Ember.Handlebars.helpers); data = data || {};
7
+ var buffer = '', stack1, escapeExpression=this.escapeExpression;
8
+
9
+
10
+ data.buffer.push("<p>\n Hello ");
11
+ stack1 = helpers._triageMustache.call(depth0, "name", {hash:{},hashTypes:{},hashContexts:{},contexts:[depth0],types:["ID"],data:data});
12
+ if(stack1 || stack1 === 0) { data.buffer.push(stack1); }
13
+ data.buffer.push(", here is a horrible picure:\n <br />\n <img ");
14
+ data.buffer.push(escapeExpression(helpers['bind-attr'].call(depth0, {hash:{
15
+ 'src': ("horriblePictureUrl")
16
+ },hashTypes:{'src': "ID"},hashContexts:{'src': depth0},contexts:[],types:[],data:data})));
17
+ data.buffer.push(" />\n</p>\n");
18
+ return buffer;
19
+
20
+ });
21
+
22
+ exports["default"] = template;
23
+
24
+ }});
@@ -0,0 +1,17 @@
1
+ Ember.TEMPLATES['my-package/my_handlebars_template'] = Ember.Handlebars.template(function anonymous(Handlebars,depth0,helpers,partials,data) {
2
+ this.compilerInfo = [4,'>= 1.0.0'];
3
+ helpers = this.merge(helpers, Ember.Handlebars.helpers); data = data || {};
4
+ var buffer = '', stack1, escapeExpression=this.escapeExpression;
5
+
6
+
7
+ data.buffer.push("<p>\n Hello ");
8
+ stack1 = helpers._triageMustache.call(depth0, "name", {hash:{},hashTypes:{},hashContexts:{},contexts:[depth0],types:["ID"],data:data});
9
+ if(stack1 || stack1 === 0) { data.buffer.push(stack1); }
10
+ data.buffer.push(", here is a horrible picure:\n <br />\n <img ");
11
+ data.buffer.push(escapeExpression(helpers['bind-attr'].call(depth0, {hash:{
12
+ 'src': ("horriblePictureUrl")
13
+ },hashTypes:{'src': "ID"},hashContexts:{'src': depth0},contexts:[],types:[],data:data})));
14
+ data.buffer.push(" />\n</p>\n");
15
+ return buffer;
16
+
17
+ });
@@ -0,0 +1,17 @@
1
+ Ember.TEMPLATES['my-package/my_hbs_template'] = Ember.Handlebars.template(function anonymous(Handlebars,depth0,helpers,partials,data) {
2
+ this.compilerInfo = [4,'>= 1.0.0'];
3
+ helpers = this.merge(helpers, Ember.Handlebars.helpers); data = data || {};
4
+ var buffer = '', stack1, escapeExpression=this.escapeExpression;
5
+
6
+
7
+ data.buffer.push("<p>\n Hello ");
8
+ stack1 = helpers._triageMustache.call(depth0, "name", {hash:{},hashTypes:{},hashContexts:{},contexts:[depth0],types:["ID"],data:data});
9
+ if(stack1 || stack1 === 0) { data.buffer.push(stack1); }
10
+ data.buffer.push(", here is a horrible picure:\n <br />\n <img ");
11
+ data.buffer.push(escapeExpression(helpers['bind-attr'].call(depth0, {hash:{
12
+ 'src': ("horriblePictureUrl")
13
+ },hashTypes:{'src': "ID"},hashContexts:{'src': depth0},contexts:[],types:[],data:data})));
14
+ data.buffer.push(" />\n</p>\n");
15
+ return buffer;
16
+
17
+ });
@@ -0,0 +1,5 @@
1
+ <p>
2
+ Hello {{name}}, here is a horrible picure:
3
+ <br />
4
+ <img {{bind-attr src=horriblePictureUrl}} />
5
+ </p>
@@ -0,0 +1,5 @@
1
+ <p>
2
+ Hello {{name}}, here is a horrible picure:
3
+ <br />
4
+ <img {{bind-attr src=horriblePictureUrl}} />
5
+ </p>
@@ -0,0 +1,5 @@
1
+ <p>
2
+ Hello {{name}}, here is a horrible picure:
3
+ <br />
4
+ <img {{bind-attr src=horriblePictureUrl}} />
5
+ </p>
@@ -0,0 +1,26 @@
1
+ define("my-package/hbs_template",
2
+ ["exports"],
3
+ function(__exports__) {
4
+
5
+ "use strict";
6
+ var template = Ember.Handlebars.template(function anonymous(Handlebars,depth0,helpers,partials,data) {
7
+ this.compilerInfo = [4,'>= 1.0.0'];
8
+ helpers = this.merge(helpers, Ember.Handlebars.helpers); data = data || {};
9
+ var buffer = '', stack1, escapeExpression=this.escapeExpression;
10
+
11
+
12
+ data.buffer.push("<p>\n Hello ");
13
+ stack1 = helpers._triageMustache.call(depth0, "name", {hash:{},hashTypes:{},hashContexts:{},contexts:[depth0],types:["ID"],data:data});
14
+ if(stack1 || stack1 === 0) { data.buffer.push(stack1); }
15
+ data.buffer.push(", here is a horrible picure:\n <br />\n <img ");
16
+ data.buffer.push(escapeExpression(helpers['bind-attr'].call(depth0, {hash:{
17
+ 'src': ("horriblePictureUrl")
18
+ },hashTypes:{'src': "ID"},hashContexts:{'src': depth0},contexts:[],types:[],data:data})));
19
+ data.buffer.push(" />\n</p>\n");
20
+ return buffer;
21
+
22
+ });
23
+
24
+ __exports__["default"] = template;
25
+
26
+ });
@@ -0,0 +1,82 @@
1
+ require 'spec_helper'
2
+
3
+ require 'embork/sprockets/ember_handlebars_compiler'
4
+
5
+ require 'pry'
6
+
7
+
8
+ describe 'Embork::Sprockets::EmberHandlebarsCompiler' do
9
+ before(:all) { Embork::Sprockets::EmberHandlebarsCompiler.namespace = 'my-package' }
10
+ after(:all) { Embork::Sprockets::EmberHandlebarsCompiler.namespace = nil }
11
+ let(:root_path) { File.expand_path('../ember_handlebars_compiler', __FILE__) }
12
+
13
+ let(:app) do
14
+ s = Sprockets::Environment.new root_path
15
+ s.register_engine '.handlebars', Embork::Sprockets::EmberHandlebarsCompiler
16
+ s.register_engine '.hbs', Embork::Sprockets::EmberHandlebarsCompiler
17
+ s.append_path '.'
18
+ Rack::Builder.new do
19
+ run s
20
+ end
21
+ end
22
+
23
+ context 'Globals' do
24
+ before(:all) { Embork::Sprockets::EmberHandlebarsCompiler.compile_to = :globals }
25
+ after(:all) { Embork::Sprockets::EmberHandlebarsCompiler.compile_to = :amd }
26
+
27
+ let(:global_hbs_specimen) { File.read(File.join(root_path, 'global_hbs_template.js')).strip }
28
+ let(:global_handlebars_specimen) { File.read(File.join(root_path, 'global_handlebars_template.js')).strip }
29
+ it 'compiles handlebars source to ember handlebars' do
30
+ get '/my_handlebars_template.js'
31
+ expect(last_response).to be_ok
32
+ expect(last_response.body).to eq(global_handlebars_specimen)
33
+ end
34
+
35
+ it 'compiles hbs source to ember handlebars' do
36
+ get '/my_hbs_template.js'
37
+ expect(last_response).to be_ok
38
+ expect(last_response.body).to eq(global_hbs_specimen)
39
+ end
40
+ end
41
+
42
+ context 'CommonJS' do
43
+ before(:all) { Embork::Sprockets::EmberHandlebarsCompiler.compile_to = :cjs }
44
+ after(:all) { Embork::Sprockets::EmberHandlebarsCompiler.compile_to = :amd }
45
+
46
+ let(:cjs_specimen) { File.read(File.join(root_path, 'cjs_template.js')).strip }
47
+
48
+ it 'compiles hbs source to ember handlebars' do
49
+ get '/my_hbs_template.js'
50
+ expect(last_response).to be_ok
51
+ expect(last_response.body.strip).to eq(cjs_specimen)
52
+ end
53
+ end
54
+
55
+ context 'AMD' do
56
+ let(:amd_specimen) { File.read(File.join(root_path, 'amd_template.js')).strip }
57
+
58
+ it 'compiles hbs source to ember handlebars' do
59
+ get '/my_hbs_template.js'
60
+ expect(last_response).to be_ok
61
+ expect(last_response.body.strip).to eq(amd_specimen)
62
+ end
63
+ end
64
+
65
+ context 'Transformed names' do
66
+ before(:all) do
67
+ transform = Proc.new do |module_name|
68
+ module_name.split('/').tap{ |parts| parts.shift }.join('_')
69
+ end
70
+ Embork::Sprockets::EmberHandlebarsCompiler.transform = transform
71
+ end
72
+ after(:all) { Embork::Sprockets::EmberHandlebarsCompiler.transform = nil }
73
+
74
+ let(:transformed_specimen) { File.read(File.join(root_path, 'transformed_template.js')).strip }
75
+
76
+ it 'transforms module names with a given proc' do
77
+ get '/my/hbs/template.js'
78
+ expect(last_response).to be_ok
79
+ expect(last_response.body.strip).to eq(transformed_specimen)
80
+ end
81
+ end
82
+ end