ember-cli-rails-assets-6 0.6.2.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2054ef506715b40221c284dbe44c99614cb5347bbaa111831ec9928ba893deb3
4
+ data.tar.gz: e95641066476364865bfa44b6242f286945a1d874f6ab7747c98f4a7593c24fe
5
+ SHA512:
6
+ metadata.gz: 555e0bc7e8f4ad61e7bc9a056ebd57120b55c2885f0740e43b3dce0fcd270666b942bb8a9f4f2960789f1055b32db36f3b7e7750489f3d711834b36bd9e9ad25
7
+ data.tar.gz: ae197e756b8c79c0baf248ecd0a4e8bfdbf34e7640f21d3ccb5683e363c578b68d65a10653dff08cd4b2e76204aa0c83a61134d6714311b90696de24449ffb66
data/README.md ADDED
@@ -0,0 +1,165 @@
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
+ #### Rendering without `<base>` element
112
+
113
+ To render the asset elements without using a `<base>` element, pass the URL or
114
+ path to prepend:
115
+
116
+ ```erb
117
+ <-- assuming Ember's assets are mounted to `"/"` -->
118
+ <%= include_ember_script_tags :frontend, prepend: "/" %>
119
+ <%= include_ember_stylesheet_tags :frontend, prepend: "/" %>
120
+
121
+ <%= include_ember_script_tags :admin_panel, prepend: "/" %>
122
+ <%= include_ember_stylesheet_tags :admin_panel, prepend: "/" %>
123
+ ```
124
+
125
+ ## EmberCLI support
126
+
127
+ This project supports:
128
+
129
+ * EmberCLI versions `>= 1.13.13`
130
+
131
+ ## Ruby and Rails support
132
+
133
+ This project supports:
134
+
135
+ * Ruby versions `>= 2.1.0`
136
+ * Rails versions `>=4.1.x`.
137
+
138
+ ## Contributing
139
+
140
+ See the [CONTRIBUTING] document.
141
+ Thank you, [contributors]!
142
+
143
+ [CONTRIBUTING]: CONTRIBUTING.md
144
+ [contributors]: https://github.com/seanpdoyle/ember-cli-rails-assets/graphs/contributors
145
+
146
+ ## License
147
+
148
+ Open source templates are Copyright (c) 2015 Sean Doyle.
149
+ It contains free software that may be redistributed
150
+ under the terms specified in the [LICENSE] file.
151
+
152
+ [LICENSE]: /LICENSE.txt
153
+
154
+ ## About
155
+
156
+ ember-cli-rails was originally created by
157
+ [Pavel Pravosud][rwz] and
158
+ [Jonathan Jackson][rondale-sc].
159
+
160
+ ember-cli-rails-assets was extracted from ember-cli-rails is maintained by
161
+ [Sean Doyle][seanpdoyle].
162
+
163
+ [rwz]: https://github.com/rwz
164
+ [rondale-sc]: https://github.com/rondale-sc
165
+ [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,25 @@
1
+ require "ember_cli/assets/lookup"
2
+
3
+ module EmberCliRailsAssetsHelper
4
+ def include_ember_script_tags(name, prepend: "")
5
+ EmberCli[name].build
6
+
7
+ assets = EmberCli::Assets::Lookup.new(EmberCli[name])
8
+
9
+ assets.javascript_assets.
10
+ map { |src| [prepend, src].join }.
11
+ map { |src| %{<script src="#{src}"></script>}.html_safe }.
12
+ inject(&:+)
13
+ end
14
+
15
+ def include_ember_stylesheet_tags(name, prepend: "")
16
+ EmberCli[name].build
17
+
18
+ assets = EmberCli::Assets::Lookup.new(EmberCli[name])
19
+
20
+ assets.stylesheet_assets.
21
+ map { |src| [prepend, src].join }.
22
+ map { |src| %{<link rel="stylesheet" href="#{src}">}.html_safe }.
23
+ inject(&:+)
24
+ end
25
+ 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,11 @@
1
+ module EmberCli
2
+ module Assets
3
+ class Engine < ::Rails::Engine
4
+ initializer "ember-cli-rails-assets" do
5
+ ActiveSupport.on_load(:action_controller) do
6
+ ActionController::Base.helper EmberCliRailsAssetsHelper
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ module EmberCli
2
+ module Assets
3
+ class BuildError < StandardError; end
4
+ end
5
+ 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.2.1"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ember-cli-rails-assets-6
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.2.1
5
+ platform: ruby
6
+ authors:
7
+ - Sean Doyle
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-11-29 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/lookup.rb
30
+ - lib/ember_cli/assets/paths.rb
31
+ - lib/ember_cli/assets/version.rb
32
+ homepage: https://github.com/seanpdoyle/ember-cli-rails-assets
33
+ licenses:
34
+ - MIT
35
+ metadata: {}
36
+ post_install_message:
37
+ rdoc_options: []
38
+ require_paths:
39
+ - lib
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ requirements: []
51
+ rubygems_version: 3.0.3
52
+ signing_key:
53
+ specification_version: 4
54
+ summary: Include EmberCLI-generated JavaScript and CSS stylesheet tags in your Rails
55
+ layouts
56
+ test_files: []