assets-watchify 0.1.1 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f2c12f4b19795435aaa980226d2a8f89346c3123
4
- data.tar.gz: 9f4a56fd987a94497f6bafc65c07ad5c88ed343b
3
+ metadata.gz: 0fc574bdc0daf1342d47c720bd1b962c9f2a6745
4
+ data.tar.gz: c7520b80c34aa9c47f868595ca6845b9aa159d07
5
5
  SHA512:
6
- metadata.gz: f77f519bdc6895873c0563b3d23c6f7f7a700eab19e2d91dd031680748510470c2abcd1f5cc85286aaa423a3e3671862bc3857e15796ed5d92cce1b959419231
7
- data.tar.gz: af97267c82f9acccf7b8b758313b63b6bb43e8039ff9ff83c43770992b7df648a24deab6236196b3414bcb822411f77119b75068f89ad0e7d1555608cfcd92cd
6
+ metadata.gz: a56590dd75819e9e506a70428dfcb1fef54ad7f10db853bc845995b2f1a00261eac1c29166605fd9c42601a070bd53f39a5968a826f2cf80a91bcfb9db1fc73a
7
+ data.tar.gz: f568d30307814c2dd959aa65ea1aeb58ac6c6d88d4ec022d277dcc34ed67ab8e06fe6243837270adf887323a428c6e52f4e249456d3b0cb0c75fbadf7ed7648a
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in assets-watchify.gemspec
4
- gemspec
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in assets-watchify.gemspec
4
+ gemspec
@@ -1,22 +1,22 @@
1
- Copyright (c) 2015 Stas Ukolov
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ Copyright (c) 2015 Stas Ukolov
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -66,21 +66,14 @@ server {
66
66
  ## Precompilation
67
67
 
68
68
  It's useful sometimes to compile large JavaScript on Rails server start.
69
- Request it via Bundles constant , eg:
69
+ Request this with `preload` method:
70
70
 
71
71
  ```ruby
72
72
  # config/initializers/watchify.rb
73
- Assets::Watchify::Bundles['application.js']=nil
74
- Assets::Watchify::Bundles['other.js']=nil
75
- ```
76
- Precompiling `application.js` should be frequent, there exists
77
- `defaults!` method for it:
78
-
79
- ```ruby
80
- # config/initializers/watchify.rb
81
- Assets::Watchify.defaults! rescue nil
73
+ Assets::Watchify.preload 'application.js', 'my/other.js' rescue nil
82
74
  ```
83
75
 
76
+ `preload` without arguments is `preload 'application.js'`.
84
77
 
85
78
  ## See also
86
79
 
data/Rakefile CHANGED
@@ -1 +1 @@
1
- require "bundler/gem_tasks"
1
+ require "bundler/gem_tasks"
@@ -1,32 +1,32 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'assets/watchify/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "assets-watchify"
8
- spec.version = Assets::Watchify::VERSION
9
- spec.authors = ["Stas Ukolov"]
10
- spec.email = ["ukoloff@gmail.com"]
11
- spec.summary = 'Fast serving Rails assets in development'
12
- spec.description = ''
13
- spec.homepage = "https://github.com/ukoloff/assets-watchify"
14
- spec.license = "MIT"
15
-
16
- spec.files = `git ls-files`.split($/)
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
20
-
21
- spec.add_dependency "railties"
22
- spec.add_dependency 'source_map'
23
- spec.add_dependency 'listen'
24
- if Gem.win_platform?
25
- spec.add_dependency 'wdm'
26
- spec.add_dependency 'execjs-xtrn'
27
- spec.add_dependency 'openssl-win-root'
28
- end
29
-
30
- spec.add_development_dependency "bundler", "~> 1.3"
31
- spec.add_development_dependency "rake"
32
- end
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'assets/watchify/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "assets-watchify"
8
+ spec.version = Assets::Watchify::VERSION
9
+ spec.authors = ["Stas Ukolov"]
10
+ spec.email = ["ukoloff@gmail.com"]
11
+ spec.summary = 'Fast serving Rails assets in development'
12
+ spec.description = ''
13
+ spec.homepage = "https://github.com/ukoloff/assets-watchify"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "railties"
22
+ spec.add_dependency 'source_map'
23
+ spec.add_dependency 'listen'
24
+ if Gem.win_platform?
25
+ spec.add_dependency 'wdm'
26
+ spec.add_dependency 'execjs-xtrn'
27
+ spec.add_dependency 'openssl-win-root'
28
+ end
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.3"
31
+ spec.add_development_dependency "rake"
32
+ end
@@ -7,14 +7,36 @@ end
7
7
 
8
8
  class Rails::Application
9
9
  initializer :assets_watchify do
10
- require_relative 'watchify/boot'
10
+ Assets::Watchify.boot!
11
11
  end
12
12
  end
13
13
 
14
14
  module Assets::Watchify
15
- Bundles={}
15
+ Folder='w6y'
16
16
 
17
- def self.defaults!
18
- Bundles['application.js']=nil
17
+ @bundles={}
18
+
19
+ def self.preload *args
20
+ args=['application.js'] if args.empty?
21
+ args.flatten.compact.each{|js| @bundles[js]=nil}
22
+ end
23
+
24
+ def self.use?
25
+ defined?(Rails::Server) &&
26
+ 'development'==Rails.env &&
27
+ @root.directory?
28
+ end
29
+
30
+ def self.boot!
31
+ @prefix=Rails.application.config.assets.prefix
32
+ @path=@prefix+'/'+Folder
33
+ @root=Rails.root.join "public"+@path
34
+ return unless use?
35
+ require_relative "watchify/main"
36
+ start!
37
+ end
38
+
39
+ def self.mkdir
40
+ FileUtils.mkpath @root
19
41
  end
20
42
  end
@@ -8,17 +8,13 @@ module Assets::Watchify
8
8
  require_relative 'sprockets'
9
9
 
10
10
  def self.clean
11
- Dir.glob Root.join '**', '*' do |f|
11
+ Dir.glob @root.join '**', '*' do |f|
12
12
  File.delete f rescue nil
13
13
  end
14
14
  end
15
15
 
16
- def self.mkdir
17
- FileUtils.mkpath Root
18
- end
19
-
20
16
  def self.rmdir
21
- FileUtils.remove_entry Root
17
+ FileUtils.remove_entry @root
22
18
  end
23
19
 
24
20
  def self.ms seconds
@@ -37,12 +33,12 @@ module Assets::Watchify
37
33
 
38
34
  t2 = Time.now
39
35
 
40
- unless File.exist? js = Root.join(z.digest_path)
41
- File.delete Bundles[name], "#{Bundles[name]}.map" rescue nil if Bundles[name]
42
- Bundles[name] = js
36
+ unless File.exist? js = @root.join(z.digest_path)
37
+ File.delete @bundles[name], "#{@bundles[name]}.map" rescue nil if @bundles[name]
38
+ @bundles[name] = js
43
39
  FileUtils.mkpath js.dirname
44
40
  jsf = File.open js, 'w+'
45
- map = SourceMap.new file: js.basename, source_root: '/assets', generated_output: jsf
41
+ map = SourceMap.new file: js.basename, source_root: @prefix, generated_output: jsf
46
42
  z.to_a.each {|d| map.add_generated d.source, source: d.logical_path+'?body=1'}
47
43
  map.save "#{js}.map"
48
44
  jsf.puts
@@ -51,11 +47,11 @@ module Assets::Watchify
51
47
  t3 = Time.now
52
48
  puts "#{self} built '#{name}' (#{ms t2-t1}+#{ms t3-t2}=#{ms t3-t1})..."
53
49
  end
54
- "<script src='/assets/#{Folder}/#{z.digest_path}'></script><!-- #{z.length}/#{z.to_a.length} -->"
50
+ "<script src='#{@path}/#{z.digest_path}'></script><!-- #{z.length}/#{z.to_a.length} -->"
55
51
  end
56
52
 
57
53
  def self.ping
58
- Bundles.keys.each{|name| jstag name}
54
+ @bundles.keys.each{|name| jstag name}
59
55
  end
60
56
 
61
57
  def self.path? f
@@ -66,15 +62,11 @@ module Assets::Watchify
66
62
  true
67
63
  end
68
64
 
69
- def self.pathz
70
- @paths||=Rails.application.config.assets.paths#.select{|f| path? f}
71
- end
72
-
73
65
  def self.start!
74
66
  clean
75
67
  Rails.application.config.assets.debug = false # Let CSS to glue either
76
68
 
77
- paths=pathz
69
+ paths=Rails.application.config.assets.paths.select{|f| path? f}
78
70
 
79
71
  Thread.new do
80
72
  listener = Listen.to paths do |m,a,r|
@@ -94,6 +86,4 @@ module Assets::Watchify
94
86
  ping
95
87
  end
96
88
  end
97
-
98
- start!
99
89
  end
@@ -1,5 +1,5 @@
1
- module Assets::Watchify::Helper
2
- def javascript_include_tag(*sources)
3
- sources.map {|s| Assets::Watchify.jstag s }.join("\n").html_safe
4
- end
5
- end
1
+ module Assets::Watchify::Helper
2
+ def javascript_include_tag(*sources)
3
+ sources.map {|s| Assets::Watchify.jstag s }.join("\n").html_safe
4
+ end
5
+ end
@@ -1,5 +1,5 @@
1
1
  module Assets
2
2
  module Watchify
3
- VERSION = "0.1.1"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -28,7 +28,7 @@ namespace :apps do
28
28
  FileUtils.mkdir_p "#{app}/public/assets/w6y"
29
29
  File.open "#{app}/config/initializers/w6y.rb", 'w' do |f|
30
30
  f.puts <<-EOF.each_line.map(&:strip)
31
- Assets::Watchify.defaults! rescue nil
31
+ Assets::Watchify.preload rescue nil
32
32
  EOF
33
33
  end
34
34
  File.open "#{app}/config/routes.rb", 'w' do |f|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: assets-watchify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stas Ukolov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-24 00:00:00.000000000 Z
11
+ date: 2015-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -137,7 +137,6 @@ files:
137
137
  - Rakefile
138
138
  - assets-watchify.gemspec
139
139
  - lib/assets/watchify.rb
140
- - lib/assets/watchify/boot.rb
141
140
  - lib/assets/watchify/main.rb
142
141
  - lib/assets/watchify/sprockets.rb
143
142
  - lib/assets/watchify/version.rb
@@ -162,7 +161,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
162
161
  version: '0'
163
162
  requirements: []
164
163
  rubyforge_project:
165
- rubygems_version: 2.0.14
164
+ rubygems_version: 2.4.6
166
165
  signing_key:
167
166
  specification_version: 4
168
167
  summary: Fast serving Rails assets in development
@@ -1,15 +0,0 @@
1
- require_relative "version"
2
-
3
- module Assets::Watchify
4
- Folder='w6y'
5
-
6
- Root=Rails.root.join "public/assets", Folder
7
-
8
- def self.use?
9
- defined?(Rails::Server) &&
10
- 'development'==Rails.env &&
11
- Dir.exist?(Root)
12
- end
13
-
14
- require_relative "main" if use?
15
- end