Skip to content

Commit 186db0c

Browse files
Merge pull request #231 from stiwwelll/noscript_tag
Add noscript tag
2 parents 7b13968 + 34c16da commit 186db0c

File tree

5 files changed

+92
-0
lines changed

5 files changed

+92
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
%noscript{@tag_attributes}
2+
- if options[:text].nil? && block_given?
3+
= yield
4+
- else
5+
= options[:text]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module Matestack::Ui::Core::Noscript
2+
class Noscript < Matestack::Ui::Core::Component::Static
3+
4+
end
5+
end

docs/components/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ You can build your [own components](/docs/extend/custom_components.md) as well,
3333
- [link](/docs/components/link.md)
3434
- [label](/docs/components/label.md)
3535
- [progress](/docs/components/progress.md)
36+
- [noscript](/docs/components/noscript.md)
3637

3738
## Dynamic Core Components
3839

docs/components/noscript.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# matestack core component: Noscript
2+
3+
Show [specs](/spec/usage/components/noscript_spec.rb)
4+
5+
The HTML noscript tag implemented in ruby.
6+
7+
## Parameters
8+
9+
This component can take 2 optional configuration params and either yield content or display what gets passed to the `text` configuration param.
10+
11+
#### # id (optional)
12+
Expects a string with all ids the noscript should have.
13+
14+
#### # class (optional)
15+
Expects a string with all classes the noscript should have.
16+
17+
## Example 1: Yield a given block
18+
19+
```ruby
20+
noscript id: "foo", class: "bar" do
21+
plain 'Hello World' # optional content
22+
end
23+
```
24+
25+
returns
26+
27+
```html
28+
<noscript id="foo" class="bar">
29+
Hello World
30+
</noscript>
31+
```
32+
33+
## Example 2: Render options[:text] param
34+
35+
```ruby
36+
noscript id: "foo", class: "bar", text: 'Hello World'
37+
```
38+
39+
returns
40+
41+
```html
42+
<noscript id="foo" class="bar">
43+
Hello World
44+
</noscript>
45+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
require_relative '../../support/utils'
2+
include Utils
3+
4+
describe 'Noscript 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+
# simple noscript
13+
noscript text: 'I am simple'
14+
15+
# enhanced noscript
16+
noscript id: 'my-id', class: 'my-class' do
17+
plain 'I am enhanced'
18+
end
19+
}
20+
end
21+
22+
end
23+
24+
visit '/example'
25+
26+
static_output = page.html
27+
28+
expected_static_output = <<~HTML
29+
<noscript>I am simple</noscript>
30+
<noscript id="my-id" class="my-class">I am enhanced</noscript>
31+
HTML
32+
33+
expect(stripped(static_output)).to include(stripped(expected_static_output))
34+
end
35+
36+
end

0 commit comments

Comments
 (0)