Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use archive.json to populate the html package index, rather than ad-h…

…oc sexp parsing
  • Loading branch information...
commit fdae5acf111b49ffbaa18167f7509e2cd7215b1f 1 parent 7944652
Steve Purcell purcell authored
Showing with 47 additions and 32 deletions.
  1. +1 −1  Makefile
  2. +8 −29 html/index.erb
  3. +35 −0 json-fix.el
  4. +3 −2 package-build.el
2  Makefile
View
@@ -17,7 +17,7 @@ build:
$(EVAL) "(package-build-all)"
html: index
-index:
+index: archive.json
@echo " • Building html index ..."
$(MAKE) -C $(HTMLDIR)
37 html/index.erb
View
@@ -11,43 +11,22 @@
**Last Update:** *<%= Time.now.strftime("%Y.%m.%d %H:%M %z") %>*
<%
- def parse str
- # credit to: http://stackoverflow.com/q/3128406/154508
- 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
-
+ require 'json'
+ archive_json = JSON.parse(File.open("../archive.json").read)
headers = ["Package", "Version", "Description", "Source"]
- data = parse(File.open("../packages/archive-contents").read)[1..-1]
- data.map! do |row|
- pkgname = row[0]
- pkgurl = "packages/#{row[0]}-#{row[1]}." + (row[-1] == "single" ? "el" : "tar")
+ data = archive_json.keys.sort.map do |pkgname|
+ versions, deps, descr, pkgtype = archive_json[pkgname]
+ version = versions.max.to_s
+ pkgurl = "packages/#{pkgname}-#{version}." + (pkgtype == "single" ? "el" : "tar")
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*/
descr, source = $1, $3
end
- ["[#{pkgname}](#{pkgurl})", row[1][0], descr, "[#{source}](#{recipe_url})"]
+ ["[#{pkgname}](#{pkgurl})", version, descr, "[#{source}](#{recipe_url})"]
end
- data.sort!
colwidth = [0,0,0, 9]
35 json-fix.el
View
@@ -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 package-build.el
View
@@ -650,16 +650,17 @@ FILES is a list of (SOURCE . DEST) relative filepath pairs."
;; Utility functions
(autoload 'json-encode "json")
+(eval-after-load 'json '(load (expand-file-name "json-fix")))
(defun package-build-alist-as-json (fn)
(interactive)
(with-temp-file fn
- (insert (json-encode package-build-alist))))
+ (insert (json-encode package-build-alist))))
(defun package-build-archive-alist-as-json (fn)
(interactive)
(with-temp-file fn
- (insert (json-encode package-build-archive-alist))))
+ (insert (json-encode package-build-archive-alist))))
(provide 'package-build)
Please sign in to comment.
Something went wrong with that request. Please try again.