Skip to content

Commit 50710d0

Browse files
committed
wip
1 parent 14a63cd commit 50710d0

File tree

11 files changed

+67
-155
lines changed

11 files changed

+67
-155
lines changed

ruby/hyper-component/Gemfile.lock

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ GEM
142142
globalid (0.4.1)
143143
activesupport (>= 4.2.0)
144144
hike (1.2.3)
145-
i18n (1.1.0)
145+
i18n (1.1.1)
146146
concurrent-ruby (~> 1.0)
147147
ice_nine (0.11.2)
148148
interception (0.5)
@@ -151,17 +151,17 @@ GEM
151151
rails-dom-testing (>= 1, < 3)
152152
railties (>= 4.2.0)
153153
thor (>= 0.14, < 2.0)
154-
libv8 (6.3.292.48.1-x86_64-darwin-15)
154+
libv8 (6.3.292.48.1)
155155
listen (3.1.5)
156156
rb-fsevent (~> 0.9, >= 0.9.4)
157157
rb-inotify (~> 0.9, >= 0.9.7)
158158
ruby_dep (~> 1.2)
159159
loofah (2.2.2)
160160
crass (~> 1.0.2)
161161
nokogiri (>= 1.5.9)
162-
mail (2.7.0)
162+
mail (2.7.1)
163163
mini_mime (>= 0.1.1)
164-
marcel (0.3.2)
164+
marcel (0.3.3)
165165
mimemagic (~> 0.3.2)
166166
memoizable (0.4.2)
167167
thread_safe (~> 0.3, >= 0.3.1)
@@ -176,7 +176,7 @@ GEM
176176
libv8 (~> 6.3)
177177
minitest (5.11.3)
178178
nio4r (2.3.1)
179-
nokogiri (1.8.4)
179+
nokogiri (1.8.5)
180180
mini_portile2 (~> 2.3.0)
181181
opal (0.11.3)
182182
ast (>= 2.3.0)
@@ -263,13 +263,13 @@ GEM
263263
tilt
264264
rspec-core (3.8.0)
265265
rspec-support (~> 3.8.0)
266-
rspec-expectations (3.8.1)
266+
rspec-expectations (3.8.2)
267267
diff-lcs (>= 1.2.0, < 2.0)
268268
rspec-support (~> 3.8.0)
269269
rspec-mocks (3.8.0)
270270
diff-lcs (>= 1.2.0, < 2.0)
271271
rspec-support (~> 3.8.0)
272-
rspec-rails (3.8.0)
272+
rspec-rails (3.8.1)
273273
actionpack (>= 3.0)
274274
activesupport (>= 3.0)
275275
railties (>= 3.0)
@@ -317,7 +317,7 @@ GEM
317317
equalizer (~> 0.0.9)
318318
parser (>= 2.3.1.2, < 2.6)
319319
procto (~> 0.0.2)
320-
webdrivers (3.4.2)
320+
webdrivers (3.4.3)
321321
nokogiri (~> 1.6)
322322
rubyzip (~> 1.0)
323323
selenium-webdriver (~> 3.0)

ruby/hyper-component/lib/hyperstack/component/element.rb

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -66,42 +66,8 @@ def delete
6666
# Deprecated version of delete method
6767
alias as_node delete
6868

69-
# Any other method applied to an element will be treated as class name (haml style) thus
70-
# div.foo.bar(id: :fred) is the same as saying div(class: "foo bar", id: :fred)
71-
#
72-
# single underscores become dashes, and double underscores become a single underscore
73-
#
74-
# params may be provide to each class (but typically only to the last for easy reading.)
75-
76-
def method_missing(class_name, args = {}, &new_block)
77-
return dup.render.method_missing(class_name, args, &new_block) unless rendered?
78-
Hyperstack::Internal::Component::RenderingContext.replace(
79-
self,
80-
Hyperstack::Internal::Component::RenderingContext.build do
81-
Hyperstack::Internal::Component::RenderingContext.render(type, build_new_properties(class_name, args), &new_block)
82-
end
83-
)
84-
end
85-
86-
def rendered?
87-
Hyperstack::Internal::Component::RenderingContext.rendered? self
88-
end
89-
90-
def self.haml_class_name(class_name)
91-
class_name.gsub(/__|_/, '__' => '_', '_' => '-')
92-
end
93-
9469
private
9570

96-
def build_new_properties(class_name, args)
97-
class_name = self.class.haml_class_name(class_name)
98-
new_props = @properties.dup
99-
new_props[:className] = "\
100-
#{class_name} #{new_props[:className]} #{args.delete(:class)} #{args.delete(:className)}\
101-
".split(' ').uniq.join(' ')
102-
new_props.merge! args
103-
end
104-
10571
# built in events, events going to native components, and events going to reactrb
10672

10773
# built in events will have their event param translated to the Event wrapper

ruby/hyper-component/lib/hyperstack/ext/component/object.rb

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
1-
# Lazy load HTML tag constants in the form DIV or A
2-
# This is needed to allow for a HAML expression like this DIV.my_class
31
class Object
4-
class << self
5-
alias _reactrb_tag_original_const_missing const_missing
2+
# Lazy load HTML tag constants in the form DIV or A
3+
# This is needed to allow for a tags to be used in expressions like
4+
# render(DIV) do ...
5+
# By lazy loading we don't unecessarily create a pile of constant element tags
6+
# that will probably never get used.
67

7-
def const_missing(const_name)
8-
# Opal uses const_missing to initially define things,
9-
# so we always call the original, and respond to the exception
10-
_reactrb_tag_original_const_missing(const_name)
11-
rescue StandardError => e
12-
Hyperstack::Internal::Component::Tags.html_tag_class_for(const_name) || raise(e)
8+
class Object
9+
class << self
10+
alias _reactrb_tag_original_const_missing const_missing
11+
12+
def const_missing(const_name)
13+
# Opal uses const_missing to initially define things,
14+
# so we always call the original, and respond to the exception
15+
_reactrb_tag_original_const_missing(const_name)
16+
rescue StandardError => e
17+
Hyperstack::Internal::Component::Tags.html_tag_class_for(const_name) || raise(e)
18+
end
1319
end
1420
end
21+
1522
# to_key method returns a suitable unique id that can be used as
1623
# a react `key`. Other classes may override to_key as needed
1724
# for example hyper_mesh returns the object id of the internal

ruby/hyper-component/lib/hyperstack/internal/component/tags.rb

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,12 @@ module Tags
3030
end
3131

3232
const_set tag.upcase, tag
33-
34-
# deprecated: remove
35-
if tag == 'p'
36-
define_method(tag) do |*params, &children|
37-
if children || params.count == 0 || (params.count == 1 && params.first.is_a?(Hash))
38-
RenderingContext.render(tag, *params, &children)
39-
else
40-
Kernel.p(*params)
41-
end
42-
end
43-
else
44-
#alias_method tag, tag.upcase
45-
end
46-
# end of deprecated code
4733
end
4834

4935
# this is used for haml style (i.e. DIV.foo.bar) class tags which is deprecated
5036
def self.html_tag_class_for(tag)
5137
downcased_tag = tag.downcase
52-
if tag =~ /[A-Z]+/ && HTML_TAGS.include?(downcased_tag)
38+
if tag =~ /^[A-Z]+$/ && HTML_TAGS.include?(downcased_tag)
5339
Object.const_set tag, ReactWrapper.create_element(downcased_tag)
5440
end
5541
end

ruby/hyper-component/spec/client_features/component_spec.rb

Lines changed: 3 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ class Lorem; end
372372
optional :bar, type: String
373373
end
374374

375-
def render; DIV; end
375+
def render; DIV {}; end
376376
end
377377
Hyperstack::Component::ReactTestUtils.render_component_into_document(Foo, bar: 10, lorem: Lorem.new)
378378
end
@@ -390,7 +390,7 @@ class Lorem; end
390390
optional :bar, type: String
391391
end
392392

393-
def render; DIV; end
393+
def render; DIV {}; end
394394
end
395395
Hyperstack::Component::ReactTestUtils.render_component_into_document(Foo, foo: 10, bar: '10', lorem: Lorem.new)
396396
end
@@ -587,67 +587,12 @@ class Foo
587587
include Hyperstack::Component
588588

589589
def render
590-
DIV() # this fails but DIV {} passes. Why?
590+
DIV()
591591
end
592592
end
593593
end
594-
binding.pry
595594
expect(page.body).to include('<div data-react-class="Hyperstack.Internal.Component.TopLevelRailsComponent" data-react-props="{&quot;render_params&quot;:{},&quot;component_name&quot;:&quot;Foo&quot;,&quot;controller&quot;:&quot;HyperstackTest&quot;}"><div></div></div>')
596595
end
597-
598-
it 'redefines `p` to make method missing work' do
599-
mount 'Foo' do
600-
class Foo
601-
include Hyperstack::Component
602-
603-
def render
604-
DIV {
605-
p(class_name: 'foo')
606-
p
607-
DIV { 'lorem ipsum' }
608-
p(id: '10')
609-
}
610-
end
611-
end
612-
end
613-
expect(page.body).to include('<div><p class="foo"></p><p></p><div>lorem ipsum</div><p id="10"></p></div>')
614-
end
615-
616-
it 'only overrides `p` in render context' do
617-
mount 'Foo' do
618-
class Foo
619-
include Hyperstack::Component
620-
621-
def self.result
622-
@@result ||= 'ooopsy'
623-
end
624-
625-
def self.result_two
626-
@@result_two ||= 'ooopsy'
627-
end
628-
629-
before_mount do
630-
@@result = p 'first'
631-
end
632-
633-
after_mount do
634-
@@result_two = p 'second'
635-
end
636-
637-
def render
638-
p do
639-
'third'
640-
end
641-
end
642-
end
643-
end
644-
expect_evaluate_ruby('Kernel.p "first"').to eq('first')
645-
expect_evaluate_ruby('p "second"').to eq('second')
646-
expect_evaluate_ruby('Foo.result').to eq('first')
647-
expect_evaluate_ruby('Foo.result_two').to eq('second')
648-
expect(page.body[-40..-10]).to include("<p>third</p>")
649-
expect(page.body[-40..-10]).not_to include("<p>first</p>")
650-
end
651596
end
652597

653598
describe 'new react 15/16 custom isMounted implementation' do

ruby/hyper-component/spec/client_features/dsl_spec.rb

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -219,25 +219,6 @@ def render
219219
expect(page.body[-60..-19]).to include('<span>a man walks into a bar</span>')
220220
end
221221

222-
it "can add class names by the haml .class notation" do
223-
mount 'Foo' do
224-
module Mod
225-
class Bar
226-
include Hyperstack::Component
227-
collect_other_params_as :attributes
228-
def render
229-
"a man walks into a bar".span(params.attributes)
230-
end
231-
end
232-
end
233-
class Foo < HyperComponent
234-
def render
235-
Mod::Bar().the_class.other_class
236-
end
237-
end
238-
end
239-
expect(page.body[-90..-19]).to include('<span class="other-class the-class">a man walks into a bar</span>')
240-
end
241222

242223
it "can use the 'class' keyword for classes" do
243224
mount 'Foo' do

ruby/hyper-component/spec/test_app/app/views/components.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
require 'hyperstack/component/auto-import'
1010
require 'js'
1111
require 'hyper-store'
12+
require 'hyperstack/internal/component/haml'
1213

1314
# these mechanisms are deprecated in favor of using the features of hyper-spec. However
1415
# in order to expedite getting Hyperstack 1.0 released we are just leaving these methods

ruby/hyper-spec/Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ gem 'hyper-component', path: '../hyper-component'
33
gem 'hyper-store', path: '../hyper-store'
44
gem 'hyper-state', path: '../hyper-state'
55
gem 'hyperstack-config', path: '../hyperstack-config'
6+
#gem 'unparser', path: '../../../unparser'
67
gemspec

0 commit comments

Comments
 (0)