Skip to content

Commit

Permalink
pulled name_purge changes; fixed variable casing; removed dave files
Browse files Browse the repository at this point in the history
  • Loading branch information
joshkestenberg committed Jul 4, 2017
2 parents 666105f + 338c437 commit e4f98da
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ sudo apt-get install texlive-xetex
# initaite a new contract
claw new john examples/templates/consultant.md
# change to the newly created directory
cd john
# edit the params
vim params.toml
# save your revisions to the hash log
claw revise
# compile the markdown and output a final pdf using pandoc
claw compile --output pdf john
claw compile --output pdf
```
17 changes: 6 additions & 11 deletions contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,20 +136,15 @@ template = "{{ .TemplateHash}}"
//-----------------------------------------

func compileContract(cmd *cobra.Command, args []string) error {
if len(args) != 1 {
return fmt.Errorf("compile expects one arg: name")
}

name := args[0]

// load the params from toml file
params, err := loadConfig(name)
params, err := loadConfig()
if err != nil {
return err
}

// read the contract template
b, err := ioutil.ReadFile(filepath.Join(name, "template.md"))
b, err := ioutil.ReadFile("template.md")
if err != nil {
return err
}
Expand Down Expand Up @@ -208,21 +203,21 @@ func compileContract(cmd *cobra.Command, args []string) error {

switch outputType {
case "md":
if err := ioutil.WriteFile(filepath.Join(name, "contract.md"), markdownOutput, 0600); err != nil {
if err := ioutil.WriteFile("contract.md", markdownOutput, 0600); err != nil {
return err
}
case "html":
htmlOutput := markdown2html(markdownOutput)
if err := ioutil.WriteFile(filepath.Join(name, "contract.html"), htmlOutput, 0600); err != nil {
if err := ioutil.WriteFile("contract.html", htmlOutput, 0600); err != nil {
return err
}
case "pdf":
// requires the md to be written
mdPath := filepath.Join(name, "contract.md")
mdPath := "contract.md"
if err := ioutil.WriteFile(mdPath, markdownOutput, 0600); err != nil {
return err
}
cmd := exec.Command("pandoc", mdPath, "--latex-engine=xelatex", "-o", filepath.Join(name, "contract.pdf"))
cmd := exec.Command("pandoc", mdPath, "--latex-engine=xelatex", "-o", "contract.pdf")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
Expand Down
5 changes: 3 additions & 2 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ func appendNew(list []string, name string) []string {
}

// load params config
func loadConfig(rootDir string) (*viper.Viper, error) {

func loadConfig() (*viper.Viper, error) {
config := viper.New()
config.SetConfigName("params")
config.SetConfigType("toml")
config.AddConfigPath(rootDir)
config.AddConfigPath(".")
err := config.ReadInConfig()
if err != nil {
return nil, err
Expand Down

0 comments on commit e4f98da

Please sign in to comment.