Class: SimpleLayerTag

Inherits:
Object
  • Object
show all
Defined in:
lib/slt/simple_layer_tag.rb

Overview

Author

liveralmask

Copyright

Copyright © 2013 liveralmask

License

MIT

Instance Method Summary collapse

Constructor Details

#initializeSimpleLayerTag

Returns a new instance of SimpleLayerTag.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/slt/simple_layer_tag.rb', line 6

def initialize
	@singleTagList = []
	
	@singleHtmlTagList = [
		"br",
		"img",
		"hr",
		"meta",
		"input",
		"embed",
		"area",
		"base",
		"col",
		"keygen",
		"link",
		"param",
		"source"
	]
end

Instance Method Details

#html(str) ⇒ Object



78
79
80
# File 'lib/slt/simple_layer_tag.rb', line 78

def html( str )
	self.tag( str, @singleHtmlTagList )
end

#tag(str, singleTagList = []) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
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
# File 'lib/slt/simple_layer_tag.rb', line 31

def tag( str, singleTagList = [] )
	@singleTagList = singleTagList
	
	# 処理しやすい形式に変換しておく
	list = parse( str )
	
	tagList = []
	unfinishedTagList = []
	list.each{|hash|
		# 処理している階層より前の終了タグを出力
		tagList.concat( extract_end_tag_list( unfinishedTagList, hash[ "level" ] ) )
		
		case hash[ "keyword" ]
		when KEYWORD_COPY		# コピー
			tagList.push( hash[ "value" ] )
			
			# 階層の順序を維持するために必要
			hash[ "keyword" ]	= ""
			unfinishedTagList.push( hash )
		when KEYWORD_COMMENT	# コメント
			tagList.push( comment_tag( hash[ "value" ] ) )
			
			# 階層の順序を維持するために必要
			hash[ "keyword" ]	= ""
			unfinishedTagList.push( hash )
		else					# タグ
			tag = start_tag( hash )
			if tag.empty?
				next if hash[ "value" ].strip.empty?	# 空白行は無視
				
				tagList.push( comment_tag( "Error => #{hash[ 'number' ]}:#{hash[ 'value' ]}" ) )
				next
			end
			
			tagList.push( tag )
			unfinishedTagList.push( hash )
		end
	}
	
	# 残りの終了タグ
	tagList.concat( extract_end_tag_list( unfinishedTagList ) )
	
	tagText = "#{tagList.join.strip}"
	
	return tagText
end