view_component 2.66.0 → 2.71.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -1
- data/app/assets/vendor/prism.css +3 -195
- data/app/assets/vendor/prism.min.js +11 -11
- data/app/controllers/concerns/view_component/preview_actions.rb +2 -2
- data/app/helpers/preview_helper.rb +1 -1
- data/app/views/view_components/preview.html.erb +2 -2
- data/docs/CHANGELOG.md +85 -0
- data/lib/rails/generators/abstract_generator.rb +2 -2
- data/lib/rails/generators/component/component_generator.rb +4 -4
- data/lib/rails/generators/locale/component_generator.rb +1 -1
- data/lib/rails/generators/preview/component_generator.rb +1 -1
- data/lib/view_component/base.rb +21 -2
- data/lib/view_component/engine.rb +1 -1
- data/lib/view_component/slotable_v2.rb +4 -3
- data/lib/view_component/test_helpers.rb +52 -4
- data/lib/view_component/version.rb +1 -1
- metadata +14 -15
- data/lib/view_component/render_preview_helper.rb +0 -46
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0fbced9eb4c36f970d2b46f99dfd3aca2043b619b807b89b27ae772596c3fe1d
|
|
4
|
+
data.tar.gz: 82ccdda90514c215f72b6e4d654db71b3ed42e55a52c8eebbd99742f047d0b4f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e874d63dd57bd39186244c95f351e975d8bb8e54f21c8619659b171084426c5c038ad52e710760fb0ef7301ed956c9eac99a3be5bc6f48fea0aa35f8c4459186
|
|
7
|
+
data.tar.gz: db9fef63203b0cde5f7a867c553ef776b8b485ac21b4e7911ec78d0a5e3e8d484545b715dfd41f71c31bdab0f155d605b11554be8b33c21373e94f76aa132907
|
data/LICENSE.txt
CHANGED
data/app/assets/vendor/prism.css
CHANGED
|
@@ -1,196 +1,4 @@
|
|
|
1
|
-
/* PrismJS 1.
|
|
1
|
+
/* PrismJS 1.28.0
|
|
2
2
|
https://prismjs.com/download.html#themes=prism-tomorrow&languages=markup+clike+erb+haml+markup-templating+ruby&plugins=line-highlight+highlight-keywords+normalize-whitespace */
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* Based on https://github.com/chriskempson/tomorrow-theme
|
|
6
|
-
* @author Rose Pritchard
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
code[class*="language-"],
|
|
10
|
-
pre[class*="language-"] {
|
|
11
|
-
color: #ccc;
|
|
12
|
-
background: none;
|
|
13
|
-
font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
|
|
14
|
-
font-size: 1em;
|
|
15
|
-
text-align: left;
|
|
16
|
-
white-space: pre;
|
|
17
|
-
word-spacing: normal;
|
|
18
|
-
word-break: normal;
|
|
19
|
-
word-wrap: normal;
|
|
20
|
-
line-height: 1.5;
|
|
21
|
-
|
|
22
|
-
-moz-tab-size: 4;
|
|
23
|
-
-o-tab-size: 4;
|
|
24
|
-
tab-size: 4;
|
|
25
|
-
|
|
26
|
-
-webkit-hyphens: none;
|
|
27
|
-
-moz-hyphens: none;
|
|
28
|
-
-ms-hyphens: none;
|
|
29
|
-
hyphens: none;
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/* Code blocks */
|
|
34
|
-
pre[class*="language-"] {
|
|
35
|
-
padding: 1em;
|
|
36
|
-
margin: .5em 0;
|
|
37
|
-
overflow: auto;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
:not(pre) > code[class*="language-"],
|
|
41
|
-
pre[class*="language-"] {
|
|
42
|
-
background: #2d2d2d;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/* Inline code */
|
|
46
|
-
:not(pre) > code[class*="language-"] {
|
|
47
|
-
padding: .1em;
|
|
48
|
-
border-radius: .3em;
|
|
49
|
-
white-space: normal;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
.token.comment,
|
|
53
|
-
.token.block-comment,
|
|
54
|
-
.token.prolog,
|
|
55
|
-
.token.doctype,
|
|
56
|
-
.token.cdata {
|
|
57
|
-
color: #999;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
.token.punctuation {
|
|
61
|
-
color: #ccc;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
.token.tag,
|
|
65
|
-
.token.attr-name,
|
|
66
|
-
.token.namespace,
|
|
67
|
-
.token.deleted {
|
|
68
|
-
color: #e2777a;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
.token.function-name {
|
|
72
|
-
color: #6196cc;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
.token.boolean,
|
|
76
|
-
.token.number,
|
|
77
|
-
.token.function {
|
|
78
|
-
color: #f08d49;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
.token.property,
|
|
82
|
-
.token.class-name,
|
|
83
|
-
.token.constant,
|
|
84
|
-
.token.symbol {
|
|
85
|
-
color: #f8c555;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
.token.selector,
|
|
89
|
-
.token.important,
|
|
90
|
-
.token.atrule,
|
|
91
|
-
.token.keyword,
|
|
92
|
-
.token.builtin {
|
|
93
|
-
color: #cc99cd;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
.token.string,
|
|
97
|
-
.token.char,
|
|
98
|
-
.token.attr-value,
|
|
99
|
-
.token.regex,
|
|
100
|
-
.token.variable {
|
|
101
|
-
color: #7ec699;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
.token.operator,
|
|
105
|
-
.token.entity,
|
|
106
|
-
.token.url {
|
|
107
|
-
color: #67cdcc;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
.token.important,
|
|
111
|
-
.token.bold {
|
|
112
|
-
font-weight: bold;
|
|
113
|
-
}
|
|
114
|
-
.token.italic {
|
|
115
|
-
font-style: italic;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
.token.entity {
|
|
119
|
-
cursor: help;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
.token.inserted {
|
|
123
|
-
color: green;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
pre[data-line] {
|
|
127
|
-
position: relative;
|
|
128
|
-
padding: 1em 0 1em 3em;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
.line-highlight {
|
|
132
|
-
position: absolute;
|
|
133
|
-
left: 0;
|
|
134
|
-
right: 0;
|
|
135
|
-
padding: inherit 0;
|
|
136
|
-
margin-top: 1em; /* Same as .prism’s padding-top */
|
|
137
|
-
|
|
138
|
-
background: hsla(24, 20%, 50%,.08);
|
|
139
|
-
background: linear-gradient(to right, hsla(24, 20%, 50%,.1) 70%, hsla(24, 20%, 50%,0));
|
|
140
|
-
|
|
141
|
-
pointer-events: none;
|
|
142
|
-
|
|
143
|
-
line-height: inherit;
|
|
144
|
-
white-space: pre;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
@media print {
|
|
148
|
-
.line-highlight {
|
|
149
|
-
/*
|
|
150
|
-
* This will prevent browsers from replacing the background color with white.
|
|
151
|
-
* It's necessary because the element is layered on top of the displayed code.
|
|
152
|
-
*/
|
|
153
|
-
-webkit-print-color-adjust: exact;
|
|
154
|
-
color-adjust: exact;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
.line-highlight:before,
|
|
159
|
-
.line-highlight[data-end]:after {
|
|
160
|
-
content: attr(data-start);
|
|
161
|
-
position: absolute;
|
|
162
|
-
top: .4em;
|
|
163
|
-
left: .6em;
|
|
164
|
-
min-width: 1em;
|
|
165
|
-
padding: 0 .5em;
|
|
166
|
-
background-color: hsla(24, 20%, 50%,.4);
|
|
167
|
-
color: hsl(24, 20%, 95%);
|
|
168
|
-
font: bold 65%/1.5 sans-serif;
|
|
169
|
-
text-align: center;
|
|
170
|
-
vertical-align: .3em;
|
|
171
|
-
border-radius: 999px;
|
|
172
|
-
text-shadow: none;
|
|
173
|
-
box-shadow: 0 1px white;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
.line-highlight[data-end]:after {
|
|
177
|
-
content: attr(data-end);
|
|
178
|
-
top: auto;
|
|
179
|
-
bottom: .4em;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
.line-numbers .line-highlight:before,
|
|
183
|
-
.line-numbers .line-highlight:after {
|
|
184
|
-
content: none;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
pre[id].linkable-line-numbers span.line-numbers-rows {
|
|
188
|
-
pointer-events: all;
|
|
189
|
-
}
|
|
190
|
-
pre[id].linkable-line-numbers span.line-numbers-rows > span:before {
|
|
191
|
-
cursor: pointer;
|
|
192
|
-
}
|
|
193
|
-
pre[id].linkable-line-numbers span.line-numbers-rows > span:hover:before {
|
|
194
|
-
background-color: rgba(128, 128, 128, .2);
|
|
195
|
-
}
|
|
196
|
-
|
|
3
|
+
code[class*=language-],pre[class*=language-]{color:#ccc;background:0 0;font-family:Consolas,Monaco,'Andale Mono','Ubuntu Mono',monospace;font-size:1em;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none}pre[class*=language-]{padding:1em;margin:.5em 0;overflow:auto}:not(pre)>code[class*=language-],pre[class*=language-]{background:#2d2d2d}:not(pre)>code[class*=language-]{padding:.1em;border-radius:.3em;white-space:normal}.token.block-comment,.token.cdata,.token.comment,.token.doctype,.token.prolog{color:#999}.token.punctuation{color:#ccc}.token.attr-name,.token.deleted,.token.namespace,.token.tag{color:#e2777a}.token.function-name{color:#6196cc}.token.boolean,.token.function,.token.number{color:#f08d49}.token.class-name,.token.constant,.token.property,.token.symbol{color:#f8c555}.token.atrule,.token.builtin,.token.important,.token.keyword,.token.selector{color:#cc99cd}.token.attr-value,.token.char,.token.regex,.token.string,.token.variable{color:#7ec699}.token.entity,.token.operator,.token.url{color:#67cdcc}.token.bold,.token.important{font-weight:700}.token.italic{font-style:italic}.token.entity{cursor:help}.token.inserted{color:green}
|
|
4
|
+
pre[data-line]{position:relative;padding:1em 0 1em 3em}.line-highlight{position:absolute;left:0;right:0;padding:inherit 0;margin-top:1em;background:hsla(24,20%,50%,.08);background:linear-gradient(to right,hsla(24,20%,50%,.1) 70%,hsla(24,20%,50%,0));pointer-events:none;line-height:inherit;white-space:pre}@media print{.line-highlight{-webkit-print-color-adjust:exact;color-adjust:exact}}.line-highlight:before,.line-highlight[data-end]:after{content:attr(data-start);position:absolute;top:.4em;left:.6em;min-width:1em;padding:0 .5em;background-color:hsla(24,20%,50%,.4);color:#f4f1ef;font:bold 65%/1.5 sans-serif;text-align:center;vertical-align:.3em;border-radius:999px;text-shadow:none;box-shadow:0 1px #fff}.line-highlight[data-end]:after{content:attr(data-end);top:auto;bottom:.4em}.line-numbers .line-highlight:after,.line-numbers .line-highlight:before{content:none}pre[id].linkable-line-numbers span.line-numbers-rows{pointer-events:all}pre[id].linkable-line-numbers span.line-numbers-rows>span:before{cursor:pointer}pre[id].linkable-line-numbers span.line-numbers-rows>span:hover:before{background-color:rgba(128,128,128,.2)}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
/* PrismJS 1.
|
|
1
|
+
/* PrismJS 1.28.0
|
|
2
2
|
https://prismjs.com/download.html#themes=prism-tomorrow&languages=markup+clike+erb+haml+markup-templating+ruby&plugins=line-highlight+highlight-keywords+normalize-whitespace */
|
|
3
|
-
var _self="undefined"!=typeof window?window:"undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope?self:{},Prism=function(
|
|
4
|
-
Prism.languages.markup={comment:/<!--[\s\S]*?-->/,prolog:/<\?[\s\S]+?\?>/,doctype:{pattern:/<!DOCTYPE(?:[^>"'[\]]|"[^"]*"|'[^']*')+(?:\[(?:[^<"'\]]|"[^"]*"|'[^']*'|<(?!!--)|<!--(?:[^-]|-(?!->))*-->)*\]\s*)?>/i,greedy:!0,inside:{"internal-subset":{pattern:/(
|
|
5
|
-
Prism.languages.clike={comment:[{pattern:/(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/,lookbehind:!0,greedy:!0},{pattern:/(^|[^\\:])\/\/.*/,lookbehind:!0,greedy:!0}],string:{pattern:/(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,greedy:!0},"class-name":{pattern:/(\b(?:class|
|
|
6
|
-
!function(e){e.languages.ruby=e.languages.extend("clike",{comment:
|
|
7
|
-
!function(
|
|
8
|
-
!function(
|
|
9
|
-
!function(
|
|
10
|
-
!function(){if("undefined"!=typeof Prism&&"undefined"!=typeof document&&document.querySelector){var t
|
|
11
|
-
"undefined"!=typeof Prism&&Prism.hooks.add("wrap",function(e){"keyword"===e.type&&e.classes.push("keyword-"+e.content)});
|
|
12
|
-
!function(){if("undefined"!=typeof Prism
|
|
3
|
+
var _self="undefined"!=typeof window?window:"undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope?self:{},Prism=function(e){var n=/(?:^|\s)lang(?:uage)?-([\w-]+)(?=\s|$)/i,t=0,r={},a={manual:e.Prism&&e.Prism.manual,disableWorkerMessageHandler:e.Prism&&e.Prism.disableWorkerMessageHandler,util:{encode:function e(n){return n instanceof i?new i(n.type,e(n.content),n.alias):Array.isArray(n)?n.map(e):n.replace(/&/g,"&").replace(/</g,"<").replace(/\u00a0/g," ")},type:function(e){return Object.prototype.toString.call(e).slice(8,-1)},objId:function(e){return e.__id||Object.defineProperty(e,"__id",{value:++t}),e.__id},clone:function e(n,t){var r,i;switch(t=t||{},a.util.type(n)){case"Object":if(i=a.util.objId(n),t[i])return t[i];for(var l in r={},t[i]=r,n)n.hasOwnProperty(l)&&(r[l]=e(n[l],t));return r;case"Array":return i=a.util.objId(n),t[i]?t[i]:(r=[],t[i]=r,n.forEach((function(n,a){r[a]=e(n,t)})),r);default:return n}},getLanguage:function(e){for(;e;){var t=n.exec(e.className);if(t)return t[1].toLowerCase();e=e.parentElement}return"none"},setLanguage:function(e,t){e.className=e.className.replace(RegExp(n,"gi"),""),e.classList.add("language-"+t)},currentScript:function(){if("undefined"==typeof document)return null;if("currentScript"in document)return document.currentScript;try{throw new Error}catch(r){var e=(/at [^(\r\n]*\((.*):[^:]+:[^:]+\)$/i.exec(r.stack)||[])[1];if(e){var n=document.getElementsByTagName("script");for(var t in n)if(n[t].src==e)return n[t]}return null}},isActive:function(e,n,t){for(var r="no-"+n;e;){var a=e.classList;if(a.contains(n))return!0;if(a.contains(r))return!1;e=e.parentElement}return!!t}},languages:{plain:r,plaintext:r,text:r,txt:r,extend:function(e,n){var t=a.util.clone(a.languages[e]);for(var r in n)t[r]=n[r];return t},insertBefore:function(e,n,t,r){var i=(r=r||a.languages)[e],l={};for(var o in i)if(i.hasOwnProperty(o)){if(o==n)for(var s in t)t.hasOwnProperty(s)&&(l[s]=t[s]);t.hasOwnProperty(o)||(l[o]=i[o])}var u=r[e];return r[e]=l,a.languages.DFS(a.languages,(function(n,t){t===u&&n!=e&&(this[n]=l)})),l},DFS:function e(n,t,r,i){i=i||{};var l=a.util.objId;for(var o in n)if(n.hasOwnProperty(o)){t.call(n,o,n[o],r||o);var s=n[o],u=a.util.type(s);"Object"!==u||i[l(s)]?"Array"!==u||i[l(s)]||(i[l(s)]=!0,e(s,t,o,i)):(i[l(s)]=!0,e(s,t,null,i))}}},plugins:{},highlightAll:function(e,n){a.highlightAllUnder(document,e,n)},highlightAllUnder:function(e,n,t){var r={callback:t,container:e,selector:'code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code'};a.hooks.run("before-highlightall",r),r.elements=Array.prototype.slice.apply(r.container.querySelectorAll(r.selector)),a.hooks.run("before-all-elements-highlight",r);for(var i,l=0;i=r.elements[l++];)a.highlightElement(i,!0===n,r.callback)},highlightElement:function(n,t,r){var i=a.util.getLanguage(n),l=a.languages[i];a.util.setLanguage(n,i);var o=n.parentElement;o&&"pre"===o.nodeName.toLowerCase()&&a.util.setLanguage(o,i);var s={element:n,language:i,grammar:l,code:n.textContent};function u(e){s.highlightedCode=e,a.hooks.run("before-insert",s),s.element.innerHTML=s.highlightedCode,a.hooks.run("after-highlight",s),a.hooks.run("complete",s),r&&r.call(s.element)}if(a.hooks.run("before-sanity-check",s),(o=s.element.parentElement)&&"pre"===o.nodeName.toLowerCase()&&!o.hasAttribute("tabindex")&&o.setAttribute("tabindex","0"),!s.code)return a.hooks.run("complete",s),void(r&&r.call(s.element));if(a.hooks.run("before-highlight",s),s.grammar)if(t&&e.Worker){var c=new Worker(a.filename);c.onmessage=function(e){u(e.data)},c.postMessage(JSON.stringify({language:s.language,code:s.code,immediateClose:!0}))}else u(a.highlight(s.code,s.grammar,s.language));else u(a.util.encode(s.code))},highlight:function(e,n,t){var r={code:e,grammar:n,language:t};if(a.hooks.run("before-tokenize",r),!r.grammar)throw new Error('The language "'+r.language+'" has no grammar.');return r.tokens=a.tokenize(r.code,r.grammar),a.hooks.run("after-tokenize",r),i.stringify(a.util.encode(r.tokens),r.language)},tokenize:function(e,n){var t=n.rest;if(t){for(var r in t)n[r]=t[r];delete n.rest}var a=new s;return u(a,a.head,e),o(e,a,n,a.head,0),function(e){for(var n=[],t=e.head.next;t!==e.tail;)n.push(t.value),t=t.next;return n}(a)},hooks:{all:{},add:function(e,n){var t=a.hooks.all;t[e]=t[e]||[],t[e].push(n)},run:function(e,n){var t=a.hooks.all[e];if(t&&t.length)for(var r,i=0;r=t[i++];)r(n)}},Token:i};function i(e,n,t,r){this.type=e,this.content=n,this.alias=t,this.length=0|(r||"").length}function l(e,n,t,r){e.lastIndex=n;var a=e.exec(t);if(a&&r&&a[1]){var i=a[1].length;a.index+=i,a[0]=a[0].slice(i)}return a}function o(e,n,t,r,s,g){for(var f in t)if(t.hasOwnProperty(f)&&t[f]){var h=t[f];h=Array.isArray(h)?h:[h];for(var d=0;d<h.length;++d){if(g&&g.cause==f+","+d)return;var v=h[d],p=v.inside,m=!!v.lookbehind,y=!!v.greedy,k=v.alias;if(y&&!v.pattern.global){var x=v.pattern.toString().match(/[imsuy]*$/)[0];v.pattern=RegExp(v.pattern.source,x+"g")}for(var b=v.pattern||v,w=r.next,A=s;w!==n.tail&&!(g&&A>=g.reach);A+=w.value.length,w=w.next){var E=w.value;if(n.length>e.length)return;if(!(E instanceof i)){var P,L=1;if(y){if(!(P=l(b,A,e,m))||P.index>=e.length)break;var S=P.index,O=P.index+P[0].length,j=A;for(j+=w.value.length;S>=j;)j+=(w=w.next).value.length;if(A=j-=w.value.length,w.value instanceof i)continue;for(var C=w;C!==n.tail&&(j<O||"string"==typeof C.value);C=C.next)L++,j+=C.value.length;L--,E=e.slice(A,j),P.index-=A}else if(!(P=l(b,0,E,m)))continue;S=P.index;var N=P[0],_=E.slice(0,S),M=E.slice(S+N.length),W=A+E.length;g&&W>g.reach&&(g.reach=W);var z=w.prev;if(_&&(z=u(n,z,_),A+=_.length),c(n,z,L),w=u(n,z,new i(f,p?a.tokenize(N,p):N,k,N)),M&&u(n,w,M),L>1){var I={cause:f+","+d,reach:W};o(e,n,t,w.prev,A,I),g&&I.reach>g.reach&&(g.reach=I.reach)}}}}}}function s(){var e={value:null,prev:null,next:null},n={value:null,prev:e,next:null};e.next=n,this.head=e,this.tail=n,this.length=0}function u(e,n,t){var r=n.next,a={value:t,prev:n,next:r};return n.next=a,r.prev=a,e.length++,a}function c(e,n,t){for(var r=n.next,a=0;a<t&&r!==e.tail;a++)r=r.next;n.next=r,r.prev=n,e.length-=a}if(e.Prism=a,i.stringify=function e(n,t){if("string"==typeof n)return n;if(Array.isArray(n)){var r="";return n.forEach((function(n){r+=e(n,t)})),r}var i={type:n.type,content:e(n.content,t),tag:"span",classes:["token",n.type],attributes:{},language:t},l=n.alias;l&&(Array.isArray(l)?Array.prototype.push.apply(i.classes,l):i.classes.push(l)),a.hooks.run("wrap",i);var o="";for(var s in i.attributes)o+=" "+s+'="'+(i.attributes[s]||"").replace(/"/g,""")+'"';return"<"+i.tag+' class="'+i.classes.join(" ")+'"'+o+">"+i.content+"</"+i.tag+">"},!e.document)return e.addEventListener?(a.disableWorkerMessageHandler||e.addEventListener("message",(function(n){var t=JSON.parse(n.data),r=t.language,i=t.code,l=t.immediateClose;e.postMessage(a.highlight(i,a.languages[r],r)),l&&e.close()}),!1),a):a;var g=a.util.currentScript();function f(){a.manual||a.highlightAll()}if(g&&(a.filename=g.src,g.hasAttribute("data-manual")&&(a.manual=!0)),!a.manual){var h=document.readyState;"loading"===h||"interactive"===h&&g&&g.defer?document.addEventListener("DOMContentLoaded",f):window.requestAnimationFrame?window.requestAnimationFrame(f):window.setTimeout(f,16)}return a}(_self);"undefined"!=typeof module&&module.exports&&(module.exports=Prism),"undefined"!=typeof global&&(global.Prism=Prism);
|
|
4
|
+
Prism.languages.markup={comment:{pattern:/<!--(?:(?!<!--)[\s\S])*?-->/,greedy:!0},prolog:{pattern:/<\?[\s\S]+?\?>/,greedy:!0},doctype:{pattern:/<!DOCTYPE(?:[^>"'[\]]|"[^"]*"|'[^']*')+(?:\[(?:[^<"'\]]|"[^"]*"|'[^']*'|<(?!!--)|<!--(?:[^-]|-(?!->))*-->)*\]\s*)?>/i,greedy:!0,inside:{"internal-subset":{pattern:/(^[^\[]*\[)[\s\S]+(?=\]>$)/,lookbehind:!0,greedy:!0,inside:null},string:{pattern:/"[^"]*"|'[^']*'/,greedy:!0},punctuation:/^<!|>$|[[\]]/,"doctype-tag":/^DOCTYPE/i,name:/[^\s<>'"]+/}},cdata:{pattern:/<!\[CDATA\[[\s\S]*?\]\]>/i,greedy:!0},tag:{pattern:/<\/?(?!\d)[^\s>\/=$<%]+(?:\s(?:\s*[^\s>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))|(?=[\s/>])))+)?\s*\/?>/,greedy:!0,inside:{tag:{pattern:/^<\/?[^\s>\/]+/,inside:{punctuation:/^<\/?/,namespace:/^[^\s>\/:]+:/}},"special-attr":[],"attr-value":{pattern:/=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+)/,inside:{punctuation:[{pattern:/^=/,alias:"attr-equals"},{pattern:/^(\s*)["']|["']$/,lookbehind:!0}]}},punctuation:/\/?>/,"attr-name":{pattern:/[^\s>\/]+/,inside:{namespace:/^[^\s>\/:]+:/}}}},entity:[{pattern:/&[\da-z]{1,8};/i,alias:"named-entity"},/&#x?[\da-f]{1,8};/i]},Prism.languages.markup.tag.inside["attr-value"].inside.entity=Prism.languages.markup.entity,Prism.languages.markup.doctype.inside["internal-subset"].inside=Prism.languages.markup,Prism.hooks.add("wrap",(function(a){"entity"===a.type&&(a.attributes.title=a.content.replace(/&/,"&"))})),Object.defineProperty(Prism.languages.markup.tag,"addInlined",{value:function(a,e){var s={};s["language-"+e]={pattern:/(^<!\[CDATA\[)[\s\S]+?(?=\]\]>$)/i,lookbehind:!0,inside:Prism.languages[e]},s.cdata=/^<!\[CDATA\[|\]\]>$/i;var t={"included-cdata":{pattern:/<!\[CDATA\[[\s\S]*?\]\]>/i,inside:s}};t["language-"+e]={pattern:/[\s\S]+/,inside:Prism.languages[e]};var n={};n[a]={pattern:RegExp("(<__[^>]*>)(?:<!\\[CDATA\\[(?:[^\\]]|\\](?!\\]>))*\\]\\]>|(?!<!\\[CDATA\\[)[^])*?(?=</__>)".replace(/__/g,(function(){return a})),"i"),lookbehind:!0,greedy:!0,inside:t},Prism.languages.insertBefore("markup","cdata",n)}}),Object.defineProperty(Prism.languages.markup.tag,"addAttribute",{value:function(a,e){Prism.languages.markup.tag.inside["special-attr"].push({pattern:RegExp("(^|[\"'\\s])(?:"+a+")\\s*=\\s*(?:\"[^\"]*\"|'[^']*'|[^\\s'\">=]+(?=[\\s>]))","i"),lookbehind:!0,inside:{"attr-name":/^[^\s=]+/,"attr-value":{pattern:/=[\s\S]+/,inside:{value:{pattern:/(^=\s*(["']|(?!["'])))\S[\s\S]*(?=\2$)/,lookbehind:!0,alias:[e,"language-"+e],inside:Prism.languages[e]},punctuation:[{pattern:/^=/,alias:"attr-equals"},/"|'/]}}}})}}),Prism.languages.html=Prism.languages.markup,Prism.languages.mathml=Prism.languages.markup,Prism.languages.svg=Prism.languages.markup,Prism.languages.xml=Prism.languages.extend("markup",{}),Prism.languages.ssml=Prism.languages.xml,Prism.languages.atom=Prism.languages.xml,Prism.languages.rss=Prism.languages.xml;
|
|
5
|
+
Prism.languages.clike={comment:[{pattern:/(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/,lookbehind:!0,greedy:!0},{pattern:/(^|[^\\:])\/\/.*/,lookbehind:!0,greedy:!0}],string:{pattern:/(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,greedy:!0},"class-name":{pattern:/(\b(?:class|extends|implements|instanceof|interface|new|trait)\s+|\bcatch\s+\()[\w.\\]+/i,lookbehind:!0,inside:{punctuation:/[.\\]/}},keyword:/\b(?:break|catch|continue|do|else|finally|for|function|if|in|instanceof|new|null|return|throw|try|while)\b/,boolean:/\b(?:false|true)\b/,function:/\b\w+(?=\()/,number:/\b0x[\da-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?/i,operator:/[<>]=?|[!=]=?=?|--?|\+\+?|&&?|\|\|?|[?*/~^%]/,punctuation:/[{}[\];(),.:]/};
|
|
6
|
+
!function(e){e.languages.ruby=e.languages.extend("clike",{comment:{pattern:/#.*|^=begin\s[\s\S]*?^=end/m,greedy:!0},"class-name":{pattern:/(\b(?:class|module)\s+|\bcatch\s+\()[\w.\\]+|\b[A-Z_]\w*(?=\s*\.\s*new\b)/,lookbehind:!0,inside:{punctuation:/[.\\]/}},keyword:/\b(?:BEGIN|END|alias|and|begin|break|case|class|def|define_method|defined|do|each|else|elsif|end|ensure|extend|for|if|in|include|module|new|next|nil|not|or|prepend|private|protected|public|raise|redo|require|rescue|retry|return|self|super|then|throw|undef|unless|until|when|while|yield)\b/,operator:/\.{2,3}|&\.|===|<?=>|[!=]?~|(?:&&|\|\||<<|>>|\*\*|[+\-*/%<>!^&|=])=?|[?:]/,punctuation:/[(){}[\].,;]/}),e.languages.insertBefore("ruby","operator",{"double-colon":{pattern:/::/,alias:"punctuation"}});var n={pattern:/((?:^|[^\\])(?:\\{2})*)#\{(?:[^{}]|\{[^{}]*\})*\}/,lookbehind:!0,inside:{content:{pattern:/^(#\{)[\s\S]+(?=\}$)/,lookbehind:!0,inside:e.languages.ruby},delimiter:{pattern:/^#\{|\}$/,alias:"punctuation"}}};delete e.languages.ruby.function;var t="(?:"+["([^a-zA-Z0-9\\s{(\\[<=])(?:(?!\\1)[^\\\\]|\\\\[^])*\\1","\\((?:[^()\\\\]|\\\\[^]|\\((?:[^()\\\\]|\\\\[^])*\\))*\\)","\\{(?:[^{}\\\\]|\\\\[^]|\\{(?:[^{}\\\\]|\\\\[^])*\\})*\\}","\\[(?:[^\\[\\]\\\\]|\\\\[^]|\\[(?:[^\\[\\]\\\\]|\\\\[^])*\\])*\\]","<(?:[^<>\\\\]|\\\\[^]|<(?:[^<>\\\\]|\\\\[^])*>)*>"].join("|")+")",i='(?:"(?:\\\\.|[^"\\\\\r\n])*"|(?:\\b[a-zA-Z_]\\w*|[^\\s\0-\\x7F]+)[?!]?|\\$.)';e.languages.insertBefore("ruby","keyword",{"regex-literal":[{pattern:RegExp("%r"+t+"[egimnosux]{0,6}"),greedy:!0,inside:{interpolation:n,regex:/[\s\S]+/}},{pattern:/(^|[^/])\/(?!\/)(?:\[[^\r\n\]]+\]|\\.|[^[/\\\r\n])+\/[egimnosux]{0,6}(?=\s*(?:$|[\r\n,.;})#]))/,lookbehind:!0,greedy:!0,inside:{interpolation:n,regex:/[\s\S]+/}}],variable:/[@$]+[a-zA-Z_]\w*(?:[?!]|\b)/,symbol:[{pattern:RegExp("(^|[^:]):"+i),lookbehind:!0,greedy:!0},{pattern:RegExp("([\r\n{(,][ \t]*)"+i+"(?=:(?!:))"),lookbehind:!0,greedy:!0}],"method-definition":{pattern:/(\bdef\s+)\w+(?:\s*\.\s*\w+)?/,lookbehind:!0,inside:{function:/\b\w+$/,keyword:/^self\b/,"class-name":/^\w+/,punctuation:/\./}}}),e.languages.insertBefore("ruby","string",{"string-literal":[{pattern:RegExp("%[qQiIwWs]?"+t),greedy:!0,inside:{interpolation:n,string:/[\s\S]+/}},{pattern:/("|')(?:#\{[^}]+\}|#(?!\{)|\\(?:\r\n|[\s\S])|(?!\1)[^\\#\r\n])*\1/,greedy:!0,inside:{interpolation:n,string:/[\s\S]+/}},{pattern:/<<[-~]?([a-z_]\w*)[\r\n](?:.*[\r\n])*?[\t ]*\1/i,alias:"heredoc-string",greedy:!0,inside:{delimiter:{pattern:/^<<[-~]?[a-z_]\w*|\b[a-z_]\w*$/i,inside:{symbol:/\b\w+/,punctuation:/^<<[-~]?/}},interpolation:n,string:/[\s\S]+/}},{pattern:/<<[-~]?'([a-z_]\w*)'[\r\n](?:.*[\r\n])*?[\t ]*\1/i,alias:"heredoc-string",greedy:!0,inside:{delimiter:{pattern:/^<<[-~]?'[a-z_]\w*'|\b[a-z_]\w*$/i,inside:{symbol:/\b\w+/,punctuation:/^<<[-~]?'|'$/}},string:/[\s\S]+/}}],"command-literal":[{pattern:RegExp("%x"+t),greedy:!0,inside:{interpolation:n,command:{pattern:/[\s\S]+/,alias:"string"}}},{pattern:/`(?:#\{[^}]+\}|#(?!\{)|\\(?:\r\n|[\s\S])|[^\\`#\r\n])*`/,greedy:!0,inside:{interpolation:n,command:{pattern:/[\s\S]+/,alias:"string"}}}]}),delete e.languages.ruby.string,e.languages.insertBefore("ruby","number",{builtin:/\b(?:Array|Bignum|Binding|Class|Continuation|Dir|Exception|FalseClass|File|Fixnum|Float|Hash|IO|Integer|MatchData|Method|Module|NilClass|Numeric|Object|Proc|Range|Regexp|Stat|String|Struct|Symbol|TMS|Thread|ThreadGroup|Time|TrueClass)\b/,constant:/\b[A-Z][A-Z0-9_]*(?:[?!]|\b)/}),e.languages.rb=e.languages.ruby}(Prism);
|
|
7
|
+
!function(e){function n(e,n){return"___"+e.toUpperCase()+n+"___"}Object.defineProperties(e.languages["markup-templating"]={},{buildPlaceholders:{value:function(t,a,r,o){if(t.language===a){var c=t.tokenStack=[];t.code=t.code.replace(r,(function(e){if("function"==typeof o&&!o(e))return e;for(var r,i=c.length;-1!==t.code.indexOf(r=n(a,i));)++i;return c[i]=e,r})),t.grammar=e.languages.markup}}},tokenizePlaceholders:{value:function(t,a){if(t.language===a&&t.tokenStack){t.grammar=e.languages[a];var r=0,o=Object.keys(t.tokenStack);!function c(i){for(var u=0;u<i.length&&!(r>=o.length);u++){var g=i[u];if("string"==typeof g||g.content&&"string"==typeof g.content){var l=o[r],s=t.tokenStack[l],f="string"==typeof g?g:g.content,p=n(a,l),k=f.indexOf(p);if(k>-1){++r;var m=f.substring(0,k),d=new e.Token(a,e.tokenize(s,t.grammar),"language-"+a,s),h=f.substring(k+p.length),v=[];m&&v.push.apply(v,c([m])),v.push(d),h&&v.push.apply(v,c([h])),"string"==typeof g?i.splice.apply(i,[u,1].concat(v)):g.content=v}}else g.content&&c(g.content)}return i}(t.tokens)}}}})}(Prism);
|
|
8
|
+
!function(e){e.languages.erb={delimiter:{pattern:/^(\s*)<%=?|%>(?=\s*$)/,lookbehind:!0,alias:"punctuation"},ruby:{pattern:/\s*\S[\s\S]*/,alias:"language-ruby",inside:e.languages.ruby}},e.hooks.add("before-tokenize",(function(n){e.languages["markup-templating"].buildPlaceholders(n,"erb",/<%=?(?:[^\r\n]|[\r\n](?!=begin)|[\r\n]=begin\s(?:[^\r\n]|[\r\n](?!=end))*[\r\n]=end)+?%>/g)})),e.hooks.add("after-tokenize",(function(n){e.languages["markup-templating"].tokenizePlaceholders(n,"erb")}))}(Prism);
|
|
9
|
+
!function(n){n.languages.haml={"multiline-comment":{pattern:/((?:^|\r?\n|\r)([\t ]*))(?:\/|-#).*(?:(?:\r?\n|\r)\2[\t ].+)*/,lookbehind:!0,alias:"comment"},"multiline-code":[{pattern:/((?:^|\r?\n|\r)([\t ]*)(?:[~-]|[&!]?=)).*,[\t ]*(?:(?:\r?\n|\r)\2[\t ].*,[\t ]*)*(?:(?:\r?\n|\r)\2[\t ].+)/,lookbehind:!0,inside:n.languages.ruby},{pattern:/((?:^|\r?\n|\r)([\t ]*)(?:[~-]|[&!]?=)).*\|[\t ]*(?:(?:\r?\n|\r)\2[\t ].*\|[\t ]*)*/,lookbehind:!0,inside:n.languages.ruby}],filter:{pattern:/((?:^|\r?\n|\r)([\t ]*)):[\w-]+(?:(?:\r?\n|\r)(?:\2[\t ].+|\s*?(?=\r?\n|\r)))+/,lookbehind:!0,inside:{"filter-name":{pattern:/^:[\w-]+/,alias:"symbol"}}},markup:{pattern:/((?:^|\r?\n|\r)[\t ]*)<.+/,lookbehind:!0,inside:n.languages.markup},doctype:{pattern:/((?:^|\r?\n|\r)[\t ]*)!!!(?: .+)?/,lookbehind:!0},tag:{pattern:/((?:^|\r?\n|\r)[\t ]*)[%.#][\w\-#.]*[\w\-](?:\([^)]+\)|\{(?:\{[^}]+\}|[^{}])+\}|\[[^\]]+\])*[\/<>]*/,lookbehind:!0,inside:{attributes:[{pattern:/(^|[^#])\{(?:\{[^}]+\}|[^{}])+\}/,lookbehind:!0,inside:n.languages.ruby},{pattern:/\([^)]+\)/,inside:{"attr-value":{pattern:/(=\s*)(?:"(?:\\.|[^\\"\r\n])*"|[^)\s]+)/,lookbehind:!0},"attr-name":/[\w:-]+(?=\s*!?=|\s*[,)])/,punctuation:/[=(),]/}},{pattern:/\[[^\]]+\]/,inside:n.languages.ruby}],punctuation:/[<>]/}},code:{pattern:/((?:^|\r?\n|\r)[\t ]*(?:[~-]|[&!]?=)).+/,lookbehind:!0,inside:n.languages.ruby},interpolation:{pattern:/#\{[^}]+\}/,inside:{delimiter:{pattern:/^#\{|\}$/,alias:"punctuation"},ruby:{pattern:/[\s\S]+/,inside:n.languages.ruby}}},punctuation:{pattern:/((?:^|\r?\n|\r)[\t ]*)[~=\-&!]+/,lookbehind:!0}};for(var e=["css",{filter:"coffee",language:"coffeescript"},"erb","javascript","less","markdown","ruby","scss","textile"],t={},r=0,a=e.length;r<a;r++){var i=e[r];i="string"==typeof i?{filter:i,language:i}:i,n.languages[i.language]&&(t["filter-"+i.filter]={pattern:RegExp("((?:^|\\r?\\n|\\r)([\\t ]*)):{{filter_name}}(?:(?:\\r?\\n|\\r)(?:\\2[\\t ].+|\\s*?(?=\\r?\\n|\\r)))+".replace("{{filter_name}}",(function(){return i.filter}))),lookbehind:!0,inside:{"filter-name":{pattern:/^:[\w-]+/,alias:"symbol"},text:{pattern:/[\s\S]+/,alias:[i.language,"language-"+i.language],inside:n.languages[i.language]}}})}n.languages.insertBefore("haml","filter",t)}(Prism);
|
|
10
|
+
!function(){if("undefined"!=typeof Prism&&"undefined"!=typeof document&&document.querySelector){var e,t="line-numbers",i="linkable-line-numbers",n=/\n(?!$)/g,r=!0;Prism.plugins.lineHighlight={highlightLines:function(o,u,c){var h=(u="string"==typeof u?u:o.getAttribute("data-line")||"").replace(/\s+/g,"").split(",").filter(Boolean),d=+o.getAttribute("data-line-offset")||0,f=(function(){if(void 0===e){var t=document.createElement("div");t.style.fontSize="13px",t.style.lineHeight="1.5",t.style.padding="0",t.style.border="0",t.innerHTML=" <br /> ",document.body.appendChild(t),e=38===t.offsetHeight,document.body.removeChild(t)}return e}()?parseInt:parseFloat)(getComputedStyle(o).lineHeight),p=Prism.util.isActive(o,t),g=o.querySelector("code"),m=p?o:g||o,v=[],y=g.textContent.match(n),b=y?y.length+1:1,A=g&&m!=g?function(e,t){var i=getComputedStyle(e),n=getComputedStyle(t);function r(e){return+e.substr(0,e.length-2)}return t.offsetTop+r(n.borderTopWidth)+r(n.paddingTop)-r(i.paddingTop)}(o,g):0;h.forEach((function(e){var t=e.split("-"),i=+t[0],n=+t[1]||i;if(!((n=Math.min(b,n))<i)){var r=o.querySelector('.line-highlight[data-range="'+e+'"]')||document.createElement("div");if(v.push((function(){r.setAttribute("aria-hidden","true"),r.setAttribute("data-range",e),r.className=(c||"")+" line-highlight"})),p&&Prism.plugins.lineNumbers){var s=Prism.plugins.lineNumbers.getLine(o,i),l=Prism.plugins.lineNumbers.getLine(o,n);if(s){var a=s.offsetTop+A+"px";v.push((function(){r.style.top=a}))}if(l){var u=l.offsetTop-s.offsetTop+l.offsetHeight+"px";v.push((function(){r.style.height=u}))}}else v.push((function(){r.setAttribute("data-start",String(i)),n>i&&r.setAttribute("data-end",String(n)),r.style.top=(i-d-1)*f+A+"px",r.textContent=new Array(n-i+2).join(" \n")}));v.push((function(){r.style.width=o.scrollWidth+"px"})),v.push((function(){m.appendChild(r)}))}}));var P=o.id;if(p&&Prism.util.isActive(o,i)&&P){l(o,i)||v.push((function(){o.classList.add(i)}));var E=parseInt(o.getAttribute("data-start")||"1");s(".line-numbers-rows > span",o).forEach((function(e,t){var i=t+E;e.onclick=function(){var e=P+"."+i;r=!1,location.hash=e,setTimeout((function(){r=!0}),1)}}))}return function(){v.forEach(a)}}};var o=0;Prism.hooks.add("before-sanity-check",(function(e){var t=e.element.parentElement;if(u(t)){var i=0;s(".line-highlight",t).forEach((function(e){i+=e.textContent.length,e.parentNode.removeChild(e)})),i&&/^(?: \n)+$/.test(e.code.slice(-i))&&(e.code=e.code.slice(0,-i))}})),Prism.hooks.add("complete",(function e(i){var n=i.element.parentElement;if(u(n)){clearTimeout(o);var r=Prism.plugins.lineNumbers,s=i.plugins&&i.plugins.lineNumbers;l(n,t)&&r&&!s?Prism.hooks.add("line-numbers",e):(Prism.plugins.lineHighlight.highlightLines(n)(),o=setTimeout(c,1))}})),window.addEventListener("hashchange",c),window.addEventListener("resize",(function(){s("pre").filter(u).map((function(e){return Prism.plugins.lineHighlight.highlightLines(e)})).forEach(a)}))}function s(e,t){return Array.prototype.slice.call((t||document).querySelectorAll(e))}function l(e,t){return e.classList.contains(t)}function a(e){e()}function u(e){return!!(e&&/pre/i.test(e.nodeName)&&(e.hasAttribute("data-line")||e.id&&Prism.util.isActive(e,i)))}function c(){var e=location.hash.slice(1);s(".temporary.line-highlight").forEach((function(e){e.parentNode.removeChild(e)}));var t=(e.match(/\.([\d,-]+)$/)||[,""])[1];if(t&&!document.getElementById(e)){var i=e.slice(0,e.lastIndexOf(".")),n=document.getElementById(i);n&&(n.hasAttribute("data-line")||n.setAttribute("data-line",""),Prism.plugins.lineHighlight.highlightLines(n,t,"temporary ")(),r&&document.querySelector(".temporary.line-highlight").scrollIntoView())}}}();
|
|
11
|
+
"undefined"!=typeof Prism&&Prism.hooks.add("wrap",(function(e){"keyword"===e.type&&e.classes.push("keyword-"+e.content)}));
|
|
12
|
+
!function(){if("undefined"!=typeof Prism){var e=Object.assign||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n]);return e},t={"remove-trailing":"boolean","remove-indent":"boolean","left-trim":"boolean","right-trim":"boolean","break-lines":"number",indent:"number","remove-initial-line-feed":"boolean","tabs-to-spaces":"number","spaces-to-tabs":"number"};n.prototype={setDefaults:function(t){this.defaults=e(this.defaults,t)},normalize:function(t,n){for(var r in n=e(this.defaults,n)){var i=r.replace(/-(\w)/g,(function(e,t){return t.toUpperCase()}));"normalize"!==r&&"setDefaults"!==i&&n[r]&&this[i]&&(t=this[i].call(this,t,n[r]))}return t},leftTrim:function(e){return e.replace(/^\s+/,"")},rightTrim:function(e){return e.replace(/\s+$/,"")},tabsToSpaces:function(e,t){return t=0|t||4,e.replace(/\t/g,new Array(++t).join(" "))},spacesToTabs:function(e,t){return t=0|t||4,e.replace(RegExp(" {"+t+"}","g"),"\t")},removeTrailing:function(e){return e.replace(/\s*?$/gm,"")},removeInitialLineFeed:function(e){return e.replace(/^(?:\r?\n|\r)/,"")},removeIndent:function(e){var t=e.match(/^[^\S\n\r]*(?=\S)/gm);return t&&t[0].length?(t.sort((function(e,t){return e.length-t.length})),t[0].length?e.replace(RegExp("^"+t[0],"gm"),""):e):e},indent:function(e,t){return e.replace(/^[^\S\n\r]*(?=\S)/gm,new Array(++t).join("\t")+"$&")},breakLines:function(e,t){t=!0===t?80:0|t||80;for(var n=e.split("\n"),i=0;i<n.length;++i)if(!(r(n[i])<=t)){for(var o=n[i].split(/(\s+)/g),a=0,l=0;l<o.length;++l){var s=r(o[l]);(a+=s)>t&&(o[l]="\n"+o[l],a=s)}n[i]=o.join("")}return n.join("\n")}},"undefined"!=typeof module&&module.exports&&(module.exports=n),Prism.plugins.NormalizeWhitespace=new n({"remove-trailing":!0,"remove-indent":!0,"left-trim":!0,"right-trim":!0}),Prism.hooks.add("before-sanity-check",(function(e){var n=Prism.plugins.NormalizeWhitespace;if((!e.settings||!1!==e.settings["whitespace-normalization"])&&Prism.util.isActive(e.element,"whitespace-normalization",!0))if(e.element&&e.element.parentNode||!e.code){var r=e.element.parentNode;if(e.code&&r&&"pre"===r.nodeName.toLowerCase()){for(var i in null==e.settings&&(e.settings={}),t)if(Object.hasOwnProperty.call(t,i)){var o=t[i];if(r.hasAttribute("data-"+i))try{var a=JSON.parse(r.getAttribute("data-"+i)||"true");typeof a===o&&(e.settings[i]=a)}catch(e){}}for(var l=r.childNodes,s="",c="",u=!1,m=0;m<l.length;++m){var f=l[m];f==e.element?u=!0:"#text"===f.nodeName&&(u?c+=f.nodeValue:s+=f.nodeValue,r.removeChild(f),--m)}if(e.element.children.length&&Prism.plugins.KeepMarkup){var d=s+e.element.innerHTML+c;e.element.innerHTML=n.normalize(d,e.settings),e.code=e.element.textContent}else e.code=s+e.code+c,e.code=n.normalize(e.code,e.settings)}}else e.code=n.normalize(e.code,e.settings)}))}function n(t){this.defaults=e({},t)}function r(e){for(var t=0,n=0;n<e.length;++n)e.charCodeAt(n)=="\t".charCodeAt(0)&&(t+=3);return e.length+t}}();
|
|
@@ -43,12 +43,12 @@ module ViewComponent
|
|
|
43
43
|
|
|
44
44
|
# :doc:
|
|
45
45
|
def default_preview_layout
|
|
46
|
-
|
|
46
|
+
ViewComponent::Base.config.default_preview_layout
|
|
47
47
|
end
|
|
48
48
|
|
|
49
49
|
# :doc:
|
|
50
50
|
def show_previews?
|
|
51
|
-
|
|
51
|
+
ViewComponent::Base.config.show_previews
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
# :doc:
|
|
@@ -22,7 +22,7 @@ module PreviewHelper
|
|
|
22
22
|
# Fetch template source via finding it through preview paths
|
|
23
23
|
# to accomodate source view when exclusively using templates
|
|
24
24
|
# for previews for Rails < 6.1.
|
|
25
|
-
all_template_paths =
|
|
25
|
+
all_template_paths = ViewComponent::Base.config.preview_paths.map do |preview_path|
|
|
26
26
|
Dir.glob("#{preview_path}/**/*")
|
|
27
27
|
end.flatten
|
|
28
28
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<% if @render_args[:component] %>
|
|
2
|
-
<% if
|
|
2
|
+
<% if ViewComponent::Base.config.render_monkey_patch_enabled || Rails.version.to_f >= 6.1 %>
|
|
3
3
|
<%= render(@render_args[:component], @render_args[:args], &@render_args[:block]) %>
|
|
4
4
|
<% else %>
|
|
5
5
|
<%= render_component(@render_args[:component], &@render_args[:block]) %>
|
|
@@ -8,6 +8,6 @@
|
|
|
8
8
|
<%= render template: @render_args[:template], locals: @render_args[:locals] || {} %>
|
|
9
9
|
<% end %>
|
|
10
10
|
|
|
11
|
-
<% if
|
|
11
|
+
<% if ViewComponent::Base.config.show_previews_source %>
|
|
12
12
|
<%= preview_source %>
|
|
13
13
|
<% end %>
|
data/docs/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
layout: default
|
|
3
3
|
title: Changelog
|
|
4
|
+
nav_order: 5
|
|
4
5
|
---
|
|
5
6
|
|
|
6
7
|
<!-- Add unreleased changes under the "main" heading. -->
|
|
@@ -9,6 +10,90 @@ title: Changelog
|
|
|
9
10
|
|
|
10
11
|
## main
|
|
11
12
|
|
|
13
|
+
## 2.71.0
|
|
14
|
+
|
|
15
|
+
**ViewComponent has moved to a new organization: [https://github.com/viewcomponent/view_component](https://github.com/viewcomponent/view_component). See [https://github.com/viewcomponent/view_component/issues/1424](https://github.com/viewcomponent/view_component/issues/1424) for more details.**
|
|
16
|
+
|
|
17
|
+
## 2.70.0
|
|
18
|
+
|
|
19
|
+
* `render_preview` can pass parameters to preview.
|
|
20
|
+
|
|
21
|
+
*Joel Hawksley*
|
|
22
|
+
|
|
23
|
+
* Fix docs typos.
|
|
24
|
+
|
|
25
|
+
*Joel Hawksley*
|
|
26
|
+
|
|
27
|
+
* Add architectural decisions to documentation and rename sidebar sections.
|
|
28
|
+
|
|
29
|
+
*Joel Hawksley*
|
|
30
|
+
|
|
31
|
+
* Clarify documentation on testability of Rails views.
|
|
32
|
+
|
|
33
|
+
*Joel Hawksley*
|
|
34
|
+
|
|
35
|
+
* Add Arrows to list of companies using ViewComponent.
|
|
36
|
+
|
|
37
|
+
*Matt Swanson*
|
|
38
|
+
|
|
39
|
+
* Add WIP to list of companies using ViewComponent.
|
|
40
|
+
|
|
41
|
+
*Marc Köhlbrugge*
|
|
42
|
+
|
|
43
|
+
* Update slots documentation to include how to reference slots.
|
|
44
|
+
|
|
45
|
+
*Brittany Ellich*
|
|
46
|
+
|
|
47
|
+
* Add Clio to list of companies using ViewComponent.
|
|
48
|
+
|
|
49
|
+
*Mike Buckley*
|
|
50
|
+
|
|
51
|
+
## 2.69.0
|
|
52
|
+
|
|
53
|
+
* Add missing `require` to fix `pvc` build.
|
|
54
|
+
|
|
55
|
+
*Joel Hawksley*
|
|
56
|
+
|
|
57
|
+
* Add `config.view_component.use_consistent_rendering_lifecycle` to ensure side-effects in `content` are consistently evaluated before components are rendered. This change effectively means that `content` is evaluated for every component render where `render?` returns true. As a result, code that's passed to a component via a block/content will now always be evaluated, before `#call`, which can reveal bugs in existing components. This configuration option defaults to `false` but will be enabled in 3.0 and the old behavior will be removed.
|
|
58
|
+
|
|
59
|
+
*Blake Williams*
|
|
60
|
+
|
|
61
|
+
* Update Prism to version 1.28.0.
|
|
62
|
+
|
|
63
|
+
*Thomas Hutterer*
|
|
64
|
+
|
|
65
|
+
* Corrects the deprecation warning for named slots to show the file and line where the slot is called.
|
|
66
|
+
|
|
67
|
+
*River Bailey*
|
|
68
|
+
|
|
69
|
+
## 2.68.0
|
|
70
|
+
|
|
71
|
+
* Update `gemspec` author to be ViewComponent team.
|
|
72
|
+
|
|
73
|
+
*Joel Hawksley*
|
|
74
|
+
|
|
75
|
+
* Fix bug where `ViewComponent::Compiler` wasn't required.
|
|
76
|
+
|
|
77
|
+
*Joel Hawksley*
|
|
78
|
+
|
|
79
|
+
## 2.67.0
|
|
80
|
+
|
|
81
|
+
* Use ViewComponent::Base.config as the internal endpoint for config.
|
|
82
|
+
|
|
83
|
+
*Simon Fish*
|
|
84
|
+
|
|
85
|
+
* Fix bug where `#with_request_url`, when used with query string, set the incorrect `request.path` and `request.fullpath`.
|
|
86
|
+
|
|
87
|
+
*Franz Liedke*
|
|
88
|
+
|
|
89
|
+
* Add link to [ViewComponentAttributes](https://github.com/amba-Health/view_component_attributes) in Resources section of docs.
|
|
90
|
+
|
|
91
|
+
*Romaric Pascal*
|
|
92
|
+
|
|
93
|
+
* `render_preview` test helper is available by default. It is no longer necessary to include `ViewComponent::RenderPreviewHelper`.
|
|
94
|
+
|
|
95
|
+
*Joel Hawksley*
|
|
96
|
+
|
|
12
97
|
## 2.66.0
|
|
13
98
|
|
|
14
99
|
* Add missing `generate.sidecar`, `generate.stimulus_controller`, `generate.locale`, `generate.distinct_locale_files`, `generate.preview` config options to `config.view_component`.
|
|
@@ -29,7 +29,7 @@ module ViewComponent
|
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
def component_path
|
|
32
|
-
|
|
32
|
+
ViewComponent::Base.config.view_component_path
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
def stimulus_controller
|
|
@@ -42,7 +42,7 @@ module ViewComponent
|
|
|
42
42
|
end
|
|
43
43
|
|
|
44
44
|
def sidecar?
|
|
45
|
-
options["sidecar"] ||
|
|
45
|
+
options["sidecar"] || ViewComponent::Base.config.generate.sidecar
|
|
46
46
|
end
|
|
47
47
|
end
|
|
48
48
|
end
|
|
@@ -13,12 +13,12 @@ module Rails
|
|
|
13
13
|
check_class_collision suffix: "Component"
|
|
14
14
|
|
|
15
15
|
class_option :inline, type: :boolean, default: false
|
|
16
|
-
class_option :locale, type: :boolean, default:
|
|
16
|
+
class_option :locale, type: :boolean, default: ViewComponent::Base.config.generate.locale
|
|
17
17
|
class_option :parent, type: :string, desc: "The parent class for the generated component"
|
|
18
|
-
class_option :preview, type: :boolean, default:
|
|
18
|
+
class_option :preview, type: :boolean, default: ViewComponent::Base.config.generate.preview
|
|
19
19
|
class_option :sidecar, type: :boolean, default: false
|
|
20
20
|
class_option :stimulus, type: :boolean,
|
|
21
|
-
default:
|
|
21
|
+
default: ViewComponent::Base.config.generate.stimulus_controller
|
|
22
22
|
|
|
23
23
|
def create_component_file
|
|
24
24
|
template "component.rb", File.join(component_path, class_path, "#{file_name}_component.rb")
|
|
@@ -41,7 +41,7 @@ module Rails
|
|
|
41
41
|
def parent_class
|
|
42
42
|
return options[:parent] if options[:parent]
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
ViewComponent::Base.config.component_parent_class || default_parent_class
|
|
45
45
|
end
|
|
46
46
|
|
|
47
47
|
def initialize_signature
|
|
@@ -12,7 +12,7 @@ module Locale
|
|
|
12
12
|
class_option :sidecar, type: :boolean, default: false
|
|
13
13
|
|
|
14
14
|
def create_locale_file
|
|
15
|
-
if
|
|
15
|
+
if ViewComponent::Base.config.generate.distinct_locale_files
|
|
16
16
|
I18n.available_locales.each do |locale|
|
|
17
17
|
create_file destination(locale), translations_hash([locale]).to_yaml
|
|
18
18
|
end
|
|
@@ -9,7 +9,7 @@ module Preview
|
|
|
9
9
|
check_class_collision suffix: "ComponentPreview"
|
|
10
10
|
|
|
11
11
|
def create_preview_file
|
|
12
|
-
preview_paths =
|
|
12
|
+
preview_paths = ViewComponent::Base.config.preview_paths
|
|
13
13
|
return if preview_paths.count > 1
|
|
14
14
|
|
|
15
15
|
path_prefix = preview_paths.one? ? preview_paths.first : "test/components/previews"
|
data/lib/view_component/base.rb
CHANGED
|
@@ -4,9 +4,11 @@ require "action_view"
|
|
|
4
4
|
require "active_support/configurable"
|
|
5
5
|
require "view_component/collection"
|
|
6
6
|
require "view_component/compile_cache"
|
|
7
|
+
require "view_component/compiler"
|
|
7
8
|
require "view_component/config"
|
|
8
9
|
require "view_component/content_areas"
|
|
9
10
|
require "view_component/polymorphic_slots"
|
|
11
|
+
require "view_component/preview"
|
|
10
12
|
require "view_component/slotable"
|
|
11
13
|
require "view_component/slotable_v2"
|
|
12
14
|
require "view_component/translatable"
|
|
@@ -18,7 +20,7 @@ module ViewComponent
|
|
|
18
20
|
delegate(*ViewComponent::Config.defaults.keys, to: :config)
|
|
19
21
|
|
|
20
22
|
def config
|
|
21
|
-
|
|
23
|
+
@config ||= ViewComponent::Config.defaults
|
|
22
24
|
end
|
|
23
25
|
end
|
|
24
26
|
|
|
@@ -130,6 +132,11 @@ module ViewComponent
|
|
|
130
132
|
before_render
|
|
131
133
|
|
|
132
134
|
if render?
|
|
135
|
+
# Ensure `content` is evaluated before rendering the template, this is
|
|
136
|
+
# needed so slots and other side-effects are performed before the
|
|
137
|
+
# component template is evaluated.
|
|
138
|
+
content if self.class.use_consistent_rendering_lifecycle
|
|
139
|
+
|
|
133
140
|
render_template_for(@__vc_variant).to_s + _output_postamble
|
|
134
141
|
else
|
|
135
142
|
""
|
|
@@ -335,6 +342,18 @@ module ViewComponent
|
|
|
335
342
|
# Defaults to `nil`. If this is falsy, `app/components` is used.
|
|
336
343
|
#
|
|
337
344
|
|
|
345
|
+
# Evaluate `#content` before `#call` to ensure side-effects are present
|
|
346
|
+
# during component renders. This will be the default behavior in a future
|
|
347
|
+
# release.
|
|
348
|
+
#
|
|
349
|
+
# ```ruby
|
|
350
|
+
# config.view_component.use_consistent_rendering_lifecycle = true
|
|
351
|
+
# ```
|
|
352
|
+
#
|
|
353
|
+
# Defaults to `false`
|
|
354
|
+
#
|
|
355
|
+
mattr_accessor :use_consistent_rendering_lifecycle, instance_writer: false, default: false
|
|
356
|
+
|
|
338
357
|
# Parent class for generated components
|
|
339
358
|
#
|
|
340
359
|
# ```ruby
|
|
@@ -496,7 +515,7 @@ module ViewComponent
|
|
|
496
515
|
|
|
497
516
|
# Removes the first part of the path and the extension.
|
|
498
517
|
child.virtual_path = child.source_location.gsub(
|
|
499
|
-
/(.*#{Regexp.quote(
|
|
518
|
+
/(.*#{Regexp.quote(ViewComponent::Base.config.view_component_path)})|(\.rb)/, ""
|
|
500
519
|
)
|
|
501
520
|
|
|
502
521
|
# Set collection parameter to the extended component
|
|
@@ -5,7 +5,7 @@ require "view_component/base"
|
|
|
5
5
|
|
|
6
6
|
module ViewComponent
|
|
7
7
|
class Engine < Rails::Engine # :nodoc:
|
|
8
|
-
config.view_component = ViewComponent::
|
|
8
|
+
config.view_component = ViewComponent::Base.config
|
|
9
9
|
|
|
10
10
|
rake_tasks do
|
|
11
11
|
load "view_component/rails/tasks/view_component.rake"
|
|
@@ -92,10 +92,11 @@ module ViewComponent
|
|
|
92
92
|
get_slot(slot_name)
|
|
93
93
|
else
|
|
94
94
|
if _warn_on_deprecated_slot_setter
|
|
95
|
-
|
|
96
|
-
|
|
95
|
+
stack = caller_locations(3)
|
|
96
|
+
msg = "Setting a slot with `##{slot_name}` is deprecated and will be removed in ViewComponent v3.0.0. " \
|
|
97
97
|
"Use `#with_#{slot_name}` to set the slot instead."
|
|
98
|
-
|
|
98
|
+
|
|
99
|
+
ViewComponent::Deprecation.warn(msg, stack)
|
|
99
100
|
end
|
|
100
101
|
|
|
101
102
|
set_slot(slot_name, nil, *args, &block)
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "view_component/render_preview_helper"
|
|
4
|
-
|
|
5
3
|
module ViewComponent
|
|
6
4
|
module TestHelpers
|
|
7
5
|
begin
|
|
@@ -67,6 +65,55 @@ module ViewComponent
|
|
|
67
65
|
Nokogiri::HTML.fragment(@rendered_content)
|
|
68
66
|
end
|
|
69
67
|
|
|
68
|
+
# Render a preview inline. Internally sets `page` to be a `Capybara::Node::Simple`,
|
|
69
|
+
# allowing for Capybara assertions to be used:
|
|
70
|
+
#
|
|
71
|
+
# ```ruby
|
|
72
|
+
# render_preview(:default)
|
|
73
|
+
# assert_text("Hello, World!")
|
|
74
|
+
# ```
|
|
75
|
+
#
|
|
76
|
+
# Note: `#rendered_preview` expects a preview to be defined with the same class
|
|
77
|
+
# name as the calling test, but with `Test` replaced with `Preview`:
|
|
78
|
+
#
|
|
79
|
+
# MyComponentTest -> MyComponentPreview etc.
|
|
80
|
+
#
|
|
81
|
+
# In RSpec, `Preview` is appended to `described_class`.
|
|
82
|
+
#
|
|
83
|
+
# @param name [String] The name of the preview to be rendered.
|
|
84
|
+
# @param params [Hash] Parameters to be passed to the preview.
|
|
85
|
+
# @return [Nokogiri::HTML]
|
|
86
|
+
def render_preview(name, params: {})
|
|
87
|
+
begin
|
|
88
|
+
preview_klass = if respond_to?(:described_class)
|
|
89
|
+
raise "`render_preview` expected a described_class, but it is nil." if described_class.nil?
|
|
90
|
+
|
|
91
|
+
"#{described_class}Preview"
|
|
92
|
+
else
|
|
93
|
+
self.class.name.gsub("Test", "Preview")
|
|
94
|
+
end
|
|
95
|
+
preview_klass = preview_klass.constantize
|
|
96
|
+
rescue NameError
|
|
97
|
+
raise NameError, "`render_preview` expected to find #{preview_klass}, but it does not exist."
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
previews_controller = build_controller(Rails.application.config.view_component.preview_controller.constantize)
|
|
101
|
+
|
|
102
|
+
# From what I can tell, it's not possible to overwrite all request parameters
|
|
103
|
+
# at once, so we set them individually here.
|
|
104
|
+
params.each do |k, v|
|
|
105
|
+
previews_controller.request.params[k] = v
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
previews_controller.request.params[:path] = "#{preview_klass.preview_name}/#{name}"
|
|
109
|
+
previews_controller.response = ActionDispatch::Response.new
|
|
110
|
+
result = previews_controller.previews
|
|
111
|
+
|
|
112
|
+
@rendered_content = result
|
|
113
|
+
|
|
114
|
+
Nokogiri::HTML.fragment(@rendered_content)
|
|
115
|
+
end
|
|
116
|
+
|
|
70
117
|
# Execute the given block in the view context. Internally sets `page` to be a
|
|
71
118
|
# `Capybara::Node::Simple`, allowing for Capybara assertions to be used:
|
|
72
119
|
#
|
|
@@ -151,10 +198,11 @@ module ViewComponent
|
|
|
151
198
|
old_request_query_string = request.query_string
|
|
152
199
|
old_controller = defined?(@controller) && @controller
|
|
153
200
|
|
|
201
|
+
path, query = path.split("?", 2)
|
|
154
202
|
request.path_info = path
|
|
155
203
|
request.path_parameters = Rails.application.routes.recognize_path(path)
|
|
156
|
-
request.set_header("action_dispatch.request.query_parameters", Rack::Utils.parse_nested_query(
|
|
157
|
-
request.set_header(Rack::QUERY_STRING,
|
|
204
|
+
request.set_header("action_dispatch.request.query_parameters", Rack::Utils.parse_nested_query(query))
|
|
205
|
+
request.set_header(Rack::QUERY_STRING, query)
|
|
158
206
|
yield
|
|
159
207
|
ensure
|
|
160
208
|
request.path_info = old_request_path_info
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: view_component
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.71.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
|
-
-
|
|
7
|
+
- ViewComponent Team
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2022-08-
|
|
11
|
+
date: 2022-08-31 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|
|
@@ -104,16 +104,16 @@ dependencies:
|
|
|
104
104
|
name: bundler
|
|
105
105
|
requirement: !ruby/object:Gem::Requirement
|
|
106
106
|
requirements:
|
|
107
|
-
- - "
|
|
107
|
+
- - "~>"
|
|
108
108
|
- !ruby/object:Gem::Version
|
|
109
|
-
version:
|
|
109
|
+
version: '2'
|
|
110
110
|
type: :development
|
|
111
111
|
prerelease: false
|
|
112
112
|
version_requirements: !ruby/object:Gem::Requirement
|
|
113
113
|
requirements:
|
|
114
|
-
- - "
|
|
114
|
+
- - "~>"
|
|
115
115
|
- !ruby/object:Gem::Version
|
|
116
|
-
version:
|
|
116
|
+
version: '2'
|
|
117
117
|
- !ruby/object:Gem::Dependency
|
|
118
118
|
name: erb_lint
|
|
119
119
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -300,19 +300,18 @@ dependencies:
|
|
|
300
300
|
name: yard-activesupport-concern
|
|
301
301
|
requirement: !ruby/object:Gem::Requirement
|
|
302
302
|
requirements:
|
|
303
|
-
- - "
|
|
303
|
+
- - "~>"
|
|
304
304
|
- !ruby/object:Gem::Version
|
|
305
|
-
version:
|
|
305
|
+
version: 0.0.1
|
|
306
306
|
type: :development
|
|
307
307
|
prerelease: false
|
|
308
308
|
version_requirements: !ruby/object:Gem::Requirement
|
|
309
309
|
requirements:
|
|
310
|
-
- - "
|
|
310
|
+
- - "~>"
|
|
311
311
|
- !ruby/object:Gem::Version
|
|
312
|
-
version:
|
|
312
|
+
version: 0.0.1
|
|
313
313
|
description:
|
|
314
314
|
email:
|
|
315
|
-
- opensource+view_component@github.com
|
|
316
315
|
executables: []
|
|
317
316
|
extensions: []
|
|
318
317
|
extra_rdoc_files: []
|
|
@@ -371,7 +370,6 @@ files:
|
|
|
371
370
|
- lib/view_component/render_component_helper.rb
|
|
372
371
|
- lib/view_component/render_component_to_string_helper.rb
|
|
373
372
|
- lib/view_component/render_monkey_patch.rb
|
|
374
|
-
- lib/view_component/render_preview_helper.rb
|
|
375
373
|
- lib/view_component/render_to_string_monkey_patch.rb
|
|
376
374
|
- lib/view_component/rendering_component_helper.rb
|
|
377
375
|
- lib/view_component/rendering_monkey_patch.rb
|
|
@@ -386,7 +384,7 @@ files:
|
|
|
386
384
|
- lib/view_component/version.rb
|
|
387
385
|
- lib/view_component/with_content_helper.rb
|
|
388
386
|
- lib/yard/mattr_accessor_handler.rb
|
|
389
|
-
homepage: https://
|
|
387
|
+
homepage: https://viewcomponent.org
|
|
390
388
|
licenses:
|
|
391
389
|
- MIT
|
|
392
390
|
metadata:
|
|
@@ -409,5 +407,6 @@ requirements: []
|
|
|
409
407
|
rubygems_version: 3.2.32
|
|
410
408
|
signing_key:
|
|
411
409
|
specification_version: 4
|
|
412
|
-
summary:
|
|
410
|
+
summary: A framework for building reusable, testable & encapsulated view components
|
|
411
|
+
in Ruby on Rails.
|
|
413
412
|
test_files: []
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module ViewComponent
|
|
4
|
-
module RenderPreviewHelper
|
|
5
|
-
# Render a preview inline. Internally sets `page` to be a `Capybara::Node::Simple`,
|
|
6
|
-
# allowing for Capybara assertions to be used:
|
|
7
|
-
#
|
|
8
|
-
# ```ruby
|
|
9
|
-
# render_preview(:default)
|
|
10
|
-
# assert_text("Hello, World!")
|
|
11
|
-
# ```
|
|
12
|
-
#
|
|
13
|
-
# Note: `#rendered_preview` expects a preview to be defined with the same class
|
|
14
|
-
# name as the calling test, but with `Test` replaced with `Preview`:
|
|
15
|
-
#
|
|
16
|
-
# MyComponentTest -> MyComponentPreview etc.
|
|
17
|
-
#
|
|
18
|
-
# In RSpec, `Preview` is appended to `described_class`.
|
|
19
|
-
#
|
|
20
|
-
# @param preview [String] The name of the preview to be rendered.
|
|
21
|
-
# @return [Nokogiri::HTML]
|
|
22
|
-
def render_preview(name)
|
|
23
|
-
begin
|
|
24
|
-
preview_klass = if respond_to?(:described_class)
|
|
25
|
-
raise "`render_preview` expected a described_class, but it is nil." if described_class.nil?
|
|
26
|
-
|
|
27
|
-
"#{described_class}Preview"
|
|
28
|
-
else
|
|
29
|
-
self.class.name.gsub("Test", "Preview")
|
|
30
|
-
end
|
|
31
|
-
preview_klass = preview_klass.constantize
|
|
32
|
-
rescue NameError
|
|
33
|
-
raise NameError, "`render_preview` expected to find #{preview_klass}, but it does not exist."
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
previews_controller = build_controller(Rails.application.config.view_component.preview_controller.constantize)
|
|
37
|
-
previews_controller.request.params[:path] = "#{preview_klass.preview_name}/#{name}"
|
|
38
|
-
previews_controller.response = ActionDispatch::Response.new
|
|
39
|
-
result = previews_controller.previews
|
|
40
|
-
|
|
41
|
-
@rendered_content = result
|
|
42
|
-
|
|
43
|
-
Nokogiri::HTML.fragment(@rendered_content)
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
end
|