webpack-assets 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
+ SHA1:
3
+ metadata.gz: d00f84da28bbfed1dbad13321cfe342a49d54cf0
4
+ data.tar.gz: aec9cdd15326d352bea1e66555c93f5223caa2e3
5
+ SHA512:
6
+ metadata.gz: ea027ecf2b0c27ece780210558ec43d121f318f0e34f1fdccce062023ca4b6070cf8bebb79a62155f5f89798cd44c501ec1722ada91d6accf4ad037217c85f86
7
+ data.tar.gz: 835edf46dcbbdaeaa2901eaea5ae29264d65440c86779a1481058a4460a5983e14c9facee560500e273b130654b4cfa31cf64e1fa7aefff862e474127b8ebc5d
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,21 @@
1
+ Metrics/LineLength:
2
+ Max: 120
3
+
4
+ Style/Documentation:
5
+ Enabled: false
6
+
7
+ Style/SpaceInsideHashLiteralBraces:
8
+ EnforcedStyle: no_space
9
+
10
+ Style/PercentLiteralDelimiters:
11
+ PreferredDelimiters:
12
+ '%r': '{}'
13
+ '%i': '[]'
14
+ '%w': '[]'
15
+ '%W': '[]'
16
+
17
+ Style/RegexpLiteral:
18
+ EnforcedStyle: mixed
19
+
20
+ Style/AndOr:
21
+ EnforcedStyle: conditionals
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,42 @@
1
+ # Contributing
2
+
3
+ If you discover issues, have ideas for improvements or new features,
4
+ please report them to the [issue tracker][1] of the repository or
5
+ submit a pull request. Please, try to follow these guidelines when you
6
+ do so.
7
+
8
+ ## Issue reporting
9
+
10
+ * Check that the issue has not already been reported.
11
+ * Check that the issue has not already been fixed in the latest code
12
+ (a.k.a. `master`).
13
+ * Be clear, concise and precise in your description of the problem.
14
+ * Open an issue with a descriptive title and a summary in grammatically correct,
15
+ complete sentences.
16
+ * Include any relevant code to the issue summary.
17
+
18
+ ## Pull requests
19
+
20
+ * Read [how to properly contribute to open source projects on Github][2].
21
+ * Fork the project.
22
+ * Use a topic/feature branch to easily amend a pull request later, if necessary.
23
+ * Write [good commit messages][3].
24
+ * Use the same coding conventions as the rest of the project.
25
+ * Commit and push until you are happy with your contribution.
26
+ * Make sure to add tests for it. This is important so I don't break it
27
+ in a future version unintentionally.
28
+ * Please try not to mess with the Rakefile, version, or history. If
29
+ you want to have your own version, or is otherwise necessary, that
30
+ is fine, but please isolate to its own commit so I can cherry-pick
31
+ around it.
32
+ * Make sure the test suite is passing and the code you wrote doesn't produce
33
+ RuboCop offenses.
34
+ * [Squash related commits together][5].
35
+ * Open a [pull request][4] that relates to *only* one subject with a clear title
36
+ and description in grammatically correct, complete sentences.
37
+
38
+ [1]: https://github.com/toptal/webpack-assets/issues
39
+ [2]: http://gun.io/blog/how-to-github-fork-branch-and-pull-request
40
+ [3]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
41
+ [4]: https://help.github.com/articles/using-pull-requests
42
+ [5]: http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in webpack-assets.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Toptal LLC
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,96 @@
1
+ # Webpack Assets
2
+
3
+ `webpack-assets` gem is a lightweight
4
+ [webpack](https://github.com/webpack/webpack)-[Rails](https://github.com/rails/rails)
5
+ integration. It provides the necessary view helpers to completely replace Rails
6
+ Asset Pipeline with webpack. Any custom webpack configuration should be
7
+ supported if it satisfies the assumptions described in
8
+ [the corresponding section](#webpack-configuration).
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'webpack-assets'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install webpack-assets
25
+
26
+ ## Usage
27
+
28
+ Minimal configuration (`config/initializers/webpack.rb`):
29
+
30
+ ```ruby
31
+ Webpack.configure do |config|
32
+ config.port = 4000
33
+ config.public_path = '/assets'
34
+ config.static_path = 'front/static'
35
+ end
36
+ ```
37
+
38
+ Required settings:
39
+
40
+ - `port` - the port webpack dev server is running on.
41
+ - `public_path` - the base path for assets.
42
+ - `static_path` - the root path for static files.
43
+
44
+ Optional settings:
45
+
46
+ - `use_server` - whether webpack dev server is being used (`Rails.env.development?` by default).
47
+
48
+ - `extract_css` - whether css is extracted to a separate file (`!Rails.env.development?` by default).
49
+
50
+ - `host` - the host with the port webpack dev server is running on (can be used instead of `port` option).
51
+
52
+ Example usage:
53
+
54
+ ```ruby
55
+ Webpack.configure do |config|
56
+ if ENV['WEBPACK_HOST']
57
+ config.host = ENV['WEBPACK_HOST']
58
+ else
59
+ config.port = 4000
60
+ end
61
+ end
62
+ ```
63
+
64
+ View helpers:
65
+
66
+ - `webpack_js_tag` is a replacement for `javascript_include_tag`.
67
+
68
+ - `webpack_css_tag` is a replacement for `stylesheet_link_tag`.
69
+
70
+ - `webpack_static_file_url` resolves paths to static files (assets used directly from HTML), e.g.:
71
+
72
+ ```erb
73
+ <%= image_tag webpack_static_file_url('img/logo.png') %>
74
+ ```
75
+
76
+ ## Webpack configuration
77
+
78
+ `webpack-assets` makes several assumptions:
79
+
80
+ - [`assets-webpack-plugin`](https://github.com/sporto/assets-webpack-plugin) is used to prepare `webpack-assets.json` assets manifest.
81
+
82
+ - [`static-files-webpack-plugin`](https://github.com/kossnocorp/static-files-webpack-plugin) is used to prepare `static.json` assets manifest.
83
+
84
+ ## Development
85
+
86
+ After checking out the repo, run `bundle install` to install dependencies. Then, run `rake spec` to run the tests.
87
+
88
+ 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).
89
+
90
+ ## Contributing
91
+
92
+ Bug reports and pull requests are welcome on GitHub at https://github.com/toptal/webpack-assets. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
93
+
94
+ ## License
95
+
96
+ 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,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/lib/webpack.rb ADDED
@@ -0,0 +1,51 @@
1
+ require 'webpack/assets/version'
2
+ require 'webpack/configuration'
3
+
4
+ module Webpack
5
+ class << self
6
+ # @return [Webpack::Configuration]
7
+ def config
8
+ @config ||= Configuration.new
9
+ end
10
+
11
+ # @yield config
12
+ # @yieldparam [Webpack::Configuration]
13
+ # @example
14
+ # Webpack.configure do |config|
15
+ # config.port = 4000
16
+ # config.path = '/assets'
17
+ # end
18
+ def configure
19
+ yield config
20
+ config.validate!
21
+ end
22
+
23
+ # @param entries [Hash]
24
+ def load_entries(entries)
25
+ @entries = entries
26
+ end
27
+
28
+ # @param name [String]
29
+ # @param ext [String]
30
+ # @return [String]
31
+ def fetch_entry(name, ext)
32
+ entries = @entries[name]
33
+ entry = entries[ext] if entries
34
+ fail "#{name}.#{ext} does not exist" unless entry
35
+ entry
36
+ end
37
+
38
+ # @param static_files [Hash]
39
+ def load_static_files(static_files)
40
+ @static_files = static_files
41
+ end
42
+
43
+ # @param path [String]
44
+ # @return [String]
45
+ def fetch_static_file(path)
46
+ static_file = @static_files[path]
47
+ fail "#{path} does not exist" unless static_file
48
+ static_file
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,8 @@
1
+ require 'webpack'
2
+ require 'webpack/view_helpers'
3
+ require 'webpack/rails' if defined?(Rails)
4
+ require 'active_support/lazy_load_hooks'
5
+
6
+ ActiveSupport.on_load(:action_view) do
7
+ include Webpack::ViewHelpers
8
+ end
@@ -0,0 +1,5 @@
1
+ module Webpack
2
+ module Assets
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
@@ -0,0 +1,26 @@
1
+ module Webpack
2
+ class Configuration
3
+ # @attribute port [Integer]
4
+ attr_accessor :port
5
+
6
+ # @attribute host [String]
7
+ attr_accessor :host
8
+
9
+ # @attribute public_path [String]
10
+ attr_accessor :public_path
11
+
12
+ # @attribute static_path [String]
13
+ attr_accessor :static_path
14
+
15
+ # @attribute use_server [Boolean]
16
+ attr_accessor :use_server
17
+
18
+ # @attribute extract_css [Boolean]
19
+ attr_accessor :extract_css
20
+
21
+ def validate!
22
+ fail 'Webpack public_path is not configured' unless public_path
23
+ fail 'Webpack port is not configured' unless port || host
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,24 @@
1
+ require 'rails/railtie'
2
+
3
+ module Webpack
4
+ module Assets
5
+ class Railtie < Rails::Railtie
6
+ config.before_initialize do
7
+ Webpack.config.use_server = Rails.env.development?
8
+ Webpack.config.extract_css = !Rails.env.development?
9
+ end
10
+
11
+ config.to_prepare do
12
+ {load_entries: 'webpack-assets.json', load_static_files: 'static.json'}.each do |load_method, filename|
13
+ path = Rails.root.join(filename)
14
+ if File.exist?(path)
15
+ data = JSON.parse(File.read(path))
16
+ else
17
+ data = {}
18
+ end
19
+ Webpack.public_send(load_method, data)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,64 @@
1
+ module Webpack
2
+ module ViewHelpers
3
+ def webpack_context
4
+ Context.new(self)
5
+ end
6
+
7
+ # @param name [String]
8
+ def webpack_js_tag(name)
9
+ javascript_include_tag(webpack_entry_url(name, :js))
10
+ end
11
+
12
+ # @param name [String]
13
+ def webpack_css_tag(name)
14
+ stylesheet_link_tag(webpack_entry_url(name, :css)) if Webpack.config.extract_css
15
+ end
16
+
17
+ # @param name [String]
18
+ # @param ext [String]
19
+ # @return [String]
20
+ def webpack_entry_url(name, ext)
21
+ webpack_context.entry_url(name, ext)
22
+ end
23
+
24
+ # @param path [String]
25
+ # @return [String]
26
+ def webpack_static_file_url(path)
27
+ webpack_context.static_file_url(path)
28
+ end
29
+
30
+ class Context
31
+ attr_reader :view_context
32
+
33
+ def initialize(view_context)
34
+ @view_context = view_context
35
+ end
36
+
37
+ def entry_url(name, ext)
38
+ if Webpack.config.use_server
39
+ server_url("#{name}.#{ext}")
40
+ else
41
+ Webpack.fetch_entry(name.to_s, ext.to_s)
42
+ end
43
+ end
44
+
45
+ def static_file_url(path)
46
+ if Webpack.config.use_server
47
+ server_url(path)
48
+ else
49
+ Webpack.fetch_static_file("#{Webpack.config.static_path}/#{path}")
50
+ end
51
+ end
52
+
53
+ private
54
+
55
+ def server_url(path)
56
+ "//#{server_host}#{Webpack.config.public_path}/#{path}"
57
+ end
58
+
59
+ def server_host
60
+ Webpack.config.host || "#{view_context.request.host}:#{Webpack.config.port}"
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'webpack/assets/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'webpack-assets'
8
+ spec.version = Webpack::Assets::VERSION
9
+ spec.authors = ['Sergey Nartimov']
10
+ spec.email = ['sergey.nartimov@toptal.com']
11
+
12
+ spec.summary = 'Webpack Assets for Rails.'
13
+ spec.homepage = 'https://github.com/toptal/webpack-assets'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.require_paths = ['lib']
18
+
19
+ spec.add_dependency 'actionpack', '>= 4.2.4'
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.10'
22
+ spec.add_development_dependency 'rake', '~> 10.0'
23
+ spec.add_development_dependency 'rspec'
24
+ spec.add_development_dependency 'rspec-rails'
25
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: webpack-assets
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sergey Nartimov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-02-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: actionpack
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 4.2.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 4.2.4
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.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
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: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-rails
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description:
84
+ email:
85
+ - sergey.nartimov@toptal.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".rubocop.yml"
93
+ - ".travis.yml"
94
+ - CODE_OF_CONDUCT.md
95
+ - CONTRIBUTING.md
96
+ - Gemfile
97
+ - LICENSE.txt
98
+ - README.md
99
+ - Rakefile
100
+ - lib/webpack.rb
101
+ - lib/webpack/assets.rb
102
+ - lib/webpack/assets/version.rb
103
+ - lib/webpack/configuration.rb
104
+ - lib/webpack/rails.rb
105
+ - lib/webpack/view_helpers.rb
106
+ - webpack-assets.gemspec
107
+ homepage: https://github.com/toptal/webpack-assets
108
+ licenses:
109
+ - MIT
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.4.5.1
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: Webpack Assets for Rails.
131
+ test_files: []