<commit_before>local book = SILE.require("classes/book")
local plain = SILE.require("classes/plain")
local cabook = book { id = "cabook" }

cabook:declareOption("crop", "true")
cabook:declareOption("background", "true")
cabook:declareOption("verseindex", "false")

cabook.init = function (self)
  if cabook.options.crop() == "true" then
    cabook:loadPackage("crop", CASILE.casiledir)
  end
  if cabook.options.verseindex() == "true" then
    cabook:loadPackage("verseindex", CASILE.casiledir)
  else
    SILE.registerCommand("markverse", function (options, content) end)
  end
  return book:init()
end

cabook.endPage = function (self)
  cabook:moveTocNodes()
  if cabook.moveTovNodes then cabook:moveTovNodes() end

  if not SILE.scratch.headers.skipthispage then
    SILE.settings.pushState()
    SILE.settings.reset()
    if cabook:oddPage() then
      SILE.call("output-right-running-head")
    else
      SILE.call("output-left-running-head")
    end
    SILE.settings.popState()
  end
  SILE.scratch.headers.skipthispage = false

  local ret = plain.endPage(cabook)
  if cabook.options.crop() == "true" then cabook:outputCropMarks() end
  return ret
end

cabook.finish = function (self)
  if cabook.moveTovNodes then
    cabook:writeTov()
    SILE.call("tableofverses")
  end
  return book:finish()
end

-- CaSILE books sometimes have sections, sometimes don't.
-- Initialize some sectioning levels to work either way
SILE.scratch.counters["sectioning"] = {
  value =  { 0, 0 },
  display = { "ORDINAL", "STRING" }
}

-- I can't figure out how or where, but book.endPage() gets run on the last page
book.endPage = cabook.endPage

return cabook
<commit_msg>Add class option for binding type (will affect some layouts)<commit_after>local book = SILE.require("classes/book")
local plain = SILE.require("classes/plain")
local cabook = book { id = "cabook" }

cabook:declareOption("binding", "none") -- none, paperback, hardcover, stapled
cabook:declareOption("crop", "true")
cabook:declareOption("background", "true")
cabook:declareOption("verseindex", "false")

cabook.init = function (self)
  if cabook.options.crop() == "true" then
    cabook:loadPackage("crop", CASILE.casiledir)
  end
  if cabook.options.verseindex() == "true" then
    cabook:loadPackage("verseindex", CASILE.casiledir)
  else
    SILE.registerCommand("markverse", function (options, content) end)
  end
  return book:init()
end

cabook.endPage = function (self)
  cabook:moveTocNodes()
  if cabook.moveTovNodes then cabook:moveTovNodes() end

  if not SILE.scratch.headers.skipthispage then
    SILE.settings.pushState()
    SILE.settings.reset()
    if cabook:oddPage() then
      SILE.call("output-right-running-head")
    else
      SILE.call("output-left-running-head")
    end
    SILE.settings.popState()
  end
  SILE.scratch.headers.skipthispage = false

  local ret = plain.endPage(cabook)
  if cabook.options.crop() == "true" then cabook:outputCropMarks() end
  return ret
end

cabook.finish = function (self)
  if cabook.moveTovNodes then
    cabook:writeTov()
    SILE.call("tableofverses")
  end
  return book:finish()
end

-- CaSILE books sometimes have sections, sometimes don't.
-- Initialize some sectioning levels to work either way
SILE.scratch.counters["sectioning"] = {
  value =  { 0, 0 },
  display = { "ORDINAL", "STRING" }
}

-- I can't figure out how or where, but book.endPage() gets run on the last page
book.endPage = cabook.endPage

return cabook

{'fraction_non_alphanumeric': 0.1270990156340475, 'fraction_numerical': 0.0011580775911986102, 'mean_word_length': 4.2909647779479325, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7092447', 'n_tokens_mistral': 1199, 'n_tokens_neox': 1180, 'n_words': 283}