js-packer-rails 0.0.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: be8656037311c739980bfa750443d267011d9a95
4
+ data.tar.gz: 5e06acddc8209ff2125b9bad919130bfb359f536
5
+ SHA512:
6
+ metadata.gz: 202d8dd58340b98a52d8741fdfd1ab51aa0f093c0ad912484183cc16e2c23a9569ac987fdcbc617cf08667717c4d0ee707f5b8ee86a34fec8c1feae2cb23075b
7
+ data.tar.gz: d49b9451207e7f3983b9b99133fe15a3749c8534104eefe2a55ed4821e55b57fd5b070f492e152dfd05f92ee7bac95319b7083ba02c180b2d21a8f5eb32db734
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in js-packer-rails.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,128 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ js-packer-rails (0.0.1)
5
+ railties (>= 4.0.1)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actioncable (5.2.0)
11
+ actionpack (= 5.2.0)
12
+ nio4r (~> 2.0)
13
+ websocket-driver (>= 0.6.1)
14
+ actionmailer (5.2.0)
15
+ actionpack (= 5.2.0)
16
+ actionview (= 5.2.0)
17
+ activejob (= 5.2.0)
18
+ mail (~> 2.5, >= 2.5.4)
19
+ rails-dom-testing (~> 2.0)
20
+ actionpack (5.2.0)
21
+ actionview (= 5.2.0)
22
+ activesupport (= 5.2.0)
23
+ rack (~> 2.0)
24
+ rack-test (>= 0.6.3)
25
+ rails-dom-testing (~> 2.0)
26
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
27
+ actionview (5.2.0)
28
+ activesupport (= 5.2.0)
29
+ builder (~> 3.1)
30
+ erubi (~> 1.4)
31
+ rails-dom-testing (~> 2.0)
32
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
33
+ activejob (5.2.0)
34
+ activesupport (= 5.2.0)
35
+ globalid (>= 0.3.6)
36
+ activemodel (5.2.0)
37
+ activesupport (= 5.2.0)
38
+ activerecord (5.2.0)
39
+ activemodel (= 5.2.0)
40
+ activesupport (= 5.2.0)
41
+ arel (>= 9.0)
42
+ activestorage (5.2.0)
43
+ actionpack (= 5.2.0)
44
+ activerecord (= 5.2.0)
45
+ marcel (~> 0.3.1)
46
+ activesupport (5.2.0)
47
+ concurrent-ruby (~> 1.0, >= 1.0.2)
48
+ i18n (>= 0.7, < 2)
49
+ minitest (~> 5.1)
50
+ tzinfo (~> 1.1)
51
+ arel (9.0.0)
52
+ builder (3.2.3)
53
+ concurrent-ruby (1.0.5)
54
+ crass (1.0.4)
55
+ erubi (1.7.1)
56
+ globalid (0.4.1)
57
+ activesupport (>= 4.2.0)
58
+ i18n (1.0.1)
59
+ concurrent-ruby (~> 1.0)
60
+ loofah (2.2.2)
61
+ crass (~> 1.0.2)
62
+ nokogiri (>= 1.5.9)
63
+ mail (2.7.0)
64
+ mini_mime (>= 0.1.1)
65
+ marcel (0.3.2)
66
+ mimemagic (~> 0.3.2)
67
+ method_source (0.9.0)
68
+ mimemagic (0.3.2)
69
+ mini_mime (1.0.0)
70
+ mini_portile2 (2.3.0)
71
+ minitest (5.11.3)
72
+ nio4r (2.3.0)
73
+ nokogiri (1.8.2)
74
+ mini_portile2 (~> 2.3.0)
75
+ rack (2.0.4)
76
+ rack-test (1.0.0)
77
+ rack (>= 1.0, < 3)
78
+ rails (5.2.0)
79
+ actioncable (= 5.2.0)
80
+ actionmailer (= 5.2.0)
81
+ actionpack (= 5.2.0)
82
+ actionview (= 5.2.0)
83
+ activejob (= 5.2.0)
84
+ activemodel (= 5.2.0)
85
+ activerecord (= 5.2.0)
86
+ activestorage (= 5.2.0)
87
+ activesupport (= 5.2.0)
88
+ bundler (>= 1.3.0)
89
+ railties (= 5.2.0)
90
+ sprockets-rails (>= 2.0.0)
91
+ rails-dom-testing (2.0.3)
92
+ activesupport (>= 4.2.0)
93
+ nokogiri (>= 1.6)
94
+ rails-html-sanitizer (1.0.4)
95
+ loofah (~> 2.2, >= 2.2.2)
96
+ railties (5.2.0)
97
+ actionpack (= 5.2.0)
98
+ activesupport (= 5.2.0)
99
+ method_source
100
+ rake (>= 0.8.7)
101
+ thor (>= 0.18.1, < 2.0)
102
+ rake (10.5.0)
103
+ sprockets (3.7.1)
104
+ concurrent-ruby (~> 1.0)
105
+ rack (> 1, < 3)
106
+ sprockets-rails (3.2.1)
107
+ actionpack (>= 4.0)
108
+ activesupport (>= 4.0)
109
+ sprockets (>= 3.0.0)
110
+ thor (0.20.0)
111
+ thread_safe (0.3.6)
112
+ tzinfo (1.2.5)
113
+ thread_safe (~> 0.1)
114
+ websocket-driver (0.7.0)
115
+ websocket-extensions (>= 0.1.0)
116
+ websocket-extensions (0.1.3)
117
+
118
+ PLATFORMS
119
+ ruby
120
+
121
+ DEPENDENCIES
122
+ bundler (~> 1.16)
123
+ js-packer-rails!
124
+ rails (>= 4.0.1)
125
+ rake (~> 10.0)
126
+
127
+ BUNDLED WITH
128
+ 1.16.0
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Jakub Cieslar
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,151 @@
1
+ # Js::Packer::Rails
2
+ The Packer allows you to easily include JavaScript bundle into your Rails project.
3
+ JavaScript world offers a lot of great tools for bundling, uglifying, minifying... So, use it in your Rails app!
4
+ It could be Webpack or Grunt or Gulp or Any New Awesome JS tool :)
5
+ I believe the choice of the tools should depend on issues you want to solve, so use JS tool to prepare your source JS code.
6
+
7
+ The Packer:
8
+ * don't care how do you bundle your JavaScript
9
+ * don't use Rails assets pipeline
10
+ * is only for Rails framework
11
+ * require JavaScript manifest file
12
+ * add 3 helper methods to your view:
13
+ ```
14
+ js_bundle_tag(*sources)
15
+ js_bundle_hash(source)
16
+ js_bundle_name(source)
17
+ ```
18
+
19
+ ## Installation
20
+
21
+ Add this line to your application's Gemfile:
22
+
23
+ ```ruby
24
+ gem 'js-packer-rails'
25
+ ```
26
+
27
+ And then execute:
28
+
29
+ $ bundle
30
+
31
+ Or install it yourself as:
32
+
33
+ $ gem install js-packer-rails
34
+
35
+ ## Usage
36
+
37
+ ### JavaScript manifest file
38
+
39
+ Example format of manifest:
40
+
41
+ ```json
42
+ /* admin-bundle.json */
43
+ {
44
+ "admin-bundle.js": "admin-bundle-f65a6b9fb09ba93b7ea6.js"
45
+ }
46
+ ```
47
+
48
+ So if your bundle name is: `bundle-example-name` then you have to generate manifest json:
49
+ `bundle-example-name.json` which maps your bundle name into bundle name with hash:
50
+
51
+ ```json
52
+ {
53
+ "bundle-example-name.js": "bundle-example-name-[bundle hash].js"
54
+ }
55
+ ```
56
+
57
+ ### Rails view
58
+
59
+ #### js_bundle_tag
60
+
61
+ Just use `js_bundle_tag` in your view or layout by passing your bundle name:
62
+
63
+ ```
64
+ <%= js_bundle_tag 'admin-bundle' %>
65
+ ```
66
+
67
+ If you would like to include more then one bundle for view or layout just add more bundle names:
68
+
69
+ ```
70
+ <%= js_bundle_tag 'admin-bundle', 'user-bundle' %>
71
+ ```
72
+
73
+ #### js_bundle_hash
74
+
75
+ Helper `js_bundle_hash` would be useful to get your code version for your source maps:
76
+
77
+ ```
78
+ <%= js_bundle_hash 'admin-bundle' %>
79
+ ```
80
+
81
+ ### js_bundle_name
82
+
83
+ Helper `js_bundle_name` return your bundle name with proper hash taken from manifest:
84
+
85
+ ```
86
+ <%= js_bundle_name 'admin-bundle' %>
87
+ ```
88
+
89
+ ### Bundle JavaScript
90
+
91
+ Packer would be looking for JavaScript ` manifest` and `bundle` by default in directory `public/bundles/javascripts/`.
92
+
93
+ ### Configuration
94
+
95
+ You can change default directory of your manifest and bundle via YAML file: `config/packer.yml`
96
+
97
+ You can define paths by two params: `manifest_path` and `bundle_path`. Manifest and bundle should be in public directory. `manifest_path` should contain path starting from `public/` but `bundle_path` should skip `public/`
98
+
99
+ Example:
100
+
101
+ ```yml
102
+ default: &default
103
+ manifest_path: public/js/bundles
104
+ bundle_path: js/bundles
105
+
106
+ development:
107
+ <<: *default
108
+ test:
109
+ <<: *default
110
+ production:
111
+ <<: *default
112
+ ```
113
+
114
+ ### Example Webpack setup
115
+
116
+ Use webpack plugin `webpack-manifest-plugin`
117
+
118
+ ```js
119
+ const path = require('path')
120
+ const ManifestPlugin = require('webpack-manifest-plugin')
121
+
122
+ module.exports = {
123
+ entry: {
124
+ 'admin-bundle': path.resolve(__dirname, 'src', 'index.js'),
125
+ },
126
+ output: {
127
+ filename: 'admin-bundle-[hash].js',
128
+ sourceMapFilename: 'admin-bundle-[hash].js.map',
129
+ path: path.resolve('../../public/bundles/javascripts/'),
130
+ },
131
+ plugins: [
132
+ new ManifestPlugin({
133
+ fileName: 'admin-bundle.json',
134
+ }),
135
+ ],
136
+ }
137
+ ```
138
+
139
+ ## Development
140
+
141
+ 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.
142
+
143
+ 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).
144
+
145
+ ## Contributing
146
+
147
+ Bug reports and pull requests are welcome on GitHub at https://github.com/jcieslar/js-packer-rails.
148
+
149
+ ## License
150
+
151
+ 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,11 @@
1
+ require "bundler/gem_tasks"
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rake/testtask'
5
+ Rake::TestTask.new(:test) do |test|
6
+ test.libs << 'lib' << 'test'
7
+ test.pattern = 'test/**/*_test.rb'
8
+ test.verbose = true
9
+ end
10
+
11
+ task :default => :test
@@ -0,0 +1,29 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "js/packer/rails/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "js-packer-rails"
8
+ spec.version = Js::Packer::Rails::VERSION
9
+ spec.authors = ["Jakub Cieslar"]
10
+ spec.email = ["cieslar.jakub@gmail.com"]
11
+
12
+ spec.summary = %q{Pack your JS bundle into Rails app! Use whatever tool you want for your JS assets}
13
+ spec.description = %q{Pack your JS bundle into Rails app! Use whatever tool you want for your JS assets}
14
+ spec.homepage = "https://github.com/jcieslar/js-packer-rails"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_dependency "railties", ">= 4.0.1"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.16"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rails", ">= 4.0.1"
29
+ end
@@ -0,0 +1,2 @@
1
+ require 'js/packer/rails/version'
2
+ require 'js/packer/rails/railtie' if defined?(Rails)
@@ -0,0 +1,14 @@
1
+ require 'js/packer/rails/view_helpers'
2
+ require 'rails'
3
+
4
+ module Js
5
+ module Packer
6
+ module Rails
7
+ class Railtie < ::Rails::Railtie
8
+ initializer "js_packer_rails.view_helpers" do
9
+ ActionView::Base.send :include, ViewHelpers
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,7 @@
1
+ module Js
2
+ module Packer
3
+ module Rails
4
+ VERSION = "0.0.1"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,53 @@
1
+ require 'rails'
2
+
3
+ module Js
4
+ module Packer
5
+ module Rails
6
+ module ViewHelpers
7
+ def js_bundle_tag(*sources)
8
+ sources.uniq.map do |source|
9
+ bundle_name = js_bundle_name(source)
10
+ content_tag :script, '', src: "#{bundle_path(bundle_name)}"
11
+ end.join("\n").html_safe
12
+ end
13
+
14
+ def js_bundle_hash(source)
15
+ bundle_name = js_bundle_name(source)
16
+ bundle_name.gsub("#{source}-", '').gsub('.js', '')
17
+ end
18
+
19
+ def js_bundle_name(source)
20
+ manifest_file = File.read(manifest_path(source))
21
+ manifest = JSON.parse(manifest_file)
22
+ manifest[source + '.js']
23
+ end
24
+
25
+ private
26
+
27
+ def manifest_path(source)
28
+ "#{::Rails.root}/#{config_manifest_path}/#{source}.json"
29
+ end
30
+
31
+ def bundle_path(bundle_name)
32
+ "/#{config_bundle_path}/#{bundle_name}"
33
+ end
34
+
35
+ def config?
36
+ File.exist?("#{::Rails.root}/config/packer.yml")
37
+ end
38
+
39
+ def config
40
+ YAML.load_file("#{::Rails.root}/config/packer.yml")[::Rails.env]
41
+ end
42
+
43
+ def config_manifest_path
44
+ config? ? config['manifest_path'] : 'public/bundles/javascripts'
45
+ end
46
+
47
+ def config_bundle_path
48
+ config? ? config['bundle_path'] : 'bundles/javascripts'
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: js-packer-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jakub Cieslar
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-04-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: railties
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 4.0.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 4.0.1
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: rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 4.0.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 4.0.1
69
+ description: Pack your JS bundle into Rails app! Use whatever tool you want for your
70
+ JS assets
71
+ email:
72
+ - cieslar.jakub@gmail.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - Gemfile
78
+ - Gemfile.lock
79
+ - LICENSE
80
+ - README.md
81
+ - Rakefile
82
+ - js-packer-rails.gemspec
83
+ - lib/js-packer-rails.rb
84
+ - lib/js/packer/rails/railtie.rb
85
+ - lib/js/packer/rails/version.rb
86
+ - lib/js/packer/rails/view_helpers.rb
87
+ homepage: https://github.com/jcieslar/js-packer-rails
88
+ licenses:
89
+ - MIT
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.6.13
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Pack your JS bundle into Rails app! Use whatever tool you want for your JS
111
+ assets
112
+ test_files: []