Skip to content
This repository has been archived by the owner on Oct 30, 2023. It is now read-only.

Commit

Permalink
Merge pull request #6 from clint-tseng/cxlt/media-types
Browse files Browse the repository at this point in the history
new: support new media appearance types.
  • Loading branch information
issa-tseng authored Mar 6, 2019
2 parents cbb7fb5 + f5bf226 commit 16c6d7f
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 3 deletions.
26 changes: 24 additions & 2 deletions lib/convert.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions spec/src/convert-question-spec.ls
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,50 @@ describe \type ->
test 'media: image' ->
explicit = { type: \inputMedia, kind: \Image } |> convert-simple
expect(explicit.type).toBe(\image)
expect(explicit.appearance).toBeUndefined()

implicit = { type: \inputMedia } |> convert-simple
expect(implicit.type).toBe(\image)

test 'media: image/new' ->
explicit = { type: \inputMedia, kind: 'New Image' } |> convert-simple
expect(explicit.type).toBe(\image)
expect(explicit.appearance).toBe(\new)

test 'media: image/selfie' ->
explicit = { type: \inputMedia, kind: \Selfie } |> convert-simple
expect(explicit.type).toBe(\image)
expect(explicit.appearance).toBe(\new-front)

test 'media: image/annotate' ->
explicit = { type: \inputMedia, kind: \Annotate } |> convert-simple
expect(explicit.type).toBe(\image)
expect(explicit.appearance).toBe(\annotate)

test 'media: image/draw' ->
explicit = { type: \inputMedia, kind: \Draw } |> convert-simple
expect(explicit.type).toBe(\image)
expect(explicit.appearance).toBe(\draw)

test 'media: image/signature' ->
explicit = { type: \inputMedia, kind: \Signature } |> convert-simple
expect(explicit.type).toBe(\image)
expect(explicit.appearance).toBe(\signature)

test 'media: audio' ->
result = { type: \inputMedia, kind: \Audio } |> convert-simple
expect(result.type).toBe(\audio)
expect(result.appearance).toBeUndefined()

test 'media: video' ->
result = { type: \inputMedia, kind: \Video } |> convert-simple
expect(result.type).toBe(\video)
expect(result.appearance).toBeUndefined()

test 'media: video/selfie' ->
result = { type: \inputMedia, kind: 'Selfie Video' } |> convert-simple
expect(result.type).toBe(\video)
expect(result.appearance).toBe(\new-front)

test \barcode ->
result = { type: \inputBarcode } |> convert-simple
Expand Down
24 changes: 23 additions & 1 deletion src/convert.ls
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,24 @@ range-appearance-conversion =
'Vertical Slider': \vertical
'Picker': \picker

media-type-conversion =
'Image': \image
'New Image': \image
'Selfie': \image
'Annotate': \image
'Draw': \image
'Signature': \image
'Audio': \audio
'Video': \video
'Selfie Video': \video
media-appearance-conversion =
'New Image': \new
'Signature': \signature
'Annotate': \annotate
'Draw': \draw
'Selfie': \new-front
'Selfie Video': \new-front

# make unit testing easier.
new-context = -> { seen-fields: {}, choices: {}, warnings: [] }

Expand Down Expand Up @@ -161,6 +179,10 @@ convert-question = (question, context, prefix = []) ->
if question.type is \inputDate
question.appearance = date-kind-conversion[question.kind] if date-type-conversion[question.kind]?

# if media, we may need to apply an appearance.
if question.type is \inputMedia and media-appearance-conversion[question.kind]?
question.appearance = media-appearance-conversion[question.kind]

# field-list appearance.
if (delete question.fieldList) is true
question.appearance = \field-list
Expand All @@ -174,7 +196,7 @@ convert-question = (question, context, prefix = []) ->
else
\range
else if question.type is \inputMedia
((delete question.kind) ? \image).toLowerCase()
media-type-conversion[(delete question.kind) ? 'Image']
else if question.type is \inputDate
date-type-conversion[(delete question.kind) ? 'Full Date']
else if question.type is \inputLocation
Expand Down

0 comments on commit 16c6d7f

Please sign in to comment.