File: number_anchor.rb

package info (click to toggle)
tdiary 5.4.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,092 kB
  • sloc: ruby: 23,031; javascript: 1,029; xml: 325; makefile: 26; sh: 2
file content (46 lines) | stat: -rw-r--r-- 961 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# number_anchor.rb
#
# number_anchor: アンカーにid属性を付加する
#          アンカー画像を異なるものにするためのもの
# 	   使用するさいは、設定画面のヘッダに
#	   <%= use_number_anchor( アンカーの種数 ) %>
#	   と書いてください。
#
# Copyright (C) 2002 by zoe <http://www.kasumi.sakura.ne.jp/~zoe/tdiary/>
# Distributed under the GPL2 or any later version.
#

def use_number_anchor( n = 1 )
	@use_number_anchor = true
	@total_anchor = n
	""
end

alias :_orig_anchor :anchor

def anchor( s )
	if @use_number_anchor == true then
	if /^(\d+)#?([pct])?(\d*)?$/ =~ s then
		if $2 then
			n = $3.to_i
			if n && n > @total_anchor then
				n = (n % @total_anchor)
			end
			"#{_orig_anchor(s)}\" class=\"#$2#{'%02d' % n}"
		else
			_orig_anchor(s)
		end
	else
		""
	end
	else
		_orig_anchor(s)
	end
end

# Local Variables:
# mode: ruby
# indent-tabs-mode: t
# tab-width: 3
# ruby-indent-level: 3
# End: