项目作者: RoyalIcing

项目描述 :
Friendly syntax for creating schemas, output to Swift, React PropTypes, Elm, Golang, MongoDB, and more
高级语言: JavaScript
项目地址: git://github.com/RoyalIcing/lofi-schema-elm.git
创建时间: 2017-04-01T05:04:55Z
项目社区:https://github.com/RoyalIcing/lofi-schema-elm

开源协议:

下载


#lofi #schema in Elm

Low fidelity schemas. Write with a friendly syntax and convert to other forms easily.

Interactive demo

I’ve made an online tool to convert #lofi schemas. Convert to React PropTypes, Mongoose schemas, Joi validations, and MySQL commands.

Basic usage

  1. import Html exposing (Html, section, h2, pre, text)
  2. import Lofi.Parse exposing (parseElement)
  3. import Lofi.Schema exposing (Schema, fromElement)
  4. import Lofi.Schema.Output.MySQL as MySQL
  5. import Lofi.Schema.Output.Mongoose as Mongoose
  6. import Lofi.Schema.Output.Joi as Joi
  7. import Lofi.Schema.Output.ReactProps as ReactProps
  8. import Lofi.Schema.Output.Swift as Swift
  9. import Lofi.Schema.Output.Elm as Elm
  10. import Lofi.Schema.Output.Go as Go
  11. type alias Model =
  12. { collectionName : String
  13. , individualName : String
  14. , lines : List String
  15. }
  16. model : Model
  17. model =
  18. { collectionName = "Users"
  19. , individualName = "User"
  20. , lines =
  21. [ "First name"
  22. , "Middle name #optional"
  23. , "Last name #text #max: 255"
  24. , "Email #email"
  25. , "Date of birth #date"
  26. , "Last signed in at #time #now"
  27. , "Favorite number #number #default: 7"
  28. ]
  29. }
  30. view : Model -> Html Msg
  31. view model =
  32. let
  33. elements =
  34. List.map parseElement model.lines
  35. schema : Schema
  36. schema =
  37. { collectionName = model.collectionName
  38. , individualName = model.individualName
  39. , items = List.map fromElement elements
  40. }
  41. in
  42. section []
  43. [ article []
  44. [ h2 [] [ text "React PropTypes" ]
  45. , pre [] [ text (ReactProps.createPropTypesCode schema) ]
  46. ]
  47. , article []
  48. [ h2 [] [ text "Mongoose" ]
  49. , pre [] [ text (Mongoose.createModelCode schema) ]
  50. ]
  51. , article []
  52. [ h2 [] [ text "Swift" ]
  53. , pre [] [ text (Swift.createStructCode schema) ]
  54. ]
  55. , article []
  56. [ h2 [] [ text "Elm" ]
  57. , pre [] [ text (Elm.createTypeAliasCode schema) ]
  58. ]
  59. , article []
  60. [ h2 [] [ text "Golang" ]
  61. , pre [] [ text (Go.createStructCode schema) ]
  62. ]
  63. , article []
  64. [ h2 [] [ text "Joi" ]
  65. , pre [] [ text (Joi.createSchemaCode schema) ]
  66. ]
  67. , article []
  68. [ h2 [] [ text "MySQL" ]
  69. , pre [] [ text (MySQL.createTableCommand schema) ]
  70. , pre [] [ text (MySQL.insertRowCommand schema) ]
  71. ]
  72. ]