Skip to content

Commit

Permalink
Everything works except POST /start.
Browse files Browse the repository at this point in the history
  • Loading branch information
mabasic committed May 24, 2021
1 parent 7054060 commit c6cf66c
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 34 deletions.
1 change: 0 additions & 1 deletion src/boot.phel
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@
"GET"
(get request :method))))
redirects)]
# (println ((get route :page) request (router/get-parameters (:url route) (:path (:uri request)))))
(cond
(and (nil? route) (nil? redirect)) (page-not-found/render request)
(not (nil? redirect)) ((:handler redirect) (:to redirect))
Expand Down
2 changes: 1 addition & 1 deletion src/ekko.phel
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
(defn is-active [active-item path]
(cond
(string? path) (if (= (php/preg_match (regex path) active-item) 1) " active" "")
(array? path) (if (find (fn [x] (= (php/preg_match (regex x) active-item) 1)) path) " active" "")))
(vector? path) (if (find (fn [x] (= (php/preg_match (regex x) active-item) 1)) path) " active" "")))
10 changes: 8 additions & 2 deletions src/helpers.phel
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(:require mabasic\json\json))

# It returns data from :parsed-body if any, otherwise it looks for data
# in php://input, else it returns and empty table.
# in php://input, else it returns an empty hash-map.
(defn extract-data-from-request [request]
(or
(:parsed-body request)
Expand All @@ -27,4 +27,10 @@
(symbol? x) (str (php/-> x (getName)))
(keyword? x) (str (php/-> x (getName)))
(float? x) (str x)
true x))
true x))

# This is only temporary until [#287](https://github.com/phel-lang/phel-lang/issues/287) is resolved.
(defn convert-to-php-array
"This should be faster than converting to a list instead"
[vector]
(apply php/array vector))
20 changes: 10 additions & 10 deletions src/pages/portfolio.phel
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@

(defn black []
[:div
(for [item :in projects/index]
[:div {:class "row mb-5"}
[:div {:class "col"}
[:h2 (get item :year)]
[:hr {:style "width: 130px;" :class "mb-4"}]
(for [project-subset :in (partition 4 (get item :projects))]
[:div {:class "row"}
(for [project :in project-subset]
[:div {:class "col-lg-3"}
(project-partial/render project)])])]])])
(helpers/convert-to-php-array (for [item :in projects/index]
[:div {:class "row mb-5"}
[:div {:class "col"}
[:h2 (get item :year)]
[:hr {:style "width: 130px;" :class "mb-4"}]
(helpers/convert-to-php-array (for [project-subset :in (partition 4 (get item :projects))]
[:div {:class "row"}
(helpers/convert-to-php-array (for [project :in project-subset]
[:div {:class "col-lg-3"}
(project-partial/render project)]))]))]]))])

(defn render [request]
{:status 200
Expand Down
23 changes: 12 additions & 11 deletions src/pages/posts/index.phel
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(ns app\pages\posts\index
(:require app\layouts\main)
(:require app\posts))
(:require app\posts)
(:require app\helpers))

(def per-page 6)

Expand All @@ -14,19 +15,19 @@
(if (> max-page 1)
[:nav {:aria-label "Page navigation"}
[:ul {:class "pagination pagination-sm"}
(for [index :range [1 (+ max-page 1)]]
[:li {:class (str "page-item" (if (= page index) " active"))}
[:a {:class "page-link" :href (str "/blog?page=" index)} index]])]])))
(helpers/convert-to-php-array (for [index :range [1 (+ max-page 1)]]
[:li {:class (str "page-item" (if (= page index) " active"))}
[:a {:class "page-link" :href (str "/blog?page=" index)} index]]))]])))

(defn black [posts posts-count page]
[:div {:class "row"}
[:div {:class "col"}
(for [post :in posts]
[:article {:class "post-index"}
[:h2 {:class "h4"}
[:a {:href (posts/generate-slug post) :class "link-light"} (posts/get-title post)]]
[:p (posts/get-excerpt post)]
[:p [:small (posts/get-formatted-date post) " ‧ " (posts/get-author post)]]])
(helpers/convert-to-php-array (for [post :in posts]
[:article {:class "post-index"}
[:h2 {:class "h4"}
[:a {:href (posts/generate-slug post) :class "link-light"} (posts/get-title post)]]
[:p (posts/get-excerpt post)]
[:p [:small (posts/get-formatted-date post) " ‧ " (posts/get-author post)]]]))
(if-not (= (count posts) 0) (pagination posts-count page)
[:p {:class "lead"} "There are no posts on this page."])]])

Expand All @@ -50,5 +51,5 @@
request
{:title "Blog | Mario Bašić"
:meta-description "Read all my blog posts."
:white white
:white (white)
:black (black (posts/paginate all-posts page per-page) posts-count page)})}))
7 changes: 4 additions & 3 deletions src/partials/project.phel
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(ns app\partials\project
(:require app\pages\home :refer [unit]))
(:require app\pages\home :refer [unit])
(:require app\helpers))

(defn render [project]
(unit
Expand All @@ -21,5 +22,5 @@
[:div
(get project :description)
[:br]
(for [badge :in (get project :badges)]
[:span {:class "badge"} "#" badge])]}))
(helpers/convert-to-php-array (for [badge :in (get project :badges)]
[:span {:class "badge"} "#" badge]))]}))
6 changes: 3 additions & 3 deletions src/router.phel
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
(do
(foreach [index part route-parts]
(if (= (php/preg_match (str "/^{" regex "}$/i") part) 1)
# :slug 0
# :slug 0
(put parameters (get-keyword-from-route-parameter part) index)))
(foreach [key index parameters]
(put parameters key (get url-parts index)))
(foreach [key value (persistent parameters)]
(put parameters key (get url-parts value)))
(persistent parameters))))
4 changes: 2 additions & 2 deletions src/validator.phel
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
(if (nil? field-value) true)))

# It returns :result true if validation has passed.
# In this case :errors should be an empty table.
# In this case :errors should be an empty hash-map.
(defn validate [request rules]
(let [errors (transient {})]
(foreach [field field-rules rules]
Expand All @@ -80,7 +80,7 @@
(= field-rule :required) (rule-required request field)
(= field-rule :string) (rule-string request field)
(= field-rule :accepted) (rule-accepted request field)
(table? field-rule)
(hash-map? field-rule)
(case (:rule field-rule)
# Handles additional string rule options like: max, min, etc ...
:string (rule-string request field field-rule))))))]
Expand Down
4 changes: 3 additions & 1 deletion tests/ekko.phel
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@
(is (= "" (ekko/is-active "/blog" "/blog/*")))
(is (= " active" (ekko/is-active "/blog/post" "/blog/*")))
(is (= "" (ekko/is-active "/blog" "/*/*")))
(is (= " active" (ekko/is-active "/blog/post" "/*/*"))))
(is (= " active" (ekko/is-active "/blog/post" "/*/*")))
(is (= " active" (ekko/is-active "/2021/05/24/slug" "/*/*/*/*")))
(is (= " active" (ekko/is-active "/2021/05/24/slug" ["/blog" "/*/*/*/*"]))))

0 comments on commit c6cf66c

Please sign in to comment.