Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
purescript-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Grégoire Locqueville
purescript-gargantext
Commits
8c37dc08
Commit
8c37dc08
authored
Jul 19, 2020
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[CodeType] Adding Python for reading
parent
09e2e9d6
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
76 additions
and
11 deletions
+76
-11
CodeEditor.css
dist/styles/CodeEditor.css
+4
-0
CodeEditor.sass
dist/styles/CodeEditor.sass
+3
-0
CodeEditor.purs
src/Gargantext/Components/CodeEditor.purs
+15
-2
Corpus.purs
src/Gargantext/Components/Nodes/Corpus.purs
+27
-7
Types.purs
src/Gargantext/Components/Nodes/Corpus/Types.purs
+27
-2
No files found.
dist/styles/CodeEditor.css
View file @
8c37dc08
...
...
@@ -109,6 +109,10 @@
font-family
:
Fira
code
,
Fira
Mono
,
Consolas
,
Menlo
,
Courier
,
monospace
;
white-space
:
pre
;
}
.code-editor
.editor
.html.language-python
{
font-family
:
Fira
code
,
Fira
Mono
,
Consolas
,
Menlo
,
Courier
,
monospace
;
white-space
:
pre
;
}
.code-editor
.editor
.html.language-json
{
font-family
:
Fira
code
,
Fira
Mono
,
Consolas
,
Menlo
,
Courier
,
monospace
;
white-space
:
pre
;
...
...
dist/styles/CodeEditor.sass
View file @
8c37dc08
...
...
@@ -89,6 +89,9 @@
&
.language-haskell
font-family
:
Fira
code
,
Fira
Mono
,
Consolas
,
Menlo
,
Courier
,
monospace
white-space
:
pre
&
.language-python
font-family
:
Fira
code
,
Fira
Mono
,
Consolas
,
Menlo
,
Courier
,
monospace
white-space
:
pre
&
.language-json
font-family
:
Fira
code
,
Fira
Mono
,
Consolas
,
Menlo
,
Courier
,
monospace
white-space
:
pre
...
...
src/Gargantext/Components/CodeEditor.purs
View file @
8c37dc08
...
...
@@ -28,7 +28,8 @@ type Code = String
type Html = String
type Error = String
data CodeType = Haskell | JSON | Markdown
data CodeType = Haskell | JSON | Markdown | Python
derive instance genericCodeType :: Generic CodeType _
instance eqCodeType :: Eq CodeType where
eq = genericEq
...
...
@@ -56,6 +57,7 @@ codeNlFix _ c = if endsWith "\n" c then (c <> " ") else c
render :: CodeType -> Code -> Either Error Html
render Haskell code = Right $ renderHaskell $ codeNlFix Haskell code
render Python code = Right $ renderPython $ codeNlFix Python code
render JSON code = result
where
parsedE = jsonParser code
...
...
@@ -67,8 +69,13 @@ render Markdown code = Right $ renderMd $ codeNlFix Markdown code
previewPostProcess :: CodeType -> Element -> Effect Unit
previewPostProcess Haskell htmlEl = do
HLJS.highlightBlock htmlEl
previewPostProcess Python htmlEl = do
HLJS.highlightBlock htmlEl
previewPostProcess JSON htmlEl = do
HLJS.highlightBlock htmlEl
previewPostProcess Markdown _ = pure unit
-- TODO Replace with markdown-it?
...
...
@@ -84,6 +91,10 @@ renderMd = renderMd' MD.defaultToMarkupOptions
renderHaskell :: String -> String
renderHaskell s = s
renderPython :: String -> String
renderPython s = s
codeEditor :: Record Props -> R.Element
codeEditor p = R.createElement codeEditorCpt p []
...
...
@@ -144,6 +155,7 @@ codeEditorCpt = R.hooksComponent "G.C.CE.CodeEditor" cpt
langClass Haskell = " language-haskell"
langClass JSON = " language-json"
langClass Markdown = " language-md"
langClass Python = " language-python"
previewHidden :: ViewType -> String
previewHidden Preview = ""
...
...
@@ -244,7 +256,7 @@ codeTypeSelectorCpt = R.hooksComponent "G.C.CE.CodeTypeSelector" cpt
, on: { change: onSelectChange codeType onChange }
, style: { width: "150px" }
}
(option <$> [
Haskell, JSON, Markdow
n])
(option <$> [
JSON, Markdown, Haskell, Pytho
n])
option :: CodeType -> R.Element
option value = H.option { value: show value } [ H.text $ show value ]
...
...
@@ -255,6 +267,7 @@ codeTypeSelectorCpt = R.hooksComponent "G.C.CE.CodeTypeSelector" cpt
"Haskell" -> Haskell
"JSON" -> JSON
"Markdown" -> Markdown
"Python" -> Python
_ -> Markdown
setCodeType $ const codeType
onChange codeType
...
...
src/Gargantext/Components/Nodes/Corpus.purs
View file @
8c37dc08
...
...
@@ -20,7 +20,7 @@ import Gargantext.Prelude
import Gargantext.Components.CodeEditor as CE
import Gargantext.Components.Node (NodePoly(..), HyperdataList)
import Gargantext.Components.Nodes.Corpus.Types (CorpusData, FTField, Field(..), FieldType(..), Hash, Hyperdata(..), defaultField, defaultHaskell', defaultJSON', defaultMarkdown')
import Gargantext.Components.Nodes.Corpus.Types (CorpusData, FTField, Field(..), FieldType(..), Hash, Hyperdata(..), defaultField, defaultHaskell', default
Python', default
JSON', defaultMarkdown')
import Gargantext.Data.Array as GDA
import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Routes (SessionRoute(NodeAPI, Children))
...
...
@@ -312,25 +312,45 @@ fieldCodeEditorCpt = R.hooksComponent "G.C.N.C.fieldCodeEditorCpt" cpt
where
cpt {field: Field {typ: typ@(Haskell {haskell})}, onChange} _ = do
pure $ CE.codeEditor {code: haskell, defaultCodeType: CE.Haskell, onChange: changeCode onChange typ}
cpt {field: Field {typ: typ@(Python {python})}, onChange} _ = do
pure $ CE.codeEditor {code: python, defaultCodeType: CE.Python, onChange: changeCode onChange typ}
cpt {field: Field {typ: typ@(JSON j)}, onChange} _ = do
pure $ CE.codeEditor {code, defaultCodeType: CE.JSON, onChange: changeCode onChange typ}
where
code = R2.stringify (encodeJson j) 2
cpt {field: Field {typ: typ@(Markdown {text})}, onChange} _ = do
pure $ CE.codeEditor {code: text, defaultCodeType: CE.Markdown, onChange: changeCode onChange typ}
-- Per
of
rms the matrix of code type changes
-- Per
fo
rms the matrix of code type changes
-- (FieldType -> Effect Unit) is the callback function for fields array
-- FieldType is the current element that we will modify
-- CE.CodeType is the editor code type (might have been the cause of the trigger)
-- CE.Code is the editor code (might have been the cause of the trigger)
changeCode :: (FieldType -> Effect Unit) -> FieldType -> CE.CodeType -> CE.Code -> Effect Unit
changeCode onc (Haskell hs) CE.Haskell c = onc $ Haskell $ hs { haskell = c }
changeCode onc (Haskell {haskell}) CE.JSON c = onc $ JSON $ defaultJSON' { desc = haskell }
changeCode onc (Haskell hs) CE.Haskell c = onc $ Haskell $ hs { haskell = c }
changeCode onc (Haskell hs) CE.Python c = onc $ Python $ defaultPython' { python = c }
changeCode onc (Haskell {haskell}) CE.JSON c = onc $ JSON $ defaultJSON' { desc = haskell }
changeCode onc (Haskell {haskell}) CE.Markdown c = onc $ Markdown $ defaultMarkdown' { text = haskell }
changeCode onc (Python hs) CE.Python c = onc $ Python $ hs { python = c }
changeCode onc (Python hs) CE.Haskell c = onc $ Haskell $ defaultHaskell' { haskell = c }
changeCode onc (Python {python}) CE.JSON c = onc $ JSON $ defaultJSON' { desc = python }
changeCode onc (Python {python}) CE.Markdown c = onc $ Markdown $ defaultMarkdown' { text = python }
changeCode onc (Markdown md) CE.Haskell c = onc $ Haskell $ defaultHaskell' { haskell = c }
changeCode onc (Markdown md) CE.Python c = onc $ Python $ defaultPython' { python = c }
changeCode onc (Markdown md) CE.JSON c = onc $ Markdown $ defaultMarkdown' { text = c }
changeCode onc (Markdown md) CE.Markdown c = onc $ Markdown $ md { text = c }
changeCode onc (JSON j@{desc}) CE.Haskell c = onc $ Haskell $ defaultHaskell' { haskell = haskell }
where
haskell = R2.stringify (encodeJson j) 2
changeCode onc (JSON j@{desc}) CE.Python c = onc $ Python $ defaultPython' { python = toCode }
where
toCode = R2.stringify (encodeJson j) 2
changeCode onc (JSON j) CE.JSON c = do
case jsonParser c of
Left err -> log2 "[fieldCodeEditor'] cannot parse json" c
...
...
@@ -340,9 +360,9 @@ changeCode onc (JSON j) CE.JSON c = do
changeCode onc (JSON j) CE.Markdown c = onc $ Markdown $ defaultMarkdown' { text = text }
where
text = R2.stringify (encodeJson j) 2
changeCode onc (Markdown md) CE.Haskell c = onc $ Haskell $ defaultHaskell' { haskell = c }
changeCode onc (Markdown md) CE.JSON c = onc $ Markdown $ defaultMarkdown' { text = c }
changeCode onc (Markdown md) CE.Markdown c = onc $ Markdown $ md { text = c }
type LoadProps =
( nodeId :: Int
...
...
src/Gargantext/Components/Nodes/Corpus/Types.purs
View file @
8c37dc08
...
...
@@ -52,6 +52,10 @@ data FieldType =
Haskell { haskell :: HaskellCode
, tag :: Tag
}
| Python { python :: HaskellCode
, tag :: Tag
}
| JSON { authors :: Author
, desc :: Description
, query :: Query
...
...
@@ -103,6 +107,12 @@ instance decodeFTField :: DecodeJson (Field FieldType) where
haskell <- data_ .: "haskell"
tag <- data_ .: "tag"
pure $ Haskell {haskell, tag}
"Python" -> do
python <- data_ .: "python"
tag <- data_ .: "tag"
pure $ Python {python, tag}
"JSON" -> do
authors <- data_ .: "authors"
desc <- data_ .: "desc"
...
...
@@ -124,8 +134,9 @@ instance encodeFTField :: EncodeJson (Field FieldType) where
~> "type" := typ' typ
~> jsonEmptyObject
where
typ' (Haskell _) = "Haskell"
typ' (JSON _) = "JSON"
typ' (Haskell _) = "Haskell"
typ' (Python _) = "Python"
typ' (JSON _) = "JSON"
typ' (Markdown _) = "Markdown"
instance encodeFieldType :: EncodeJson FieldType where
...
...
@@ -133,6 +144,12 @@ instance encodeFieldType :: EncodeJson FieldType where
"haskell" := haskell
~> "tag" := "HaskellField"
~> jsonEmptyObject
encodeJson (Python {python}) =
"python" := python
~> "tag" := "PythonField"
~> jsonEmptyObject
encodeJson (JSON {authors, desc, query, tag, title}) =
"authors" := authors
~> "desc" := desc
...
...
@@ -145,6 +162,14 @@ instance encodeFieldType :: EncodeJson FieldType where
~> "text" := text
~> jsonEmptyObject
defaultPython :: FieldType
defaultPython = Python defaultPython'
defaultPython' :: { python :: String, tag :: String }
defaultPython' = { python: "import Foo"
, tag : "PythonField"
}
defaultHaskell :: FieldType
defaultHaskell = Haskell defaultHaskell'
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment