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

Commit

Permalink
new: allow form.metadata.htitle to override settings sheet form title.
Browse files Browse the repository at this point in the history
* this accounts for the "Title on Device" form properties setting in the
  ODK Build UI.
* progress on getodk/build#154 .
  • Loading branch information
issa-tseng committed Jul 6, 2017
1 parent 7e52b27 commit 791778e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
8 changes: 6 additions & 2 deletions lib/convert.js

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

4 changes: 4 additions & 0 deletions spec/src/convert-form-spec.ls
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,10 @@ describe 'settings generation' ->
expect(result[1][0]).toBe(\myform)
expect(result[1][1]).toMatch(/build_myform_[0-9]+/)

test 'uses metadata htitle for form title if provided' ->
result = gen-settings({ title: \myform, metadata: { htitle: 'override title' } })
expect(result[1][0]).toBe('override title')

test 'sanitizes form title' ->
result = gen-settings({ title: 'Untitled! Test Form' })
expect(result[1][1]).toMatch(/build_Untitled-Test-Form_[0-9]+/)
Expand Down
7 changes: 6 additions & 1 deletion src/convert.ls
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,12 @@ convert-question = (question, context, prefix = []) ->
# return. context is mutated (:/) so does not need to be returned.
question

gen-settings = (form) -> [ [ \form_title, \form_id ], [ form.title, "build_#{form.title?.replace(/([^a-z0-9]+)/ig, '-')}_#{Math.floor((new Date()).getTime() / 1000)}" ] ]
gen-settings = (form) ->
form-title = if is-nonsense(form.metadata?.htitle) then form.title else form.metadata?.htitle
form-id = "build_#{form.title?.replace(/([^a-z0-9]+)/ig, '-')}_#{Math.floor((new Date()).getTime() / 1000)}"

[ [ \form_title, \form_id ],
[ form-title, form-id ] ]

# the main show.
convert-form = (form) ->
Expand Down

0 comments on commit 791778e

Please sign in to comment.