module Togglate
Constants
- VERSION
Public Class Methods
append_code(method, opts)
click to toggle source
# File lib/togglate.rb, line 28 def append_code(method, opts) send("#{method}_code", opts) end
commentout(text, tag:'original')
click to toggle source
# File lib/togglate.rb, line 19 def commentout(text, tag:'original') comments = [] comment_re = /\n?^<!--#{tag}\n(.*?)^-->\n?/m remains = text.gsub(comment_re) { |m| comments << $1; '' } return comments*"\n", remains end
Also aliased as: comment_out
create(text, opts={})
click to toggle source
# File lib/togglate.rb, line 9 def create(text, opts={}) wrapped = BlockWrapper.new(text, opts).run if opts[:embed_code] code = append_code(opts[:method], opts) "#{wrapped}\n#{code}" else wrapped end end
hover_code(name:'original', **opts)
click to toggle source
# File lib/togglate.rb, line 61 def hover_code(name:'original', **opts) <<-"CODE" <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script> <script> $(function() { $("*").contents().filter(function() { return this.nodeType==8 && this.nodeValue.match(/^#{name}/); }).each(function(i, e) { var tooltips = e.nodeValue.replace(/^#{name}\s*[\\n\\r]|[\\n\\r]$/g, ''); $(this).prev().attr('title', tooltips); }); }); </script> CODE end
toggle_code(name:'original', toggle_link_text:["*", "hide"], **opts)
click to toggle source
# File lib/togglate.rb, line 32 def toggle_code(name:'original', toggle_link_text:["*", "hide"], **opts) <<-"CODE" <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script> <script> $(function() { $("*").contents().filter(function() { return this.nodeType==8 && this.nodeValue.match(/^#{name}/); }).each(function(i, e) { var tooltips = e.nodeValue.replace(/^#{name} *[\\n\\r]|[\\n\\r]$/g, ''); var link = "<span><a href='#' onclick='javascript:return false;' class='toggleLink'>" + "#{toggle_link_text[0]}" + "</a></span>"; $(this).prev().append(link); $(this).prev().after("<pre style='display:none'>"+ tooltips + "</pre>"); }); $('.toggleLink').click( function() { if ($(this).text()=="#{toggle_link_text[0]}") { $(this).parent().parent().next('pre').slideDown(200); $(this).text("#{toggle_link_text[1]}"); } else { $(this).parent().parent().next('pre').slideUp(200); $(this).text("#{toggle_link_text[0]}"); }; }); }); </script> CODE end