Module: Slideshow::TextFilter
Instance Method Summary collapse
- #comments_percent_style(content) ⇒ Object
- #directives_bang_style_to_percent_style(content) ⇒ Object
- #directives_percent_style(content) ⇒ Object
- #erb_rename_helper_hack(content) ⇒ Object
- #old_comments_percent_style ⇒ Object
Instance Method Details
#comments_percent_style(content) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/slideshow/filters/text_filter.rb', line 15 def comments_percent_style( content ) # skip filter for pandoc # - pandoc uses % for its own markdown extension return content if @markup_type == :markdown && Markdown.lib == 'pandoc-ruby' old_comments_percent_style( content ) end |
#directives_bang_style_to_percent_style(content) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/slideshow/filters/text_filter.rb', line 24 def directives_bang_style_to_percent_style( content ) # for compatibility allow !SLIDE/!STYLE as an alternative to %slide/%style-directive bang_count = 0 # get unparsed helpers e.g. SLIDE|STYLE unparsed = config.helper_unparsed.map { |item| item.upcase }.join( '|' ) content.gsub!(/^!(#{unparsed})(.*)$/) do |match| bang_count += 1 "<%= #{$1.downcase} '#{$2 ? $2 : ''}' %>" end puts " Patching !-directives (#{bang_count} #{config.helper_unparsed.join('/')}-directives)..." content end |
#directives_percent_style(content) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/slideshow/filters/text_filter.rb', line 43 def directives_percent_style( content ) # skip filter for pandoc # - pandoc uses % for its own markdown extension # - don't process % pass it along/through to pandoc return content if @markup_type == :markdown && Markdown.lib == 'pandoc-ruby' directive_unparsed = 0 directive_expr = 0 directive_block_beg = 0 directive_block_end = 0 # process directives (plus skip %begin/%end comment-blocks) inside_block = 0 inside_helper = false content2 = "" content.each_line do |line| if line =~ /^%([a-zA-Z][a-zA-Z0-9_]*)(.*)/ directive = $1.downcase params = $2 logger.debug "processing %-directive: #{directive}" # slide, style if config.helper_unparsed.include?( directive ) directive_unparsed += 1 content2 << "<%= #{directive} '#{params ? params : ''}' %>" elsif config.helper_exprs.include?( directive ) directive_expr += 1 content2 << "<%= #{directive} #{params ? erb_simple_params(directive,params) : ''} %>" elsif inside_helper && directive == 'end' inside_helper = false directive_block_end += 1 content2 << "%>" elsif inside_block > 0 && directive == 'end' inside_block -= 1 directive_block_end += 1 content2 << "<% end %>" elsif [ 'comment', 'comments', 'begin', 'end' ].include?( directive ) # skip begin/end comment blocks content2 << line elsif [ 'helper', 'helpers' ].include?( directive ) inside_helper = true directive_block_beg += 1 content2 << "<%" else inside_block += 1 directive_block_beg += 1 content2 << "<% #{directive} #{params ? erb_simple_params(directive,params) : ''} do %>" end else content2 << line end end puts " Preparing %-directives (" + "#{directive_unparsed} #{config.helper_unparsed.join('/')} directives, " + "#{directive_expr} #{config.helper_exprs.join('/')} expr-directives, " + "#{directive_block_beg}/#{directive_block_end} block-directives)..." content2 end |
#erb_rename_helper_hack(content) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/slideshow/filters/text_filter.rb', line 115 def erb_rename_helper_hack( content ) # note: include is a ruby keyword; rename to s9_include so we can use it rename_counter = 0 # turn renames into something like: # include|class etc. renames = config.helper_renames.join( '|' ) content.gsub!( /<%=[ \t]*(#{renames})/ ) do |match| rename_counter += 1 "<%= s9_#{$1}" end puts " Patching embedded Ruby (erb) code for aliases (#{rename_counter} #{config.helper_renames.join('/')}-aliases)..." content end |
#old_comments_percent_style ⇒ Object
13 |
# File 'lib/slideshow/filters/text_filter.rb', line 13 alias_method :old_comments_percent_style, :comments_percent_style |