vieweditattachhistoryswikistopchangessearchhelp

挿入時のカラータグ指定簡略化

IdFormatter class >> #appendFormat:request:response:shelf:book:page:

appendFormat: text request: request response: response shelf: shelf book: book page: page
	| append content today string color signPos colorPos |
	content _ String streamContents: [:stream |
		(text includes: $_) ifTrue: [
			"_ means appends are seperated by lines"
			stream
				nextPutAll: '_';
				nextPutAll: String cr].
		string _ (((book settingsAt: 'saveFormatter') 
			format: (request fieldsKey: 'append') 
			request: request 
			response: response 
			shelf: shelf 
			book: book 
			page: page)) asString.
		(text includes: $%) ifTrue: [
			"% means appends color tag"
			color _ ((signPos _ string reverse findString: '--') > 0 and: [
				((colorPos _ string lastIndexOf: $%) > 0) and: [
					(colorPos _ string size - colorPos) < signPos]]) 
						ifTrue: [self estimBrowerColor: 
							(string copyLast: colorPos) withoutTrailingBlanks asLowercase] 
						ifFalse: [nil].
			color ifNotNil: [
				stream nextPutAll: '<font color=', color, '>'.
				string _ string copyFrom: 1 to: string size - colorPos - 1]].
		stream
			nextPutAll: string.
		color ifNotNil: [stream
			nextPutAll: '</font>'].
		(text includes: $@) ifTrue: [
			"@ means appends include timestamps"
			today _ Date today.
			stream
				nextPutAll: ' <tt><em><font color=gray>- ';
				nextPutAll: today yyyymmdd;
				nextPutAll: ', ';
				nextPutAll: Time now print24.
			stream
				nextPutAll: '</font></em></tt>'].
		stream nextPutAll: String cr].
	"+ means appends are self replicating
	^ means append areas stay at top and appends go down"
	append _ text, String cr.
	^((text occurrencesOf: $+) > 1)
		ifTrue: [append, content, append]
		ifFalse: [(text includes: $^)
			ifTrue: [append, content]
			ifFalse: [content, append]]


IdFormatter class estimBrowerColor: {utility}

estimBrowerColor: aString 
	| match m color |
	match _ 0.
	#(navy green maroon darkblue darkred midnightblue mediumblue darkslategray 
	indigo forestgreen saddlebrown darkolivegreen firebrick brown blue lime red teal 
	purple olive seagreen darkslateblue darkcyan darkmagenta olivedrab sienna crimson 
	limegreen dimgray orangered darkgoldenrod chocolate mediumseagreen mediumvioletred 
	darkviolet lawngreen lightseagreen steelblue springgreen chartreuse slategray gray 
	indianred royalblue darkorange slateblue peru mediumspringgreen blueviolet darkorchid 
	lightslategray yellowgreen cadetblue darkturquoise goldenrod orange deeppink tomato 
	dodgerblue deepskyblue coral mediumslateblue gold darkseagreen rosybrown greenyellow 
	mediumaquamarine mediumpurple palevioletred darkkhaki mediumorchid mediumturquoise 
	cornflowerblue salmon turquoise lightcoral sandybrown darksalmon darkgray cyan aqua 
	magenta fuchsia yellow lightgreen tan lightsalmon hotpink burlywood orchid palegreen 
	skyblue silver lightskyblue aquamarine lightsteelblue plum violet khaki lightblue thistle 
	powderblue lightpink lightgrey palegoldenrod wheat pink navajowhite paleturquoise 
	peachpuff gainsboro moccasin bisque blanchedalmond antiquewhite papayawhip 
	mistyrose lavender beige lightgoldenrodyellow lemonchiffon linen cornsilk oldlace 
	lightcyan lightyellow honeydew whitesmoke seashell lavenderblush aliceblue floralwhite 
	azure mintcream ivory ghostwhite snow)
		do: [:c | match < (m _ c howManyMatch: aString)
				ifTrue: [color _ c. match _ m]].
	^ color

このページを編集 (3413 bytes)


Congratulations! 以下の 1 ページから参照されています。

This page has been visited 2338 times.