redjs-sprockets 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f489bcea536400bb0fd1e76cbb954315e449c00e
4
- data.tar.gz: e769556a216ea9d387a01dbe97c477b1a8bcac5c
3
+ metadata.gz: 2968a08d3594575ae78f62506cc4807ccb8395af
4
+ data.tar.gz: c9f3f57629dff78b1d2c754e84bc2382afdd980c
5
5
  SHA512:
6
- metadata.gz: 0eaa59fddff0a77472e7261e9bda96a50541af3eeed610a89a9fb40d8938195a6ff09652be2930cb005a2a8df533830e2b8c1d66d5ef969e247a55b31a4e9b8d
7
- data.tar.gz: e781e45f5560613caf28b086442626ae7af82aa98e422cc116a460078b89fbfd7a152c4a2f7fe39dd5616961105cc35ebc1b11ff1e018729b560f4f5ba7d98b7
6
+ metadata.gz: f87bfad06caac0200e0737e67592db1717f3419449546d3875ef89a2d432ab51802d1e5407bf85356d71e5bdd278136eedd9aa354771cc278840c56a9c41c213
7
+ data.tar.gz: 3b52a31964e7ce506ad4d675a6469035f0dfc48a5bb4b811e6f5e7b93ac28ccfd11a3a8945ce3adc33bc2b3723fc17a2ca86a5cbe30a000bdef86ad6e38fc6d9
data/README.md CHANGED
@@ -28,12 +28,12 @@ activate :redjs_sprockets
28
28
  #### Bare Sprockets
29
29
  On any other platform, which include Sprockets, you can activate redjs like this
30
30
  ~~~ruby
31
- # pass a Sprockets::Base instance as an argument to the Redjs::Sprockets.register method
32
- Redjs::Sprockets.register my_sprockets_instance
31
+ # pass a Sprockets::Base instance as an argument to the RedJS::Sprockets.register method
32
+ RedJS::Sprockets.register my_sprockets_instance
33
33
  ~~~
34
34
 
35
35
  ## Usage
36
- Add the '.red' extension after '.js' for files that will be using the Redjs dependecy manager.
36
+ Add the '.red' extension after '.js' for files that will be using the RedJS dependecy manager.
37
37
  In those files four functions will be available.
38
38
 
39
39
  #### $require( path_to_file )
@@ -55,6 +55,17 @@ If the value is a function, its execution result will be assotiated.
55
55
  #### $defines( key, value )
56
56
  Assotiate the value with the key.
57
57
 
58
+ ### Usage Without '.red' Extension
59
+
60
+ ~~~ruby
61
+ // app/config/redjs.rb
62
+
63
+ RedJS::Sprockets.auto_usage_paths << Rails.root.join( 'app', 'assets', 'javascripts', 'red' )
64
+
65
+ # now any js file in app/assets/javascripts/red will be postprocessed by RedJS
66
+ # regardless of it's extensions
67
+ ~~~
68
+
58
69
  ### Example
59
70
 
60
71
  ~~~js
@@ -1,7 +1,7 @@
1
1
  require 'sprockets'
2
2
  require 'pathname'
3
3
 
4
- module Redjs
4
+ module RedJS
5
5
 
6
6
  JAVASCRIPTS_PATH = Pathname.new( __FILE__ ).dirname.join( 'javascripts' ).to_s
7
7
 
@@ -9,6 +9,7 @@ end
9
9
 
10
10
  require 'redjs/version'
11
11
  require 'redjs/processor'
12
+ require 'redjs/sprockets/base'
12
13
  require 'redjs/sprockets/v' + Sprockets::VERSION[ 0 ]
13
14
 
14
15
  require 'redjs/platforms/rails' if defined? Rails
@@ -1,8 +1,7 @@
1
1
  require 'middleman-core'
2
- require 'pry'
3
2
 
4
3
 
5
- module Redjs
4
+ module RedJS
6
5
 
7
6
  module Platforms
8
7
 
@@ -14,13 +13,13 @@ module Redjs
14
13
 
15
14
  super
16
15
 
17
- Redjs::Sprockets.auto_usage_paths.merge options[ :auto_usage ]
16
+ RedJS::Sprockets.auto_usage_paths.merge options[ :auto_usage ]
18
17
 
19
- ::Tilt.register :red, Redjs::Sprockets
18
+ ::Tilt.register :red, RedJS::Sprockets
20
19
 
21
20
  app.after_configuration do
22
21
 
23
- Redjs::Sprockets.register sprockets
22
+ RedJS::Sprockets.register sprockets
24
23
 
25
24
  end
26
25
 
@@ -33,4 +32,4 @@ module Redjs
33
32
  end
34
33
 
35
34
 
36
- ::Middleman::Extensions.register :redjs_sprockets, Redjs::Platforms::Middleman
35
+ ::Middleman::Extensions.register :redjs_sprockets, RedJS::Platforms::Middleman
@@ -1,7 +1,7 @@
1
1
  require 'rails/engine'
2
2
 
3
3
 
4
- module Redjs
4
+ module RedJS
5
5
 
6
6
  module Platforms
7
7
 
@@ -9,7 +9,7 @@ module Redjs
9
9
 
10
10
  initializer 'redjs_rails.setup_engine', group: :all do | app |
11
11
 
12
- Redjs::Sprockets.register app.assets
12
+ RedJS::Sprockets.register app.assets
13
13
 
14
14
  end
15
15
 
@@ -1,7 +1,7 @@
1
1
  require 'pathname'
2
2
 
3
3
 
4
- module Redjs
4
+ module RedJS
5
5
 
6
6
  class Processor
7
7
 
@@ -0,0 +1,68 @@
1
+ require 'set'
2
+
3
+
4
+ module RedJS
5
+
6
+ module Base
7
+
8
+ def self.included ( base )
9
+
10
+ base.extend ClassMethods
11
+
12
+ base.class_eval do
13
+
14
+ @mime_type = 'application/javascript'
15
+
16
+ @extention = :red
17
+
18
+ @processor = proc do | context, data |
19
+
20
+ result = RedJS::Processor.process context.logical_path, data
21
+
22
+ result[ :required ].each { | required_path | context.require_asset required_path }
23
+
24
+ result[ :data ]
25
+
26
+ end
27
+
28
+ end
29
+
30
+ end
31
+
32
+ module ClassMethods
33
+
34
+ def auto_usage_paths
35
+
36
+ @auto_usage_paths ||= Set.new
37
+
38
+ end
39
+
40
+ def register ( sprockets )
41
+
42
+ sprockets.append_path RedJS::JAVASCRIPTS_PATH
43
+
44
+ auto_usage_paths.each { | auto_usage | sprockets.prepend_path auto_usage }
45
+
46
+ sprockets.register_postprocessor @mime_type, @extention do | context, data |
47
+
48
+ path = context.pathname.to_s
49
+
50
+ if path !~ /\.red[^\/]*$/ && auto_usage_paths.any? { | auto_usage | path.include?( auto_usage.to_s ) }
51
+
52
+ @processor.call context, data
53
+
54
+ else
55
+
56
+ data
57
+
58
+ end
59
+
60
+ end
61
+
62
+ end
63
+
64
+ end
65
+
66
+ end
67
+
68
+ end
@@ -1,51 +1,19 @@
1
1
  require 'set'
2
2
 
3
3
 
4
- module Redjs
4
+ module RedJS
5
5
 
6
6
  class Sprockets < Sprockets::Processor
7
7
 
8
- self.default_mime_type = 'application/javascript'
8
+ include RedJS::Base
9
9
 
10
- @processor = proc do | context, data |
11
-
12
- result = Redjs::Processor.process context.logical_path, data
13
-
14
- result[ :required ].each { | required_path | context.require_asset required_path }
15
-
16
- result[ :data ]
17
-
18
- end
19
-
20
- def self.auto_usage_paths
21
-
22
- @auto_usage_paths ||= Set.new
23
-
24
- end
10
+ self.default_mime_type = @mime_type
25
11
 
26
12
  def self.register ( sprockets )
27
13
 
28
- sprockets.append_path Redjs::JAVASCRIPTS_PATH
29
-
30
- auto_usage_paths.each { | auto_usage | sprockets.prepend_path auto_usage }
31
-
32
- sprockets.register_engine :red, self
33
-
34
- sprockets.register_postprocessor default_mime_type, :red do | context, data |
35
-
36
- path = context.pathname.to_s
37
-
38
- if path !~ /\.red[^\/]*$/ && auto_usage_paths.any? { | auto_usage | path.include?( auto_usage.to_s ) }
39
-
40
- @processor.call context, data
41
-
42
- else
43
-
44
- data
45
-
46
- end
14
+ super sprockets
47
15
 
48
- end
16
+ sprockets.register_engine @extention, self
49
17
 
50
18
  end
51
19
 
@@ -1,16 +1,21 @@
1
1
  require 'set'
2
2
 
3
- # not work yet
4
3
 
5
- module Redjs
4
+ module RedJS
6
5
 
7
6
  class Sprockets
8
7
 
8
+ include RedJS::Base
9
+
9
10
  def self.call ( input )
10
11
 
11
- result = Redjs::Processor.process input[ :filename ], input[ :data ]
12
+ result = RedJS::Processor.process input[ :name ], input[ :data ]
13
+
14
+ required = result[ :required ].map do | path |
15
+
16
+ input[ :environment ].resolve( path, accept: @mime_type, compat: false )[ 0 ]
12
17
 
13
- required = result[ :required ].map{ | path | input[ :environment ].resolve path }
18
+ end
14
19
 
15
20
  {
16
21
  data: result[ :data ],
@@ -21,9 +26,9 @@ module Redjs
21
26
 
22
27
  def self.register ( sprockets )
23
28
 
24
- sprockets.register_engine '.red', self, mime_type: 'application/javascript'
29
+ super sprockets
25
30
 
26
- sprockets.append_path Redjs::JAVASCRIPTS_PATH
31
+ sprockets.register_engine @extention, self, mime_type: @mime_type
27
32
 
28
33
  end
29
34
 
@@ -1,5 +1,5 @@
1
- module Redjs
1
+ module RedJS
2
2
 
3
- VERSION = '0.2.2'
3
+ VERSION = '0.3.0'
4
4
 
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redjs-sprockets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Maganov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-28 00:00:00.000000000 Z
11
+ date: 2015-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -95,6 +95,7 @@ files:
95
95
  - lib/redjs/platforms/middleman.rb
96
96
  - lib/redjs/platforms/rails.rb
97
97
  - lib/redjs/processor.rb
98
+ - lib/redjs/sprockets/base.rb
98
99
  - lib/redjs/sprockets/v2.rb
99
100
  - lib/redjs/sprockets/v3.rb
100
101
  - lib/redjs/version.rb