Merge branch 'development' into development_fix_hero_and_ci
* development: ... # Conflicts: # lib/core/herocmds/docusaurus.v # lib/data/encoderhero/decoder.v # lib/data/encoderhero/postgres_client_decoder_test.v # lib/web/site/play.v
This commit is contained in:
@@ -19,12 +19,12 @@ fn decode_struct[T](_ T, data string) !T {
|
||||
mut typ := T{}
|
||||
// println(data)
|
||||
$if T is $struct {
|
||||
obj_name := texttools.snake_case(T.name.all_after_last('.'))
|
||||
mut action_name := 'define.${obj_name}'
|
||||
obj_name := T.name.all_after_last('.').to_lower()
|
||||
mut action_name := '${obj_name}.define'
|
||||
if !data.contains(action_name) {
|
||||
action_name = 'configure.${obj_name}'
|
||||
action_name = '${obj_name}.configure'
|
||||
if !data.contains(action_name) {
|
||||
return error('Data does not contain action name: define.${obj_name} or ${action_name}')
|
||||
return error('Data does not contain action name: ${obj_name}.define or ${action_name}')
|
||||
}
|
||||
}
|
||||
actions_split := data.split('!!')
|
||||
|
||||
@@ -118,7 +118,7 @@ pub fn (mut e Encoder) encode_struct[T](t T) ! {
|
||||
mut mytype := reflection.type_of[T](t)
|
||||
struct_attrs := attrs_get_reflection(mytype)
|
||||
|
||||
mut action_name := texttools.snake_case(T.name.all_after_last('.'))
|
||||
mut action_name := T.name.all_after_last('.').to_lower()
|
||||
// println('action_name: ${action_name} ${T.name}')
|
||||
if 'alias' in struct_attrs {
|
||||
action_name = struct_attrs['alias'].to_lower()
|
||||
|
||||
@@ -10,12 +10,12 @@ pub mut:
|
||||
dbname string = 'postgres'
|
||||
}
|
||||
|
||||
const postgres_client_blank = '!!define.postgresql_client'
|
||||
const postgres_client_full = '!!define.postgresql_client name:production user:app_user port:5433 host:db.example.com password:secret123 dbname:myapp'
|
||||
const postgres_client_partial = '!!define.postgresql_client name:dev host:localhost password:devpass'
|
||||
const postgres_client_blank = '!!postgresql_client.configure'
|
||||
const postgres_client_full = '!!postgresql_client.configure name:production user:app_user port:5433 host:db.example.com password:secret123 dbname:myapp'
|
||||
const postgres_client_partial = '!!postgresql_client.configure name:dev host:localhost password:devpass'
|
||||
|
||||
const postgres_client_complex = '
|
||||
!!define.postgresql_client name:staging user:stage_user port:5434 host:staging.db.com password:stagepass dbname:stagingdb
|
||||
!!postgresql_client.configure name:staging user:stage_user port:5434 host:staging.db.com password:stagepass dbname:stagingdb
|
||||
'
|
||||
|
||||
fn test_postgres_client_decode_blank() ! {
|
||||
@@ -136,17 +136,17 @@ const play_script = '
|
||||
# PostgresqlClient Encode/Decode Play Script
|
||||
# This script demonstrates encoding and decoding PostgresqlClient configurations
|
||||
|
||||
!!define.postgresql_client name:playground user:play_user
|
||||
port:5432
|
||||
host:localhost
|
||||
password:playpass
|
||||
!!postgresql_client.configure name:playground user:play_user
|
||||
port:5432
|
||||
host:localhost
|
||||
password:playpass
|
||||
dbname:playdb
|
||||
|
||||
# You can also use partial configurations
|
||||
!!define.postgresql_client name:quick_test host:127.0.0.1
|
||||
!!postgresql_client.configure name:quick_test host:127.0.0.1
|
||||
|
||||
# Default configuration (all defaults)
|
||||
!!define.postgresql_client
|
||||
!!postgresql_client.configure
|
||||
'
|
||||
|
||||
fn test_play_script() ! {
|
||||
@@ -158,7 +158,7 @@ fn test_play_script() ! {
|
||||
mut clients := []PostgresqlClient{}
|
||||
|
||||
for line in lines {
|
||||
if line.starts_with('!!define.postgresql_client') {
|
||||
if line.starts_with('!!postgresql_client.configure') {
|
||||
client := decode[PostgresqlClient](line)!
|
||||
clients << client
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
module elements
|
||||
|
||||
|
||||
//TODO: def is broken, way how we do it is bad
|
||||
// TODO: def is broken, way how we do it is bad
|
||||
|
||||
@[heap]
|
||||
pub struct Def {
|
||||
|
||||
@@ -39,7 +39,7 @@ fn (self Paragraph) html() !string {
|
||||
mut out := self.DocBase.html()! // the children should have all the content
|
||||
if self.children.len == 1 {
|
||||
if out.trim_space() != '' {
|
||||
if self.children[0] or { panic("bug") } is Link {
|
||||
if self.children[0] or { panic('bug') } is Link {
|
||||
return out
|
||||
} else {
|
||||
return out
|
||||
|
||||
@@ -26,13 +26,13 @@ struct TestChild {
|
||||
}
|
||||
|
||||
const test_child = TestChild{
|
||||
child_name: 'test_child'
|
||||
child_number: 3
|
||||
child_yesno: false
|
||||
child_liststr: ['three', 'four']
|
||||
child_listint: [3, 4]
|
||||
child_name: 'test_child'
|
||||
child_number: 3
|
||||
child_yesno: false
|
||||
child_liststr: ['three', 'four']
|
||||
child_listint: [3, 4]
|
||||
child_listbool: [true, false]
|
||||
child_listu32: [u32(5), u32(6)]
|
||||
child_listu32: [u32(5), u32(6)]
|
||||
}
|
||||
|
||||
const test_struct = TestStruct{
|
||||
@@ -51,7 +51,6 @@ const test_struct = TestStruct{
|
||||
child: test_child
|
||||
}
|
||||
|
||||
|
||||
const test_child_params = Params{
|
||||
params: [
|
||||
Param{
|
||||
@@ -116,7 +115,6 @@ const test_params = Params{
|
||||
}]
|
||||
}
|
||||
|
||||
|
||||
fn test_encode_struct() {
|
||||
encoded_struct := encode[TestStruct](test_struct)!
|
||||
assert encoded_struct == test_params
|
||||
|
||||
Reference in New Issue
Block a user