Skip to content

Commit dbac29f

Browse files
Merge pull request #362 from tir38/tir38/update-templates
Update templates
2 parents ca547f8 + 048c96d commit dbac29f

File tree

3 files changed

+127
-38
lines changed

3 files changed

+127
-38
lines changed
Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
#set( $LayoutRunnerName = "${NAME}LayoutRunner" )
2-
#set( $ViewBindingName = "YourViewBinding" )
3-
#set( $RenderingName = "YourRendering" )
1+
## Unlike the Workflow Templates, we never generate inner classes for view bindings
2+
## or rendering types. i.e. they are never "optional"
43
package ${PACKAGE_NAME}
54

65
import com.squareup.workflow1.ui.LayoutRunner
@@ -10,20 +9,19 @@ import com.squareup.workflow1.ui.ViewFactory
109
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
1110

1211
#parse("File Header.java")
13-
// TODO Change "YourViewBinding" and "YourRendering" to your actual types.
1412
@OptIn(WorkflowUiExperimentalApi::class)
15-
class $LayoutRunnerName(
16-
private val binding: ${ViewBindingName}
17-
) : LayoutRunner<${RenderingName}> {
13+
class $Name(
14+
private val binding: $VIEW_BINDING_TYPE
15+
) : LayoutRunner<$RENDERING_TYPE> {
1816

1917
override fun showRendering(
20-
rendering: ${RenderingName},
18+
rendering: $RENDERING_TYPE,
2119
viewEnvironment: ViewEnvironment
2220
) {
2321
TODO("Update ViewBinding from rendering")
2422
}
2523

26-
companion object : ViewFactory<${RenderingName}> by bind(
27-
${ViewBindingName}::inflate, ::$LayoutRunnerName
24+
companion object : ViewFactory<$RENDERING_TYPE> by bind(
25+
$VIEW_BINDING_TYPE::inflate, ::$NAME
2826
)
2927
}

fileTemplates/Stateful Workflow.kt

Lines changed: 69 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,87 @@
1-
#set( $WorkflowName = "${NAME}Workflow" )
2-
package ${PACKAGE_NAME}
1+
#set ($prefix = $NAME.replace('Workflow', '') )
2+
## build props string
3+
#if( $PROPS_TYPE_OPTIONAL == '')
4+
#set ($props_type = $prefix + "Props")
5+
#else
6+
#set ($props_type = $PROPS_TYPE_OPTIONAL)
7+
#end
8+
## build state string
9+
#if( $STATE_TYPE_OPTIONAL == '')
10+
#set ($state_type = $prefix + "State")
11+
#else
12+
#set ($state_type = $STATE_TYPE_OPTIONAL)
13+
#end
14+
## build output string
15+
#if( $OUTPUT_TYPE_OPTIONAL == '')
16+
#set ($output_type = $prefix + "Output")
17+
#else
18+
#set ($output_type = $OUTPUT_TYPE_OPTIONAL)
19+
#end
20+
## build rendering string
21+
#if( $RENDERING_TYPE_OPTIONAL == '')
22+
#set ($rendering_type = $prefix + "Rendering")
23+
#else
24+
#set ($rendering_type = $RENDERING_TYPE_OPTIONAL)
25+
#end
26+
package $PACKAGE_NAME
327

428
import com.squareup.workflow1.Snapshot
529
import com.squareup.workflow1.StatefulWorkflow
6-
import ${PACKAGE_NAME}.${WorkflowName}.Output
7-
import ${PACKAGE_NAME}.${WorkflowName}.Props
8-
import ${PACKAGE_NAME}.${WorkflowName}.Rendering
9-
import ${PACKAGE_NAME}.${WorkflowName}.State
30+
31+
#if( $PROPS_TYPE_OPTIONAL == '') ## import if we create below
32+
import $PACKAGE_NAME.$NAME.$props_type
33+
#end
34+
#if( $STATE_TYPE_OPTIONAL == '') ## import if we create below
35+
import $PACKAGE_NAME.$NAME.$state_type
36+
#end
37+
#if( $OUTPUT_TYPE_OPTIONAL == '') ## import if we create below
38+
import $PACKAGE_NAME.$NAME.$output_type
39+
#end
40+
#if( $RENDERING_TYPE_OPTIONAL == '') ## import if we create below
41+
import $PACKAGE_NAME.$NAME.$rendering_type
42+
#end
1043

1144
#parse("File Header.java")
12-
class ${WorkflowName} : StatefulWorkflow<Props, State, Output, Rendering>() {
45+
object $NAME : StatefulWorkflow<$props_type, $state_type, $output_type, $rendering_type>() {
1346

14-
data class Props
15-
data class State
16-
data class Output
17-
data class Rendering
47+
#if( $PROPS_TYPE_OPTIONAL == '') ## create if not supplied
48+
data class $props_type(
49+
// TODO add args
50+
)
51+
#end
52+
53+
#if( $STATE_TYPE_OPTIONAL == '') ## create if not supplied
54+
data class $state_type(
55+
// TODO add args
56+
)
57+
#end
58+
59+
#if( $OUTPUT_TYPE_OPTIONAL == '') ## create if not supplied
60+
data class $output_type(
61+
// TODO add args
62+
)
63+
#end
64+
65+
#if( $RENDERING_TYPE_OPTIONAL == '') ## create if not supplied
66+
data class $rendering_type(
67+
// TODO add args
68+
)
69+
#end
1870

1971
override fun initialState(
20-
props: Props,
72+
props: $props_type,
2173
snapshot: Snapshot?
22-
): State = TODO("Initialize state")
74+
): $state_type = TODO("Initialize state")
2375

2476
override fun render(
25-
renderProps: Props,
26-
renderState: State,
77+
props: $props_type,
78+
state: $state_type,
2779
context: RenderContext
28-
): Rendering {
80+
): $rendering_type {
2981
TODO("Render")
3082
}
3183

32-
override fun snapshotState(state: State): Snapshot? = Snapshot.write {
84+
override fun snapshotState(state: $state_type): Snapshot? = Snapshot.write {
3385
TODO("Save state")
3486
}
3587
}

fileTemplates/Stateless Workflow.kt

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,61 @@
1-
#set( $WorkflowName = "${NAME}Workflow" )
2-
package ${PACKAGE_NAME}
1+
#set ($prefix = $NAME.replace('Workflow', '') )
2+
## build props string
3+
#if( $PROPS_TYPE_OPTIONAL == '')
4+
#set ($props_type = $prefix + "Props")
5+
#else
6+
#set ($props_type = $PROPS_TYPE_OPTIONAL)
7+
#end
8+
## build output string
9+
#if( $OUTPUT_TYPE_OPTIONAL == '')
10+
#set ($output_type = $prefix + "Output")
11+
#else
12+
#set ($output_type = $OUTPUT_TYPE_OPTIONAL)
13+
#end
14+
## build rendering string
15+
#if( $RENDERING_TYPE_OPTIONAL == '')
16+
#set ($rendering_type = $prefix + "Rendering")
17+
#else
18+
#set ($rendering_type = $RENDERING_TYPE_OPTIONAL)
19+
#end
20+
package $PACKAGE_NAME
321

422
import com.squareup.workflow1.StatelessWorkflow
5-
import ${PACKAGE_NAME}.${WorkflowName}.Output
6-
import ${PACKAGE_NAME}.${WorkflowName}.Props
7-
import ${PACKAGE_NAME}.${WorkflowName}.Rendering
23+
24+
#if( $PROPS_TYPE_OPTIONAL == '') ## import if we create below
25+
import $PACKAGE_NAME.$NAME.$props_type
26+
#end
27+
#if( $OUTPUT_TYPE_OPTIONAL == '') ## import if we create below
28+
import $PACKAGE_NAME.$NAME.$output_type
29+
#end
30+
#if( $RENDERING_TYPE_OPTIONAL == '') ## import if we create below
31+
import $PACKAGE_NAME.$NAME.$rendering_type
32+
#end
833

934
#parse("File Header.java")
10-
class ${WorkflowName} : StatelessWorkflow<Props, Output, Rendering>() {
35+
object $NAME : StatelessWorkflow<$props_type, $output_type, $rendering_type>() {
36+
37+
#if( $PROPS_TYPE_OPTIONAL == '') ## create if not supplied
38+
data class $props_type(
39+
// TODO add args
40+
)
41+
#end
1142

12-
data class Props
13-
data class Output
14-
data class Rendering
43+
#if( $OUTPUT_TYPE_OPTIONAL == '') ## create if not supplied
44+
data class $output_type(
45+
// TODO add args
46+
)
47+
#end
48+
49+
#if( $RENDERING_TYPE_OPTIONAL == '') ## create if not supplied
50+
data class $rendering_type(
51+
// TODO add args
52+
)
53+
#end
1554

1655
override fun render(
17-
renderProps: Props,
56+
props: $props_type,
1857
context: RenderContext
19-
): Rendering {
58+
): $rendering_type {
2059
TODO("Render")
2160
}
2261
}

0 commit comments

Comments
 (0)