mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-17 21:40:39 -07:00
feat: tablerowloop object
See: https://www.rubydoc.info/gems/liquid/Liquid/TablerowloopDrop
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import { Drop } from './drop'
|
||||
|
||||
export class ForloopDrop extends Drop {
|
||||
protected i: number = 0
|
||||
length: number
|
||||
constructor (length: number) {
|
||||
super()
|
||||
this.length = length
|
||||
}
|
||||
next () {
|
||||
this.i++
|
||||
}
|
||||
index0 () {
|
||||
return this.i
|
||||
}
|
||||
index () {
|
||||
return this.i + 1
|
||||
}
|
||||
first () {
|
||||
return this.i === 0
|
||||
}
|
||||
last () {
|
||||
return this.i === this.length - 1
|
||||
}
|
||||
rindex () {
|
||||
return this.length - this.i
|
||||
}
|
||||
rindex0 () {
|
||||
return this.length - this.i - 1
|
||||
}
|
||||
valueOf () {
|
||||
return JSON.stringify(this)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import { ForloopDrop } from './forloop-drop'
|
||||
|
||||
export class TablerowloopDrop extends ForloopDrop {
|
||||
private cols: number
|
||||
constructor (length: number, cols: number) {
|
||||
super(length)
|
||||
this.length = length
|
||||
this.cols = cols
|
||||
}
|
||||
row () {
|
||||
return Math.floor(this.i / this.cols) + 1
|
||||
}
|
||||
col0 () {
|
||||
return (this.i % this.cols)
|
||||
}
|
||||
col () {
|
||||
return this.col0() + 1
|
||||
}
|
||||
col_first () { // eslint-disable-line
|
||||
return this.col0() === 0
|
||||
}
|
||||
col_last () { // eslint-disable-line
|
||||
return this.col() === this.cols
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user