Skip to content

Commit

Permalink
latex header
Browse files Browse the repository at this point in the history
  • Loading branch information
milesstoetzner committed Sep 21, 2024
1 parent 6459cc9 commit 12dc9bc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,6 @@ topology_template:
is_customer: {equal: [{variability_input: env}, CUSTOMER]}
is_development: {equal: [{variability_input: env}, DEVELOPMENT]}

# TODO: remove these
options:
#technology_constraint: false
#required_technology_check: false
#required_artifact_constraint: false
#expected_artifact_check: true

inputs:
env:
type: string
Expand Down
4 changes: 3 additions & 1 deletion src/controller/utils/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ export type RuleOptions = {

export default async function (options: RuleOptions) {
options.format = options.format ?? 'yaml'
return files.toFormat(Registry.rules, options.format)
return files.toFormat(Registry.rules, options.format, {
latex: {headers: ['component', 'artifact', 'hosting', 'technology', 'weight']},
})
}
33 changes: 17 additions & 16 deletions src/utils/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,35 +163,36 @@ export async function loadXML<T>(file: string) {
return (await xml2js.parseStringPromise(loadFile(file) /*, options */)) as T
}

export function toFormat(obj: any, format: string) {
export function toFormat(obj: any, format: string, options: {latex?: LatexOptions} = {}) {
if (format === 'yaml') return toYAML(obj)
if (format === 'json') return toJSON(obj)
if (format === 'ini') return toINI(obj)
if (format === 'env') return toENV(obj)
if (format === 'xml') return toXML(obj)
if (format === 'latex') return toLatex(obj)
if (format === 'latex') return toLatex(obj, options.latex)

throw new Error(`Format "${format}" not supported`)
}

export function toLatex(obj: any) {
export type LatexOptions = {
headers?: string[]
}

export function toLatex(obj: any, options: LatexOptions = {}) {
assert.isArray(obj)
// TODO: this is dirty
const list = obj as {[key: string]: any}[]

/**
* Collect all possible keys
const keys = new Set<string>()
list.forEach(item => {
Object.keys(item).forEach(key => keys.add(key))
})
// TODO: remove this
keys.delete('details')
keys.delete('reason')
*/
// Collect all possible keys
const defaultKeys = () => {
const dk: string[] = []
list.forEach(item => {
Object.keys(item).forEach(key => keys.push(key))
})
return dk
}

const keys = ['component', 'artifact', 'hosting', 'technology', 'weight']
const keys = options.headers ?? defaultKeys()

const data = []

Expand All @@ -210,7 +211,7 @@ export function toLatex(obj: any) {
for (const key of keys) {
const raw = item[key]
// TODO: not latex safe
const string = JSON.stringify(raw)
const value = JSON.stringify(raw)
tmp.push(raw)
}
data.push(tmp.join(' & ') + '\\\\')
Expand Down

0 comments on commit 12dc9bc

Please sign in to comment.