Browse Source

Added possibility to add notes.

master
Silas Vedder 3 years ago
parent
commit
51aa9c81ff
  1. 5
      README.md
  2. 3
      cl-bible.lisp
  3. 28
      clog.lisp
  4. 34
      data.lisp
  5. 21
      package.lisp
  6. 76
      verse.lisp

5
README.md

@ -1,3 +1,6 @@
# cl-bible # cl-bible
## Screenshots
![Screenshot](screenshot.png) ![Screenshot](screenshot.png)
## installation
You need sbcl and quicklisp set up.

3
cl-bible.lisp

@ -11,4 +11,5 @@
(loop)) (loop))
(defun build () (defun build ()
(sb-ext:save-lisp-and-die "bible" :executable t :toplevel #'main)) (mapc (lambda (bible) (mapc (lambda (verse) (setf (cl-bible.verse:notes verse) nil)) bible)) (list cl-bible.data::*mng* cl-bible.data::*kjv* cl-bible.data::*vul* cl-bible.data::*grb*))
#+sbcl (sb-ext:save-lisp-and-die "bible" :executable t :toplevel #'main))

28
clog.lisp

@ -22,10 +22,9 @@
(results (s:find-in-bible d:*bible* phrase))) (results (s:find-in-bible d:*bible* phrase)))
(set-on-click lift-search (lift-search-window canvas results)) (set-on-click lift-search (lift-search-window canvas results))
(create-p div :content (ergebnis/se (create-p div :content (ergebnis/se
(length results))) (length results)))
(mapc (lambda (verse) (mapc (lambda (verse)
(create-p div :content (v:verse-to-clog verse div))
(v:verse-to-string verse)))
results))) results)))
(defun searcher (window) (defun searcher (window)
@ -45,7 +44,7 @@
("Greek Bible" "grb")))) ("Greek Bible" "grb"))))
(lambda (results) (lambda (results)
(d:update-bible (cadar results)) (d:update-bible (cadar results))
:title "Load a Bible")))) :title "Load a Bible"))))
(defun load-chapter (canvas) (defun load-chapter (canvas)
(lambda (data) (lambda (data)
@ -59,16 +58,15 @@
:width 650))) :width 650)))
(div (create-div win))) (div (create-div win)))
(mapc (lambda (verse) (mapc (lambda (verse)
(create-p div :content (v:verse-to-clog verse div))
(v:verse-to-string verse)))
(s:find-chapter (s:find-book d:*bible* book) chapter))))) (s:find-chapter (s:find-book d:*bible* book) chapter)))))
(defun get-chapter (window body) (defun get-chapter (window body)
(lambda (obj) (lambda (obj)
(declare (ignore obj)) (declare (ignore obj))
(form-dialog window "Which chapter do you want?" (form-dialog window "Which chapter do you want?"
'(("Book" "book" :text "Book") '(("Book" "book" :text)
("Chapter" "chapter" :text "Chapter")) ("Chapter" "chapter" :text))
(load-chapter body) (load-chapter body)
:title "Load a Chapter"))) :title "Load a Chapter")))
@ -87,7 +85,7 @@
(create-gui-menu-item drop-down (create-gui-menu-item drop-down
:content "Search" :content "Search"
:on-click (searcher window)) :on-click (searcher window))
(create-gui-menu-item drop-down (create-gui-menu-item drop-down
:content "Get Chapter" :content "Get Chapter"
:on-click (get-chapter window body)) :on-click (get-chapter window body))
(create-gui-menu-item drop-down (create-gui-menu-item drop-down
@ -99,7 +97,17 @@
(declare (ignore obj)) (declare (ignore obj))
(loop for win = (current-window body) (loop for win = (current-window body)
unless win do (return) unless win do (return)
do (window-close win)))))) do (window-close win))))
(create-gui-menu-item mbar
:content "Save notes"
:on-click (lambda (obj)
(declare (ignore obj))
(d:persist)))
(create-gui-menu-item mbar
:content "Load notes"
:on-click (lambda (obj)
(declare (ignore obj))
(d:load-bibles)))))
(defun on-new-window (body) (defun on-new-window (body)

34
data.lisp

@ -10,11 +10,22 @@
"cl-bible" "cl-bible"
(format nil "resources/~A.tsv" bible)))))) (format nil "resources/~A.tsv" bible))))))
(defvar *bible*) (defun load-bible (filename)
(defvar *mng* (init-bible)) (v:from-sexp
(defvar *vul* (init-bible "vul")) (read-from-string
(defvar *grb* (init-bible "grb")) (uiop:read-file-string (uiop:native-namestring filename)))))
(defvar *kjv* (init-bible "kjv"))
(defvar *mng* (load-bible "~/.bible/menge.sexp"))
(defvar *vul* (load-bible "~/.bible/vulgata.sexp"))
(defvar *grb* (load-bible "~/.bible/greek.sexp"))
(defvar *kjv* (load-bible "~/.bible/kjv.sexp"))
(defvar *bible* *mng*)
(defun load-bibles ()
(setf *mng* (load-bible "~/.bible/menge.sexp"))
(setf *vul* (load-bible "~/.bible/vulgata.sexp"))
(setf *grb* (load-bible "~/.bible/greek.sexp"))
(setf *kjv* (load-bible "~/.bible/kjv.sexp")))
(defun update-bible (str) (defun update-bible (str)
(let ((bibles `(("mng" . ,*mng*) (let ((bibles `(("mng" . ,*mng*)
@ -22,3 +33,16 @@
("vul" . ,*vul*) ("vul" . ,*vul*)
("grb" . ,*grb*)))) ("grb" . ,*grb*))))
(setf *bible* (cdr (assoc str bibles :test #'string=))))) (setf *bible* (cdr (assoc str bibles :test #'string=)))))
(defun persist-bible (bible filename)
(with-open-file (file (uiop:native-namestring (concatenate 'string "~/.bible/" filename ".sexp"))
:direction :output
:if-exists :overwrite
:if-does-not-exist :create)
(print (v:to-sexp bible) file)))
(defun persist ()
(let ((bibles (list *mng* *vul* *grb* *kjv*))
(files '("menge" "vulgata" "greek" "kjv")))
(ensure-directories-exist (uiop:native-namestring "~/.bible/"))
(mapcar #'persist-bible bibles files)))

21
package.lisp

@ -2,13 +2,16 @@
(defpackage #:cl-bible.verse (defpackage #:cl-bible.verse
(:use #:cl) (:use #:cl)
(:export verse-to-string (:export verse-to-clog
string-to-verse string-to-verse
to-sexp
from-sexp
bname bname
bsname bsname
chapter chapter
vnumber vnumber
text)) text
notes))
(defpackage #:cl-bible.search (defpackage #:cl-bible.search
(:use #:cl) (:use #:cl)
@ -28,7 +31,9 @@
(:local-nicknames (#:s #:cl-bible.search) (:local-nicknames (#:s #:cl-bible.search)
(#:v #:cl-bible.verse)) (#:v #:cl-bible.verse))
(:export update-bible (:export update-bible
*bible*)) *bible*
persist
load-bibles))
(defpackage #:cl-bible.clog (defpackage #:cl-bible.clog
(:use #:cl #:clog #:clog-gui) (:use #:cl #:clog #:clog-gui)
@ -42,4 +47,14 @@
(:use #:cl #:clog #:clog-gui) (:use #:cl #:clog #:clog-gui)
(:local-nicknames (#:c #:cl-bible.clog)) (:local-nicknames (#:c #:cl-bible.clog))
(:export start (:export start
main
build)) build))
(defpackage #:cl-bible-user
(:use #:cl
#:cl-bible
#:cl-bible.verse
#:cl-bible.data
#:cl-bible.search)
(:local-nicknames (#:c #:clog)
(#:cg #:clog-gui)))

76
verse.lisp

@ -12,10 +12,13 @@
(%number :initarg :number (%number :initarg :number
:reader vnumber) :reader vnumber)
(%text :initarg :text (%text :initarg :text
:reader text))) :reader text)
(%notes :initarg :notes
:initform '()
:accessor notes)))
(defmethod print-object ((verse verse) stream) (defmethod print-object ((verse verse) stream)
(format stream (verse-to-string verse " "))) (format stream (verse-to-string verse :separator " ")))
(defun string-to-verse (string) (defun string-to-verse (string)
(let ((verse (uiop:split-string string :separator '(#\Tab)))) (let ((verse (uiop:split-string string :separator '(#\Tab))))
@ -25,16 +28,79 @@
:number (nth 4 verse) :number (nth 4 verse)
:text (nth 5 verse)))) :text (nth 5 verse))))
(defgeneric verse-to-string (verse &optional separator)) (defgeneric verse-to-string (verse &key separator))
(defmethod verse-to-string (verse &optional (separator " ")) (defmethod verse-to-string (verse &key (separator " "))
(format nil "~A ~A:~A~A~A" (cadr verse) (format nil "~A ~A:~A~A~A" (cadr verse)
(nth 3 verse) (nth 3 verse)
(nth 4 verse) (nth 4 verse)
separator separator
(nth 5 verse))) (nth 5 verse)))
(defmethod verse-to-string ((verse verse) &optional (separator "<br/>"))
(defmethod verse-to-string ((verse verse) &key (separator "<br/>"))
(format nil "~A ~A:~A~A ~A" (bsname verse) (format nil "~A ~A:~A~A ~A" (bsname verse)
(chapter verse) (chapter verse)
(vnumber verse) (vnumber verse)
separator separator
(text verse))) (text verse)))
(defmethod show-notes ((verse verse) (parent clog:clog-obj))
(let* ((win (clog-gui:create-gui-window parent
:title "Notes"
:content (let ((notes (notes verse)))
(if notes
(format nil "~{~A~^<br/>~}" notes)
"No notes found"))))
(_ (clog:create-br (clog-gui:window-content win)))
(button (clog:create-button (clog-gui:window-content win)
:content "Add notes")))
(declare (ignore _))
(clog:set-on-click button
(lambda (obj)
(declare (ignore obj))
(add-notes verse parent)))))
(defmethod add-notes ((verse verse) (parent clog:clog-obj))
(let* ((win (clog-gui:window-content
(clog-gui:create-gui-window parent
:title "Add note")))
(form (clog:create-form win))
(text (clog:create-text-area form :rows 4))
(button (clog:create-button form :content "submit")))
(clog:set-on-click button
(lambda (obj)
(declare (ignore obj))
(push (clog:value text) (notes verse))))))
(defgeneric verse-to-clog (verse parent))
(defmethod verse-to-clog ((verse verse) (parent clog:clog-obj))
(let* ((verse-string (verse-to-string verse))
(display (clog:create-p parent
:content verse-string)))
(clog:set-on-click display
(lambda (obj)
(declare (ignore obj))
(show-notes verse parent)))))
(defgeneric to-sexp (verse))
(defmethod to-sexp ((verse verse))
(list (bname verse)
(bsname verse)
(chapter verse)
(vnumber verse)
(text verse)
(notes verse)))
(defmethod to-sexp ((bible cons))
(mapcar #'to-sexp bible))
(defun verse-from-sexp (sexp)
(make-instance 'verse
:bname (car sexp)
:bsname (cadr sexp)
:chapter (caddr sexp)
:number (nth 3 sexp)
:text (nth 4 sexp)
:notes (nth 5 sexp)))
(defun from-sexp (bible)
(mapcar #'verse-from-sexp bible))

Loading…
Cancel
Save