ember-cli-rails-assets 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d9d27e277cf10886915fb58467bfa30c7dbddb7f
4
+ data.tar.gz: b102c16267cf48f6071e72a2ac51ab62fa12fa59
5
+ SHA512:
6
+ metadata.gz: 83c0399fc6a84daeefe674ca3cc07410f5b7aec539f6e95592c6246c202282539c8a3826c7001668e4132b15e70752b724efe881d1e71bcff5db7ca3831d6cff
7
+ data.tar.gz: c5d32d55fa4762282a2c7e1fb3e97692d93a9a1934cd4a9dda48523c7d829e81f7d6c067a98a91bdda0b5df0b950b5015688d78d097624112a3f42d203923769
data/README.md ADDED
@@ -0,0 +1,151 @@
1
+ # EmberCLI Rails - Assets
2
+
3
+ The `ember-cli-rails-assets` gem extends [`ember-cli-rails`][ember-cli-rails] to
4
+ enable rendering EmberCLI-generated JavaScript and CSS stylesheets into your
5
+ Rails application's layout HTML.
6
+
7
+ **This project and the behavior it supports is deprecated.**
8
+
9
+ Rendering EmberCLI applications with `render_ember_app` is the recommended,
10
+ actively supported method of serving EmberCLI applications.
11
+
12
+ However, for the sake of backwards compatibility, `ember-cli-rails-assets`
13
+ supports injecting the EmberCLI-generated assets into an existing Rails layout.
14
+
15
+ [ember-cli-rails]: https://github.com/thoughtbot/ember-cli-rails
16
+
17
+ ## Install
18
+
19
+ Add the following to your `Gemfile`:
20
+
21
+ ```ruby
22
+ gem "ember-cli-rails-assets"
23
+ ```
24
+
25
+ Then run `bundle install`:
26
+
27
+ ```bash
28
+ $ bundle install
29
+ ```
30
+
31
+ ## Setup
32
+
33
+ To configure your project to use `ember-cli-rails`, follow the instructions
34
+ listed in the [`ember-cli-rails` README][README].
35
+
36
+ To configure your project to user `ember-cli-rails-assets`, ensure each Ember
37
+ application's `ember-cli-build.js` includes the following values:
38
+
39
+ ```js
40
+ // frontend/ember-cli-build.js
41
+
42
+ module.exports = function(defaults) {
43
+ var app = new EmberApp(defaults, {
44
+ // http://ember-cli.com/user-guide/#application-configuration
45
+ storeConfigInMeta: false,
46
+
47
+ fingerprint: {
48
+ // https://github.com/rickharrison/broccoli-asset-rev#options
49
+ generateAssetMap: true,
50
+ },
51
+ });
52
+ };
53
+ ```
54
+
55
+ [README]: https://github.com/thoughtbot/ember-cli-rails#readme
56
+
57
+ ## Mount
58
+
59
+ Mount the Ember application (in this example, the `frontend` application) to the
60
+ desired path:
61
+
62
+ ```rb
63
+ # config/routes.rb
64
+
65
+ Rails.application.routes.draw do
66
+ mount_ember_app :frontend, to: "/", controller: "ember#index"
67
+ end
68
+ ```
69
+
70
+ Then, in the corresponding view, use the asset helpers:
71
+
72
+ ```erb
73
+ <!-- app/views/ember/index.html.erb -->
74
+
75
+ <%= include_ember_script_tags :frontend %>
76
+ <%= include_ember_stylesheet_tags :frontend %>
77
+ ```
78
+
79
+ ## Caveats
80
+
81
+ ### Mounting
82
+
83
+ If you're using the `include_ember` style helpers with a single-page Ember
84
+ application that defers routing to the Rails application, insert a call to
85
+ `mount_ember_assets` at the bottom of your routes file to serve the
86
+ EmberCLI-generated assets:
87
+
88
+ ```rb
89
+ # config/routes.rb
90
+ Rails.application.routes.draw do
91
+ mount_ember_assets :frontend, to: "/"
92
+ end
93
+ ```
94
+
95
+ ### Rendering
96
+
97
+ When injecting the EmberCLI-generated assets with the `include_ember_script_tags`
98
+ and `include_ember_stylesheet_tags` helpers to a path other than `"/"`, a
99
+ `<base>` tag must also be injected with a corresponding `href` value:
100
+
101
+ ```erb
102
+ <base href="/">
103
+ <%= include_ember_script_tags :frontend %>
104
+ <%= include_ember_stylesheet_tags :frontend %>
105
+
106
+ <base href="/admin_panel/">
107
+ <%= include_ember_script_tags :admin_panel %>
108
+ <%= include_ember_stylesheet_tags :admin_panel %>
109
+ ```
110
+
111
+ ## EmberCLI support
112
+
113
+ This project supports:
114
+
115
+ * EmberCLI versions `>= 1.13.13`
116
+
117
+ ## Ruby and Rails support
118
+
119
+ This project supports:
120
+
121
+ * Ruby versions `>= 2.1.0`
122
+ * Rails versions `>=4.1.x`.
123
+
124
+ ## Contributing
125
+
126
+ See the [CONTRIBUTING] document.
127
+ Thank you, [contributors]!
128
+
129
+ [CONTRIBUTING]: CONTRIBUTING.md
130
+ [contributors]: https://github.com/seanpdoyle/ember-cli-rails-assets/graphs/contributors
131
+
132
+ ## License
133
+
134
+ Open source templates are Copyright (c) 2015 Sean Doyle.
135
+ It contains free software that may be redistributed
136
+ under the terms specified in the [LICENSE] file.
137
+
138
+ [LICENSE]: /LICENSE.txt
139
+
140
+ ## About
141
+
142
+ ember-cli-rails was originally created by
143
+ [Pavel Pravosud][rwz] and
144
+ [Jonathan Jackson][rondale-sc].
145
+
146
+ ember-cli-rails-assets was extracted from ember-cli-rails is maintained by
147
+ [Sean Doyle][seanpdoyle].
148
+
149
+ [rwz]: https://github.com/rwz
150
+ [rondale-sc]: https://github.com/rondale-sc
151
+ [seanpdoyle]: https://github.com/seanpdoyle
data/Rakefile ADDED
@@ -0,0 +1,39 @@
1
+ require "rubygems"
2
+ begin
3
+ require "bundler/setup"
4
+ rescue LoadError
5
+ puts "You must `gem install bundler` and `bundle install` to run rake tasks"
6
+ end
7
+ require "appraisal"
8
+
9
+ require "rdoc/task"
10
+
11
+ RDoc::Task.new(:rdoc) do |rdoc|
12
+ rdoc.rdoc_dir = "rdoc"
13
+ rdoc.title = "EmberCli::Assets"
14
+ rdoc.options << "--line-numbers"
15
+ rdoc.rdoc_files.include("README.md")
16
+ rdoc.rdoc_files.include("{app,lib}/**/*.rb")
17
+ end
18
+
19
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
20
+ load "rails/tasks/engine.rake"
21
+ load "rails/tasks/statistics.rake"
22
+
23
+ Bundler::GemHelper.install_tasks
24
+
25
+ require "rspec/core/rake_task"
26
+
27
+ task(:default).clear
28
+ task default: :spec
29
+
30
+ if defined? RSpec
31
+ task(:spec).clear
32
+ RSpec::Core::RakeTask.new(:spec) do |t|
33
+ t.verbose = false
34
+ end
35
+ end
36
+
37
+ if !ENV["APPRAISAL_INITIALIZED"] && !ENV["TRAVIS"]
38
+ task :default => :appraisal
39
+ end
@@ -0,0 +1,23 @@
1
+ require "ember_cli/assets/lookup"
2
+
3
+ module EmberCliRailsAssetsHelper
4
+ def include_ember_script_tags(name)
5
+ EmberCli[name].build
6
+
7
+ assets = EmberCli::Assets::Lookup.new(EmberCli[name])
8
+
9
+ assets.javascript_assets.
10
+ map { |src| %{<script src="#{src}"></script>}.html_safe }.
11
+ inject(&:+)
12
+ end
13
+
14
+ def include_ember_stylesheet_tags(name)
15
+ EmberCli[name].build
16
+
17
+ assets = EmberCli::Assets::Lookup.new(EmberCli[name])
18
+
19
+ assets.stylesheet_assets.
20
+ map { |src| %{<link rel="stylesheet" href="#{src}">}.html_safe }.
21
+ inject(&:+)
22
+ end
23
+ end
@@ -0,0 +1,6 @@
1
+ require "ember_cli/assets/engine"
2
+
3
+ module EmberCli
4
+ module Assets
5
+ end
6
+ end
@@ -0,0 +1,68 @@
1
+ require "ember_cli/assets/errors"
2
+
3
+ module EmberCli
4
+ module Assets
5
+ class AssetMap
6
+ def initialize(name:, asset_map:)
7
+ @name = name
8
+ @asset_map = asset_map
9
+ end
10
+
11
+ def javascripts
12
+ assert_asset_map!
13
+
14
+ [
15
+ asset_matching(/vendor(.*)\.js\z/),
16
+ asset_matching(/#{name}(.*)\.js\z/),
17
+ ]
18
+ end
19
+
20
+ def stylesheets
21
+ assert_asset_map!
22
+
23
+ [
24
+ asset_matching(/vendor(.*)\.css\z/),
25
+ asset_matching(/#{name}(.*)\.css\z/),
26
+ ]
27
+ end
28
+
29
+ private
30
+
31
+ attr_reader :name, :asset_map
32
+
33
+ def asset_matching(regex)
34
+ matching_asset = files.detect { |asset| asset =~ regex }
35
+
36
+ if matching_asset.to_s.empty?
37
+ raise_missing_asset(regex)
38
+ end
39
+
40
+ prepend + matching_asset
41
+ end
42
+
43
+ def prepend
44
+ asset_map["prepend"].to_s
45
+ end
46
+
47
+ def files
48
+ Array(assets.values)
49
+ end
50
+
51
+ def assets
52
+ asset_map["assets"] || {}
53
+ end
54
+
55
+ def raise_missing_asset(regex)
56
+ raise BuildError.new("Failed to find assets matching `#{regex}`")
57
+ end
58
+
59
+ def assert_asset_map!
60
+ if assets.empty?
61
+ raise BuildError.new <<-MSG
62
+ Missing `#{name}/assets/assetMap.json`
63
+ MSG
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,35 @@
1
+ module EmberCli
2
+ module Assets
3
+ class DirectoryAssetMap
4
+ def initialize(directory)
5
+ @directory = Pathname.new(directory)
6
+ end
7
+
8
+ def to_h
9
+ {
10
+ "assets" => files_with_data,
11
+ "prepend" => "assets/",
12
+ }
13
+ end
14
+
15
+ private
16
+
17
+ attr_reader :directory
18
+
19
+ def files_with_data
20
+ files.reduce({}) do |manifest, file|
21
+ name = File.basename(file.path)
22
+
23
+ manifest[name] = name
24
+
25
+ manifest
26
+ end
27
+ end
28
+
29
+
30
+ def files
31
+ directory.children.map { |path| File.new(path) }
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,13 @@
1
+ module EmberCli
2
+ module Assets
3
+ class Engine < ::Rails::Engine
4
+ initializer "ember-cli-rails-assets" do
5
+ require "ember_cli/assets/ext/action_dispatch/routing/mapper"
6
+ end
7
+
8
+ config.to_prepare do
9
+ ActionController::Base.helper EmberCliRailsAssetsHelper
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ module EmberCli
2
+ module Assets
3
+ class BuildError < StandardError; end
4
+ end
5
+ end
@@ -0,0 +1,12 @@
1
+ module ActionDispatch
2
+ module Routing
3
+ class Mapper
4
+ def mount_ember_assets(app_name, to: "/")
5
+ app = EmberCli[app_name]
6
+ rack_app = Rack::File.new(app.dist_path.to_s)
7
+
8
+ mount rack_app => to
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,52 @@
1
+ require "ember_cli/assets/paths"
2
+ require "ember_cli/assets/asset_map"
3
+ require "ember_cli/assets/directory_asset_map"
4
+
5
+ module EmberCli
6
+ module Assets
7
+ class Lookup
8
+ def initialize(app)
9
+ @paths = Paths.new(app)
10
+ end
11
+
12
+ def javascript_assets
13
+ asset_map.javascripts
14
+ end
15
+
16
+ def stylesheet_assets
17
+ asset_map.stylesheets
18
+ end
19
+
20
+ private
21
+
22
+ attr_reader :paths
23
+
24
+ def asset_map
25
+ AssetMap.new(
26
+ name: name_from_package_json,
27
+ asset_map: asset_map_hash.to_h,
28
+ )
29
+ end
30
+
31
+ def asset_map_file
32
+ paths.asset_map
33
+ end
34
+
35
+ def asset_map_hash
36
+ if asset_map_file.present? && asset_map_file.exist?
37
+ JSON.parse(asset_map_file.read)
38
+ else
39
+ DirectoryAssetMap.new(paths.assets)
40
+ end
41
+ end
42
+
43
+ def name_from_package_json
44
+ package_json.fetch("name")
45
+ end
46
+
47
+ def package_json
48
+ @package_json ||= JSON.parse(paths.package_json.read)
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,25 @@
1
+ module EmberCli
2
+ module Assets
3
+ class Paths
4
+ def initialize(app)
5
+ @app = app
6
+ end
7
+
8
+ def assets
9
+ app.dist_path.join("assets")
10
+ end
11
+
12
+ def asset_map
13
+ Pathname.glob(assets.join("assetMap*.json")).first
14
+ end
15
+
16
+ def package_json
17
+ app.root_path.join("package.json")
18
+ end
19
+
20
+ protected
21
+
22
+ attr_reader :app
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,5 @@
1
+ module EmberCli
2
+ module Assets
3
+ VERSION = "0.6.1"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ember-cli-rails-assets
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.1
5
+ platform: ruby
6
+ authors:
7
+ - Sean Doyle
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-12-19 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Include EmberCLI-generated JavaScript and CSS stylesheet tags in your
14
+ Rails layouts
15
+ email:
16
+ - sean.p.doyle24@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - README.md
22
+ - Rakefile
23
+ - app/helpers/ember_cli_rails_assets_helper.rb
24
+ - lib/ember-cli-rails-assets.rb
25
+ - lib/ember_cli/assets/asset_map.rb
26
+ - lib/ember_cli/assets/directory_asset_map.rb
27
+ - lib/ember_cli/assets/engine.rb
28
+ - lib/ember_cli/assets/errors.rb
29
+ - lib/ember_cli/assets/ext/action_dispatch/routing/mapper.rb
30
+ - lib/ember_cli/assets/lookup.rb
31
+ - lib/ember_cli/assets/paths.rb
32
+ - lib/ember_cli/assets/version.rb
33
+ homepage: https://github.com/seanpdoyle/ember-cli-rails-assets
34
+ licenses:
35
+ - MIT
36
+ metadata: {}
37
+ post_install_message:
38
+ rdoc_options: []
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubyforge_project:
53
+ rubygems_version: 2.4.5.1
54
+ signing_key:
55
+ specification_version: 4
56
+ summary: Include EmberCLI-generated JavaScript and CSS stylesheet tags in your Rails
57
+ layouts
58
+ test_files: []