모듈:Rating
보이기
{{#css: .template-documentation {
clear: both; margin: 1em 0 0 0; padding: 1em
} /* 아래 상자 */ .mbox-text {
clear: both; background-color: #e8ffe8;
}
.template-documentation-template-data .mw-templatedata-doc-desc {
display: none;
}
}}
이 모듈은 점수를 별 그림으로 출력할 수 있도록 하는 모듈입니다. 이 모듈은 틀:순환에서 사용하는 loop 함수와 틀:등급에서 사용하는 stars 함수로 구성됩니다. 별을 출력하는 별점의 경우에는 소수 부분 m에 대해서
- - 회색 별을 출력(소수 부분 버림)
- - 반쪽 별을 출력
- - 노란 별을 출력(소수 부분 올림)
하게 됩니다.
사용법
loop 함수
{{#invoke:Rating|loop|1= |2= }}
| 변수 이름 | 설명 | 기본값 | 필수 및 선택 여부 |
|---|---|---|---|
| 변수 #1 | 문자열을 반복할 횟수 | 비어 있음 | 필수 |
| 변수 #2 | 반복 출력할 문자열 | 비어 있음 | 필수 |
stars 함수
{{#invoke:Rating|stars|1= |2= }}
| 변수 이름 | 설명 | 기본값 | 필수 및 선택 여부 |
|---|---|---|---|
| 변수 #1 | 평가 점수 | 비어 있음 | 필수 |
| 변수 #2 | 만점일 때 별의 개수 | 비어 있음 | 필수 |
위 설명은 모듈:Rating/설명문서의 내용을 가져와 보여주고 있습니다.
연습장이나 사용자 문서에서 틀의 사용이나 수정을 연습할 수 있습니다.
--한국어 위키백과에서 가져왔습니다.
local rating = {}
function rating.loop(frame)
local times = tonumber( frame.args[1] )
local str = frame.args[2]
return string.rep(str,times)
end
function rating.stars(frame)
local pts = frame.args[1]
local fs = frame.args[2]
local point = tonumber(pts)
local f = tonumber(fs) -- 만점
if point == nil or f == nil then
return '<strong class="error">평가에 대해 명기하십시오.</strong>'
end
if point > f then
return '<strong class="error">점수가 만점보다 높을 수 없습니다.</strong>'
end
-- FIXME: 별 크기 조정 시도 시 스크립트 오류 발생
if f > 6 then
size = "7px"
else
size = "11px"
end
local img_spec = size ..'|' .. pts..'/'..fs..' 별'
local complete_star = '[[그림:Star full.svg|'..img_spec..']]'
local complete_stars = string.rep(complete_star, math.floor(point))
local empty_star = '[[그림:Star empty.svg|'..img_spec..']]'
local empty_stars = string.rep(empty_star, math.floor(f-point))
local minor = point - math.floor(point) -- 판별식
if minor == 0 then -- point+floor(f-point)=point+f-floor(point); if minor = 0 then ans = f else ans = f-1
return complete_stars..empty_stars
elseif minor > 0 and minor <= 0.25 then
return complete_stars..empty_star..empty_stars
elseif minor > 0.25 and minor < 0.75 then
local half_star = '[[그림:Star half.svg|'..img_spec..']]'
return complete_stars..half_star..empty_stars
else
return complete_stars..complete_star..empty_stars
end
end
return rating