File tree Expand file tree Collapse file tree 4 files changed +68
-1
lines changed
app/concepts/matestack/ui/core/raw Expand file tree Collapse file tree 4 files changed +68
-1
lines changed Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change 2
2
3
3
Show [ specs] ( /spec/usage/components/plain_spec.rb )
4
4
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 ` < ` etc.) .
6
6
7
7
## Parameters
8
8
Original file line number Diff line number Diff line change
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
+ ```
Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments