Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rwz committed Nov 24, 2014
0 parents commit 27c74d8
Show file tree
Hide file tree
Showing 12 changed files with 220 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/.bundle/
/.yardoc
/Gemfile.lock
/_yardoc/
/coverage/
/doc/
/pkg/
/spec/reports/
/tmp/
*.bundle
*.so
*.o
*.a
mkmf.log
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source "https://rubygems.org"

gemspec

gem "pry"
22 changes: 22 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Copyright (c) 2014 Pavel Pravosud

MIT License

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Ember::Cli::Rails

TODO: Write a gem description

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'ember-cli-rails'
```

And then execute:

$ bundle

Or install it yourself as:

$ gem install ember-cli-rails

## Usage

TODO: Write usage instructions here

## Contributing

1. Fork it ( https://github.com/[my-github-username]/ember-cli-rails/fork )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require "bundler/gem_tasks"

15 changes: 15 additions & 0 deletions ember-cli-rails.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require_relative "./lib/ember-cli/version"

Gem::Specification.new do |spec|
spec.name = "ember-cli-rails"
spec.version = EmberCLI::VERSION
spec.authors = ["Pavel Pravosud"]
spec.email = ["pavel@pravosud.com"]
spec.summary = "Helps integrate EmberCLI with Rails"
spec.homepage = "https://github.com/rwz/ember-cli-rails"
spec.license = "MIT"
spec.files = Dir["README.md", "LICENSE.txt", "lib/**/*"]

spec.required_ruby_version = "~> 2.0"
spec.add_dependency "railties", "~> 4.0"
end
45 changes: 45 additions & 0 deletions lib/ember-cli-rails.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
require "ember-cli/railtie" if defined?(Rails)

module EmberCLI
extend self

autoload :BuildServer, "ember-cli/build_server"
autoload :Configuration, "ember-cli/configuration"
autoload :RackServer, "ember-cli/rack_server"

def configure
yield configuration
end

def configuration
Configuration.instance
end

def prepare!
Rack::Server.prepend RackServer
Rails.configuration.assets.paths << root.join("assets").to_s
at_exit{ cleanup }
end

def start!
configuration.app_list.each(&:start)
end

def stop!
configuration.app_list.each(&:stop)
end

def root
@root ||= Rails.root.join("tmp", "ember-cli-#{uid}")
end

private

def uid
@uid ||= SecureRandom.uuid
end

def cleanup
root.rmtree if root.exist?
end
end
47 changes: 47 additions & 0 deletions lib/ember-cli/build_server.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
module EmberCLI
class BuildServer
attr_reader :name, :options, :pid

def initialize(name, **options)
@name, @options = name.to_s, options
end

def start
symlink_to_assets_root

@pid = spawn(command).tap do |pid|
at_exit{ stop }
end
end

def stop
Process.kill "INT", pid if pid
@pid = nil
end

private

def command
<<-CMD.squish
cd #{app_path};
ember build --watch --output-path #{dist_path}
CMD
end

def app_path
options.fetch(:path){ Rails.root.join("app", name) }
end

def symlink_to_assets_root
assets_path.join(name).make_symlink dist_path.join("assets")
end

def dist_path
@dist_path ||= EmberCLI.root.join("apps", name).tap(&:mkpath)
end

def assets_path
@assets_path ||= EmberCLI.root.join("assets").tap(&:mkpath)
end
end
end
15 changes: 15 additions & 0 deletions lib/ember-cli/configuration.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require "singleton"

module EmberCLI
class Configuration
include Singleton

def app(name, **options)
app_list << BuildServer.new(name, options)
end

def app_list
@app_list ||= []
end
end
end
10 changes: 10 additions & 0 deletions lib/ember-cli/rack_server.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module EmberCLI
module RackServer
def start
EmberCLI.start! if defined?(Rails.application) && app == Rails.application
super
ensure
EmberCLI.stop!
end
end
end
11 changes: 11 additions & 0 deletions lib/ember-cli/railtie.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module EmberCLI
class Railtie < Rails::Railtie
initializer "ember-cli-rails.rack-server" do
EmberCLI.prepare! if development_mode?
end

def development_mode?
!Rails.env.production? && Rails.configuration.consider_all_requests_local
end
end
end
3 changes: 3 additions & 0 deletions lib/ember-cli/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module EmberCLI
VERSION = "0.0.1".freeze
end

0 comments on commit 27c74d8

Please sign in to comment.