Sha256: e2c47050a1d11482afecd57dd5d746381d8c4fa6e0e9d6bb543c42be1e8c6460

Contents?: true

Size: 952 Bytes

Versions: 8

Compression:

Stored size: 952 Bytes

Contents

require 'cgi'

module Mizuho

class Heading
	# The heading title, as HTML. Non-HTML special characters are already escaped.
	attr_accessor :title
	attr_accessor :level
	attr_accessor :basename
	attr_accessor :anchor
	attr_accessor :parent
	attr_accessor :children
	
	def initialize
		@children = []
	end
	
	def find_parent_with_level(level)
		h = self
		while h && h.level != level
			h = h.parent
		end
		return h
	end
	
	# The heading title without section number, as HTML. Non-HTML special characters
	# are already escaped.
	def title_without_numbers
		return title.sub(/^(\d+\.)+ /, '')
	end
	
	# The heading title without section number, as plain text. Contains no HTML
	# elements. Non-HTML special characters are NOT escaped.
	def plain_title
		return CGI::unescapeHTML(title_without_numbers.gsub(%r{</?[a-z]+>}i, ''))
	end
	
	def each_descendant(&block)
		children.each do |h|
			block.call(h)
			h.each_descendant(&block)
		end
	end
end

end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
FooBarWidget-mizuho-0.9.0 lib/mizuho/heading.rb
FooBarWidget-mizuho-0.9.1 lib/mizuho/heading.rb
FooBarWidget-mizuho-0.9.2 lib/mizuho/heading.rb
FooBarWidget-mizuho-0.9.3 lib/mizuho/heading.rb
FooBarWidget-mizuho-0.9.4 lib/mizuho/heading.rb
FooBarWidget-mizuho-0.9.5 lib/mizuho/heading.rb
mizuho-0.9.8 lib/mizuho/heading.rb
mizuho-0.9.6 lib/mizuho/heading.rb