wedge 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/wedge.rb +7 -5
- data/lib/wedge/component.rb +1 -3
- data/lib/wedge/config.rb +1 -1
- data/lib/wedge/html.rb +13 -8
- data/lib/wedge/version.rb +1 -1
- data/spec/spec_helper.rb +3 -2
- data/spec/wedge/component_spec.rb +37 -0
- data/spec/wedge_spec.rb +25 -0
- metadata +7 -11
- data/test/test.js +0 -59
- data/test/test_basic_component.rb +0 -34
- data/test/test_browserio.rb +0 -13
- data/test/test_helper.rb +0 -38
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a94aeb77ec52e4aeac034e6f49461c0a83d563e3
|
4
|
+
data.tar.gz: 1bf42f2f509758307845f8aaf82e9e09df0772ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 995a85b4e0cf6ebbce656c4d72238bfe254460a28c5912d0c5eb06e918cb36d7c39666fe923514e1fa06c35837cf8a074cf7b4608f689e47bc19393381de9a08
|
7
|
+
data.tar.gz: c98f4ecfc2025f8d2e2942a393025a0ad7f4a0d2649643d5ee84b636a5b7da408b549d060b6f76f2ca5c24fe8ebdcd887c6bf2f7ef90db2d9fc705005e6f17cf
|
data/lib/wedge.rb
CHANGED
@@ -47,10 +47,12 @@ class Wedge
|
|
47
47
|
|
48
48
|
def html!(scope = false, &block)
|
49
49
|
if !block_given?
|
50
|
-
|
50
|
+
html = HTML::DSL.html(&scope).to_html
|
51
51
|
else
|
52
|
-
|
52
|
+
html = HTML::DSL.scope!(scope).html(&block).to_html
|
53
53
|
end
|
54
|
+
|
55
|
+
DOM.new html
|
54
56
|
end
|
55
57
|
|
56
58
|
def script_tag
|
@@ -130,9 +132,9 @@ class Wedge
|
|
130
132
|
# fix: make this a config option i.e.
|
131
133
|
# gems: [:ability_list]
|
132
134
|
# then grab that path and add it to the opal path list
|
133
|
-
Dir["#{gems_dir}/**/"].sort.each do |folder|
|
134
|
-
|
135
|
-
end
|
135
|
+
# Dir["#{gems_dir}/**/"].sort.each do |folder|
|
136
|
+
# Wedge::Opal.append_path "#{folder}/lib"
|
137
|
+
# end
|
136
138
|
end
|
137
139
|
end
|
138
140
|
end
|
data/lib/wedge/component.rb
CHANGED
data/lib/wedge/config.rb
CHANGED
data/lib/wedge/html.rb
CHANGED
@@ -40,16 +40,20 @@ td textarea tfoot th thead time title tr track tt u ul var video wbr}
|
|
40
40
|
# http://erikonrails.snowedin.net/?p=379
|
41
41
|
class DSL
|
42
42
|
def initialize(tag, *args, &block)
|
43
|
-
@tag
|
44
|
-
@content
|
45
|
-
@attributes
|
43
|
+
@tag = tag
|
44
|
+
@content = args.find { |a| a.instance_of? String }
|
45
|
+
@attributes = args.find { |a| a.instance_of? Hash }
|
46
46
|
@attr_string = []
|
47
47
|
self.instance_eval &block if block_given?
|
48
48
|
end
|
49
49
|
|
50
50
|
def to_html
|
51
|
-
|
52
|
-
|
51
|
+
if @tag
|
52
|
+
@attr_string << " #{@attributes.map {|k,v| "#{k}=#{v.to_s.inspect}" }.join(" ")}" if @attributes
|
53
|
+
"<#{@tag}#{@attr_string.join}>#{@content}#{children.map(&:to_html).join}</#{@tag}>"
|
54
|
+
else
|
55
|
+
"#{@content}#{children.map(&:to_html).join}"
|
56
|
+
end
|
53
57
|
end
|
54
58
|
|
55
59
|
def children
|
@@ -57,7 +61,7 @@ td textarea tfoot th thead time title tr track tt u ul var video wbr}
|
|
57
61
|
end
|
58
62
|
|
59
63
|
# Some of these are Kernel or Object methods or whatever that we need to explicitly override
|
60
|
-
[:p, :select].each do |name|
|
64
|
+
[:p, :select].each do |name|
|
61
65
|
define_method name do |*args, &block|
|
62
66
|
send :method_missing, name, *args, &block
|
63
67
|
end
|
@@ -77,8 +81,9 @@ td textarea tfoot th thead time title tr track tt u ul var video wbr}
|
|
77
81
|
self.class.scope
|
78
82
|
end
|
79
83
|
|
80
|
-
|
81
|
-
|
84
|
+
# fix: opal bug. for some reason this can't be in the class << self block.
|
85
|
+
def self.html &block
|
86
|
+
DSL.scope!(scope).new(nil, nil, &block)
|
82
87
|
end
|
83
88
|
|
84
89
|
class << self
|
data/lib/wedge/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'wedge/component'
|
3
|
+
|
4
|
+
class Comp < Wedge::Component
|
5
|
+
name :comp
|
6
|
+
html (html! {
|
7
|
+
html do
|
8
|
+
body do
|
9
|
+
button 'bar'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
}.to_html) do
|
13
|
+
tmpl :foo, dom.find('button')
|
14
|
+
end
|
15
|
+
|
16
|
+
def foo
|
17
|
+
'bar'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe Wedge::Component do
|
22
|
+
subject(:comp) { Wedge[:comp] }
|
23
|
+
|
24
|
+
it 'should respond to foo' do
|
25
|
+
expect(subject.foo).to eq 'bar'
|
26
|
+
end
|
27
|
+
|
28
|
+
if Wedge.server?
|
29
|
+
it 'should set/get templates' do
|
30
|
+
expect(subject.tmpl(:foo).to_html).to eq '<button>bar</button>'
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should return html with opal js' do
|
34
|
+
expect(subject.to_js(:foo)).to match /Opal/
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/spec/wedge_spec.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'wedge'
|
3
|
+
|
4
|
+
describe Wedge do
|
5
|
+
context 'config' do
|
6
|
+
if Wedge.server?
|
7
|
+
it 'should have an assets key' do
|
8
|
+
expect(Wedge.config.assets_key).not_to be_nil
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should return javascript and resource maps', :slow do
|
12
|
+
expect(Wedge.javascript).to match /Opal/
|
13
|
+
expect(Wedge.source_map).to match /mappings/
|
14
|
+
end
|
15
|
+
else
|
16
|
+
it 'should not have an assets key' do
|
17
|
+
expect(Wedge.config.assets_key).to be_nil
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
it '#html!' do
|
23
|
+
expect(Wedge.html! { button('test') }.to_html).to eq '<button>test</button>'
|
24
|
+
end
|
25
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wedge
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- cj
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: opal
|
@@ -257,11 +257,9 @@ files:
|
|
257
257
|
- spec/playground/layout_spec.rb
|
258
258
|
- spec/playground/uploader_spec.rb
|
259
259
|
- spec/spec_helper.rb
|
260
|
+
- spec/wedge/component_spec.rb
|
260
261
|
- spec/wedge/plugins/uploader_spec.rb
|
261
|
-
-
|
262
|
-
- test/test_basic_component.rb
|
263
|
-
- test/test_browserio.rb
|
264
|
-
- test/test_helper.rb
|
262
|
+
- spec/wedge_spec.rb
|
265
263
|
- wedge.gemspec
|
266
264
|
homepage: ''
|
267
265
|
licenses:
|
@@ -283,7 +281,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
283
281
|
version: '0'
|
284
282
|
requirements: []
|
285
283
|
rubyforge_project:
|
286
|
-
rubygems_version: 2.
|
284
|
+
rubygems_version: 2.2.2
|
287
285
|
signing_key:
|
288
286
|
specification_version: 4
|
289
287
|
summary: Components for the Browser and Server
|
@@ -292,9 +290,7 @@ test_files:
|
|
292
290
|
- spec/playground/layout_spec.rb
|
293
291
|
- spec/playground/uploader_spec.rb
|
294
292
|
- spec/spec_helper.rb
|
293
|
+
- spec/wedge/component_spec.rb
|
295
294
|
- spec/wedge/plugins/uploader_spec.rb
|
296
|
-
-
|
297
|
-
- test/test_basic_component.rb
|
298
|
-
- test/test_browserio.rb
|
299
|
-
- test/test_helper.rb
|
295
|
+
- spec/wedge_spec.rb
|
300
296
|
has_rdoc:
|
data/test/test.js
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
var page = require('webpage').create();
|
2
|
-
page.settings.localToRemoteUrlAccessEnabled = true;
|
3
|
-
page.settings.resourceTimeout = 1000;
|
4
|
-
// page.content = "<!doctype html>\n<html>\n<head>\new<script type=\"text/javascript\" src=\"https://code.jquery.com/jquery-1.11.2.min.js\"></script>\n</head>\n<body>\n<div id=\"foo\">bar<div>\n</body>\n</html>";
|
5
|
-
var content = '<!doctype html>';
|
6
|
-
content += '<html><head>';
|
7
|
-
content += '<script type="text/javascript" src="https://code.jquery.com/jquery-1.11.2.min.js"></script>';
|
8
|
-
content += '</head><body>';
|
9
|
-
content += '<h1 id="foo">bar</h1>';
|
10
|
-
content += '</body></html>';
|
11
|
-
|
12
|
-
// page.content = "<div id='foo'>bar</div>";
|
13
|
-
|
14
|
-
page.onConsoleMessage = function(msg) {
|
15
|
-
console.log(msg);
|
16
|
-
};
|
17
|
-
|
18
|
-
page.onResourceTimeout = function(a) {
|
19
|
-
phantom.exit(1);
|
20
|
-
};
|
21
|
-
|
22
|
-
page.onError = function(msg, trace) {
|
23
|
-
|
24
|
-
var msgStack = ['ERROR: ' + msg];
|
25
|
-
|
26
|
-
if (trace && trace.length) {
|
27
|
-
msgStack.push('TRACE:');
|
28
|
-
trace.forEach(function(t) {
|
29
|
-
msgStack.push(' -> ' + t.file + ': ' + t.line + (t.function ? ' (in function "' + t.function +'")' : ''));
|
30
|
-
});
|
31
|
-
}
|
32
|
-
|
33
|
-
console.log(msgStack.join('\n'));
|
34
|
-
phantom.exit();
|
35
|
-
};
|
36
|
-
|
37
|
-
phantom.onError = function(msg, trace) {
|
38
|
-
var msgStack = ['PHANTOM ERROR: ' + msg];
|
39
|
-
if (trace && trace.length) {
|
40
|
-
msgStack.push('TRACE:');
|
41
|
-
trace.forEach(function(t) {
|
42
|
-
msgStack.push(' -> ' + (t.file || t.sourceURL) + ': ' + t.line + (t.function ? ' (in function ' + t.function +')' : ''));
|
43
|
-
});
|
44
|
-
}
|
45
|
-
console.log(msgStack.join('\n'));
|
46
|
-
phantom.exit();
|
47
|
-
};
|
48
|
-
|
49
|
-
page.content = content
|
50
|
-
|
51
|
-
page.onLoadFinished = function() {
|
52
|
-
page.evaluate(function() {
|
53
|
-
console.log($('#foo').html());
|
54
|
-
});
|
55
|
-
phantom.exit();
|
56
|
-
};
|
57
|
-
|
58
|
-
// page.includeJs("http://code.jquery.com/jquery-1.11.2.min.js", function(){
|
59
|
-
// });
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require_relative 'test_helper'
|
2
|
-
|
3
|
-
class BasicComponent < Wedge::Component
|
4
|
-
name :basic
|
5
|
-
html <<-HTML
|
6
|
-
<!DOCTYPE html>
|
7
|
-
<html>
|
8
|
-
<body>
|
9
|
-
<div id='foo'>bar</div>
|
10
|
-
</body>
|
11
|
-
</html>
|
12
|
-
HTML
|
13
|
-
dom do
|
14
|
-
tmpl :foo, dom.find('#foo')
|
15
|
-
end
|
16
|
-
|
17
|
-
def foo
|
18
|
-
'bar'
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
class TestComponent < Minitest::Test
|
23
|
-
def test_calling_basic_component
|
24
|
-
assert_equal 'bar', wedge(:basic).foo
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_parsing_html
|
28
|
-
assert_equal '<div id="foo">bar</div>', wedge(:basic).tmpl(:foo).to_html
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_returning_js
|
32
|
-
assert wedge(:basic).to_js(:foo)[/Opal/]
|
33
|
-
end
|
34
|
-
end
|
data/test/test_browserio.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
require 'phantomjs'
|
2
|
-
require_relative 'test_helper'
|
3
|
-
|
4
|
-
class Testwedge < Minitest::Test
|
5
|
-
def test_javascript_and_source_maps
|
6
|
-
assert wedge.javascript[/Opal/]
|
7
|
-
assert wedge.source_map[/mappings/]
|
8
|
-
end
|
9
|
-
|
10
|
-
# def test_moo
|
11
|
-
# Phantomjs.run('./test/test.js')
|
12
|
-
# end
|
13
|
-
end
|
data/test/test_helper.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'bundler'
|
2
|
-
Bundler.setup :default, ENV.fetch('RACK_ENV') { 'development' }
|
3
|
-
|
4
|
-
require 'minitest/autorun'
|
5
|
-
require 'minitest/reporters'
|
6
|
-
require 'wedge'
|
7
|
-
|
8
|
-
require 'pry'
|
9
|
-
require 'awesome_print'
|
10
|
-
|
11
|
-
Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new # spec-like progress
|
12
|
-
|
13
|
-
module Minitest
|
14
|
-
class Test
|
15
|
-
extend Minitest::Spec::DSL
|
16
|
-
|
17
|
-
def session
|
18
|
-
@_session ||= OpenStruct.new
|
19
|
-
end
|
20
|
-
|
21
|
-
def wedge(name, *args, &block)
|
22
|
-
Wedge[name, *args, &block]
|
23
|
-
end
|
24
|
-
|
25
|
-
# def app(*args)
|
26
|
-
# a = Class.new(PropertyLink).new
|
27
|
-
#
|
28
|
-
# a.instance_variable_set(:@_request, OpenStruct.new(
|
29
|
-
# session: session,
|
30
|
-
# env: {
|
31
|
-
# 'rack.session' => {}
|
32
|
-
# }
|
33
|
-
# ))
|
34
|
-
#
|
35
|
-
# a.component(*args)
|
36
|
-
# end
|
37
|
-
end
|
38
|
-
end
|