Skip to content

Commit

Permalink
Use archive.json to populate the html package index, rather than ad-h…
Browse files Browse the repository at this point in the history
…oc sexp parsing
  • Loading branch information
purcell committed Jul 25, 2012
1 parent 7944652 commit fdae5ac
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 32 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -17,7 +17,7 @@ build:
$(EVAL) "(package-build-all)" $(EVAL) "(package-build-all)"


html: index html: index
index: index: archive.json
@echo " • Building html index ..." @echo " • Building html index ..."
$(MAKE) -C $(HTMLDIR) $(MAKE) -C $(HTMLDIR)


Expand Down
37 changes: 8 additions & 29 deletions html/index.erb
Expand Up @@ -11,43 +11,22 @@
**Last Update:** *<%= Time.now.strftime("%Y.%m.%d %H:%M %z") %>* **Last Update:** *<%= Time.now.strftime("%Y.%m.%d %H:%M %z") %>*


<% <%
def parse str require 'json'
# credit to: http://stackoverflow.com/q/3128406/154508 archive_json = JSON.parse(File.open("../archive.json").read)
tokens = str.scan(/#{Regexp.escape("(")}|#{Regexp.escape(")")}|"(?:\\.|[^"])+"|[a-zA-Z0-9\'\-\_\+]+/)

stack = [[]]

tokens.each do |tok|
case tok
when "("
stack << []
when ")"
stack[-2] << stack.pop
when /^"(.*)\"$/
stack[-1] << $1
else
stack[-1] << tok
end
end

return stack[-1][-1]
end



headers = ["Package", "Version", "Description", "Source"] headers = ["Package", "Version", "Description", "Source"]
data = parse(File.open("../packages/archive-contents").read)[1..-1]


data.map! do |row| data = archive_json.keys.sort.map do |pkgname|
pkgname = row[0] versions, deps, descr, pkgtype = archive_json[pkgname]
pkgurl = "packages/#{row[0]}-#{row[1]}." + (row[-1] == "single" ? "el" : "tar") version = versions.max.to_s
pkgurl = "packages/#{pkgname}-#{version}." + (pkgtype == "single" ? "el" : "tar")
recipe_url = "https://github.com/milkypostman/melpa/blob/master/recipes/#{pkgname}" recipe_url = "https://github.com/milkypostman/melpa/blob/master/recipes/#{pkgname}"
descr, source = row[3..-2].join(" "), "other" source = 'unknown'
if descr =~ /(.*?)(\s*-\*-.*?)?\s*\[source:\s*(\w+)\]\s*/ if descr =~ /(.*?)(\s*-\*-.*?)?\s*\[source:\s*(\w+)\]\s*/
descr, source = $1, $3 descr, source = $1, $3
end end
["[#{pkgname}](#{pkgurl})", row[1][0], descr, "[#{source}](#{recipe_url})"] ["[#{pkgname}](#{pkgurl})", version, descr, "[#{source}](#{recipe_url})"]
end end
data.sort!


colwidth = [0,0,0, 9] colwidth = [0,0,0, 9]


Expand Down
35 changes: 35 additions & 0 deletions json-fix.el
@@ -0,0 +1,35 @@
;;; Fixes for json.el such that integer plist / alist keys are rendered as strings, in order to comply with the json spec

(require 'json)

(defun json-encode-key-value-pair (pair)
"Encode a (key . value) PAIR as JSON, ensuring that key is encoded into a string."
(let ((encoded-key (json-encode (car pair))))
(format "%s:%s"
(if (string-match "^\"" encoded-key)
encoded-key
(json-encode-string encoded-key))
(json-encode (cdr pair)))))

(defun json-encode-hash-table (hash-table)
"Return a JSON representation of HASH-TABLE."
(json-encode-alist (maphash 'cons hash-table)))

;; List encoding (including alists and plists)

(defun json-encode-alist (alist)
"Return a JSON representation of ALIST."
(format "{%s}"
(json-join (mapcar 'json-encode-key-value-pair
alist) ", ")))

(defun json-encode-plist (plist)
"Return a JSON representation of PLIST."
(json-encode-alist
(loop while plist
collect (cons (car plist) (cadr plist))
do (setf plist (cddr plist)))))


(provide 'json-fix)
;;; json-fix.el ends here
5 changes: 3 additions & 2 deletions package-build.el
Expand Up @@ -650,16 +650,17 @@ FILES is a list of (SOURCE . DEST) relative filepath pairs."


;; Utility functions ;; Utility functions
(autoload 'json-encode "json") (autoload 'json-encode "json")
(eval-after-load 'json '(load (expand-file-name "json-fix")))


(defun package-build-alist-as-json (fn) (defun package-build-alist-as-json (fn)
(interactive) (interactive)
(with-temp-file fn (with-temp-file fn
(insert (json-encode package-build-alist)))) (insert (json-encode package-build-alist))))


(defun package-build-archive-alist-as-json (fn) (defun package-build-archive-alist-as-json (fn)
(interactive) (interactive)
(with-temp-file fn (with-temp-file fn
(insert (json-encode package-build-archive-alist)))) (insert (json-encode package-build-archive-alist))))




(provide 'package-build) (provide 'package-build)
Expand Down

0 comments on commit fdae5ac

Please sign in to comment.