monkeys-sprockets 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +22 -0
- data/README.md +51 -0
- data/lib/monkeys-sprockets.rb +8 -0
- data/lib/monkeys/changer.rb +79 -0
- data/lib/monkeys/filer.rb +68 -0
- data/lib/monkeys/liner.rb +36 -0
- data/lib/monkeys/platforms/middleman.rb +34 -0
- data/lib/monkeys/platforms/rails.rb +27 -0
- data/lib/monkeys/version.rb +5 -0
- metadata +109 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e1eedde8008c580c7ab4da3410e44e3ceefc07d0
|
4
|
+
data.tar.gz: 64eaeb7294b4f650355efb001ef7e219cd5df367
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1e1d34b9d9cb824b6ceff2c7483d7b9f5085a9fc35d1b35cb7011d2ea6b6cc52f2548e59e6ee89e7535b3ae1748007ff6ed2c31278b3a8326ffa493ed0bc4a52
|
7
|
+
data.tar.gz: 6c37dcc47e04850a44c8722e50cf5d8efade04de90195980091f205d3df55cf9d5a426eba2d605def2c9f49d5019f13d3cc1def520ff75743695815ae60fc84b
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Dmitry Maganov
|
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
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# Monkeys-Sprockets
|
2
|
+
|
3
|
+
~~~ruby
|
4
|
+
# config/initializers/monkeys.rb
|
5
|
+
|
6
|
+
# for example we will modify 'videojs-youtube' src file
|
7
|
+
# on the line 624 there a video quality changing attempt
|
8
|
+
# but it will not work, unless a video is stopped before quality change\
|
9
|
+
|
10
|
+
Monkeys::Changer.tap do | change |
|
11
|
+
|
12
|
+
# first we find a file by a full sprockets path
|
13
|
+
# path, that you currently use in a //= require directive
|
14
|
+
# but with full extensions
|
15
|
+
# in this case it's just '.js'
|
16
|
+
|
17
|
+
# sprockets will throw an error, if it couldn't find the file
|
18
|
+
|
19
|
+
change.file 'videojs-youtube/src/youtube.js' do | file |
|
20
|
+
|
21
|
+
# then we get the 624 line
|
22
|
+
# and checking that it has expected content
|
23
|
+
# if not - error will be thrown
|
24
|
+
# you can check content by string or regexp
|
25
|
+
|
26
|
+
file.line 624, 'self.ytplayer.setPlaybackQuality(quality);' do | line |
|
27
|
+
|
28
|
+
# block will receive line content
|
29
|
+
# and returned value ( a string or an array )
|
30
|
+
# will be used instead of this line
|
31
|
+
|
32
|
+
[
|
33
|
+
'var xy334 = self.paused();',
|
34
|
+
'self.ytplayer.stopVideo();',
|
35
|
+
line,
|
36
|
+
'if ( ! xy334 ) self.ytplayer.playVideo();'
|
37
|
+
]
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
~~~
|
45
|
+
|
46
|
+
And append 'monkeys/' to your require directives for this file
|
47
|
+
~~~js
|
48
|
+
//= require monkeys/videojs-youtube/src/youtube
|
49
|
+
~~~
|
50
|
+
|
51
|
+
By default all patched files will be stored in 'vendor/assets/monkeys'.
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'monkeys/filer'
|
2
|
+
|
3
|
+
|
4
|
+
module Monkeys
|
5
|
+
|
6
|
+
class Changer
|
7
|
+
|
8
|
+
@filers = []
|
9
|
+
@folder = nil
|
10
|
+
@sprockets = nil
|
11
|
+
@ready = false
|
12
|
+
|
13
|
+
class << self
|
14
|
+
|
15
|
+
attr_reader :folder
|
16
|
+
attr_reader :sprockets
|
17
|
+
attr_reader :ready
|
18
|
+
|
19
|
+
def folder= ( path )
|
20
|
+
|
21
|
+
@folder = Pathname.new path
|
22
|
+
|
23
|
+
add_folder_to_sprockets
|
24
|
+
|
25
|
+
execute
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
def sprockets= ( sprockets )
|
30
|
+
|
31
|
+
@sprockets = sprockets
|
32
|
+
|
33
|
+
add_folder_to_sprockets
|
34
|
+
|
35
|
+
execute
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
def file ( path, &block )
|
40
|
+
|
41
|
+
filer = Filer.new( self, path, &block )
|
42
|
+
|
43
|
+
@filers << filer
|
44
|
+
|
45
|
+
execute
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
def ready= ( value )
|
50
|
+
|
51
|
+
@ready = value
|
52
|
+
|
53
|
+
execute
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def add_folder_to_sprockets
|
60
|
+
|
61
|
+
@sprockets.append_path @folder if @sprockets && @folder
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
def execute
|
66
|
+
|
67
|
+
return unless @ready && @sprockets && @folder
|
68
|
+
|
69
|
+
@filers.each &:execute
|
70
|
+
|
71
|
+
@filers.clear
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'monkeys/liner'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
|
5
|
+
module Monkeys
|
6
|
+
|
7
|
+
class Filer
|
8
|
+
|
9
|
+
def initialize ( changer, path, &block )
|
10
|
+
|
11
|
+
@changer = changer
|
12
|
+
@path = path
|
13
|
+
@block = block
|
14
|
+
@created_in = created_in
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
def execute
|
19
|
+
|
20
|
+
origin_path = @changer.sprockets.resolve @path
|
21
|
+
|
22
|
+
result_path = @changer.folder.join( 'monkeys', @path )
|
23
|
+
|
24
|
+
return if is_fresh?( result_path, [ origin_path, @created_in ] )
|
25
|
+
|
26
|
+
@lines = IO.readlines origin_path
|
27
|
+
|
28
|
+
@block.call self
|
29
|
+
|
30
|
+
@lines.flatten!
|
31
|
+
|
32
|
+
FileUtils.mkdir_p( result_path.dirname ) unless File.directory?( result_path.dirname )
|
33
|
+
|
34
|
+
File.open( result_path, 'w' ) { | file | file.puts @lines }
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
def line ( *args, &block )
|
39
|
+
|
40
|
+
liner = Liner.new( *args, &block )
|
41
|
+
|
42
|
+
liner.execute @lines
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
protected
|
47
|
+
|
48
|
+
def created_in
|
49
|
+
|
50
|
+
created_in_path = caller.find { | path | ! path['/lib/monkeys/'] }
|
51
|
+
|
52
|
+
created_in_path.slice! /:\d+:in.+$/ if created_in_path
|
53
|
+
|
54
|
+
created_in_path
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
def is_fresh?( result_path, origins_paths = [] )
|
59
|
+
|
60
|
+
return false unless File.exists?( result_path )
|
61
|
+
|
62
|
+
return origins_paths.all? { | origin_path | File.mtime( result_path ) > File.mtime( origin_path ) }
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Monkeys
|
2
|
+
|
3
|
+
class Liner
|
4
|
+
|
5
|
+
def initialize ( number, check = nil, replace = nil, &block )
|
6
|
+
|
7
|
+
@number = number - 1
|
8
|
+
@check = check
|
9
|
+
@replace = replace || block
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
def error ( got )
|
14
|
+
|
15
|
+
raise StandardError, "on line #{ @number } \n expected: #{ @check } \n got: #{ got }"
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
def execute ( lines )
|
20
|
+
|
21
|
+
line = lines[ @number ]
|
22
|
+
|
23
|
+
error( line ) if @check && ! line.slice( @check )
|
24
|
+
|
25
|
+
case @replace
|
26
|
+
|
27
|
+
when Proc then lines[ @number ] = @replace.call line
|
28
|
+
when String, Array then lines[ @number ] = @replace
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'middleman-core'
|
2
|
+
|
3
|
+
|
4
|
+
module Monkeys
|
5
|
+
|
6
|
+
module Platforms
|
7
|
+
|
8
|
+
class Middleman < ::Middleman::Extension
|
9
|
+
|
10
|
+
option :folder, nil, 'A folder, where monkey patched files will be stored.'
|
11
|
+
|
12
|
+
def initialize ( app, options = {}, &block )
|
13
|
+
|
14
|
+
super
|
15
|
+
|
16
|
+
Monkeys::Changer.folder = options[ :folder ]
|
17
|
+
|
18
|
+
app.after_configuration do
|
19
|
+
|
20
|
+
Monkeys::Changer.sprockets = sprockets
|
21
|
+
Monkeys::Changer.ready = true
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
::Middleman::Extensions.register :monkeys_sprockets, Monkeys::Platforms::Middleman
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'rails/engine'
|
2
|
+
|
3
|
+
|
4
|
+
module Monkeys
|
5
|
+
|
6
|
+
module Platforms
|
7
|
+
|
8
|
+
class Rails < ::Rails::Engine
|
9
|
+
|
10
|
+
initializer 'monkeys_sprockets.setup_engine', group: :all do | app |
|
11
|
+
|
12
|
+
Monkeys::Changer.folder ||= app.root.join 'vendor/assets/monkeys'
|
13
|
+
Monkeys::Changer.sprockets = app.assets
|
14
|
+
|
15
|
+
app.config.after_initialize do
|
16
|
+
|
17
|
+
Monkeys::Changer.ready = true
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: monkeys-sprockets
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dmitry Maganov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
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: appraisal
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: sprockets
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.2.2
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.2.2
|
69
|
+
description: Change, replace, add lines in any vendor asset.
|
70
|
+
email:
|
71
|
+
- vonagam@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- LICENSE.txt
|
77
|
+
- README.md
|
78
|
+
- lib/monkeys-sprockets.rb
|
79
|
+
- lib/monkeys/changer.rb
|
80
|
+
- lib/monkeys/filer.rb
|
81
|
+
- lib/monkeys/liner.rb
|
82
|
+
- lib/monkeys/platforms/middleman.rb
|
83
|
+
- lib/monkeys/platforms/rails.rb
|
84
|
+
- lib/monkeys/version.rb
|
85
|
+
homepage: https://github.com/vonagam/monkeys-sprockets
|
86
|
+
licenses:
|
87
|
+
- MIT
|
88
|
+
metadata: {}
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options: []
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
requirements: []
|
104
|
+
rubyforge_project:
|
105
|
+
rubygems_version: 2.4.5
|
106
|
+
signing_key:
|
107
|
+
specification_version: 4
|
108
|
+
summary: Monkey patch any asset file with Sprockets.
|
109
|
+
test_files: []
|