Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
122 lines (102 sloc) 2.73 KB

LeanPub utilities for Elvish

This module provides some interfaces to the LeanPub API.

This file is written in literate programming style, to make it easy to explain. See leanpub.elv for the generated file.

Table of Contents

Usage

Install the elvish-modules package using epm:

use epm
epm:install github.com/zzamboni/elvish-modules

In your rc.elv, load this module:

use github.com/zzamboni/elvish-modules/leanpub

Implementation

api-key = ''
fn get-slug [@args]{
  if (eq $args []) {
    put [(splits / $pwd)][-1]
  } else {
    put $args[0]
  }
}
fn preview [@args]{
  slug = (get-slug $@args)
  pprint (curl -s -d "api_key="$api-key https://leanpub.com/$slug/preview.json | from-json)
}
fn subset [@args]{
  slug = (get-slug $@args)
  pprint (curl -s -d "api_key="$api-key https://leanpub.com/$slug/preview/subset.json | from-json)
}
fn status [@args]{
  slug = (get-slug $@args)
  status = (curl -s "https://leanpub.com/"$slug"/job_status?api_key="$api-key | from-json)
  if (has-key $status backtrace) {
    file = (mktemp)
    echo $status[backtrace] > $file
    del status[backtrace]
    status[error-log] = $file
  }
  put $status
  if (has-key $status error-log) {
    fail "An error occurred. The backtrace is at "$status[error-log]
  }
}
fn watch [@args]{
  slug = (get-slug $@args)
  s = (status $slug)
  while (not-eq $s [&]) {
    pprint $s
    sleep 5
    s = (status $slug)
  }
}
fn preview-and-watch [@args]{
  slug = (get-slug $@args)
  preview $slug
  watch $slug
}
fn subset-and-watch [@args]{
  slug = (get-slug $@args)
  subset $slug
  watch $slug
}
fn do-subset [@args]{
  msg = (echo $@args)
  git ci -a -m $msg
  git push
  subset-and-watch
}
fn info [@args]{
  slug = (get-slug $@args)
  pprint (curl -s "https://leanpub.com/"$slug".json?api_key="$api-key | from-json)
}
You can’t perform that action at this time.