faucet_pipeline_rails 0.2.0 → 1.0.0.rc0

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: fa546fe3ef7bf6aac77523e1cc0303a5be5f42b8
4
- data.tar.gz: aceb6e978667b31b021f0192bf268dbde9a04b60
3
+ metadata.gz: 869fc10676e02209e7ee30a2e6d023f924cbc560
4
+ data.tar.gz: c9db37a4d16c020c135afc738e0e651a7a3cb60b
5
5
  SHA512:
6
- metadata.gz: 7850f94b90e1de832d9a110df0da6c2ffcd442b85e9f36b7add465c5b89521606a126b2b52a2f03de5a13bceee7a5d6bb5ed916353ca924d14ee32f5c3509c2a
7
- data.tar.gz: f78c317c2a1325e7fc802d03c1a2c8f71a99389488f76a12db2fee0d7ae5b6ef3a26a4e0b33ddb18458a8119b3954f81167e0f0a611a556c3a89818261c96984
6
+ metadata.gz: 409d051793c04bbb82846a9aed6468c9e4e9be8f07aafa7d62e7a19352a1ad11fe7dbc1a9d642ede67e3d372bf46aad5ca53ff0cd17a053b01aa765fc1bc3c6f
7
+ data.tar.gz: b2a2a0bb416238b53c2b1c813dd9bea212e83ce14215dd1fa401f1259d4d3b343be932b8e597b6cdad413d8053e34fbdd8bc2a7678c544a24139cc90da3fde45
data/README.md CHANGED
@@ -20,18 +20,12 @@ So let's say you have a JavaScript file called `application.js` (for example in
20
20
  `public/assets/javascripts`) from that file. When you use `stylesheet_link_tag
21
21
  'public/assets/javascripts/application.js'`, you expect that the resulting HTML
22
22
  points to the file containing the hash in its filename. To do that,
23
- `faucet-pipeline` generates a manifest files for each type of asset. In this
24
- case, it needs to generate a file called `javascript.json` in
25
- `public/assets/manifests` (to change this, see the Configuration section). The
26
- file should look like this:
27
-
28
- ```json
29
- {
30
- "application.js": "/assets/javascripts/application-03118e77692b637cfc0f55bb27fef087.js"
31
- }
32
- ```
23
+ `faucet-pipeline` generates a manifest file. In the case of using it with this
24
+ Gem, it needs to save it as `public/assets/manifest.json` (to change this, see
25
+ the Configuration section)
33
26
 
34
- And that's it. This gem will take care of the rest. The resulting HTML will look like this:
27
+ And that's it. This gem will take care of the rest. The resulting HTML will
28
+ look like this:
35
29
 
36
30
  ```html
37
31
  <!-- ... -->
@@ -65,75 +59,78 @@ Or install it yourself as:
65
59
  $ gem install faucet_pipeline_rails
66
60
  ```
67
61
 
62
+ After this, you can ditch sprockets (aka the classic Rails asset pipeline)
63
+ for good. If you're on an existing Rails app, change the top of your
64
+ `config/application.rb` from `require 'rails/all'` to:
65
+
66
+ ```ruby
67
+ # Pick the frameworks you want:
68
+ require "active_model/railtie"
69
+ require "active_job/railtie"
70
+ require "active_record/railtie"
71
+ require "action_controller/railtie"
72
+ require "action_mailer/railtie"
73
+ require "action_view/railtie"
74
+ require "action_cable/engine"
75
+ # require "sprockets/railtie" # Disable sprockets
76
+ require "rails/test_unit/railtie"
77
+ ```
78
+
79
+ Make sure you customize this to your actual needs. The main takeaway here is
80
+ to not require `"sprockets/railtie"` anymore.
81
+
82
+ For fresh apps, you can just skip sprockets with:
83
+
84
+ rails new --skip-sprockets
85
+
68
86
  ## Configuration
69
87
 
70
88
  By default this gem assumes that your manifest files can be found in
71
- `public/assets/manifests`. This is a nice starting point for a `faucet.config.js`:
89
+ `public/assets/manifest.json`. This is a nice starting point for a
90
+ `faucet.config.js`:
72
91
 
73
92
  ```js
74
- let jsConfig = {
75
- manifest: {
76
- file: "public/assets/manifests/javascript.json",
77
- baseURI: (bundlePath, baseName) => `/assets/javascripts/${baseName}`
78
- },
79
- bundles: [{
80
- entryPoint: "./app/assets/javascripts/application.js",
81
- target: "public/assets/javascripts/application.js",
82
- externals: {}
83
- }]
84
- };
93
+ let jsConfig = [{
94
+ entryPoint: "./app/assets/javascripts/application.js",
95
+ target: "./public/assets/javascripts/application.js"
96
+ }];
85
97
 
86
- let sassConfig = {
87
- manifest: {
88
- file: "public/assets/manifests/stylesheet.json",
89
- baseURI: (bundlePath, baseName) => `/assets/stylesheets/${baseName}`
90
- },
91
- assets: [
92
- "public/assets/manifests/static.json"
93
- ],
94
- prefixes: {
95
- browsers: [ "last 2 versions" ]
96
- },
97
- bundles: [{
98
- entryPoint: "app/assets/stylesheets/application.scss",
99
- target: "public/assets/stylesheets/application.css"
100
- }]
101
- };
98
+ let sassConfig = [{
99
+ entryPoint: "./app/assets/stylesheets/application.scss",
100
+ target: "./public/assets/stylesheets/application.css"
101
+ }];
102
102
 
103
- let staticConfig = {
104
- manifest: {
105
- file: "public/assets/manifests/static.json",
106
- baseURI: (bundlePath, baseName) => `/assets/static/${baseName}`
107
- },
108
- bundles: [{
109
- source: "app/assets/images",
110
- target: "public/assets/static"
111
- }]
112
- }
103
+ let staticConfig = [{
104
+ source: "./app/assets/images",
105
+ target: "./public/assets/images"
106
+ }];
113
107
 
114
108
  module.exports = {
115
109
  js: jsConfig,
116
110
  sass: sassConfig,
117
111
  static: staticConfig,
118
- watchDirs: ["app/assets"]
112
+ watchDirs: ["app/assets"],
113
+ manifest: {
114
+ file: "./public/assets/manifest.json",
115
+ webRoot: "./public"
116
+ }
119
117
  };
120
118
  ```
121
119
 
122
120
  In this case, your `application.html.erb` would contain lines like these:
123
121
 
124
122
  ```erb
125
- <%= stylesheet_link_tag 'public/assets/stylesheets/application.css', media: 'all', 'data-turbolinks-track': 'reload' %>
126
- <%= javascript_include_tag 'public/assets/javascripts/application.js', 'data-turbolinks-track': 'reload' %>
123
+ <%= stylesheet_link_tag 'public/assets/application.css', media: 'all', 'data-turbolinks-track': 'reload' %>
124
+ <%= javascript_include_tag 'public/assets/application.js', 'data-turbolinks-track': 'reload' %>
127
125
  ```
128
126
 
129
- You can change the path to the manifest fiels that with the following
130
- configuration:
127
+ You can change the path to the manifest file with the following configuration:
131
128
 
132
129
  ```ruby
133
- config.x.faucet_pipeline.manifests_path = File.join("my", "own", "manifests", "path")
130
+ config.x.faucet_pipeline.manifest_path = File.join("my", "own", "manifests", "path.json")
134
131
  ```
135
132
 
136
- The `manifests_path` is relative to your Rails Root.
133
+ The `manifest_path` is relative to your Rails Root.
137
134
 
138
135
  ## Development
139
136
 
@@ -1,9 +1,8 @@
1
+ require "singleton"
2
+
1
3
  module FaucetPipelineRails
2
4
  class Manifest
3
- def initialize(manifests_path, type)
4
- @manifests_path = manifests_path
5
- @type = type
6
- end
5
+ include Singleton
7
6
 
8
7
  def fetch(asset_name)
9
8
  parsed_manifest.fetch(asset_name)
@@ -16,21 +15,22 @@ module FaucetPipelineRails
16
15
  def parsed_manifest
17
16
  JSON.parse(unparsed_manifest)
18
17
  rescue JSON::ParserError
19
- raise "The manifest file '#{manifest_path}' is invalid JSON"
18
+ raise "The manifest file '#{relative_manifest_path}' is invalid JSON"
20
19
  end
21
20
 
22
21
  def unparsed_manifest
23
- File.read(full_manifest_path)
22
+ File.read(manifest_path)
24
23
  rescue Errno::ENOENT
25
- raise "The manifest file '#{manifest_path}' is missing"
24
+ raise "The manifest file '#{relative_manifest_path}' is missing"
26
25
  end
27
26
 
28
- def full_manifest_path
29
- File.join(Rails.root, manifest_path)
27
+ def manifest_path
28
+ File.join(Rails.root, relative_manifest_path)
30
29
  end
31
30
 
32
- def manifest_path
33
- File.join(@manifests_path, "#{@type}.json")
31
+ def relative_manifest_path
32
+ Rails.configuration.x.faucet_pipeline.manifest_path ||
33
+ File.join("public", "assets", "manifest.json")
34
34
  end
35
35
  end
36
36
  end
@@ -1,9 +1,12 @@
1
- require "faucet_pipeline_rails/compute_asset_path"
1
+ require "faucet_pipeline_rails/manifest"
2
2
 
3
3
  module FaucetPipelineRails
4
4
  class Railtie < Rails::Railtie
5
5
  ActiveSupport.on_load(:action_view) do
6
- include FaucetPipelineRails::ComputeAssetPath
6
+ # Overwrite `compute_asset_path` with our own implementation
7
+ define_method(:compute_asset_path) do |source, _|
8
+ Manifest.instance.fetch(source)
9
+ end
7
10
  end
8
11
  end
9
12
  end
@@ -1,3 +1,3 @@
1
1
  module FaucetPipelineRails
2
- VERSION = "0.2.0"
2
+ VERSION = "1.0.0.rc0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faucet_pipeline_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.0.rc0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lucas Dohmen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-06 00:00:00.000000000 Z
11
+ date: 2018-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -63,7 +63,6 @@ files:
63
63
  - README.md
64
64
  - Rakefile
65
65
  - lib/faucet_pipeline_rails.rb
66
- - lib/faucet_pipeline_rails/compute_asset_path.rb
67
66
  - lib/faucet_pipeline_rails/manifest.rb
68
67
  - lib/faucet_pipeline_rails/railtie.rb
69
68
  - lib/faucet_pipeline_rails/version.rb
@@ -82,9 +81,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
82
81
  version: '0'
83
82
  required_rubygems_version: !ruby/object:Gem::Requirement
84
83
  requirements:
85
- - - ">="
84
+ - - ">"
86
85
  - !ruby/object:Gem::Version
87
- version: '0'
86
+ version: 1.3.1
88
87
  requirements: []
89
88
  rubyforge_project:
90
89
  rubygems_version: 2.6.13
@@ -1,25 +0,0 @@
1
- require "faucet_pipeline_rails/manifest"
2
-
3
- module FaucetPipelineRails
4
- module ComputeAssetPath
5
- MANIFEST_FOR_TYPE = {
6
- image: "static",
7
- stylesheet: "stylesheet",
8
- javascript: "javascript"
9
- }
10
-
11
- def compute_asset_path(source, options = {})
12
- if MANIFEST_FOR_TYPE.has_key? options[:type]
13
- manifest = Manifest.new(manifests_path, MANIFEST_FOR_TYPE[options[:type]])
14
- manifest.fetch(source)
15
- else
16
- source
17
- end
18
- end
19
-
20
- def manifests_path
21
- Rails.configuration.x.faucet_pipeline.manifests_path ||
22
- File.join("public", "assets", "manifests")
23
- end
24
- end
25
- end