Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 24 additions & 11 deletions build.boot
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
[time-to-read "0.1.0" :scope "test"]
[sitemap "0.2.4" :scope "test"]
[clj-rss "0.1.9" :scope "test"]
[gravatar "0.1.0" :scope "test"]])
[gravatar "0.1.0" :scope "test"]
[boot-jruby "0.3.0"]])

(require '[adzerk.bootlaces :refer :all])

Expand All @@ -29,8 +30,15 @@


(require '[io.perun :refer :all]
'[clojure.string :as string]
'[jeluard.boot-notify :refer [notify]])

(defn page-slug-fn [filename]
"Parses `slug` portion of the filename in the format: slug-title.ext"
(->> (string/split filename #"[-\.]")
drop-last
(string/join "-")
string/lower-case))

; testing functions
(defn renderer [global data]
Expand All @@ -43,18 +51,23 @@
(deftask build
"Build test blog. This task is just for testing different plugins together."
[]
(comp (markdown)
(draft)
(ttr)
(slug)
(permalink)
(build-date)
(gravatar :source-key :author-email :target-key :author-gravatar)
(comp (global-metadata)
;(markdown)
(asciidoctor)
;(draft)
;(ttr)
(slug :slug-fn page-slug-fn)
;(permalink)
;(build-date)
;(gravatar :source-key :author-email :target-key :author-gravatar)
;(render :renderer renderer)
;(collection :renderer index-renderer :page "index.html" :filter identity)
(sitemap :filename "sitemap.xml")
(rss :title "Hashobject" :description "Hashobject blog" :link "http://blog.hashobject.com")
(notify)))
(render :renderer 'web.views.page/render)
(collection :renderer 'web.views.index/render :page "index.html")
;(sitemap :filename "sitemap.xml")
;(rss :title "Hashobject" :description "Hashobject blog" :link "http://blog.hashobject.com")
;(notify)
))

(deftask release-snapshot
"Release snapshot"
Expand Down
24 changes: 24 additions & 0 deletions resources/asciidoctor/render-asciidoc.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# based on the Haml example by Tobias included with boot-jruby

# This script takes a reference to an adoc-file, converts them to adoc, and then
# writes the html-files as output.

# For documentation consider http://asciidoctor.org/docs/asciidoctor-diagram/

require 'asciidoctor'
require 'asciidoctor/cli'
require 'asciidoctor-diagram'

options = Asciidoctor::Cli::Options.new
#options[:safe] = Asciidoctor::SafeMode::SAFE
options[:input_files] = [$file]
options[:destination_dir] = ENV['BOOT_RSC_PATH'] + "/public" #fixme: hardcoded
#options[:attributes] = 'beta'
#options[:backend] = 'html5'
options[:header_footer] = false
#options[:verbose] = true
options[:base_dir] = ENV['BOOT_RSC_PATH'] + "/public" #fixme: hardcoded

invoker = Asciidoctor::Cli::Invoker.new(options)
puts invoker.invoke!
exit invoker.code
45 changes: 45 additions & 0 deletions resources/dummy.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
////
name: Dummy page
description: Dummy page showing off the asciidoc function
author: Nico Rikken
author-email: nico@nicorikken.eu
author-url: http://nicorikken.eu
date-created: 2015-07-15
date-modified: 2015-07-15
date-published: 2015-07-15
headline: Test-headline
in-language: en
keywords: clojure, amazon beanstalk, https, ssl, aws, heroku, deploy, web app, amazon route 53, naked domain
discussion-url: https://github.com/hashobject/perun/issues/49
////

= Test =
This is a test to see how well the rendering is done.

== Example code ==

=== Subsection ===
This is an example of a paragraph.

.Code example JSON (Javascript)
[source,javascript]
----
{"amazing":["value"]}
----

.Code example HTTP
[source,http]
----
<!DOCTYPE html>
<title>Page Title</title>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
----

== PlanUML demo ==

.PlantUML diagram
["plantuml", "plantuml-example"]
----
Bob->Alice : hello
----
399 changes: 399 additions & 0 deletions resources/public/css/asciidoc.css

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions resources/web/views/index.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
;; Based on ns blog.hashobject.views.index

(ns web.views.index
(:use [hiccup.core :only (html)]
[hiccup.page :only (html5 include-css include-js)])
(:require [clojure.string :as str]))

;; This page adheres to the asciidoc hooks for applying css markup

(defn render-page [page]
[:li
[:p
[:a {:href (str/join (list (str (:slug page)) ".html"))} (:name page)]]])

(defn render [global-meta pages]
(html5 {:lang "en"}
[:head
[:meta {:charset "utf-8"}]
[:meta {:name "viewport" :content "width=device-width, initial-scale=1.0, user-scalable=no"}]
[:title "Generated documents"]
(include-css "css/asciidoc.css")]
[:body {:class "article"}
[:div {:id "header"}
[:h1 "Generated documents"]
[:div {:id "content"}
[:div {:class "paragraph"}
[:div {:class "ulist compact"}
[:div {:class "title"} "Pages"]
[:ul
(for [page pages] (render-page page))]]]]
[:div {:id "footer"}
[:div {:id "footer-text"} "This page was generated using Perun."]]
]]))
23 changes: 23 additions & 0 deletions resources/web/views/page.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
;; Based on ns blog.hashobject.views.post

(ns web.views.page
(:use [hiccup.core :only (html)]
[hiccup.page :only (html5 include-css include-js)]))

(defn render [global-meta metadata]
(html5 {:lang "en"}
[:head
[:meta {:charset "utf-8"}]
[:meta {:name "viewport" :content "width=device-width, initial-scale=1.0, user-scalable=no"}]
[:title (str (:name metadata))]
(include-css "css/asciidoc.css")]
[:body {:class "article"}
[:div {:id "header"}
[:h1 (str (:name metadata))]
[:div {:id "details"}
[:p
[:a {:href "index.html"} "Back to overview"]]]]
[:div {:id "content"} ;to align the content via the css structure
(str (slurp (:include metadata)))]
[:div {:id "footer"}
[:div {:id "footer-text"} "This page was generated using Perun."]]]))
76 changes: 69 additions & 7 deletions src/io/perun.clj
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
;;
;; Author:: Juho Teperi (<juho.teperi@iki.fi>)
;; Author:: Anton Podviaznikov (<podviaznikov@gmail.com>)
;; Author:: Martin Klepsch (<martinklepsch@googlemail.com>)
;; Author:: Nico Rikken (<nico@nicorikken.eu>)
;; Copyright:: Copyright (c) 2015 Individual contributors, and Mpare B.V.
;; License:: Eclipse Public License 1.0
;;
;; The use and distribution terms for this software are covered by the
;; Eclipse Public License 1.0 (http://www.eclipse.org/legal/epl-v10.html)
;; which can be found in the file epl-v10.html at the root of this distribution.
;; By using this software in any fashion, you are agreeing to be bound by
;; the terms of this license.
;; You must not remove this notice, or any other, from this software.
;;

(ns io.perun
{:boot/export-tasks true}
(:require [boot.core :as boot :refer [deftask]]
[boot.pod :as pod]
[boot.util :as u]
[clojure.string :as string]
[clojure.test :as test]
[clojure.edn :as edn]
[io.perun.core :as perun]))
(:require [boot.core :as boot :refer [deftask]]
[boot.pod :as pod]
[boot.util :as u]
[clojure.string :as string]
[clojure.test :as test]
[clojure.edn :as edn]
[io.perun.core :as perun]
[clojure.java.io :as io] ;for asciidoctor
[boot.jruby :refer [jruby make-jruby]] ;for asciidoctor
[io.perun.asciidoctor]))

(def ^:private global-deps
'[])
Expand Down Expand Up @@ -58,6 +77,49 @@
(reset! prev-meta final-metadata)
fs-with-meta))))

(def ^:private +asciidoctor-defaults+ {}
; {:transfer-mode "content"}
) ;file-based transfer mode available for large texts, using file inclusion

(deftask asciidoctor
"Parse asciidoc files using asciidoctor

This task will look for files ending with `adoc` and add a `:content` or
`:include` key to their metadata containing the HTML resulting from
processing the asciidcotor file's content. The key used for handling files
can be set using `method`."
[m method METHOD str "Method for handling file content, either 'include'
or 'content' using strings or files for content
handling respectively."
a attribute ATTRIBUTE str "Attribute to use when generating files"
]
(let [prev-meta (atom {})
prev-fs (atom nil)
tmp (boot/tmp-dir!)
options (merge +asciidoctor-defaults+ *opts*)]
(boot/empty-dir! tmp) ;empty temporary directory
(boot/with-pre-wrap fileset
(let [asciidoc-files (->> fileset
(boot/fileset-diff @prev-fs)
boot/user-files
(boot/by-ext ["adoc"])
(mapv #(.getAbsolutePath (boot/tmp-file %))))
removed-files (->> fileset
(boot/fileset-removed @prev-fs)
boot/user-files
(boot/by-ext ["adoc"])
(map #(.getName (boot/tmp-file %))))
parsed-fileset (io.perun.asciidoctor/parse-asciidoc
fileset asciidoc-files options)
parsed-metadata (perun/get-meta parsed-fileset)
initial-metadata @prev-meta
final-metadata (merge initial-metadata parsed-metadata)
final-metadata (apply dissoc final-metadata removed-files)
fs-with-meta (perun/set-meta parsed-fileset final-metadata)]
(reset! prev-fs fileset)
(reset! prev-meta final-metadata)
fs-with-meta))))

(deftask global-metadata
"Read global metadata from `perun.base.edn` or configured file.

Expand Down
Loading