Skip to content

Commit

Permalink
the new stable version
Browse files Browse the repository at this point in the history
  • Loading branch information
Memorytaco committed Apr 14, 2019
1 parent 398915e commit d35bcc7
Show file tree
Hide file tree
Showing 31 changed files with 1,997 additions and 552 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

I have recently successfully build the demo site. And yes, it now will work!

However, i haven't written the tutorial and the manual page. will do this next week.
Now i'm just refing this melt and modefy its api;

## Part Preview
- the init welcome page(use css framework)
Expand All @@ -25,7 +25,7 @@ $ ./melt-install uninstall # use this to uninstall
```

## current status
* [x] add subcommand logic now
- ~~add subcommand logic now~~ done
* will add more subcommands to complete the function
- [x] add init command
- [x] add exec command
Expand Down
23 changes: 23 additions & 0 deletions melt/assert.ss
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!chezscheme
(library
(melt assert)
(export mmessage
massert)
(import (scheme))

;; there are three level errors
;; 'error 'warn 'fatal

;; 'error: the input is not correct, but the program will continue
;; 'warn: the input may induce some error
;; 'fatal: the program will breakdown and quit

;; error format:
;; <error-type>: <error-message> --> <arg-position> :<error-input> || <expect-input>
;; warn format:
;; <warn-type>: <warn-message>
;; fatal format:
;; <fatal-type>: <fatal-message> <fatal-stack>


)
23 changes: 23 additions & 0 deletions melt/asset.ss
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
(library (melt asset)
(export asset-cp
asset-list-cp)
(import (scheme)
(melt lib file)
(melt structure))

(import type-asset)

;; for single object
;; copy the src file to the target-directory
(define (asset-cp asset-obj)
(let ((src-directory (asset-source asset-obj))
(target-directory (asset-target asset-obj)))
(cp-rf src-directory
(string-append target-directory
(directory-separator-string)
src-directory))))

(define (asset-list-cp asset-list)
(map asset-cp asset-list))

)
35 changes: 35 additions & 0 deletions melt/cell.ss
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
(library
(melt cell)
(export make-cell)
(import (scheme))

(define (%check-cell-proc proc)
(if (eq? 2 (abs (procedure-arity-mask proc)))
proc
(error 'make-cell "incorrect number of arguments of cell filter definition")))

(define (%inner-proc proc)
(let ((internal (%check-cell-proc proc)))
(case-lambda
[(value)
(if (eq? 2 (abs (procedure-arity-mask value)))
(set! internal value)
(error 'make-cell "incorrect number of arguments of cell filter definition"))]
[() internal])))

(define make-cell
(case-lambda
[(default-value)
(make-cell default-value (lambda (x) x))]
[(default-value filter)
(let ((internal-value default-value)
(internal-cell (%inner-proc filter)))
(case-lambda
[(value)
(set! internal-value value)]
[(value upt-filter)
(set! internal-value value)
(internal-cell upt-filter)]
[() ((internal-cell) internal-value)]))]))

)
57 changes: 57 additions & 0 deletions melt/command.ss
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
(library
(melt command)
(export create-command
command-add!
command-remove!
command-proc
command-desc
command-name
command-query
show-commands)
(import (scheme)
(melt data)
(melt lib console))

;; command itself is a data
;; symbol, which specifics string in command line
;; string, one line description
;; procedure for the command, accept arguments
(define (create-command name desc proc)
(create-data '(name desc proc)
`(,name ,desc ,proc)))

(define (command-name command)
(data-value-query 'name command))
(define (command-desc command)
(data-value-query 'desc command))
(define (command-proc command)
(data-value-query 'proc command))

;; add one command to command data
(define (command-add! command data)
(update-data! (create-data (list (command-name command))
(list command))
data))

;; remove one command in command data
(define (command-remove! command data)
(update-data! (list (command-name command)) data))

;; query command in a data
(define (command-query name data)
(data-value-query name data))

;; display command names and its description
(define (show-commands command-data)
(define (show-command command)
(format #t " ~8a>>> ~a~%" (symbol->string (command-name command)) (command-desc command)))

; (gem:format " ~10@a-->~10a~%"
; `(("[37;1m" . ,(symbol->string (command-name command)))
; ("[38;5;166m" . ,(command-desc command)))))

(do ((command-list (data-values command-data) (cdr command-list)))
((null? command-list) #t)
(show-command (car command-list))))

)
46 changes: 46 additions & 0 deletions melt/command/init.ss
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
(library
(melt command init)
(export init-cli)
(import (scheme)
(melt command)
(melt cell)
(melt lib console))

(define (init-help)
(gemd:help (string-append
(gem:text "[37;1m" "melt")
(gem:text "[38;5;67m" " init ")
(gem:text "[38;5;253m" "name")))
(gemd:help (string-append
"if the"
(gem:text "[38;5;253m" " name ")
"is not provided, it will generate .melt in working directory")))

;; create some files
(define (initprocedure)
(mkdir ".melt")
(mkdir "public")
(mkdir "post")
(system "touch .melt/config.scm")
(system "touch .melt/melt.scm")
(mkdir ".melt/fasl")
(mkdir ".melt/resource"))

;; interface to be invoked in ui
(define command-init
(lambda args
(cond
[(null? args)
(init-help)]
[(eq? (length args) 1)
(let ((target (make-cell (car args) (lambda (value) (if (file-exists? value)
(begin (gemd:error "file exists!") #f)
value)))))
(if (target)
(begin (target (target) (lambda (value) value)) (mkdir (target)) (cd (target)) (initprocedure))))]
[else (gemd:info "only one argument required.")])))

(define init-cli
(create-command 'init
"init command to generate basic settings."
command-init)))
42 changes: 42 additions & 0 deletions melt/command/invoke.ss
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
(library
(melt command invoke)
(export invoke-cli)
(import (scheme)
(melt invoke)
(melt lib console)
(melt lib file)
(melt command)
(melt utils))

;; display the build command usage
(define (invoke-cli-help)
(gemd:info
(string-append
(gem:text "[37;1m" "melt")
(gem:text "[38;5;67m" " invoke")
(gem:text "[38;5;253m" " <main-execute-file>\n")
" If the"
(gem:text "[38;5;253m" " <main-execute-file> ")
"is not provided, use"
(gem:text "[38;5;190m" " melt.scm ")
"instead.")))

(define (invoke-cli global-invocation)
(create-command 'invoke
"melt command to execute one list actions, mostly build the site."
(lambda args
(cond
[(eq? 1 (length args))
(let ((main-ex-file (car args)))
(if (file-exists? main-ex-file)
(begin
(load main-ex-file)
(invoke global-invocation))
(begin
(gemd:error "Coundn't find config file !!")
(gemd:error (string-append "expect " (basename main-ex-file) " but the file doesn't exist!")))))]
[else
(gemd:warn "please give me the melt.scm!")
(invoke-cli-help)]))))

)
94 changes: 94 additions & 0 deletions melt/command/post.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
(library
(melt command post)
(export post)
(import (scheme)
(melt uutil)
(melt lib console)
(melt config)
(melt command))

(define (post data)
(create-command 'post "note post command."
(lambda args
(cond
[(null? args)
(gemd:help (gem:text "[38;5;15m" "this is the post command, contain 'new', 'list', and 'edit' subcommands."))
(gemd:help (gem:text "[38;5;15m" "use -h in each subcommand to get more info."))]
[(equal? (car args) "new")
(apply (action-new data) (cdr args))]
[(equal? (car args) "list")
(apply (action-list data) (cdr args))]
[(equal? (car args) "edit")
(apply (action-edit data) (cdr args))]
[(equal? (car args) "-h")
(gemd:help (gem:text "[38;5;15m" "this is the post command, contain 'new', 'list', and 'edit' subcommands."))
(gemd:help (gem:text "[38;5;15m" "use -h in each subcommand to get more info."))]
[else (gemd:error "unrecognized command, add -h to get info")]))))

;; ====================================================================
;; command new
(define (action-new data)
(lambda title
(let* ((str-num-sequence (map car (get-md-post-title-list "post")))
(numbers (sort > (map string->number str-num-sequence))))
(if (not (null? title))
(write-template (car title)
(string-append (config-value-query 'post data)
"/"
(number->string (+ 1 (car numbers))) ".md"))
(gemd:error "please provide a title\n")))))


(define (write-template title path)
(call-with-output-file
path
(lambda (port)
(display "~~~\n" port)
(format port "title : ~a~%" title)
(format port "date : ~a~%" (date-and-time))
(display "~~~\n\n" port))))

;; ====================================================================
;; command list
(define (action-list data)
(lambda args
(if (not (null? args))
(if (equal? (car args) "-h")
(gem:display
(gem:text "[38;5;15m" "A subcommand to list post sequence\n")))
(list-post data))))

(define (list-post data)
(lambda ()
(do ((title-list (sort (lambda (pre aft) (string>? (car pre) (car aft))) (get-md-post-title-list (config-value-query 'post data)))
(cdr title-list)))
((null? title-list) (gem:display (gem:text "[37m" "=====\n")))
(gemd:item (string-append
(gem:text "[38;5;15m" (car (car title-list)))
" ==> "
(gem:text "[38;5;15m" (cdr (car title-list)))
"\n")))))


;; ====================================================================
;; command edit
(define (action-edit data)
(lambda number
(let* ((str-num-sequence (map car (get-md-post-title-list "post")))
(numbers (sort > (map string->number str-num-sequence))))
(if (null? number)
((call-editor data) (number->string (car numbers)))
((call-editor data) (car number))))))


;; use external shell to call editor
(define (call-editor data)
(lambda (number)
(system (string-append (config-value-query 'editor data)
" "
(config-value-query 'post data)
"/"
number ".md"))))


)
40 changes: 20 additions & 20 deletions melt/command/serve.scm
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
(library (melt command serve)
(export serve)
(import (scheme)
(melt structure))
(library
(melt command serve)
(export serve-cli)
(import (scheme)
(melt lib console)
(melt command))

(import type-command)
(define (serve-help)
(gemd:info "the command is not ready yet"))

(define (serve-help)
(display "the command is not ready yet\n"))
(define serve-command
(lambda args
(cond
[(null? args)
(gemd:info "the command is not ready yet")]
[else
(gemd:info "the command is not ready yet")])))

(define serve-cli
(lambda args
(cond
[(null? args)
(display "the command is not ready yet\n")]
[else
(display "the command is not ready yet\n")])))
(define serve-cli
(create-command 'serve
"melt server to preview your site."
serve-command))

(define serve
(make-command 'serve
"melt server to preview your site"
serve-cli))

)
)
Loading

0 comments on commit d35bcc7

Please sign in to comment.