wedge 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/wedge/opal.rb +120 -119
- data/lib/wedge/version.rb +1 -1
- data/wedge.gemspec +1 -2
- metadata +4 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 54944284d00e24ca9e6e454c117aba4d64a9af6e
|
4
|
+
data.tar.gz: 77d2c5b902b1554c3603c281c1dd22a61aacc50b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06d7116b3e7ddef035a3905ddc83f8af1d90f0228f9a679e89747cd9f6b4ddcc1bcefc74c89ba779e60cdbc6849770334b32df7850fcc2de156f303161ae1e22
|
7
|
+
data.tar.gz: b2dcb475ae9ff5b2e03217b0c92b3cc8262a26918538ec9268b3d15df3d50672d4bba32762a0e8a8ba5c83e69eb6f7bdc881d8b40fe8ca56279b687233bf5fd5
|
data/lib/wedge/opal.rb
CHANGED
@@ -1,156 +1,157 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
# @return [String] Compiled javascript.
|
5
|
-
def javascript
|
6
|
-
to_s
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.original_compile(source, options = {})
|
11
|
-
Compiler.new(source, options).original_compile
|
12
|
-
end
|
13
|
-
|
14
|
-
class Compiler
|
15
|
-
alias_method :original_compile, :compile
|
16
|
-
def compile
|
17
|
-
@result = original_compile
|
18
|
-
|
19
|
-
if defined? Wedge
|
20
|
-
logical_path = self.file
|
21
|
-
classes = Wedge.config.component_class
|
22
|
-
comp_class = classes["#{Wedge.config.app_dir}/#{logical_path}".gsub(/\//, '__')] || classes[logical_path.gsub(/\//, '__')]
|
23
|
-
|
24
|
-
if logical_path == 'wedge'
|
25
|
-
compiled_data = Base64.encode64 Wedge.config.client_data.to_json
|
26
|
-
# We need to merge in some data that is only set on the server.
|
27
|
-
# i.e. path, assets_key etc....
|
28
|
-
@result << Opal.original_compile("require '#{self.file}'; Wedge.config.data = HashObject.new(Wedge.config.data.to_h.merge JSON.parse(Base64.decode64('#{compiled_data}')))")
|
29
|
-
# load all global plugins into wedge
|
30
|
-
Wedge.config.plugins.each do |path|
|
31
|
-
@result << Builder.build(path).to_s
|
32
|
-
end
|
33
|
-
elsif comp_class
|
34
|
-
comp_class.config.on_compile.each { |blk| comp_class.instance_exec(true, &blk) }
|
35
|
-
comp_name = comp_class.config.name
|
36
|
-
compiled_data = Base64.encode64 comp_class.config.client_data.to_json
|
37
|
-
js = ''
|
1
|
+
class Wedge
|
2
|
+
# Create our own opal instance.
|
3
|
+
Opal = ::Opal.dup
|
38
4
|
|
39
|
-
|
40
|
-
|
41
|
-
|
5
|
+
unless RUBY_ENGINE == 'opal'
|
6
|
+
module Opal
|
7
|
+
class Builder
|
8
|
+
# @return [String] Compiled javascript.
|
9
|
+
def javascript
|
10
|
+
to_s
|
11
|
+
end
|
12
|
+
end
|
42
13
|
|
43
|
-
|
14
|
+
def self.original_compile(source, options = {})
|
15
|
+
Compiler.new(source, options).original_compile
|
16
|
+
end
|
44
17
|
|
45
|
-
|
46
|
-
|
18
|
+
class Compiler
|
19
|
+
alias_method :original_compile, :compile
|
20
|
+
def compile
|
21
|
+
@result = original_compile
|
22
|
+
|
23
|
+
if defined? Wedge
|
24
|
+
logical_path = self.file
|
25
|
+
classes = Wedge.config.component_class
|
26
|
+
comp_class = classes["#{Wedge.config.app_dir}/#{logical_path}".gsub(/\//, '__')] || classes[logical_path.gsub(/\//, '__')]
|
27
|
+
|
28
|
+
if logical_path == 'wedge'
|
29
|
+
compiled_data = Base64.encode64 Wedge.config.client_data.to_json
|
30
|
+
# We need to merge in some data that is only set on the server.
|
31
|
+
# i.e. path, assets_key etc....
|
32
|
+
@result << Opal.original_compile("require '#{self.file}'; Wedge.config.data = HashObject.new(Wedge.config.data.to_h.merge JSON.parse(Base64.decode64('#{compiled_data}')))")
|
33
|
+
# load all global plugins into wedge
|
34
|
+
Wedge.config.plugins.each do |path|
|
35
|
+
@result << Builder.build(path).to_s
|
36
|
+
end
|
37
|
+
elsif comp_class
|
38
|
+
comp_class.config.on_compile.each { |blk| comp_class.instance_exec(true, &blk) }
|
39
|
+
comp_name = comp_class.config.name
|
40
|
+
compiled_data = Base64.encode64 comp_class.config.client_data.to_json
|
41
|
+
js = ''
|
42
|
+
|
43
|
+
js << "require '#{self.file}'; Wedge.config.component_class[:#{comp_name}].config.data = HashObject.new(Wedge.config.component_class[:#{comp_name}].config.data.to_h.merge JSON.parse(Base64.decode64('#{compiled_data}')))"
|
44
|
+
# todo: discuss: pass plugin settings that were set server side?
|
45
|
+
js << "; Wedge.plugin(:#{comp_name.to_s.gsub(/_plugin$/, '')})" if comp_class.config.is_plugin
|
46
|
+
|
47
|
+
@result << Opal.original_compile(js)
|
48
|
+
|
49
|
+
if compile_str = comp_class.config.compile_str
|
50
|
+
@result << compile_str
|
51
|
+
end
|
52
|
+
|
53
|
+
load_requires logical_path
|
47
54
|
end
|
48
|
-
|
49
|
-
load_requires logical_path
|
50
55
|
end
|
51
|
-
end
|
52
56
|
|
53
|
-
|
54
|
-
|
57
|
+
@result
|
58
|
+
end
|
55
59
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
+
def load_requires path_name
|
61
|
+
if requires = Wedge.config.requires[path_name.gsub(/\//, '__')]
|
62
|
+
requires.each do |path|
|
63
|
+
next unless comp_class = Wedge.config.component_class[path]
|
60
64
|
|
61
|
-
|
65
|
+
comp_class.config.on_compile.each { |blk| comp_class.instance_eval(&blk) }
|
62
66
|
|
63
|
-
|
64
|
-
|
67
|
+
comp_name = comp_class.config.name
|
68
|
+
compiled_data = Base64.encode64 comp_class.config.client_data.to_json
|
65
69
|
|
66
|
-
|
70
|
+
load_requires path
|
67
71
|
|
68
|
-
|
72
|
+
@result << Opal.original_compile("require '#{path}'; Wedge.config.component_class[:#{comp_name}].config.data = HashObject.new(Wedge.config.component_class[:#{comp_name}].config.data.to_h.merge JSON.parse(Base64.decode64('#{compiled_data}')))")
|
73
|
+
end
|
69
74
|
end
|
70
75
|
end
|
71
76
|
end
|
72
|
-
end
|
73
77
|
|
74
|
-
|
75
|
-
|
78
|
+
class Server
|
79
|
+
attr_accessor :headers, :gzip
|
76
80
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
81
|
+
def initialize debug_or_options = {}
|
82
|
+
unless Hash === debug_or_options
|
83
|
+
warn "passing a boolean to control debug is deprecated.\n"+
|
84
|
+
"Please pass an Hash instead: Server.new(debug: true)"
|
85
|
+
options = {:debug => debug_or_options}
|
86
|
+
else
|
87
|
+
options = debug_or_options
|
88
|
+
end
|
85
89
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
90
|
+
@headers = {}
|
91
|
+
@gzip = false
|
92
|
+
@use_index = true
|
93
|
+
@public_root = nil
|
94
|
+
@public_urls = ['/']
|
95
|
+
@sprockets = options.fetch(:sprockets, ::Sprockets::Environment.new)
|
96
|
+
@debug = options.fetch(:debug, true)
|
97
|
+
@prefix = options.fetch(:prefix, '/assets')
|
94
98
|
|
95
|
-
|
99
|
+
Opal.paths.each { |p| @sprockets.append_path(p) }
|
96
100
|
|
97
|
-
|
98
|
-
|
99
|
-
end
|
100
|
-
|
101
|
-
def create_app
|
102
|
-
server, sprockets, prefix, headers = self, @sprockets, self.prefix, @headers
|
103
|
-
sprockets.logger.level ||= Logger::DEBUG
|
104
|
-
source_map_enabled = self.source_map_enabled
|
105
|
-
if source_map_enabled
|
106
|
-
maps_prefix = SOURCE_MAPS_PREFIX_PATH
|
107
|
-
maps_app = SourceMapServer.new(sprockets, maps_prefix)
|
108
|
-
::Opal::Sprockets::SourceMapHeaderPatch.inject!(maps_prefix)
|
101
|
+
yield self if block_given?
|
102
|
+
create_app
|
109
103
|
end
|
110
104
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
use Index, server if server.use_index
|
116
|
-
use Headers, server
|
105
|
+
def create_app
|
106
|
+
server, sprockets, prefix, headers = self, @sprockets, self.prefix, @headers
|
107
|
+
sprockets.logger.level ||= Logger::DEBUG
|
108
|
+
source_map_enabled = self.source_map_enabled
|
117
109
|
if source_map_enabled
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
110
|
+
maps_prefix = SOURCE_MAPS_PREFIX_PATH
|
111
|
+
maps_app = SourceMapServer.new(sprockets, maps_prefix)
|
112
|
+
::Opal::Sprockets::SourceMapHeaderPatch.inject!(maps_prefix)
|
113
|
+
end
|
114
|
+
|
115
|
+
@app = Rack::Builder.app do
|
116
|
+
not_found = lambda { |env| [404, {}, []] }
|
117
|
+
use Rack::Deflater
|
118
|
+
use Rack::ShowExceptions
|
119
|
+
use Index, server if server.use_index
|
120
|
+
use Headers, server
|
121
|
+
if source_map_enabled
|
122
|
+
map(maps_prefix) do
|
123
|
+
require 'rack/conditionalget'
|
124
|
+
require 'rack/etag'
|
125
|
+
use Rack::ConditionalGet
|
126
|
+
use Rack::ETag
|
127
|
+
run maps_app
|
128
|
+
end
|
124
129
|
end
|
130
|
+
map(prefix) { run sprockets }
|
131
|
+
run Rack::Static.new(not_found, root: server.public_root, urls: server.public_urls)
|
125
132
|
end
|
126
|
-
map(prefix) { run sprockets }
|
127
|
-
run Rack::Static.new(not_found, root: server.public_root, urls: server.public_urls)
|
128
133
|
end
|
129
|
-
end
|
130
134
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
135
|
+
class Headers
|
136
|
+
def initialize(app, server)
|
137
|
+
@app = app
|
138
|
+
@server = server
|
139
|
+
end
|
136
140
|
|
137
|
-
|
138
|
-
|
139
|
-
|
141
|
+
def call(env)
|
142
|
+
if env['PATH_INFO'][@server.prefix]
|
143
|
+
status, headers, body = @app.call env
|
140
144
|
|
141
|
-
|
142
|
-
|
143
|
-
|
145
|
+
[status, headers.merge(@server.headers), [body]]
|
146
|
+
else
|
147
|
+
@app.call env
|
148
|
+
end
|
144
149
|
end
|
145
150
|
end
|
146
151
|
end
|
147
152
|
end
|
148
153
|
end
|
149
|
-
end
|
150
154
|
|
151
|
-
class Wedge
|
152
|
-
# Create our own opal instance.
|
153
|
-
Opal = ::Opal.dup
|
154
155
|
|
155
156
|
def self.version
|
156
157
|
Wedge::VERSION
|
data/lib/wedge/version.rb
CHANGED
data/wedge.gemspec
CHANGED
@@ -18,8 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_runtime_dependency "opal-
|
22
|
-
spec.add_runtime_dependency "opal-jquery", '~> 0.4.0'
|
21
|
+
spec.add_runtime_dependency "opal-jquery", '~> 0.4.1'
|
23
22
|
spec.add_runtime_dependency "nokogiri"
|
24
23
|
|
25
24
|
spec.add_development_dependency 'rspec'
|
metadata
CHANGED
@@ -1,43 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wedge
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- cj
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: opal-wedge
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 0.8.0
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: 0.8.0
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: opal-jquery
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
30
16
|
requirements:
|
31
17
|
- - "~>"
|
32
18
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.4.
|
19
|
+
version: 0.4.1
|
34
20
|
type: :runtime
|
35
21
|
prerelease: false
|
36
22
|
version_requirements: !ruby/object:Gem::Requirement
|
37
23
|
requirements:
|
38
24
|
- - "~>"
|
39
25
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.4.
|
26
|
+
version: 0.4.1
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: nokogiri
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|