diff --git a/guides/assets/javascripts/clipboard.js b/guides/assets/javascripts/clipboard.js new file mode 100644 index 00000000000..b9ed143b3e1 --- /dev/null +++ b/guides/assets/javascripts/clipboard.js @@ -0,0 +1,7 @@ +/*! + * clipboard.js v2.0.6 + * https://clipboardjs.com/ + * + * Licensed MIT © Zeno Rocha + */ +!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.ClipboardJS=e():t.ClipboardJS=e()}(this,function(){return o={},r.m=n=[function(t,e){t.exports=function(t){var e;if("SELECT"===t.nodeName)t.focus(),e=t.value;else if("INPUT"===t.nodeName||"TEXTAREA"===t.nodeName){var n=t.hasAttribute("readonly");n||t.setAttribute("readonly",""),t.select(),t.setSelectionRange(0,t.value.length),n||t.removeAttribute("readonly"),e=t.value}else{t.hasAttribute("contenteditable")&&t.focus();var o=window.getSelection(),r=document.createRange();r.selectNodeContents(t),o.removeAllRanges(),o.addRange(r),e=o.toString()}return e}},function(t,e){function n(){}n.prototype={on:function(t,e,n){var o=this.e||(this.e={});return(o[t]||(o[t]=[])).push({fn:e,ctx:n}),this},once:function(t,e,n){var o=this;function r(){o.off(t,r),e.apply(n,arguments)}return r._=e,this.on(t,r,n)},emit:function(t){for(var e=[].slice.call(arguments,1),n=((this.e||(this.e={}))[t]||[]).slice(),o=0,r=n.length;o -
#{code}
- + formatted_code = formatter.format(lexer.lex(code)) + clipboard_id = "clipboard-#{SecureRandom.hex(16)}" + <<~HTML +
+
#{formatted_code}
+ + +
HTML end @@ -79,6 +82,17 @@ module RailsGuides end end + def clipboard_content(code, language) + if language == "bash" + prompt_regexp = /^\$ / + code = code.split("\n"). + select { |line| line =~ prompt_regexp }. + map { |line| line.gsub(prompt_regexp, "") }. + join("\n") + end + ERB::Util.h(code) + end + def convert_notes(body) # The following regexp detects special labels followed by a # paragraph, perhaps at the end of the document. diff --git a/guides/source/layout.html.erb b/guides/source/layout.html.erb index 1b854edccc3..72fe9125870 100644 --- a/guides/source/layout.html.erb +++ b/guides/source/layout.html.erb @@ -9,6 +9,7 @@ +