Class: Eggshell::Bundles::Basics::InlineMacros

Inherits:
Object
  • Object
show all
Includes:
MacroHandler
Defined in:
lib/eggshell/bundles/basics.rb

Constant Summary collapse

HASH_FMT_DECORATORS =
{
	'[*' => '<b>',
	'[**' => '<strong>',
	'[_' => '<i>',
	'[__' => '<em>',
	'*]'=> '</b>',
	'**]' => '</strong>',
	'_]' => '</i>',
	'__]' => '</em>',
	'[-_' => '<u>',
	'_-]' => '</u>',
	'[-' => '<strike>',
	'-]' => '</strike>'
}.freeze

Instance Method Summary collapse

Constructor Details

#initializeInlineMacros

Returns a new instance of InlineMacros.



437
438
439
440
441
# File 'lib/eggshell/bundles/basics.rb', line 437

def initialize
	@capvar = nil
	@collbuff = nil
	@depth = 0
end

Instance Method Details

#process(buffer, macname, args, lines, depth) ⇒ Object



463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
# File 'lib/eggshell/bundles/basics.rb', line 463

def process(buffer, macname, args, lines, depth)
	prefix = macname[0..1]
	textpart = args.shift
	tag = nil

	case prefix
	when '[^'
		tag = 'sup'
	when '[.'
		tag = 'sub'
	when '[*'
		tag = macname == '[**' ? 'strong' : 'b'
	when '[/'
		tag = macname == '[//' ? 'em' : 'i'
	when '[-'
		tag = 'strike'
	when '[_'
		tag = 'u'
	when '[~'
		tag = 'a'
		link = textpart ? textpart.strip : textpart
		text = nil
		if link == ''
			text = ''
		elsif link.index('; ') == nil
			textpart = link
			args.unshift('href:'+ link);
		else
			textpart, link = link.split('; ')
			link = '' if !link
			args.unshift('href:'+link)
		end
	when '[!'
		tag = 'img'
		args.unshift('src:'+textpart)
		textpart = nil
	end
	
	buffer << restructure_html(tag, textpart ? textpart.strip : textpart, args)
end

#restructure_html(tag, text, attributes = []) ⇒ Object



504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
# File 'lib/eggshell/bundles/basics.rb', line 504

def restructure_html(tag, text, attributes = [])
	buff = "<#{tag}"
	attributes.each do |attrib|
		key, val = attrib.split(':', 2)
		# @todo html escape?
		if val
			buff = "#{buff} #{key}=\"#{val.gsub('\\|', '|')}\""
		else
			buff = "#{buff} #{key}"
		end
	end

	if text == nil
		buff += ' />'
	else
		buff = "#{buff}>#{text}</#{tag}>"
	end
	buff
end

#set_processor(eggshell) ⇒ Object



458
459
460
461
# File 'lib/eggshell/bundles/basics.rb', line 458

def set_processor(eggshell)
	@proc = eggshell
	@proc.register_macro(self, '[!', '[~', '[^', '[.', '[*', '[**', '[/', '[//', '[_', '[-')
end