Skip to content

Commit f03051d

Browse files
committed
Implement Rawhtml component
Name is WIP as right now raw clashes with the raw of Rails, which would give us the desired result (which is nice) but might be a worse choice if there were some common options etc. we wanted to use or just well... consistency :)
1 parent aa9e194 commit f03051d

File tree

4 files changed

+68
-1
lines changed

4 files changed

+68
-1
lines changed
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+
```

spec/usage/components/rawhtml_spec.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
describe "Raw Html Component", type: :feature, js: true do
2+
3+
it "allows the insertion of pure HTML: Example 1" do
4+
5+
class ExamplePage < Matestack::Ui::Page
6+
def response
7+
components {
8+
rawhtml <<~HTML
9+
<h1>Hello World</h1>
10+
<script>alert('Really Hello!')</script>
11+
HTML
12+
}
13+
end
14+
end
15+
16+
accept_alert do
17+
visit "/example"
18+
end
19+
20+
static_output = page.html
21+
22+
expect(static_output).to include("<h1>Hello World</h1>")
23+
end
24+
25+
end

0 commit comments

Comments
 (0)