Skip to content

Commit e4df711

Browse files
committed
Merge remote-tracking branch 'origin/cells-haml-love' into prepare_0.7.4_release
2 parents e01cffb + 5c61571 commit e4df711

File tree

17 files changed

+241
-10
lines changed

17 files changed

+241
-10
lines changed

app/concepts/matestack/ui/core/app/app.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Matestack::Ui::Core::App
22
class App < Trailblazer::Cell
33

4-
include ::Cell::Haml
4+
include Matestack::Ui::Core::Cell
55
include Matestack::Ui::Core::ApplicationHelper
66
include Matestack::Ui::Core::ToCell
77

app/concepts/matestack/ui/core/component/dynamic.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
module Matestack::Ui::Core::Component
22
class Dynamic < Trailblazer::Cell
3-
4-
include ::Cell::Haml
3+
include Matestack::Ui::Core::Cell
54
include Matestack::Ui::Core::ApplicationHelper
65
include Matestack::Ui::Core::ToCell
76
include Matestack::Ui::Core::HasViewContext

app/concepts/matestack/ui/core/page/page.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module Matestack::Ui::Core::Page
22
class Page < Trailblazer::Cell
33

44
include ActionView::Helpers::TranslationHelper
5-
include ::Cell::Haml
5+
include Matestack::Ui::Core::Cell
66
include Matestack::Ui::Core::ApplicationHelper
77
include Matestack::Ui::Core::ToCell
88
include Matestack::Ui::Core::HasViewContext
@@ -94,7 +94,7 @@ def show(component_key=nil, only_page=false)
9494
begin
9595
render_child_component component_key
9696
rescue => e
97-
raise "Component '#{component_key}' could not be resolved."
97+
raise "Component '#{component_key}' could not be resolved, because of #{e},\n#{e.backtrace.join("\n")}"
9898
end
9999
end
100100
end

app/concepts/matestack/ui/core/plain/plain.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module Matestack::Ui::Core::Plain
22
class Plain < Matestack::Ui::Core::Component::Static
33

44
def show
5-
@argument
5+
html_escape @argument
66
end
77

88
end
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module Matestack::Ui::Core::Rawhtml
2+
class Rawhtml < Matestack::Ui::Core::Component::Static
3+
def show
4+
@argument
5+
end
6+
end
7+
end

docs/components/plain.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Show [specs](/spec/usage/components/plain_spec.rb)
44

5-
This element simply renders the value of a variable (or simple a string) wherever you want it.
5+
This element simply renders the value of a variable (or simple a string) wherever you want it **escaping HTML tags** (`<` becomes `&lt;` etc.).
66

77
## Parameters
88

docs/components/rawhtml.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# matestack core component: Rawhtml
2+
3+
Show [specs](/spec/usage/components/rawhtml_spec.rb)
4+
5+
This element simply renders the value of a variable (or simple a string) wherever you want it **without escaping HTML**.
6+
7+
Only use this if you are sure that you have full control over the input to this function/no malicious code can find its way inside.
8+
9+
## Parameters
10+
11+
This component expects one parameter.
12+
13+
## Example 1
14+
15+
Rendering some HTML.
16+
17+
```ruby
18+
19+
def response
20+
components {
21+
rawhtml <<~HTML
22+
<h1>Hello World</h1>
23+
<script>alert('Really Hello!')</script>
24+
HTML
25+
}
26+
end
27+
28+
```
29+
30+
returns
31+
32+
```html
33+
<h1>Hello World</h1>
34+
<script>alert('Really Hello!')</script>
35+
```

lib/matestack/ui/core.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
require 'cell/rails'
55
require 'cell/haml'
66

7+
require "matestack/ui/core/cell"
78
require "matestack/ui/core/engine"
89

910
module Matestack

lib/matestack/ui/core/cell.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
module Matestack
2+
module Ui
3+
module Core
4+
# Custom Cell options/handling based on a Cell from the cells gem.
5+
#
6+
# Needed to redefine some options and gives us more control over
7+
# the cells.
8+
module Cell
9+
include ::Cell::Haml
10+
11+
# based on https://github.com/trailblazer/cells-haml/blob/master/lib/cell/haml.rb
12+
# be aware that as of February 2020 this differs from the released version though.
13+
def template_options_for(_options)
14+
# Note, cells uses Hash#delete which mutates the hash,
15+
# hence we can't use a constant here as on the first
16+
# invocation it'd lose it's suffix key
17+
{
18+
template_class: ::Tilt::HamlTemplate,
19+
escape_html: true,
20+
escape_attrs: true,
21+
suffix: "haml"
22+
}
23+
end
24+
25+
def html_escape(string)
26+
ERB::Util.html_escape(string)
27+
end
28+
end
29+
end
30+
end
31+
end
32+
33+
# Matestack::Ui::Core::Cell = ::Cell::Haml

spec/spec_helper.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
require 'rspec/retry'
4242
require "rspec/wait"
4343

44-
4544
RSpec.configure do |config|
4645
# repeat flaky tests
4746
# show retry status in spec process

0 commit comments

Comments
 (0)