Skip to content

Commit 164b505

Browse files
committed
fixed rest of failing specs, adjusted rendering in order to match previous rendering behavior
1 parent 1b107a1 commit 164b505

File tree

15 files changed

+105
-140
lines changed

15 files changed

+105
-140
lines changed

lib/matestack/ui/core/base.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ def initialize(html_tag = nil, text = nil, options = {}, &block)
3030
def extract_options(text, options)
3131
if text.is_a? Hash
3232
# we need to dup the text object because we're deleting keys from this object which manipulates the object passed in here
33-
# if this object is reused after beeing injected into this component, the keys would be missing
34-
self.options = text.dup
33+
# if this object is reused after beeing injected into this component, the keys would be missing
34+
self.options = text.dup
3535
else
3636
self.text = text
3737
# we need to dup the options object because we're deleting keys from this object which manipulates the object passed in here
38-
# if this object is reused after beeing injected into this component, the keys would be missing
38+
# if this object is reused after beeing injected into this component, the keys would be missing
3939
self.options = options.dup || {}
4040
end
4141
self.options.symbolize_keys!
@@ -68,12 +68,13 @@ def render_content
6868
if children.empty?
6969
child_content = self.escape ? ERB::Util.html_escape(text) : text if text
7070
else
71-
child_content = children.map { |child| child.render_content }.join.html_safe
71+
# using "\n" in order to preserve the 1.x rendering behavior which impacts appearance in browser
72+
child_content = (children.map { |child| " \n " + child.render_content }.join + " \n ").html_safe
7273
end
7374
result = ''
7475
if self.html_tag
7576
result = tag.public_send(self.html_tag, child_content, self.options || {})
76-
else
77+
elsif child_content
7778
result = child_content
7879
end
7980
result

lib/matestack/ui/core/properties.rb

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,38 @@ module Matestack
22
module Ui
33
module Core
44
module Properties
5-
5+
66
def self.included(base)
77
base.extend ClassMethods
88
base.send :prepend, Initializer
99
end
10-
10+
1111
module Initializer
1212
def initialize(html_tag = nil, text = nil, options = {}, &block)
1313
extract_options(text, options)
1414
create_context
15-
warn "[DEPRECATION] passing text with option :text is deprecated. Please pass text as first argument." if self.options.has_key?(:text)
15+
# warn "[DEPRECATION] passing text with option :text is deprecated. Please pass text as first argument." if self.options.has_key?(:text)
1616
self.text = self.options.delete(:text) if self.options.has_key?(:text)
1717
super
1818
end
1919
end
20-
20+
2121
module ClassMethods
2222
extend Gem::Deprecate
2323

2424
def required(*args)
2525
@required = (@required || []).concat(args)
2626
end
2727
alias requires required
28-
deprecate :requires, :required, 2021, 10
2928

3029
def optional(*args)
3130
@optional = (@optional || []).concat(args)
3231
end
33-
32+
3433
def required_property_keys
3534
@required
3635
end
37-
36+
3837
def optional_property_keys
3938
@optional
4039
end
@@ -45,20 +44,20 @@ def inherited(subclass)
4544
super
4645
end
4746
end
48-
49-
def context
47+
48+
def context
5049
@context ||= OpenStruct.new
5150
end
5251
alias :ctx :context
53-
52+
5453
def required_property_keys
5554
self.class.required_property_keys || []
5655
end
57-
56+
5857
def optional_property_keys
5958
self.class.optional_property_keys || []
6059
end
61-
60+
6261
def create_context
6362
create_context_for_properties(self.required_property_keys, required: true)
6463
create_context_for_properties(self.optional_property_keys)
@@ -78,8 +77,8 @@ def create_context_for_properties(properties, required: false)
7877
end
7978
end if properties
8079
end
81-
80+
8281
end
8382
end
8483
end
85-
end
84+
end

lib/matestack/ui/core/tag_helper.rb

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,34 @@ module Core
55
module TagHelper
66
extend Gem::Deprecate
77
include Slots
8-
8+
99
# can't take content or a block
1010
VOID_TAGS = %i[area base br col hr img input link meta param command keygen source]
11-
11+
1212
TAGS = [:a, :abbr, :acronym, :address, :applet, :area, :article, :aside, :audio, :b, :base, :basefont, :bdi, :bdo, :big, :blockquote, :body, :br, :button, :canvas, :caption, :center, :cite, :code, :col, :colgroup, :data, :datalist, :dd, :del, :details, :dfn, :dialog, :dir, :div, :dl, :dt, :em, :embed, :fieldset, :figcaption, :figure, :font, :footer, :form, :frame, :frameset, :h1, :h2, :h3, :h4, :h5, :h6, :head, :header, :hr, :html, :i, :iframe, :img, :input, :ins, :kbd, :label, :legend, :li, :link, :main, :map, :mark, :meta, :meter, :nav, :noframes, :noscript, :object, :ol, :optgroup, :option, :output, :paragraph, :param, :picture, :pre, :progress, :q, :rp, :rt, :ruby, :s, :samp, :script, :section, :select, :small, :source, :span, :strike, :strong, :style, :sub, :summary, :sup, :svg, :table, :tbody, :td, :template, :textarea, :tfoot, :th, :thead, :time, :title, :tr, :track, :tt, :u, :ul, :var, :video, :wbr]
13-
13+
1414
VOID_TAGS.each do |tag|
1515
define_method tag do |options = {}|
1616
Matestack::Ui::Core::Base.new(tag, nil, options)
1717
end
1818
end
19-
19+
2020
TAGS.each do |tag|
2121
define_method tag do |text = nil, options = {}, &block|
2222
tag = :p if tag == :paragraph
2323
Matestack::Ui::Core::Base.new(tag, text, options, &block)
2424
end
2525
end
26-
26+
2727
def plain(text)
2828
Matestack::Ui::Core::Base.new(nil, text, nil)
2929
end
30-
30+
3131
def unescape(text)
3232
Matestack::Ui::Core::Base.new(nil, text&.html_safe, escape: false)
3333
end
3434
alias unescaped unescape
35-
deprecate :unescaped, :unescape, 2021, 10
36-
35+
3736
def matestack(&block)
3837
div(id: 'matestack-ui') do
3938
Base.new(:component, component_attributes) do
@@ -61,11 +60,35 @@ def a(text = nil, options = {}, &block)
6160
Matestack::Ui::Core::Base.new(:a, text, options, &block)
6261
end
6362

63+
# support old heading component
64+
def heading(text = nil, options=nil, &block)
65+
if text.is_a?(Hash)
66+
options = text
67+
end
68+
69+
case options[:size]
70+
when 1
71+
h1(text, options, &block)
72+
when 2
73+
h2(text, options, &block)
74+
when 3
75+
h3(text, options, &block)
76+
when 4
77+
h4(text, options, &block)
78+
when 5
79+
h5(text, options, &block)
80+
when 6
81+
h6(text, options, &block)
82+
else
83+
h1(text, options, &block)
84+
end
85+
end
86+
6487
def rails_render(options = {})
6588
plain render options
6689
end
6790

6891
end
6992
end
7093
end
71-
end
94+
end

lib/matestack/ui/vue_js/components/collection/order_toggle_indicator.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ module Components
55
module Collection
66
class OrderToggleIndicator < Matestack::Ui::Component
77

8-
required :key, :asc, :desc, :default
8+
required :key, :asc, :desc
9+
optional :default
910

1011
def response
1112
span do

spec/dummy/app/controllers/legacy_views/pages_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
class LegacyViews::PagesController < ApplicationController
22
include Matestack::Ui::Core::Helper
3-
# include Matestack::Ui::Core::Collection::Helper
3+
include Matestack::Ui::VueJs::Components::Collection::Helper
4+
45
layout 'legacy_views'
56

67
def action_inline

spec/dummy/app/matestack/app.rb

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,7 @@
11
class App < Matestack::Ui::App
22

33
def response
4-
html do
5-
head do
6-
unescape csrf_meta_tags
7-
unescape Matestack::Ui::Core::Context.controller.view_context.javascript_pack_tag(:application)
8-
end
9-
end
10-
body do
11-
matestack do
12-
yield
13-
end
14-
end
4+
yield
155
end
166

17-
end
7+
end
Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,35 @@
1-
class Components::LegacyViews::Pages::Collection < Matestack::Ui::StaticComponent
1+
class Components::LegacyViews::Pages::Collection < Matestack::Ui::Component
2+
23
requires :collection_config
34

45
def response
56
heading size: 2, text: 'My Collection'
67
filter
7-
async rerender_on: "#{collection_config.id}-update", id: 'async-collection' do
8+
async rerender_on: "#{context.collection_config.id}-update", id: 'async-collection' do
89
content
910
end
1011
end
1112

1213
private
1314

1415
def filter
15-
collection_filter collection_config.config do
16-
collection_filter_input key: :title, type: :text, placeholder: "Filter by Title", label: 'Title', id: 'title-filter'
17-
collection_filter_submit do
18-
button text: "filter"
19-
end
16+
collection_filter context.collection_config.config do
17+
form_input key: :title, type: :text, placeholder: "Filter by Title", label: 'Title', id: 'title-filter'
18+
button text: "filter", type: "submit"
2019
collection_filter_reset do
2120
button text: "reset"
2221
end
2322
end
2423
end
2524

2625
def content
27-
collection_content collection_config.config do
26+
collection_content context.collection_config.config do
2827
ul do
29-
collection_config.data.each do |dummy|
28+
context.collection_config.data.each do |dummy|
3029
li text: dummy.title
3130
end
3231
end
3332
end
3433
end
3534

36-
end
35+
end
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
<h1>Collection Custom Component</h1>
2-
<%= matestack_component(:legacy_views_pages_collection, collection_config: @my_collection) %>
2+
<%= Components::LegacyViews::Pages::Collection.(collection_config: @my_collection) %>

spec/test/base/core/render/app_resolving_spec.rb

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
Rails.application.reload_routes!
2222
end
2323

24-
it "wraps a Page with a minimal default App when no App is explicitly specified" do
24+
it "does not wrap a Page with a minimal default App when no App is explicitly specified" do
2525

2626
class ExamplePage < Matestack::Ui::Page
2727

@@ -47,8 +47,9 @@ def example
4747

4848
visit "render_app_resolving_spec/example_a"
4949

50-
# dom structure implies correct rendering with wrapping minimal app
51-
text = find(:xpath, 'id("matestack-ui")/div[@class="matestack-app-wrapper"]/div[@class="matestack-page-container"]/div[@class="matestack-page-wrapper"]/div/div[@class="matestack-page-root"]/div[1]').text
50+
expect(page).not_to have_selector('div.matestack-app-wrapper')
51+
52+
text = find(:xpath, 'id("matestack-ui")/div[@class="matestack-page-container"]/div[@class="matestack-page-wrapper"]/div/div[@class="matestack-page-root"]/div[1]').text
5253
expect(text).to eq("hello from page")
5354
end
5455

@@ -166,43 +167,6 @@ def second_example
166167
expect(text).to eq("hello from page")
167168
end
168169

169-
it "does not wrap a Page with an App when explicitly set to false" do
170-
171-
class ExamplePage < Matestack::Ui::Page
172-
def response
173-
matestack do
174-
div do
175-
plain "hello from page"
176-
end
177-
end
178-
end
179-
end
180-
181-
# otherwise the matestack_app_class class var would be set as specified in the former spec
182-
class RenderTestDController < ActionController::Base
183-
include Matestack::Ui::Core::Helper
184-
layout "application"
185-
186-
def example
187-
render ExamplePage # should be wrapped by a minimal default
188-
end
189-
190-
def second_example
191-
render ExamplePage, matestack_app: false # should not be wrapped by an app at all
192-
end
193-
end
194-
195-
visit "render_app_resolving_spec/example_d"
196-
# dom structure implies correct rendering with wrapping specified app
197-
text = find(:xpath, 'id("matestack-ui")//div[@class="matestack-app-wrapper"]/div[@class="matestack-page-container"]//div[@class="matestack-page-wrapper"]/div/div[@class="matestack-page-root"]/div[1]').text
198-
expect(text).to eq("hello from page")
199-
200-
visit "render_app_resolving_spec/second_example_d"
201-
# dom structure implies correct rendering without app
202-
text = find(:xpath, '//div[@class="matestack-page-root"]/div').text
203-
expect(text).to eq("hello from page")
204-
end
205-
206170
describe "is compatible with 0.7.x namespacing approach" do
207171

208172
it "when app is defined on controller (top) level" do

spec/test/components/div_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def response
1919
end
2020

2121
visit "/example"
22+
2223
static_output = page.html
2324
expected_static_output = <<~HTML
2425
<div></div>

0 commit comments

Comments
 (0)