class Eggshell::Bundles::Basic::TextBlocks
Constants
- HTML_BLOCK
HTML tags that have end-block checks. any block starting with one of these tags will have its contents passed through until end of the tag (essentially, raw) @todo what else should be treated?
- HTML_BLOCK_END
- HTML_PASSTHRU
For lines starting with only these tags, accept as-is
- START_TEXT
Public Class Methods
new()
click to toggle source
# File lib/eggshell/bundles/basics.rb, line 42 def initialize @block_types = ['p', 'bq', 'pre', 'div', 'raw', 'html_pass', 'html_block'] end
Public Instance Methods
can_handle(line)
click to toggle source
# File lib/eggshell/bundles/basics.rb, line 48 def can_handle(line) match = START_TEXT.match(line) if match @block_type = match[1] if @block_type == 'pre' || @block_type == 'raw' return BH::COLLECT_RAW else return BH::COLLECT end end if line.match(HTML_PASSTHRU) @block_type = 'html_pass' return BH::DONE end html = line.match(HTML_BLOCK) if html @block_type = 'html_block' end_html = HTML_BLOCK_END["<#{html[1]}"] end_html = "</#{html[1]}>" if !end_html if line.match(end_html) return BH::DONE end @end_html = end_html return BH::COLLECT_RAW end return BH::RETRY end
continue_with(line)
click to toggle source
# File lib/eggshell/bundles/basics.rb, line 80 def continue_with(line) if @block_type == 'html_block' done = line.match(@end_html) if done return BH::DONE else return BH::COLLECT end else if @block_type == 'pre' || @block_type == 'raw' if line && line != '' return BH::COLLECT end elsif line if line == '' || line.match(HTML_PASSTHRU) != nil || line.match(HTML_BLOCK) != nil return BH::RETRY end return BH::COLLECT end end return BH::RETRY end
process(type, args, lines, out, call_depth = 0)
click to toggle source
# File lib/eggshell/bundles/basics.rb, line 104 def process(type, args, lines, out, call_depth = 0) buff = [] if type == 'html_pass' || type == 'html_block' out << @eggshell.expand_expr(lines.join("\n")) else # @todo if pre starts with blank line, remove it tagname = type == 'bq' ? 'blockquote' : type args = [] if !args bp = get_block_params(type, args[0]) raw = type == 'pre' || type == 'raw' line_break = raw ? '' : '<br />' lines.each do |line| str = line.is_a?(Eggshell::Line) ? line.to_s : line str.chomp! buff << str end # @todo don't call expand_expr if raw && args[0]['no_expand']? buff = buff.join("#{line_break}\n") buff = @eggshell.expand_formatting(buff) if !raw buff = @eggshell.unescape(@eggshell.expand_expr(buff)) if type != 'raw' out << [create_tag(type, bp), buff, "</#{type}>"].join('') else out << buff end end end