webpack_manifest_plugin 0.1.0

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
+ SHA1:
3
+ metadata.gz: 3404db114a180194d07bc54ddb24b1a415d8e9cd
4
+ data.tar.gz: 1a036289997bd24de6db1005f336675b7eceb2ff
5
+ SHA512:
6
+ metadata.gz: 14fec373385d027be8c6f23514c6269e871680ba5049cb7a910f8ac981099552cd867023f296a8fb1049f8f754846fae5a020caea44be2cabf80a9f59230e8ab
7
+ data.tar.gz: b0705533e3ed1e1765658461a38de77d80136db75af507e0725b50b075e4e9be0e3062ef5a7e95630032f75044c26720fd2c9510caadf36b013b4f544244888f
data/.dockerignore ADDED
@@ -0,0 +1 @@
1
+ *.gem
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /spec/test_app/log/*
11
+ /spec/test_app/tmp/*
12
+ .tags*
13
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,14 @@
1
+ AllCops:
2
+ Exclude:
3
+ - 'spec/test_app/*'
4
+ - spec/controllers/main_controller_spec.rb
5
+ Metrics/LineLength:
6
+ Max: 120
7
+ Exclude:
8
+ - 'spec/**/*'
9
+ Metrics/BlockLength:
10
+ CountComments: false
11
+ Exclude:
12
+ - 'spec/**/*'
13
+ - 'lib/webpack_manifest_plugin/tasks/main.rake'
14
+ - 'webpack_manifest_plugin.gemspec'
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,40 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2017-08-16 21:04:00 +0000 using RuboCop version 0.49.1.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 2
10
+ # Cop supports --auto-correct.
11
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
12
+ # SupportedStyles: empty_lines, no_empty_lines
13
+ Layout/EmptyLinesAroundBlockBody:
14
+ Exclude:
15
+ - 'lib/webpack_manifest_plugin/tasks/main.rake'
16
+
17
+ # Offense count: 3
18
+ # Configuration parameters: CountComments, ExcludedMethods.
19
+ Metrics/BlockLength:
20
+ Max: 51
21
+
22
+ # Offense count: 31
23
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
24
+ # URISchemes: http, https
25
+ Metrics/LineLength:
26
+ Max: 112
27
+
28
+ # Offense count: 2
29
+ Style/Documentation:
30
+ Exclude:
31
+ - 'spec/**/*'
32
+ - 'test/**/*'
33
+ - 'lib/webpack_manifest_plugin.rb'
34
+ - 'lib/webpack_manifest_plugin/engine.rb'
35
+
36
+ # Offense count: 1
37
+ # Cop supports --auto-correct.
38
+ Style/ZeroLengthPredicate:
39
+ Exclude:
40
+ - 'lib/webpack_manifest_plugin/tasks/main.rake'
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.13.1
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at https://github.com/ed-mare. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Dockerfile ADDED
@@ -0,0 +1,17 @@
1
+ FROM ruby:2.3.3
2
+
3
+ # RUN apt-get install curl
4
+ # RUN curl -sL https://deb.nodesource.com/setup | bash - && \
5
+ # apt-get install -y nodejs
6
+ # fix npm - not the latest version installed by apt-get
7
+ # RUN npm install -g npm
8
+ # install webpack
9
+ # RUN npm install -g webpack-cli
10
+
11
+ ENV GEM_HOME /home/gems/mygem
12
+ RUN mkdir -p $GEM_HOME
13
+ # https://docs.docker.com/engine/reference/builder/#workdir
14
+ WORKDIR $GEM_HOME
15
+ COPY . $GEM_HOME
16
+ RUN bundle install
17
+ # RUN cd spec/test_app && rake db:migrate && rake db:migrate RAILS_ENV=test
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in webpack_manifest_plugin.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 ed-mare
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2017 ed-mare
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,178 @@
1
+ # WebpackManifestPlugin
2
+
3
+ This Ruby gem provides a way to use assets managed with `webpack` in Rails templates. JavaScript package [webpack-manifest-plugin](https://www.npmjs.com/package/webpack-manifest-plugin) outputs a JSON file that maps assets to file paths. File paths can change depending on a webpack configuration -- a development config usually doesn't version assets while a production config does. Webpack updates CSS and JavaScript files with the file paths it outputs but not Rails templates. This gem provides a view helper for including these assets in Rails views.
4
+
5
+ ##### Warning
6
+
7
+ This has not been used in a production environment - use at your own risk. Rigorous testing has not been done against different versions of Ruby and Rails -- it has been tested against Ruby 2.3.x and Rails 5.x.
8
+
9
+ ##### Who would use this?
10
+
11
+ Those who already have a webpack asset workflow and only need to reference webpack assets in Rails templates. Otherwise, use [webpacker](https://github.com/rails/webpacker).
12
+
13
+ ##### Example App
14
+
15
+ https://github.com/ed-mare/webpackmanifestplugin-example
16
+
17
+ ## Usage
18
+
19
+ **1) Install the [webpack-manifest-plugin](https://www.npmjs.com/package/webpack-manifest-plugin):**
20
+
21
+ ```shell
22
+ npm install --save-dev webpack-manifest-plugin
23
+ ```
24
+
25
+ **2) Configure your `webpack.config.js` file(s) to use this package:**
26
+
27
+ ```javascript
28
+ /* add the plugin */
29
+ var ManifestPlugin = require('webpack-manifest-plugin');
30
+
31
+ /* in the plugins section */
32
+ plugins: [
33
+ // ...
34
+ new ManifestPlugin({
35
+ // server public path
36
+ publicPath: '/assets/'
37
+ }),
38
+ // ...
39
+ ]
40
+ ```
41
+
42
+ And manage your assets as you normally do with webpack.
43
+
44
+ ```shell
45
+ # i,e.,
46
+ webpack -d -w
47
+ ```
48
+ There is a rake task for running webpack. Ctrl-c kills it when in watch mode.
49
+
50
+ ```shell
51
+ # i,e.,
52
+ rake webpack_manifest_plugin:build
53
+
54
+ # with options
55
+ rake webpack_manifest_plugin:build['-d -w --config webpack.config.prod.js']"
56
+ ```
57
+
58
+ **3) Add this gem to your Rails application Gemfile and run `bundle`:**
59
+
60
+ ```ruby
61
+ gem 'webpack_manifest_plugin'
62
+ ```
63
+
64
+ And then execute:
65
+
66
+ ```ruby
67
+ bundle
68
+ ```
69
+
70
+ If you are creating a new Rails app, skip sprockets and yarn (unless you need yarn).
71
+
72
+ ```shell
73
+ rails new --help
74
+ #...
75
+ [--skip-yarn], [--no-skip-yarn] # Don't use Yarn for managing JavaScript dependencies
76
+ #...
77
+ -S, [--skip-sprockets], [--no-skip-sprockets] # Skip Sprockets files
78
+ #...
79
+ ```
80
+
81
+ If you want UJS and actioncable, add to package.json (with appropriate versions):
82
+
83
+ ```JSON
84
+ # package.json
85
+ "dependencies": {
86
+ "actioncable": "5.1.3",
87
+ ...
88
+ "rails-ujs": "5.1.3",
89
+ ```
90
+
91
+ **4) Configure the gem in initializers:**
92
+
93
+ ```ruby
94
+ # Configurations:
95
+
96
+ # webpack_cmd - Command to execute webpack. Defaults to 'webpack'.
97
+ # cache_manifest - boolean - defaults to false. If set to true, it loads the
98
+ # JSON file once and caches it in WebpackManifestPlugin.configuration.manifest.
99
+ # If false, it lazy loads per request.
100
+ # logger - defaults to Logger.new(STDOUT). Set to your Rails.logger or whatever
101
+ # logger you are using.
102
+
103
+ # create config/initializers/webpack_manifest_plugin.rb file and
104
+ # configure it for your app.
105
+
106
+ # Example:
107
+ WebpackManifestPlugin.configure do |c|
108
+ c.webpack_cmd = 'node node_modules/webpack/bin/webpack'
109
+ c.cache_manifest = Rails.env.production? ? true : false
110
+ c.logger = Rails.logger
111
+ end
112
+ ```
113
+
114
+ **5) Use the `webpack_manifest_path` view helper your Rails views:**
115
+
116
+ A webpack-manifest-plugin file looks something like this:
117
+
118
+ ```JSON
119
+ {
120
+ "common.css": "/assets/stylesheets/common.css",
121
+ "common.js": "/assets/javascripts/common.js",
122
+ "fonts/fontawesome-webfont.eot": "/assets/fonts/fontawesome-webfont.eot",
123
+ "fonts/fontawesome-webfont.svg?v=4.6.3": "/assets/fonts/fontawesome-webfont.svg",
124
+ "fonts/fontawesome-webfont.ttf?v=4.6.3": "/assets/fonts/fontawesome-webfont.ttf",
125
+ "images/login_cover.jpg": "/assets/images/login_cover.jpg",
126
+ "images/panel_bg.png": "/assets/images/panel_bg.png",
127
+ "react.css": "/assets/stylesheets/react.css",
128
+ "react.js": "/assets/javascripts/react.js",
129
+ "welcome.css": "/assets/stylesheets/welcome.css",
130
+ "welcome.js": "/assets/javascripts/welcome.js"
131
+ }
132
+ ```
133
+
134
+ Specify the hash key in the `webpack_manifest_path` view helper:
135
+
136
+ ```html
137
+ <img src="<%= webpack_manifest_path("images/login_cover.jpg") %>" />
138
+ <link href="<%= webpack_manifest_path("common.css") %>" rel="stylesheet" type="text/css">
139
+ <script src="<%= webpack_manifest_path("common.js") %>"></script>
140
+ ```
141
+
142
+ ## Development
143
+
144
+ 1) Build the docker image:
145
+
146
+ ```shell
147
+ docker-compose build
148
+ ```
149
+
150
+ 2) Start docker image with an interactive bash shell:
151
+
152
+ ```shell
153
+ docker-compose run --rm gem
154
+ ```
155
+
156
+ 3) Once in bash session, code, run tests, start console, etc.
157
+
158
+ ```shell
159
+ # run console with gem loaded
160
+ bundle console
161
+
162
+ # run tests
163
+ rspec
164
+ ```
165
+
166
+ ## Todo
167
+
168
+ - Test with Rails 4.1 app. Assuming it works with Rails 4.1/4.2.
169
+ - Test rake tasks.
170
+
171
+ ## Contributing
172
+
173
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ed-mare/webpack_manifest_plugin. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
174
+
175
+
176
+ ## License
177
+
178
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
7
+ require 'rake/testtask'
8
+
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'test'
11
+ t.pattern = 'test/**/*_test.rb'
12
+ t.verbose = false
13
+ end
14
+
15
+ task default: :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'webpack_manifest_plugin'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,10 @@
1
+ # docker-compose run --rm gem
2
+ version: '2'
3
+ services:
4
+ gem:
5
+ build:
6
+ context: .
7
+ dockerfile: Dockerfile
8
+ volumes:
9
+ - .:/home/gems/mygem
10
+ entrypoint: /bin/bash
@@ -0,0 +1,60 @@
1
+ module WebpackManifestPlugin
2
+ # == Gem Configurations
3
+ #
4
+ # === Example:
5
+ #
6
+ # # put in config/initializers/webpack_manifest_plugin.rb
7
+ # WebpackManifestPlugin.configure do |c|
8
+ # c.webpack_cmd = 'node node_modules/webpack/bin/webpack'
9
+ # c.cache_manifest = Rails.env.production? ? true : false
10
+ # c.logger = Rails.logger
11
+ # end
12
+ #
13
+ class Configuration
14
+ # App root. Set to Rails.root in engine initializer. Otherwise empty string.
15
+ attr_accessor :app_root
16
+
17
+ # String. Command to execute webpack. Defaults to 'webpack'.
18
+ # Used in rake tasks.
19
+ attr_accessor :webpack_cmd
20
+
21
+ # String. Relative path to app root to manifest.json file. Defaults to
22
+ # 'public/assets/manifest.json'.
23
+ attr_accessor :manifest_path
24
+
25
+ # Boolean. Cache manifest.json on application loads. Otherwise,
26
+ # it caches per request. Defaults to false.
27
+ attr_accessor :cache_manifest
28
+
29
+ # Defaults to Logger.new(STDOUT)
30
+ attr_accessor :logger
31
+
32
+ def initialize
33
+ set_defaults
34
+ end
35
+
36
+ # Hash. If cache_manifest == true, it caches the manifest here the
37
+ # first time its fetched. Otherwise, returns nil.
38
+ def manifest
39
+ @manifest ||= begin
40
+ @cache_manifest ? load_manifest : nil
41
+ end
42
+ end
43
+
44
+ def load_manifest
45
+ file_path = File.join(@app_root, @manifest_path)
46
+ Oj.load(File.read(file_path))
47
+ end
48
+
49
+ protected
50
+
51
+ def set_defaults
52
+ @app_root = ''
53
+ @webpack_cmd = 'webpack'
54
+ @manifest_path = 'public/assets/manifest.json'
55
+ @cache_manifest = false
56
+ @logger = Logger.new(STDOUT)
57
+ @manifest = nil
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,16 @@
1
+ module WebpackManifestPlugin
2
+ # Railtie hooks for gem.
3
+ class Engine < Rails::Engine
4
+ initializer 'webpack_manifest_plugin.initializers' do |app|
5
+ ActiveSupport.on_load :action_view do
6
+ include ViewHelpers
7
+ end
8
+ # assign Rails.root to app_root
9
+ WebpackManifestPlugin.configuration.app_root = app.root
10
+ end
11
+ rake_tasks do |app|
12
+ WebpackManifestPlugin.configuration.app_root = app.root
13
+ Dir[File.join(File.dirname(__FILE__), 'tasks/*.rake')].each { |f| load f }
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,36 @@
1
+ require 'fileutils'
2
+ require 'pty'
3
+
4
+ namespace :webpack_manifest_plugin do
5
+ desc 'Deletes all files in <app root>/public/assets.'
6
+ task :clean do
7
+ app_root = WebpackManifestPlugin.app_root.to_s
8
+ folder = File.join(app_root, 'public/assets')
9
+ if !app_root.empty? && Dir.exist?(folder)
10
+ FileUtils.remove_entry_secure(folder, secure: true)
11
+ else
12
+ puts "Directory #{folder} not found."
13
+ end
14
+ end
15
+
16
+ desc "Run webpack. Assumes webpack is installed at node_modules/webpack/bin/webpack.
17
+ Use with or without options. Examples:
18
+ rake webpack_manifest_plugin:build
19
+ rake webpack_manifest_plugin:build['-d --config webpack.config.prod.js']"
20
+ task :build, :options do |_t, args|
21
+ cmd = "#{WebpackManifestPlugin.configuration.webpack_cmd} #{args[:options]}"
22
+ puts "Executing #{cmd}..."
23
+
24
+ begin
25
+ PTY.spawn(cmd) do |stdout, _stdin, _pid|
26
+ begin
27
+ stdout.each { |line| print line }
28
+ rescue Errno::EIO
29
+ puts 'The process has finished.'
30
+ end
31
+ end
32
+ rescue PTY::ChildExited
33
+ puts 'webpack exited!'
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,3 @@
1
+ module WebpackManifestPlugin
2
+ VERSION = '0.1.0'.freeze
3
+ end
@@ -0,0 +1,36 @@
1
+ module WebpackManifestPlugin
2
+ # View helpers available in the application.
3
+ module ViewHelpers
4
+ # Webpack manages asset paths in your CSS and Javascript files but not in your Rails
5
+ # templates. The npm webpack-manifest-plugin generates a json file (see example
6
+ # below). 'webpack_manifest_path' uses this file to inject the correct path.
7
+ #
8
+ # {
9
+ # "common.css": "/assets/stylesheets/common.css",
10
+ # "common.js": "/assets/javascripts/common.js",
11
+ # "fonts/fontawesome-webfont.ttf?v=4.6.3": "/assets/fonts/fontawesome-webfont.ttf",
12
+ # "images/panel_bg.png": "/assets/images/panel_bg.png"
13
+ # }
14
+ #
15
+ # Specify an asset hash key like so:
16
+ #
17
+ # <img src="<%= webpack_manifest_path("images/panel_bg.png") %>" width="40px"></img>
18
+ # <script src="<%= webpack_manifest_path("common.js") %>"></script>
19
+ # <link href="<%= webpack_manifest_path("common.css") %>" rel="stylesheet" type="text/css">
20
+ #
21
+ # Returns asset path if key exists, otherwise returns the key itself. If an exception occurs,
22
+ # it logs the error and returns an empty string.
23
+ def webpack_manifest_path(key)
24
+ webpack_manifest_configs[key] || key
25
+ rescue StandardError => ex
26
+ WebpackManifestPlugin.logger.warn "Error parsing webpack manifest JSON. #{ex.message}"
27
+ ''
28
+ end
29
+
30
+ # Manifest configs as a hash.
31
+ def webpack_manifest_configs
32
+ c = WebpackManifestPlugin.configuration
33
+ c.manifest || (@webpack_manifest_configs ||= c.load_manifest)
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,32 @@
1
+ require 'oj'
2
+ require 'logger'
3
+ require 'active_support'
4
+
5
+ require 'webpack_manifest_plugin/version'
6
+ require 'webpack_manifest_plugin/configuration'
7
+ require 'webpack_manifest_plugin/view_helpers'
8
+
9
+ require 'webpack_manifest_plugin/engine' if defined?(Rails)
10
+
11
+ # Convenience methods to configurations.
12
+ module WebpackManifestPlugin
13
+ class << self
14
+ attr_writer :configuration
15
+ end
16
+
17
+ def self.configuration
18
+ @configuration ||= Configuration.new
19
+ end
20
+
21
+ def self.configure
22
+ yield configuration
23
+ end
24
+
25
+ def self.logger
26
+ WebpackManifestPlugin.configuration.logger
27
+ end
28
+
29
+ def self.app_root
30
+ WebpackManifestPlugin.configuration.app_root
31
+ end
32
+ end
@@ -0,0 +1,47 @@
1
+ # coding: utf-8
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'webpack_manifest_plugin/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'webpack_manifest_plugin'
9
+ spec.version = WebpackManifestPlugin::VERSION
10
+ spec.authors = ['ed-mare']
11
+
12
+ spec.summary = 'Gem that work with node webpack_manifest_plugin.'
13
+ spec.description = 'Provides a view helper for injecting asset paths managed by Webpack into Rails templates plus rake tasks.'
14
+ spec.homepage = 'https://github.com/ed-mare/webpack_manifest_plugin'
15
+ spec.license = 'MIT'
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
+ else
22
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
23
+ 'public gem pushes.'
24
+ end
25
+
26
+ # If you get the check your files list error...
27
+ # http://siawyoung.com/coding/ruby/invalid-gemspec.html
28
+
29
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
30
+ f.match(%r{^(test|spec|features)/})
31
+ end
32
+ spec.bindir = 'exe'
33
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
34
+ spec.require_paths = ['lib']
35
+ spec.required_ruby_version = '>= 2.1'
36
+
37
+ spec.add_dependency 'oj', '~> 3.0'
38
+ spec.add_dependency 'railties', '>= 4.1'
39
+ spec.add_dependency 'activesupport', '>= 4.1'
40
+
41
+ spec.add_development_dependency 'bundler', '~> 1.13'
42
+ spec.add_development_dependency 'rake', '~> 10.0'
43
+ spec.add_development_dependency 'rspec', '~> 3.0'
44
+ spec.add_development_dependency 'rails', '>= 4.1'
45
+ spec.add_development_dependency 'rspec-rails', '>= 3.5'
46
+ spec.add_development_dependency 'rubocop', '>= 0.47'
47
+ end
metadata ADDED
@@ -0,0 +1,194 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: webpack_manifest_plugin
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - ed-mare
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-09-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: oj
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: railties
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '4.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '4.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '4.1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '4.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.13'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.13'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rails
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '4.1'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '4.1'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec-rails
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '3.5'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '3.5'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0.47'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0.47'
139
+ description: Provides a view helper for injecting asset paths managed by Webpack into
140
+ Rails templates plus rake tasks.
141
+ email:
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".dockerignore"
147
+ - ".gitignore"
148
+ - ".rspec"
149
+ - ".rubocop.yml"
150
+ - ".rubocop_todo.yml"
151
+ - ".travis.yml"
152
+ - CODE_OF_CONDUCT.md
153
+ - Dockerfile
154
+ - Gemfile
155
+ - LICENSE.txt
156
+ - MIT-LICENSE
157
+ - README.md
158
+ - Rakefile
159
+ - bin/console
160
+ - bin/setup
161
+ - docker-compose.yml
162
+ - lib/webpack_manifest_plugin.rb
163
+ - lib/webpack_manifest_plugin/configuration.rb
164
+ - lib/webpack_manifest_plugin/engine.rb
165
+ - lib/webpack_manifest_plugin/tasks/main.rake
166
+ - lib/webpack_manifest_plugin/version.rb
167
+ - lib/webpack_manifest_plugin/view_helpers.rb
168
+ - webpack_manifest_plugin.gemspec
169
+ homepage: https://github.com/ed-mare/webpack_manifest_plugin
170
+ licenses:
171
+ - MIT
172
+ metadata:
173
+ allowed_push_host: https://rubygems.org
174
+ post_install_message:
175
+ rdoc_options: []
176
+ require_paths:
177
+ - lib
178
+ required_ruby_version: !ruby/object:Gem::Requirement
179
+ requirements:
180
+ - - ">="
181
+ - !ruby/object:Gem::Version
182
+ version: '2.1'
183
+ required_rubygems_version: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ requirements: []
189
+ rubyforge_project:
190
+ rubygems_version: 2.6.10
191
+ signing_key:
192
+ specification_version: 4
193
+ summary: Gem that work with node webpack_manifest_plugin.
194
+ test_files: []