embork 0.0.4 → 0.0.5

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: 68e08a13835911d3be709a08ed0f8c8e1d33d41f
4
- data.tar.gz: 2d1db05b1f2d067446e290a62d69d615e6dfe0d6
3
+ metadata.gz: beee56400bed3d39116dd3bfd9b3f447739f08b8
4
+ data.tar.gz: 144f885261daf6d9793b1616705d44c0ccef14a1
5
5
  SHA512:
6
- metadata.gz: c59ae75b4decaa04317aa4b0e32b064969d26a40a1ff2ea0a667baca1bb635294a04d1a85fce506714282047e3f584373c8aeec2a3a4d6e6f0da8bf7b7d2dd15
7
- data.tar.gz: 79a46ae25a8232379c62ffc16f84c60b389238a08038fdbc389ecd4ab65c68351d316de644b0a4ac5a2cf46d711895c9d73eb03c6794c92d94f59a0904f916da
6
+ metadata.gz: 300f11415db99528295500a1500762b74e295e873817caa0b4c035305bfc2c0af75239a14cbd947241229436e36503394ccb668098e270baf1d289438f001461
7
+ data.tar.gz: 6823e594fdc2f0a3a1e427e15218028cb6acc1101c85144794ceee2e8c2150fd1ec859176ba32725057f90b31d3099ab874111c5bc9b6415b3b348ac91f09c60
data/README.md CHANGED
@@ -1,24 +1,47 @@
1
1
  # Embork
2
2
 
3
- TODO: Write a gem description
3
+ Build awesome hybrid EmberJS Apps! Embork is a build system for ember backed by
4
+ sprockets. It works like any conventional build system, but with a focus on
5
+ supporting multiple build targets. It also has a facility to develop with a
6
+ rack-compatible back-end providing the index.html file.
4
7
 
5
8
  ## Installation
6
9
 
7
- Add this line to your application's Gemfile:
10
+ Install it as a gem!
8
11
 
9
- gem 'embork'
12
+ $ gem install embork
10
13
 
11
- And then execute:
14
+ ## Usage
12
15
 
13
- $ bundle
16
+ #### To create a new application:
14
17
 
15
- Or install it yourself as:
18
+ $ embork new my-app
16
19
 
17
- $ gem install embork
20
+ #### Running the development server:
18
21
 
19
- ## Usage
22
+ $ embork server <environment>
23
+
24
+ The default environment is 'development'. There is also a production environment
25
+ included with the generator, however, you may create as many environments as you
26
+ want just by copying or creating a new folder under the `config` directory.
27
+
28
+ #### Running the test suite
29
+
30
+ There are two ways to run tests. You can run the QUnit test suite in a browser
31
+ by running the test server with the test paths enabled:
32
+
33
+ $ embork server --enable-tests <environment>
34
+ $ open http://localhost:9292/tests.html
35
+
36
+ You can also run the test suite entirely via the command line:
37
+
38
+ $ embork test <environment>
20
39
 
21
- TODO: Write usage instructions here
40
+ This will run a server on a random port, and connect to it using the
41
+ `qunit-runner` [gem](https://github.com/scoremedia/qunit-runner "qunit-runner").
42
+ This is the best option to use for integrating QUnit into your ci server.
43
+ Additionally, you can use the `DISABLE_COLORS` environment variable to turn off
44
+ colour in stdout. This helps with ci servers that don't support tty color.
22
45
 
23
46
  ## Contributing
24
47
 
data/bin/embork CHANGED
@@ -1,63 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'embork'
4
- require 'thor'
3
+ require 'embork/cli'
5
4
 
6
- class EmborkCLI < Thor
7
- class_option :borkfile, :type => :string, :default => "./Borkfile",
8
- :desc => "Path to the embork config file."
9
-
10
- desc "create PACKAGE_NAME", %{generate an Embork Ember application called "PACKAGE_NAME"}
11
- option :use_ember_data, :type => :boolean, :default => false
12
- option :directory, :type => :string, :default => nil
13
- def create(package_name)
14
- puts %{Creating embork app in "%s"} % package_name
15
- Embork::Generator.new(package_name, options).generate
16
- end
17
-
18
- desc "server [ENVIRONMENT]", %{run the development or production server}
19
- option :port, :type => :numeric, :default => 9292
20
- option :host, :type => :string, :default => 'localhost'
21
- option :bundle_version, :type => :string, :default => nil
22
- option :with_latest_bundle, :type => :boolean, :default => false
23
- def server(environment = :development)
24
- borkfile = Embork::Borkfile.new options[:borkfile], environment
25
- Embork::Server.new(borkfile, options).run
26
- end
27
-
28
- desc "build [ENVIRONMENT]", %{build the project in the 'build' directory}
29
- option :keep_all_old_versions, :type => :boolean, :default => false,
30
- :desc => %{By default, older versions of the project are removed, only keeping the last few versions. This flag keeps all old versions.}
31
- def build(environment = :production)
32
- borkfile = Embork::Borkfile.new options[:borkfile], environment
33
- builder = Embork::Builder.new(borkfile)
34
- builder.build
35
- builder.clean unless options[:keep_all_old_versions]
36
- end
37
-
38
- desc "clean", %{Remove all files under the build directory}
39
- def clean
40
- borkfile = Embork::Borkfile.new options[:borkfile]
41
- FileUtils.rm_rf File.expand_path('build', borkfile.project_root)
42
- end
43
-
44
- desc "clean-cache", %{Blow away the sprockets cache}
45
- def clean_cache
46
- borkfile = Embork::Borkfile.new options[:borkfile]
47
- FileUtils.rm_rf File.expand_path('.cache', borkfile.project_root)
48
- end
49
-
50
- desc "hint", %{run jshint on the app and tests}
51
- option :only_app, :type => :boolean, :default => false
52
- option :only_tests, :type => :boolean, :default => false
53
- def hint
54
- borkfile = Embork::Borkfile.new options[:borkfile]
55
- Dir.chdir borkfile.project_root do
56
- system('npm run hint-app') unless options[:only_tests]
57
- system('npm run hint-testss') unless options[:only_app]
58
- end
59
- end
60
-
61
- end
62
-
63
- EmborkCLI.start(ARGV)
5
+ Embork::CLI.start(ARGV)
@@ -34,6 +34,11 @@ configure :development do
34
34
  end
35
35
 
36
36
  configure :production do
37
+ # Enable a javascript compressor. Whichever you enable, include the
38
+ # corresponding gem in the Gemfile.
39
+ #
40
+ # compress_with :closure_compiler
41
+ # compress_with :uglifier
37
42
  end
38
43
 
39
44
  # Use :static index to fall back to sprockets-built html files OR pass in
@@ -11,3 +11,8 @@ gem 'embork'
11
11
  # Borkfile.
12
12
  #
13
13
  # gem 'bootstrap-sass'
14
+
15
+ # Include the closure-compiler or uglifier gem to use either javascript
16
+ # compressor. They both have to be enabled through your Borkfile.
17
+ #
18
+ # gem 'closure-compiler'
@@ -1,5 +1,6 @@
1
1
  app/app.js
2
2
  app/index.html.erb
3
+ tests/tests.html.erb
3
4
  bower.json
4
5
  package.json
5
6
  Borkfile
@@ -0,0 +1 @@
1
+ //= require_tree ./fixtures
@@ -1,6 +1,3 @@
1
- /* globals requirejs,require */
2
-
3
- // TODO: load based on params
4
1
  Ember.keys(requirejs.entries).forEach(function(entry) {
5
2
  if ((/\-test/).test(entry)) {
6
3
  require(entry, null, null, true);
@@ -7,7 +7,6 @@
7
7
  <meta name="description" content="">
8
8
  <meta name="viewport" content="width=device-width, initial-scale=1">
9
9
 
10
-
11
10
  <link rel="stylesheet" href="assets/qunit.css">
12
11
  <style>
13
12
  #ember-testing-container {
@@ -25,18 +24,23 @@
25
24
  zoom: 50%;
26
25
  }
27
26
  </style>
27
+
28
+ <%%= javascript_include_tag "/application.js" %>
29
+ <%%= javascript_include_tag "/tests.js" %>
30
+
31
+ <script src="/qunit/qunit/qunit.js"></script>
32
+ <script src="/ember-qunit/dist/named-amd/main.js"></script>
33
+
28
34
  </head>
29
35
  <body>
30
36
  <div id="qunit"></div>
31
37
  <div id="qunit-fixture"></div>
32
38
 
33
- <script>
34
- window.ENV = {{ENV}};
35
- </script>
36
39
  <script src="assets/qunit.js"></script>
37
40
  <script src="assets/application.js"></script>
38
41
  <script src="assets/tests.js"></script>
39
42
  <script>
43
+ window.ENV = <%%= Embork.env %>;
40
44
  require('<%= namespace %>/tests/test-helper');
41
45
  require('<%= namespace %>/tests/test-loader');
42
46
  </script>
@@ -0,0 +1,5 @@
1
+ //= require test-helper
2
+ //= require test-loader
3
+ //= require_tree ./helpers
4
+ //= require_tree ./integration
5
+ //= require_tree ./unit
@@ -6,7 +6,7 @@ require 'embork/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'embork'
8
8
  spec.version = Embork::VERSION
9
- spec.authors = ['Matthew Smart']
9
+ spec.authors = ['Mina Smart']
10
10
  spec.email = ['mdsmart@gmail.com']
11
11
  spec.description = %q{A tool set for building ember apps.}
12
12
  spec.summary = %q{A tool set for building ember apps.}
@@ -22,12 +22,14 @@ Gem::Specification.new do |spec|
22
22
  spec.add_runtime_dependency 'ember-source', '~> 1.5.1.1'
23
23
  spec.add_runtime_dependency 'handlebars-source', '~> 1.3.0'
24
24
  spec.add_runtime_dependency 'thor', '~> 0.19.1'
25
- spec.add_runtime_dependency 'rack'
25
+ spec.add_runtime_dependency 'rack', '~> 1.5.2'
26
26
  spec.add_runtime_dependency 'coffee-script'
27
- spec.add_runtime_dependency 'sass'
27
+ spec.add_runtime_dependency 'sass', '~> 3.2.0'
28
28
  spec.add_runtime_dependency 'execjs'
29
- spec.add_runtime_dependency 'barber'
29
+ spec.add_runtime_dependency 'barber', '~> 0.4.2'
30
30
  spec.add_runtime_dependency 'colorize'
31
+ spec.add_runtime_dependency 'qunit-runner', '~> 0.0.1'
32
+ spec.add_runtime_dependency 'phrender', '~> 0.0.3'
31
33
 
32
34
  spec.add_development_dependency 'bundler', '~> 1.3'
33
35
  spec.add_development_dependency 'rspec', '~> 3.0.0.beta1'
@@ -37,5 +39,6 @@ Gem::Specification.new do |spec|
37
39
  spec.add_development_dependency 'pry', '0.9.12.2'
38
40
  spec.add_development_dependency 'compass'
39
41
  spec.add_development_dependency 'bootstrap-sass'
42
+ spec.add_development_dependency 'closure-compiler'
40
43
 
41
44
  end
@@ -10,14 +10,12 @@ require "embork/generator"
10
10
  require "embork/logger"
11
11
  require "embork/pushstate"
12
12
  require "embork/server"
13
+ require "embork/phrender"
13
14
  require "embork/sprockets"
14
15
 
15
16
  class Embork
16
- def self.env
17
- @env
18
- end
19
-
20
- def self.env=(environment)
21
- @env = environment
17
+ class << self
18
+ attr_accessor :env
19
+ attr_accessor :bundle_version
22
20
  end
23
21
  end
@@ -13,6 +13,16 @@ class Embork::Borkfile
13
13
  attr_reader :backend
14
14
  attr_reader :html
15
15
  attr_reader :frameworks
16
+ attr_reader :compressor
17
+ attr_reader :es6_transform
18
+ attr_reader :phrender_index_file
19
+ attr_reader :phrender_javascript_paths
20
+ attr_reader :phrender_raw_javascript
21
+
22
+ # request uri path to the index file.
23
+ def phrender_index_file(index_file_path = nil)
24
+ @phrender_index_file = index_file_path || @phrender_index_file
25
+ end
16
26
 
17
27
  def keep_old_versions(number_to_keep = nil)
18
28
  @keep_old_versions = number_to_keep || @keep_old_versions
@@ -27,9 +37,10 @@ class Embork::Borkfile
27
37
  include Attributes
28
38
 
29
39
  SUPPORTED_FRAMEWORKS = %w(bootstrap compass)
40
+ SUPPORTED_COMPRESSORS = %w(closure_compiler uglifier)
30
41
 
31
42
  def initialize(environment, logger)
32
- Embork.env = @environment = environment
43
+ Embork.env = @environment = environment.to_sym
33
44
  @asset_paths = []
34
45
  @helpers = []
35
46
  @sprockets_postprocessors = []
@@ -42,11 +53,16 @@ class Embork::Borkfile
42
53
  @es6_namespace = nil
43
54
  @frameworks = []
44
55
  @logger = logger
56
+ @compressor = nil
57
+ @es6_transform = nil
58
+ @phrender_javascript_paths = []
59
+ @phrender_raw_javascript = []
60
+ @phrender_index_file = nil
45
61
  end
46
62
 
47
63
  def use_framework(framework)
48
64
  framework = framework.to_s
49
- if SUPPORTED_FRAMEWORKS.include? framework.to_s
65
+ if SUPPORTED_FRAMEWORKS.include? framework
50
66
  @frameworks.push framework
51
67
  else
52
68
  @logger.critical 'Framework "%s" is not currently supported by embork.' % framework
@@ -83,6 +99,14 @@ class Embork::Borkfile
83
99
  @backend = app
84
100
  end
85
101
 
102
+ def phrender_add_javascript_file(path)
103
+ @phrender_javascript_paths.push path
104
+ end
105
+
106
+ def phrender_add_javascript(code)
107
+ @phrender_raw_javascript.push code
108
+ end
109
+
86
110
  def configure(environment, &block)
87
111
  if environment == @environment
88
112
  self.instance_exec &block
@@ -90,13 +114,33 @@ class Embork::Borkfile
90
114
  end
91
115
 
92
116
  def get_binding
93
- return binding
117
+ binding
94
118
  end
95
119
 
96
120
  def compile_html(files)
97
121
  files = [ files ] unless files.kind_of? Array
98
122
  @html.concat files
99
123
  end
124
+
125
+ def compress_with(compressor)
126
+ if SUPPORTED_COMPRESSORS.include? compressor.to_s
127
+ @compressor = compressor
128
+ else
129
+ @logger.critical 'Compressor "%s" is not currently supported by embork.' % compressor.to_s
130
+ @logger.unknown ''
131
+ exit 1
132
+ end
133
+ end
134
+
135
+ def transform_es6_module_names(transform_proc)
136
+ if transform_proc.respond_to?(:call) || transform_proc.nil?
137
+ @es6_transform = transform_proc
138
+ else
139
+ @logger.critical 'ES6 Module transform must respond to #call'
140
+ exit 1
141
+ end
142
+ end
143
+
100
144
  end
101
145
 
102
146
  include Attributes
@@ -123,8 +167,9 @@ class Embork::Borkfile
123
167
  def set_options(file)
124
168
  # Setup paths
125
169
  default_paths = [
126
- 'app',
127
170
  'config/%s' % [ @environment.to_s ],
171
+ 'app',
172
+ 'app/styles',
128
173
  'components'
129
174
  ]
130
175
  @asset_paths = default_paths.concat file.asset_paths
@@ -0,0 +1,95 @@
1
+ require 'embork'
2
+ require 'qunit/runner'
3
+ require 'thor'
4
+
5
+ class Embork::CLI < Thor
6
+ class_option :borkfile, :type => :string, :default => "./Borkfile",
7
+ :desc => "Path to the embork config file."
8
+
9
+ desc "create PACKAGE_NAME", %{generate an Embork Ember application called "PACKAGE_NAME"}
10
+ option :use_ember_data, :type => :boolean, :default => false
11
+ option :directory, :type => :string, :default => nil
12
+ def create(package_name)
13
+ puts %{Creating embork app in "%s"} % package_name
14
+ Embork::Generator.new(package_name, options).generate
15
+ end
16
+
17
+ desc "server [ENVIRONMENT]", %{run the development or production server}
18
+ option :port, :type => :numeric, :default => 9292
19
+ option :host, :type => :string, :default => 'localhost'
20
+ option :bundle_version, :type => :string, :default => nil
21
+ option :with_latest_bundle, :type => :boolean, :default => false
22
+ option :enable_tests, :type => :boolean, :default => false
23
+ def server(environment = :development)
24
+ borkfile = Embork::Borkfile.new options[:borkfile], environment
25
+ Embork::Server.new(borkfile, options).run_webrick
26
+ end
27
+
28
+ desc "phrender [ENVIRONMENT]", %{run phrender the prerenderer}
29
+ option :port, :type => :numeric, :default => 9292
30
+ option :host, :type => :string, :default => 'localhost'
31
+ option :bundle_version, :type => :string, :default => nil
32
+ option :with_latest_bundle, :type => :boolean, :default => false
33
+ def phrender(environment = :development)
34
+ borkfile = Embork::Borkfile.new options[:borkfile], environment
35
+ Embork::Phrender.new(borkfile, options).run_webrick
36
+ end
37
+
38
+ desc "test [ENVIRONMENT]", %{run the qunit test suite}
39
+ def test(environment = :development)
40
+ borkfile = Embork::Borkfile.new options[:borkfile], environment
41
+ min = 52000
42
+ max = 65000
43
+ port = (Random.rand * (max - min) + min).to_i
44
+ host = 'localhost'
45
+
46
+ server_options = {
47
+ :host => host,
48
+ :port => port,
49
+ :enable_tests => true,
50
+ :disable_logging => true
51
+ }
52
+
53
+ server = Embork::Server.new(borkfile, server_options)
54
+
55
+ server_thread = Thread.new{ server.run_webrick }
56
+
57
+ test_url = "http://%s:%s/tests.html" % [ host, port ]
58
+ Qunit::Runner.new(test_url).run(options[:timeout])
59
+ server_thread.kill
60
+ end
61
+
62
+ desc "build [ENVIRONMENT]", %{build the project in the 'build' directory}
63
+ option :keep_all_old_versions, :type => :boolean, :default => false,
64
+ :desc => %{By default, older versions of the project are removed, only keeping the last few versions. This flag keeps all old versions.}
65
+ def build(environment = :production)
66
+ borkfile = Embork::Borkfile.new options[:borkfile], environment
67
+ builder = Embork::Builder.new(borkfile)
68
+ builder.build
69
+ builder.clean unless options[:keep_all_old_versions]
70
+ end
71
+
72
+ desc "clean", %{Remove all files under the build directory}
73
+ def clean
74
+ borkfile = Embork::Borkfile.new options[:borkfile]
75
+ FileUtils.rm_rf File.expand_path('build', borkfile.project_root)
76
+ end
77
+
78
+ desc "clean-cache", %{Blow away the sprockets cache}
79
+ def clean_cache
80
+ borkfile = Embork::Borkfile.new options[:borkfile]
81
+ FileUtils.rm_rf File.expand_path('.cache', borkfile.project_root)
82
+ end
83
+
84
+ desc "hint", %{run jshint on the app and tests}
85
+ option :only_app, :type => :boolean, :default => false
86
+ option :only_tests, :type => :boolean, :default => false
87
+ def hint
88
+ borkfile = Embork::Borkfile.new options[:borkfile]
89
+ Dir.chdir borkfile.project_root do
90
+ system('npm run hint-app') unless options[:only_tests]
91
+ system('npm run hint-testss') unless options[:only_app]
92
+ end
93
+ end
94
+
95
+ end
@@ -1,5 +1,6 @@
1
1
  require 'embork/sprockets'
2
2
  require 'sprockets'
3
+ require 'tilt'
3
4
 
4
5
  class Embork::Environment
5
6
  include Embork::Sprockets::Frameworks
@@ -42,12 +43,19 @@ class Embork::Environment
42
43
  setup_processors
43
44
  setup_engines
44
45
  setup_frameworks
46
+ setup_transforms
47
+ setup_compressor if @borkfile.compressor
48
+ end
49
+
50
+ def setup_transforms
51
+ Embork::Sprockets::ES6ModuleTranspiler.transform = @borkfile.es6_transform
45
52
  end
46
53
 
47
54
  def setup_sprockets_defaults
48
55
  @sprockets_environment.register_postprocessor 'application/javascript', Embork::Sprockets::ES6ModuleTranspiler
49
56
  @sprockets_environment.register_engine '.hbs', Embork::Sprockets::EmberHandlebarsCompiler
50
57
  @sprockets_environment.register_engine '.handlebars', Embork::Sprockets::EmberHandlebarsCompiler
58
+ ::Tilt::CoffeeScriptTemplate.default_bare = true
51
59
  end
52
60
 
53
61
  def setup_paths
@@ -87,4 +95,13 @@ class Embork::Environment
87
95
  self.send method, @sprockets_environment
88
96
  end
89
97
  end
98
+
99
+ def setup_compressor
100
+ if @borkfile.compressor == :closure_compiler
101
+ @sprockets_environment.register_bundle_processor 'application/javascript',
102
+ Embork::Sprockets::ClosureCompiler
103
+ elsif @borkfile.compressor == :uglifier
104
+ @sprockets_environment.js_compressor = :uglify
105
+ end
106
+ end
90
107
  end
@@ -15,9 +15,9 @@ class Embork::Forwarder
15
15
  def call(env)
16
16
  status, headers, body = @app.call(env)
17
17
  if status == 404
18
- self.class.target.new(@app).call(env)
19
- else
20
- [ status, headers, body ]
18
+ status, headers, body = self.class.target.new(@app).call(env)
19
+ headers['Push-State-Redirect'] = 'true'
21
20
  end
21
+ [ status, headers, body ]
22
22
  end
23
23
  end
@@ -0,0 +1,21 @@
1
+ require 'phrender'
2
+ require 'embork/server'
3
+
4
+ class Embork::Phrender < Embork::Server
5
+
6
+ def build_app
7
+ cascade_apps = @cascade_apps
8
+ phrender = [Phrender::RackMiddleware, {
9
+ :javascript_files => @borkfile.phrender_javascript_paths,
10
+ :javascript => @borkfile.phrender_raw_javascript,
11
+ :index_file => @borkfile.phrender_index_file
12
+ }]
13
+ backend = @borkfile.backend
14
+ Rack::Builder.new do
15
+ use *phrender
16
+ use backend unless backend == :static_index
17
+ run Rack::Cascade.new(cascade_apps)
18
+ end
19
+ end
20
+
21
+ end
@@ -7,10 +7,11 @@ class Embork::Pushstate
7
7
  def call(env)
8
8
  status, headers, body = @app.call(env)
9
9
  if status == 404
10
- env['PATH_INFO'] = '/index.html'
11
- @app.call(env)
12
- else
13
- [ status, headers, body ]
10
+ modified_env = env.dup
11
+ modified_env['PATH_INFO'] = '/index.html'
12
+ status, headers, body = @app.call(modified_env)
13
+ headers['Push-State-Redirect'] = 'true'
14
14
  end
15
+ [ status, headers, body ]
15
16
  end
16
17
  end
@@ -11,19 +11,25 @@ class Embork::Server
11
11
  attr_reader :backend
12
12
  attr_reader :project_root
13
13
  attr_reader :sprockets_environment
14
+ attr_reader :port
15
+ attr_reader :host
16
+ attr_reader :disable_logging
14
17
  attr_reader :app
15
18
 
16
-
17
19
  def initialize(borkfile, options = {})
18
20
  @borkfile = borkfile
19
- if options.has_key?(:bundle_version) && !options[:bundle_version].nil?
20
- @bundle_version = options[:bundle_version]
21
+ if !options[:bundle_version].nil?
22
+ Embork.bundle_version = options[:bundle_version]
23
+ setup_bundled_mode
24
+ elsif options[:with_latest_bundle]
25
+ Embork.bundle_version = sorted_versions(@borkfile.project_root).first
21
26
  setup_bundled_mode
22
- elsif options.has_key?(:with_latest_bundle) && !!options[:with_latest_bundle]
23
- @asset_bundle_version = sorted_versions(@borkfile.project_root).first
27
+ elsif options[:enable_tests]
28
+ setup_test_mode
24
29
  else
25
30
  setup_dev_mode
26
31
  end
32
+ @disable_logging = options[:disable_logging]
27
33
  @port = options[:port]
28
34
  @host = options[:host]
29
35
  end
@@ -33,48 +39,53 @@ class Embork::Server
33
39
  @sprockets_environment = @environment.sprockets_environment
34
40
  @project_root = @borkfile.project_root
35
41
 
36
- set_backend
37
-
38
- container = self
39
- static_directory = File.join(container.project_root, 'static')
42
+ static_directory = File.join(project_root, 'static')
40
43
 
41
- @app = Rack::Builder.new do
42
- use container.backend
43
- use Rack::Static, :urls => [ '/images', '/fonts', ], :root => static_directory
44
-
45
- map '/' do
46
- run container.sprockets_environment
47
- end
48
- end
44
+ @cascade_apps = [
45
+ @sprockets_environment,
46
+ Rack::File.new(static_directory)
47
+ ]
48
+ @app = build_app
49
49
  end
50
50
 
51
51
  def setup_bundled_mode
52
52
  @project_root = File.join @borkfile.project_root, 'build', Embork.env.to_s
53
53
 
54
- set_backend
55
-
56
54
  static_directory = @project_root
57
- container = self
58
55
 
59
- @app = Rack::Builder.new do
60
- use container.backend
61
- use Rack::Static, :urls => [ '/' ], :root => static_directory
62
- # Should never reach here. It just need s an app to run
63
- run lambda { |env| [ 200, { 'Content-Type' => 'text/html', }, '' ] }
64
- end
56
+ @cascade_apps = [ Rack::File.new(static_directory) ]
57
+ @app = build_app
58
+ end
59
+
60
+ def setup_test_mode
61
+ setup_dev_mode
62
+ @sprockets_environment.prepend_path 'tests'
65
63
  end
66
64
 
67
- def set_backend
65
+ def build_app
68
66
  if @borkfile.backend == :static_index
69
- @backend = Embork::Pushstate
67
+ backend = Embork::Pushstate
70
68
  else
71
69
  Embork::Forwarder.target = @borkfile.backend
72
- @backend = Embork::Forwarder
70
+ backend = Embork::Forwarder
71
+ end
72
+ cascade_apps = @cascade_apps
73
+ Rack::Builder.new do
74
+ use backend
75
+ run Rack::Cascade.new(cascade_apps)
73
76
  end
74
77
  end
75
78
 
76
- def run
77
- Rack::Handler::WEBrick.run @app, :Port => @port, :Host => @host
79
+ def run_webrick
80
+ opts = {
81
+ :Port => @port,
82
+ :Host => @host
83
+ }
84
+ if @disable_logging
85
+ opts[:Logger] = WEBrick::Log.new("/dev/null")
86
+ opts[:AccessLog] = []
87
+ end
88
+ Rack::Handler::WEBrick.run @app, opts
78
89
  end
79
90
 
80
91
  end
@@ -3,4 +3,5 @@ end
3
3
  require 'embork/sprockets/helpers'
4
4
  require 'embork/sprockets/es6_module_transpiler'
5
5
  require 'embork/sprockets/ember_handlebars_compiler'
6
+ require 'embork/sprockets/closure_compiler'
6
7
  require 'embork/sprockets/frameworks'
@@ -0,0 +1,24 @@
1
+ require 'tilt'
2
+ require 'embork/logger'
3
+
4
+ class Embork::Sprockets::ClosureCompiler < Tilt::Template
5
+ self.default_mime_type = 'application/javascript'
6
+
7
+ def prepare
8
+ @logger = Embork::Logger.new STDOUT, :simple
9
+ end
10
+
11
+ def self.compiler
12
+ require 'closure-compiler'
13
+ @compiler ||= Closure::Compiler.new(
14
+ :jar_file => File.expand_path('../support/closure_compiler.jar', __FILE__),
15
+ :compilation_level => 'SIMPLE'
16
+ )
17
+ end
18
+
19
+ def evaluate(scope, locals, &block)
20
+ @logger.info 'Compressing %s.js with the closure compiler' % scope.logical_path
21
+ self.class.compiler.compile data
22
+ end
23
+
24
+ end
@@ -34,7 +34,7 @@ class Embork::Sprockets::ES6ModuleTranspiler < Tilt::Template
34
34
  self.namespace = nil
35
35
 
36
36
  def prepare
37
- # Required to be implemented by Tilt for some reason...
37
+ @logger = Embork::Logger.new(STDOUT, :simple)
38
38
  end
39
39
 
40
40
  def evaluate(scope, locals, &block)
@@ -46,7 +46,13 @@ class Embork::Sprockets::ES6ModuleTranspiler < Tilt::Template
46
46
  if manifest? || component? || template?
47
47
  data
48
48
  else
49
- wrap_in_closure(self.class.runtime.exec module_generator)
49
+ begin
50
+ compiled_module = wrap_in_closure(self.class.runtime.exec module_generator)
51
+ compiled_module.gsub! %("use strict";), '' if fixture?
52
+ compiled_module
53
+ rescue
54
+ @logger.fatal 'ES6 Module error in file %s' % @logical_path
55
+ end
50
56
  end
51
57
  end
52
58
 
@@ -72,6 +78,10 @@ class Embork::Sprockets::ES6ModuleTranspiler < Tilt::Template
72
78
  !!@logical_path.match(/^templates/)
73
79
  end
74
80
 
81
+ def fixture?
82
+ !!@logical_path.match(/^fixtures/)
83
+ end
84
+
75
85
  def wrap_in_closure(compiled_code)
76
86
  if self.class.compile_to == :cjs
77
87
  <<-CJS.strip_heredoc % [ module_name, compiled_code ]
@@ -3,8 +3,9 @@ module Embork::Sprockets::Frameworks
3
3
  begin
4
4
  require 'compass'
5
5
  sprockets_environment.append_path Compass::Frameworks['compass'].stylesheets_directory
6
+ Compass.configuration.images_path = File.join sprockets_environment.root, 'static', 'images'
6
7
  rescue LoadError => e
7
- (@logger ||= Embork::Logger.new(STDOUT)).error 'Compass gem is not installed.'
8
+ (@logger ||= Embork::Logger.new(STDOUT, :simple)).error 'Compass gem is not installed.'
8
9
  @logger.info %{Add `gem 'compass'` to your Gemfile and run `bundle` to install it.}
9
10
  exit 1
10
11
  end
@@ -5,7 +5,8 @@ module Embork::Sprockets::Helpers
5
5
  end
6
6
 
7
7
  def javascript_include_tag(path)
8
- script = self.class.use_bundled_assets ? generate_versioned_name(path) : path
8
+ path = self.class.use_bundled_assets ? generate_versioned_name(path) : path
9
+ script = asset_path(path, :type => :javascript)
9
10
  %{<script src="%s"></script>} % [ script ]
10
11
  end
11
12
 
@@ -15,7 +16,8 @@ module Embork::Sprockets::Helpers
15
16
  def stylesheet_link_tag(path, options = {})
16
17
  options = { :media => :all }.merge options
17
18
 
18
- stylesheet = self.class.use_bundled_assets ? generate_versioned_name(path) : path
19
+ path = self.class.use_bundled_assets ? generate_versioned_name(path) : path
20
+ stylesheet = asset_path(path, :type => :stylesheet)
19
21
 
20
22
  %{<link href="%s" rel="stylesheet" type="text/css" media="%s"></link>} % [
21
23
  stylesheet,
@@ -30,6 +32,27 @@ module Embork::Sprockets::Helpers
30
32
  Embork::Sprockets::ES6ModuleTranspiler.namespace
31
33
  end
32
34
 
35
+ def asset_path(path, options = {})
36
+ base_path = '/'
37
+ if !options.has_key? :type
38
+ File.join base_path, path
39
+ else
40
+ type = options[:type]
41
+ case type
42
+ when :image
43
+ File.join base_path, 'images', path
44
+ when :font
45
+ File.join base_path, 'fonts', path
46
+ when :javascript
47
+ File.join base_path, path
48
+ when :stylesheet
49
+ File.join base_path, path
50
+ else
51
+ File.join base_path, type.to_s, path
52
+ end
53
+ end
54
+ end
55
+
33
56
  protected
34
57
 
35
58
  def generate_versioned_name(path_to_file)
@@ -41,5 +64,6 @@ module Embork::Sprockets::Helpers
41
64
  versioned_name = "%s-%s%s" % [ base, self.class.bundled_version, ext ]
42
65
  (path.nil?) ? versioned_name : File.join(path, versioned_name)
43
66
  end
67
+
44
68
  end
45
69
 
@@ -1,3 +1,3 @@
1
1
  class Embork
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -21,9 +21,17 @@ compile_html [ 'index.html' ]
21
21
 
22
22
  use_framework :bootstrap
23
23
 
24
+ phrender_index_file 'phrender.html'
25
+ phrender_add_javascript_file'application.js'
26
+ phrender_add_javascript_file :ember_driver
27
+ phrender_add_javascript "require('index');"
28
+
29
+ transform_es6_module_names proc{ |name| name + 'krump' }
30
+
24
31
  configure :development do
25
32
  append_asset_path 'foo/dev/js'
26
33
  compile_html 'dev.html'
34
+ compress_with :closure_compiler
27
35
  end
28
36
 
29
37
  configure :production do
@@ -42,6 +42,20 @@ describe 'Embork::Borkfile' do
42
42
  it 'has no es6 module namespace defined' do
43
43
  expect(borkfile.es6_namespace).to eq(nil)
44
44
  end
45
+
46
+ it 'has no default compressor' do
47
+ expect(borkfile.compressor).to eq(nil)
48
+ end
49
+
50
+ it 'has no default es6 transform' do
51
+ expect(borkfile.es6_transform).to eq(nil)
52
+ end
53
+
54
+ it 'has no default phrender configuration' do
55
+ expect(borkfile.phrender_index_file).to eq(nil)
56
+ expect(borkfile.phrender_javascript_paths).to be_empty
57
+ expect(borkfile.phrender_raw_javascript).to be_empty
58
+ end
45
59
  end
46
60
 
47
61
  describe 'basic config' do
@@ -99,6 +113,23 @@ describe 'Embork::Borkfile' do
99
113
  expect(borkfile.frameworks).to include 'bootstrap'
100
114
  expect(borkfile.frameworks).not_to include 'compass'
101
115
  end
116
+
117
+ it 'configures the closure_compiler as the compressor' do
118
+ expect(borkfile.compressor).to eq(:closure_compiler)
119
+ end
120
+
121
+ it 'includes the specified es6 transform' do
122
+ expect(borkfile.es6_transform.respond_to? :call).to eq(true)
123
+ end
124
+
125
+ it 'respects the phrender configuration ' do
126
+ expect(borkfile.phrender_index_file).to eq('phrender.html')
127
+ expect(borkfile.phrender_javascript_paths).to match_array [
128
+ 'application.js',
129
+ :ember_driver
130
+ ]
131
+ expect(borkfile.phrender_raw_javascript).to include("require('index');")
132
+ end
102
133
  end
103
134
 
104
135
  describe 'relative root' do
@@ -25,7 +25,9 @@ describe 'Embork::Environment' do
25
25
  { :extension => '.bork', :klass => my_engine }
26
26
  ],
27
27
  :es6_namespace => 'my-package',
28
- :frameworks => [ 'bootstrap', 'compass' ]
28
+ :frameworks => [ 'bootstrap', 'compass' ],
29
+ :compressor => :closure_compiler,
30
+ :es6_transform => proc{ |name| name + 'foo' }
29
31
  })}
30
32
 
31
33
  let (:environment) { Embork::Environment.new borkfile }
@@ -75,4 +77,12 @@ describe 'Embork::Environment' do
75
77
  expect(environment.sprockets_environment.paths.to_s).to match /\/bootstrap-sass-.*?\/vendor\/assets\/stylesheets/
76
78
  end
77
79
 
80
+ it 'adds the Embork::Sprockets::ClosureCompiler as a bundle processor' do
81
+ expect(environment.sprockets_environment.bundle_processors('application/javascript')).to include(Embork::Sprockets::ClosureCompiler)
82
+ end
83
+
84
+ it 'sets up an es6 transform' do
85
+ expect(Embork::Sprockets::ES6ModuleTranspiler.transform.respond_to? :call).to eq(true)
86
+ end
87
+
78
88
  end
@@ -15,7 +15,12 @@ describe 'Embork::Generator' do
15
15
 
16
16
  it 'loads the list of files to be processed by ERB' do
17
17
  expect(generator.erb_files).to match_array([
18
- "Borkfile", "app/app.js", "app/index.html.erb", "bower.json", "package.json"
18
+ "Borkfile",
19
+ "app/app.js",
20
+ "app/index.html.erb",
21
+ "bower.json",
22
+ "package.json",
23
+ "tests/tests.html.erb"
19
24
  ])
20
25
  end
21
26
 
@@ -149,4 +149,15 @@ describe 'Embork::Server' do
149
149
  end
150
150
 
151
151
  end
152
+
153
+ context 'test mode' do
154
+ let(:server) { Embork::Server.new borkfile, :enable_tests => true }
155
+ let(:app) { server.app }
156
+
157
+ it 'serves out the test index' do
158
+ get '/'
159
+ expect(last_response).to be_ok
160
+ expect(last_response.body.strip).to eq(%{test-index})
161
+ end
162
+ end
152
163
  end
@@ -0,0 +1,77 @@
1
+ require 'spec_helper'
2
+
3
+ require 'embork/sprockets/helpers'
4
+
5
+ describe 'Embork::Sprockets::helpers' do
6
+ let(:context_class) do
7
+ class Context
8
+ include Embork::Sprockets::Helpers
9
+ extend Embork::Sprockets::Helpers::ClassMethods
10
+ end
11
+ Context.new
12
+ end
13
+
14
+ context '#javascript_include_tag' do
15
+ it 'builds a root directory script tag' do
16
+ expect(context_class.javascript_include_tag('application.js')).to eq(
17
+ %{<script src="/application.js"></script>})
18
+ end
19
+ end
20
+
21
+ context '#stylesheet_link_tag' do
22
+ it 'builds a root directory link tag' do
23
+ expect(context_class.stylesheet_link_tag('application.css')).to eq(
24
+ %{<link href="/application.css" rel="stylesheet" type="text/css" media="all"></link>})
25
+ end
26
+ end
27
+
28
+ context '#asset_path' do
29
+ it 'pluralizes images' do
30
+ expect(context_class.asset_path('image.png', :type => :image)).to eq(
31
+ %{/images/image.png})
32
+ end
33
+
34
+ it 'pluralizes fonts' do
35
+ expect(context_class.asset_path('font.eot', :type => :font)).to eq(
36
+ %{/fonts/font.eot})
37
+ end
38
+
39
+ it 'doesn\t sub-directory javascripts' do
40
+ expect(context_class.asset_path('file.js', :type => :javascript)).to eq(
41
+ %{/file.js})
42
+ end
43
+
44
+ it 'doesn\t sub-directory stylesheets' do
45
+ expect(context_class.asset_path('file.css', :type => :stylesheet)).to eq(
46
+ %{/file.css})
47
+ end
48
+
49
+ it 'passes arbitrary types to named subdirectories' do
50
+ expect(context_class.asset_path('file.mp3', :type => :audio)).to eq(
51
+ %{/audio/file.mp3})
52
+ expect(context_class.asset_path('file.avi', :type => :video)).to eq(
53
+ %{/video/file.avi})
54
+ end
55
+ end
56
+
57
+ context 'versioned assets' do
58
+ before(:each) do
59
+ context_class.class.use_bundled_assets = true
60
+ context_class.class.bundled_version = '12345abcd'
61
+ end
62
+
63
+ context '#javascript_include_tag' do
64
+ it 'builds a versioned script tag' do
65
+ expect(context_class.javascript_include_tag('application.js')).to eq(
66
+ %{<script src="/application-12345abcd.js"></script>})
67
+ end
68
+ end
69
+
70
+ context '#stylesheet_link_tag' do
71
+ it 'builds a versioned link tag' do
72
+ expect(context_class.stylesheet_link_tag('application.css')).to eq(
73
+ %{<link href="/application-12345abcd.css" rel="stylesheet" type="text/css" media="all"></link>})
74
+ end
75
+ end
76
+ end
77
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embork
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
- - Matthew Smart
7
+ - Mina Smart
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-05 00:00:00.000000000 Z
11
+ date: 2014-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sprockets
@@ -70,16 +70,16 @@ dependencies:
70
70
  name: rack
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: 1.5.2
76
76
  type: :runtime
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: '0'
82
+ version: 1.5.2
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: coffee-script
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -98,16 +98,16 @@ dependencies:
98
98
  name: sass
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ">="
101
+ - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '0'
103
+ version: 3.2.0
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ">="
108
+ - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '0'
110
+ version: 3.2.0
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: execjs
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -126,16 +126,16 @@ dependencies:
126
126
  name: barber
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - ">="
129
+ - - "~>"
130
130
  - !ruby/object:Gem::Version
131
- version: '0'
131
+ version: 0.4.2
132
132
  type: :runtime
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - ">="
136
+ - - "~>"
137
137
  - !ruby/object:Gem::Version
138
- version: '0'
138
+ version: 0.4.2
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: colorize
141
141
  requirement: !ruby/object:Gem::Requirement
@@ -150,6 +150,34 @@ dependencies:
150
150
  - - ">="
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: qunit-runner
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: 0.0.1
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: 0.0.1
167
+ - !ruby/object:Gem::Dependency
168
+ name: phrender
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: 0.0.3
174
+ type: :runtime
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: 0.0.3
153
181
  - !ruby/object:Gem::Dependency
154
182
  name: bundler
155
183
  requirement: !ruby/object:Gem::Requirement
@@ -262,6 +290,20 @@ dependencies:
262
290
  - - ">="
263
291
  - !ruby/object:Gem::Version
264
292
  version: '0'
293
+ - !ruby/object:Gem::Dependency
294
+ name: closure-compiler
295
+ requirement: !ruby/object:Gem::Requirement
296
+ requirements:
297
+ - - ">="
298
+ - !ruby/object:Gem::Version
299
+ version: '0'
300
+ type: :development
301
+ prerelease: false
302
+ version_requirements: !ruby/object:Gem::Requirement
303
+ requirements:
304
+ - - ">="
305
+ - !ruby/object:Gem::Version
306
+ version: '0'
265
307
  description: A tool set for building ember apps.
266
308
  email:
267
309
  - mdsmart@gmail.com
@@ -311,28 +353,34 @@ files:
311
353
  - blueprint/package.json
312
354
  - blueprint/static/.gitkeep
313
355
  - blueprint/tests/.jshintrc
356
+ - blueprint/tests/fixtures.js
314
357
  - blueprint/tests/helpers/resolver.js
315
358
  - blueprint/tests/helpers/start-app.js
316
- - blueprint/tests/index.html
317
359
  - blueprint/tests/test-helper.js
318
360
  - blueprint/tests/test-loader.js
361
+ - blueprint/tests/tests.html.erb
362
+ - blueprint/tests/tests.js
319
363
  - blueprint/tests/unit/.gitkeep
320
364
  - embork.gemspec
321
365
  - lib/embork.rb
322
366
  - lib/embork/borkfile.rb
323
367
  - lib/embork/build_versions.rb
324
368
  - lib/embork/builder.rb
369
+ - lib/embork/cli.rb
325
370
  - lib/embork/environment.rb
326
371
  - lib/embork/forwarder.rb
327
372
  - lib/embork/generator.rb
328
373
  - lib/embork/logger.rb
374
+ - lib/embork/phrender.rb
329
375
  - lib/embork/pushstate.rb
330
376
  - lib/embork/server.rb
331
377
  - lib/embork/sprockets.rb
378
+ - lib/embork/sprockets/closure_compiler.rb
332
379
  - lib/embork/sprockets/ember_handlebars_compiler.rb
333
380
  - lib/embork/sprockets/es6_module_transpiler.rb
334
381
  - lib/embork/sprockets/frameworks.rb
335
382
  - lib/embork/sprockets/helpers.rb
383
+ - lib/embork/sprockets/support/closure_compiler.jar
336
384
  - lib/embork/sprockets/support/es6-module-transpiler.js
337
385
  - lib/embork/sprockets/support/node_runner.js
338
386
  - lib/embork/version.rb
@@ -365,6 +413,7 @@ files:
365
413
  - spec/embork/server/example_app/static/fonts/.gitkeep
366
414
  - spec/embork/server/example_app/static/images/.gitkeep
367
415
  - spec/embork/server/example_app/static/images/image.png
416
+ - spec/embork/server/example_app/tests/index.html.erb
368
417
  - spec/embork/server/specimen.css
369
418
  - spec/embork/server/specimen.js
370
419
  - spec/embork/server_spec.rb
@@ -388,6 +437,7 @@ files:
388
437
  - spec/embork/sprockets/es6_module_transpiler/namespaced.js
389
438
  - spec/embork/sprockets/es6_module_transpiler/transformed.js
390
439
  - spec/embork/sprockets/es6_module_transpiler_spec.rb
440
+ - spec/embork/sprockets/helper_spec.rb
391
441
  - spec/spec_helper.rb
392
442
  homepage: ''
393
443
  licenses:
@@ -442,6 +492,7 @@ test_files:
442
492
  - spec/embork/server/example_app/static/fonts/.gitkeep
443
493
  - spec/embork/server/example_app/static/images/.gitkeep
444
494
  - spec/embork/server/example_app/static/images/image.png
495
+ - spec/embork/server/example_app/tests/index.html.erb
445
496
  - spec/embork/server/specimen.css
446
497
  - spec/embork/server/specimen.js
447
498
  - spec/embork/server_spec.rb
@@ -465,4 +516,5 @@ test_files:
465
516
  - spec/embork/sprockets/es6_module_transpiler/namespaced.js
466
517
  - spec/embork/sprockets/es6_module_transpiler/transformed.js
467
518
  - spec/embork/sprockets/es6_module_transpiler_spec.rb
519
+ - spec/embork/sprockets/helper_spec.rb
468
520
  - spec/spec_helper.rb