~bzg/choices

77d9d4765f2d81222feba2c97361e38b626dfa17 — Bastien 2 months ago a3e4b0a
Implement format strings for scores in the score final message
2 files changed, 11 insertions(+), 2 deletions(-)

M config.yml
M src/cljs/choices/core.cljs
M config.yml => config.yml +5 -1
@@ 82,7 82,11 @@ conditional-score-outputs:
    notification: "is-success"
    priority: 1
    node: "end"
    message: "1 wins! :)"
    # Final score message supports using formatting strings for
    # scores.  Strings starting with "%" and matching a score name
    # will be interpolated: e.g. here the message will display the
    # value of "score-1".
    message: "1 wins! :)  Here is the score 1: %score-1"
    condition-1: #free-form
      score-1: 1
  cas-1: # free-form

M src/cljs/choices/core.cljs => src/cljs/choices/core.cljs +6 -1
@@ 215,6 215,10 @@
     :output       @output
     :node         @node}))

(defn format-score-output-string [output scores]
  (let [scores (map (fn [[k v]] [(str "%" (name k)) v]) scores)]
    (reduce-kv string/replace output (into {} scores))))

(defn scores-result [scores]
  [:div
   (when (:display-score config)


@@ 237,7 241,8 @@
               [:div.tile.is-size-4.is-child
                {:class (str (or (not-empty notification) "is-info")
                             " notification subtitle")}
                (md-to-string output)]]))))
                (md-to-string
                 (format-score-output-string output scores))]]))))
      ;; Always display display-unconditionally when not empty
      (when-let [sticky (:display-unconditionally config)]
        [:div.tile.is-parent