File tree Expand file tree Collapse file tree 4 files changed +95
-0
lines changed
app/concepts/matestack/ui/core/code Expand file tree Collapse file tree 4 files changed +95
-0
lines changed Original file line number Diff line number Diff line change
1
+ %code {@tag_attributes}
2
+ - if options[:text].nil? && block_given?
3
+ = yield
4
+ - else
5
+ = options[:text]
Original file line number Diff line number Diff line change
1
+ module Matestack ::Ui ::Core ::Code
2
+ class Code < Matestack ::Ui ::Core ::Component ::Static
3
+
4
+ end
5
+ end
Original file line number Diff line number Diff line change
1
+ # matestack core component: Code
2
+
3
+ Show [ specs] ( /spec/usage/components/code_spec.rb )
4
+
5
+ The HTML ` <code> ` tag implemented in Ruby.
6
+
7
+ ## Parameters
8
+
9
+ This component can take 3 optional configuration params and optional content.
10
+
11
+ #### # id (optional)
12
+ Expects a string with all ids the ` <code> ` tag should have.
13
+
14
+ #### # class (optional)
15
+ Expects a string with all classes the ` <code> ` tag should have.
16
+
17
+ #### # text (optional)
18
+ Expects a string with the text that should go into the ` <code> ` tag.
19
+
20
+ ## Example 1
21
+ Rendering content into the ` code ` component
22
+
23
+ ``` ruby
24
+ code id: " foo" , class : " bar" do
25
+ plain ' puts "Hello Mate One"'
26
+ end
27
+ ```
28
+
29
+ returns
30
+
31
+ ``` html
32
+ <code id =" foo" class =" bar" >
33
+ puts "Hello Mate One"
34
+ </code >
35
+ ```
36
+
37
+ ## Example 2
38
+ Passing content to the ` text ` param
39
+
40
+ ``` ruby
41
+ code id: " foo" , class : " bar" , text: ' puts "Hello Mate Two"'
42
+ ```
43
+
44
+ returns
45
+
46
+ ``` html
47
+ <code id =" foo" class =" bar" >
48
+ puts "Hello Mate Two"
49
+ </code >
50
+ ```
Original file line number Diff line number Diff line change
1
+ require_relative '../../support/utils'
2
+ include Utils
3
+
4
+ describe 'Code Component' , type : :feature , js : true do
5
+
6
+ it 'Example 1' do
7
+
8
+ class ExamplePage < Matestack ::Ui ::Page
9
+
10
+ def response
11
+ components {
12
+ # example 1
13
+ code id : "foo" , class : "bar" do
14
+ plain 'puts "Hello Mate One"'
15
+ end
16
+ # example 2
17
+ code id : "foo" , class : "bar" , text : 'puts "Hello Mate Two"'
18
+ }
19
+ end
20
+
21
+ end
22
+
23
+ visit '/example'
24
+
25
+ static_output = page . html
26
+
27
+ expected_static_output = <<~HTML
28
+ < code id ="foo " class ="bar "> puts "Hello Mate One"</ code >
29
+ < code id ="foo " class ="bar "> puts "Hello Mate Two"</ code >
30
+ HTML
31
+
32
+ expect ( stripped ( static_output ) ) . to include ( stripped ( expected_static_output ) )
33
+ end
34
+
35
+ end
You can’t perform that action at this time.
0 commit comments