webpack_manifest 0.1.0

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
+ SHA256:
3
+ metadata.gz: eb2ef747217989c47a8781f7e049328a6794f4e069cfe014776dfa4e8670c85e
4
+ data.tar.gz: d465f2d48d57638ab060f146a19f5eee0b41e5f2b8f43626522d054f62c4bdb2
5
+ SHA512:
6
+ metadata.gz: 2b5a3fc1c9dca56074dc26efd3a8127a3a81775e45de0aa3ede5de04818281c35e9cb4e9425d0b7f398355c99eaf6f0ac0dce587f80aaebf8908ea707a800aaa
7
+ data.tar.gz: f224eaa75f9f44118f7f13e9b8f1f658a02b9462bf495bdd92a36d94de1617fe03f1049f09fee5ef32a51562ef4f31f446d2d41660283d85b58810129da8e263
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ # 0.1.0 / 2018-10-17
2
+
3
+ Initial release
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Nobuhiro Nikushi
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/README.md ADDED
@@ -0,0 +1,76 @@
1
+ # WebpackManifest
2
+
3
+ WebpackManifest is a gem that integrate ruby with npm's [webpack-manifest-plugin](https://www.npmjs.com/package/webpack-manifest-plugin).
4
+
5
+ ## Features
6
+
7
+ * Rails view helpers to access assets which are built by webpack according a manifest file.
8
+ * Multiple manifest files support
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'webpack_manifest'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install webpack_manifest
25
+
26
+ ## Usage
27
+
28
+ ### Rails view helpers
29
+
30
+ * `#asset_bundle_path`
31
+ * `#javascript_bundle_tag`
32
+ * `#stylesheet_bundle_tag`
33
+ * `#image_bundle_tag`
34
+
35
+ ### Configuration
36
+
37
+ ```rb
38
+ # In config/initializers/webpack_manifest.rb
39
+
40
+ cache = if Rails.env.development?
41
+ false
42
+ else
43
+ true
44
+ end
45
+ manifest = WebpackManifest::Manifest.new(
46
+ Rails.root.join('public', 'assets', 'manifest.json'),
47
+ cache: cache,
48
+ )
49
+ ```
50
+
51
+
52
+ ### Multiple manifest support
53
+
54
+ TBD
55
+
56
+ ## Roadmap
57
+
58
+ * [x] Implement manifest class
59
+ * [x] Implement Rails view helpers
60
+ * [ ] Configuration generator for Rails initializers
61
+ * [ ] Multiple manifest files support
62
+ * [ ] Write document more
63
+
64
+ ## Development
65
+
66
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
67
+
68
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
69
+
70
+ ## Contributing
71
+
72
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/webpack_manifest.
73
+
74
+ ## License
75
+
76
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WebpackManifest
4
+ require 'webpack_manifest/manifest'
5
+ require 'webpack_manifest/rails'
6
+ require "webpack_manifest/version"
7
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+
5
+ module WebpackManifest
6
+ class Manifest
7
+ class MissingEntryError < StandardError; end
8
+
9
+ def initialize(path_or_hash, cache: false)
10
+ @path_or_hash = path_or_hash
11
+ @cache_manifest = cache
12
+ end
13
+
14
+ def lookup!(name)
15
+ find(name) || handle_missing_entry(name)
16
+ end
17
+
18
+ def find(name)
19
+ data[name.to_s]
20
+ end
21
+
22
+ def assets
23
+ data.values
24
+ end
25
+
26
+ private
27
+
28
+ def data
29
+ if @cache_manifest
30
+ @data ||= load_data
31
+ else
32
+ load_data
33
+ end
34
+ end
35
+
36
+ def load_data
37
+ return @path_or_hash if @path_or_hash.is_a? Hash
38
+ path = @path_or_hash
39
+ File.exist?(path) ? JSON.parse(File.read(path)) : {}
40
+ end
41
+
42
+ def handle_missing_entry(name)
43
+ raise MissingEntryError, <<~MSG
44
+ Can not find #{name} in #{@path_or_hash}.
45
+ Your manifest contains:
46
+ #{JSON.pretty_generate(@data)}
47
+ MSG
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WebpackManifest
4
+ module Rails
5
+ require 'webpack_manifest/rails/helper'
6
+
7
+ class << self
8
+ # TODO: multiple manifest files support
9
+ attr_accessor :manifest
10
+ end
11
+ end
12
+ end
13
+
14
+ require 'active_support/lazy_load_hooks'
15
+
16
+ ActiveSupport.on_load :action_view do
17
+ ::ActionView::Base.send :include, WebpackManifest::Rails::Helper
18
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'action_view'
4
+
5
+ module WebpackManifest::Rails::Helper
6
+ # Example:
7
+ #
8
+ # <%= asset_bundle_path 'calendar.css' %> # => "/assets/web/pack/calendar-1016838bab065ae1e122.css"
9
+ # <%= asset_bundle_path 'icon/favicon.ico' %> # => "/assets/web/pack/icon/favicon-1016838bab065ae1e122.ico"
10
+ def asset_bundle_path(name, **options)
11
+ asset_path(
12
+ WebpackManifest::Rails.manifest.lookup!(name.to_s),
13
+ **options,
14
+ )
15
+ end
16
+
17
+ # Example:
18
+ #
19
+ # <%= javascript_bundle_tag 'calendar', 'data-turbolinks-track': 'reload' %> # =>
20
+ # <script src="/assets/web/pack/calendar-1016838bab065ae1e314.js" data-turbolinks-track="reload"></script>
21
+ #
22
+ # <%= javascript_bundle_tag 'orders/app' %> # =>
23
+ # <script src="/assets/web/pack/orders/app-1016838bab065ae1e314.js"></script>
24
+ def javascript_bundle_tag(*names, **options)
25
+ javascript_include_tag(*sources_from_manifest(names, 'js'), **options)
26
+ end
27
+
28
+ # Examples:
29
+ #
30
+ # <%= stylesheet_bundle_tag 'calendar', 'data-turbolinks-track': 'reload' %> # =>
31
+ # <link rel="stylesheet" media="screen"
32
+ # href="/assets/web/pack/calendar-1016838bab065ae1e122.css" data-turbolinks-track="reload" />
33
+ #
34
+ # <%= stylesheet_bundle_tag 'orders/style' %> # =>
35
+ # <link rel="stylesheet" media="screen"
36
+ # href="/assets/web/pack/orders/style-1016838bab065ae1e122.css" />
37
+ def stylesheet_bundle_tag(*names, **options)
38
+ stylesheet_link_tag(*sources_from_manifest(names, 'css'), **options)
39
+ end
40
+
41
+ # Examples:
42
+ #
43
+ # <%= image_bundle_tag 'icon.png'
44
+ # <img src="/assets/pack/icon-1016838bab065ae1e314.png" />
45
+ #
46
+ # <%= image_bundle_tag "icon.png", size: "16x10", alt: "Edit Entry"
47
+ # <img src="/assets/pack/icon-1016838bab065ae1e314.png" width="16" height="10" alt="Edit Entry" />
48
+ def image_bundle_tag(name, **options)
49
+ image_tag(
50
+ WebpackManifest::Rails.manifest.lookup!(name.to_s),
51
+ **options,
52
+ )
53
+ end
54
+
55
+ private
56
+
57
+ def sources_from_manifest(names, ext)
58
+ names.map { |name| WebpackManifest::Rails.manifest.lookup!(name + '.' + ext) }
59
+ end
60
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WebpackManifest
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,31 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "webpack_manifest/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "webpack_manifest"
8
+ spec.version = WebpackManifest::VERSION
9
+ spec.authors = ["Nobuhiro Nikushi"]
10
+ spec.email = ["deneb.ge@gmail.com"]
11
+
12
+ spec.summary = "A gem to integrate ruby with npm's webpack-manifest-plugin package"
13
+ spec.description = spec.summary
14
+ spec.homepage = "https://github.com/nikushi/webpack_manifest"
15
+ spec.license = "MIT"
16
+ spec.files = Dir['lib/**/*.rb'] + %w[
17
+ CHANGELOG.md
18
+ LICENSE.txt
19
+ README.md
20
+ Rakefile
21
+ webpack_manifest.gemspec
22
+ ]
23
+ spec.require_paths = ['lib']
24
+
25
+ spec.required_ruby_version = '>= 2.0.0'
26
+
27
+ spec.add_dependency 'actionview'
28
+ spec.add_development_dependency "bundler", "~> 1.16"
29
+ spec.add_development_dependency "rake", "~> 10.0"
30
+ spec.add_development_dependency "rspec", "~> 3.0"
31
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: webpack_manifest
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nobuhiro Nikushi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-10-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: actionview
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.16'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.16'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: A gem to integrate ruby with npm's webpack-manifest-plugin package
70
+ email:
71
+ - deneb.ge@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - CHANGELOG.md
77
+ - LICENSE.txt
78
+ - README.md
79
+ - Rakefile
80
+ - lib/webpack_manifest.rb
81
+ - lib/webpack_manifest/manifest.rb
82
+ - lib/webpack_manifest/rails.rb
83
+ - lib/webpack_manifest/rails/helper.rb
84
+ - lib/webpack_manifest/version.rb
85
+ - webpack_manifest.gemspec
86
+ homepage: https://github.com/nikushi/webpack_manifest
87
+ licenses:
88
+ - MIT
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: 2.0.0
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.7.7
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: A gem to integrate ruby with npm's webpack-manifest-plugin package
110
+ test_files: []