Giter VIP home page Giter VIP logo

org-generate.el's Introduction

https://raw.githubusercontent.com/conao3/files/master/blob/headers/png/org-generate.el.png https://img.shields.io/github/license/conao3/org-generate.el.svg?style=flat-square https://img.shields.io/github/tag/conao3/org-generate.el.svg?style=flat-square https://github.com/conao3/org-generate.el/workflows/Main%20workflow/badge.svg https://img.shields.io/codacy/grade/62a36f4f04524d5e8c758440e8071c45.svg?logo=codacy&style=flat-square https://img.shields.io/badge/patreon-become%20a%20patron-orange.svg?logo=patreon&style=flat-square https://img.shields.io/badge/twitter-@conao__3-blue.svg?logo=twitter&style=flat-square https://img.shields.io/badge/chat-on_slack-blue.svg?logo=slack&style=flat-square

Table of Contents

Description

Generate template files/folders from one org document.

Install

(leaf org-generate :ensure t)

Usage

Full sample file is located project root, sample.org.

Define one file template

In template org file, the first level is the template’s foldering, the second level is the template’s name.

For example, name the first level as hugo, and the second level as page or single, and you can select a expand target to choice names hugo/page or hugo/single.

We start at the third level with the definition of a file template. In this chapter, we will take the simplest example, the case of a single file extraction.

* hugo
** page
:PROPERTIES:
:org-generate-root: ~/dev/repos/hugo-src/content/blog/
:END:

# One file template example.
# To create file named as page in `org-generate-root`, do
#   M-x org-generate hugo/page
*** page.md
#+begin_src markdown
  ---
  title: "xxx"
  date: xx/xx/xx
  draft: true
  ---

  ### 1. First
  xxxx

  ### 2. Second
  yyyy
#+end_src

** single
:PROPERTIES:
:org-generate-root: ~/dev/repos/hugo-src/content/blog/
:org-generate-variable: title date
:END:
*** {{title}}.md
#+begin_src markdown
  ---
  title: {{title}}
  date: {{date}}
  category: single
  draft: true
  ---

  ### 1. First
  xxxx

  ### 2. Second
  yyyy
#+end_src

In this example, two templates are defined, hugo/page and hugo/single.

The template hugo/page is simply saved file as-is in ~/dev/repos/hugo-src/ named as page.md.

In this way, you can specify where to extract the template by default via setting org-generate-root in properties. If you omit it, you can specify it when you unpack the template.

The template named hugo/single uses the Mustache template. If you use a mustache template, You need to enumerate variables in the org-generate-variable section.

The special consideration is that the file name is defined as {{title.md}} is. This means that this template can be controll not only the content to be extracted, but also the name of the file to be extracted to.

Define multi file template

The template definition of org-genrate is flexible and powerful, and it is possible to define multiple files and folders in a single template. This feature is useful when creating a new project.

* project
** elisp
:PROPERTIES:
:org-generate-root: ~/dev/repos/
:org-generate-variable: pkg-name description
:END:

# Multi file project template example.
# To create file in `org-generate-root`, do
#   M-x org-generate project/elisp

# You can use Mustache template in folder name, file contents.
# To use this feature, you should enumeration variable
# as `org-generate-variable` value.

# NOTE: If you want to create directory hierarchy,
#       Ensure heading name suffixed with '/'.

*** {{pkg-name}}.el/
**** .github/
***** workflows/
****** test.yml
#+begin_src yml
name: Main workflow
on: [push, pull_request]
#+end_src
**** .gitignore
#+begin_src gitignore
## .gitignore

*-autoloads.el
*.elc
/.keg
#+end_src
**** Keg
#+begin_src keg
  ;; Keg

  (source gnu melpa)

  (package
   ({{pkg-name}}
     (recipe . ({{pkg-name}} :fetcher github :repo "conao3/{{pkg-name}}.el"))))

  (dev-dependency cort)
#+end_src
**** LICENSE
#+begin_src fundamental
                      GNU GENERAL PUBLIC LICENSE
                        Version 3, 29 June 2007

  Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
  Everyone is permitted to copy and distribute verbatim copies
  of this license document, but changing it is not allowed.

  ...

#+end_src
**** Makefile
#+begin_src makefile
  ## Makefile

  all:
#+end_src
**** README.org
#+begin_src org
  ,,* Description
  {{description}}.
#+end_src
**** {{pkg-name}}.el
#+begin_src elisp
;;; {{pkg-name}}.el --- {{description}}  -*- lexical-binding: t; -*-

;;; Code:

(defgroup {{pkg-name}} nil
  "{{description}}."
  :group 'convenience
  :link '(url-link :tag "Github" "https://github.com/conao3/{{pkg-name}}.el"))

(provide '{{pkg-name}})
;;; {{pkg-name}}.el ends here
#+end_src

**** {{pkg-name}}-test.el
#+begin_src elisp
;;; {{pkg-name}}-tests.el --- Test definitions for {{pkg-name}}  -*- lexical-binding: t; -*-

;;; Code:

(require 'cort)
(require '{{pkg-name}})

;; (provide '{{pkg-name}}-tests)
;;; {{pkg-name}}-tests.el ends here
#+end_src

This template is defined as project/elisp, and it creates below structure at once of the template expansion.

  • {{pkg-name}}.el/
    • .github/
      • workflows/
        • test.yml
    • .gitignore
    • Keg
    • LICENSE
    • Makefile
    • README.org
    • {{pkg-name}}.el
    • {{pkg-name}}-test.el

Using this package, you can create a project in a generic way without having to language spesific tools. (For example lein new)

Generate files

Run M-x org-generate once you have created a template with an org document. Then, select a template name and actually extract the template. When called interactively, it presents the folder where the template is extracted in a dired.

Customize

org-generate-file
The org file is used as template definition.
(default {{user-emacs-directory}}/org-generate.org)

M-x org-generate-edit to edit template file.

org-generate-with-export-as-org
If non-nil, the target’s definition is exported as org beforehand. By exporting as org before generating it is possible to use some additional org features like including files, macros replacements and the noweb reference syntax. Some examples are shown in with-export-examples.org.
(default t)

Information

Community

All feedback and suggestions are welcome!

You can use github issues, but you can also use Slack if you want a more casual conversation.

Contribution

We welcome PR!

Require tools for testing

  • keg
    cd ~/
    hub clone conao3/keg .keg
    export PATH="$HOME/.keg/bin:$PATH"
        

Running test

Below operation flow is recommended.

make                              # Install git-hooks in local .git

git branch [feature-branch]       # Create branch named [feature-branch]
git checkout [feature-branch]     # Checkout branch named [feature-branch]

# <edit loop>
emacs org-generate.el             # Edit something you want

make test                         # Test org-generate via multi version Emacs
git commit -am "brabra"           # Commit (auto-run test before commit)
# </edit loop>

hub fork                          # Create fork at GitHub
git push [user] [feature-branch]  # Push feature-branch to your fork
hub pull-request                  # Create pull-request

Migration

License

General Public License Version 3 (GPLv3)
Copyright (c) Naoya Yamashita - https://conao3.com
https://github.com/conao3/org-generate.el/blob/master/LICENSE

Author

Contributors

org-generate.el's People

Contributors

conao3 avatar hubisan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

org-generate.el's Issues

Fix GitHub Actions yml

Fix GitHub Actions yml.

  • Do test in Emacs-27.1
  • Do all test job if fail some jobs
  • Don't run double CI for PR and branch

Support yasnippet templating syntax

Would you plan on adding support for yasnippet templating syntax?

This package currently supports the Mustache template syntax, but I am not used to it. This package is similar to yankpad in that it lets you organize templates in an Org file, and it supports yasnippet snippets. This feature would allow the user to easily migrate from yasnippet/yankpad.

Export as org before generating

Just an idea: It would be quite cool to export the subtree as org before generating the template with

(org-org-export-as-org &optional ASYNC SUBTREEP VISIBLE-ONLY BODY-ONLY EXT-PLIST)
(org-org-export-as-org nil t nil t)

This would make it possible to use a lot of additional org features. The following come in to my mind but there are certainly many more:


Macros

Use macros to replace text snippets during export.

* Project template
:PROPERTIES:
:package:     test
:END:
#+MACRO: macro-input (eval (completing-read "Type: " '("First" "Second") nil t "First"))
#+MACRO: poem Rose is $1, violet's $2. Life's ordered: Org assists you.
{{{poem(red,blue)}}}
{{{macro-input}}}
{{{property(package)}}}

This lets the user select from First and Second and exports as:

#+macro: macro-input (eval (completing-read "Type: " '("First" "Second") nil t "First"))
#+macro: poem Rose is $1, violet's $2. Life's ordered: Org assists you.
Rose is red, violet's blue. Life's ordered: Org assists you.
First
test

(only part disturbing is that the user-input macro is evaluated even if the expansion is not in the subtree, but could be solved by copying the subtree to another buffer first or whatever. Or of course let the user have an org file for each template.)


Include

Include other files:

#+INCLUDE: "~/dev/file-templates/GPLv3.txt"

Source block

Source block noweb

Include the code or the result of other source blocks with noweb.

An example with a simple named block and a shell source block:

#+NAME: year
: 2020

#+NAME: whoami
#+BEGIN_SRC sh
  whoami
#+END_SRC

* Subtree
#+BEGIN_SRC emacs-lisp :noweb yes
  ; by <<whoami()>> in <<year()>>
#+END_SRC

Exports to in my case:

#+begin_src emacs-lisp
  ; by hubisan in 2020
#+end_src

Macros could be used as variables for the source blocks as far as I know.

Inlines source blocks

this is some src_elisp[:results raw]{(concat "inline" "-" "code")}
> this is some inline-code

Call on separate line or inline

The source block called can even be located in another files.

#+CALL: file.org:whoami()
my username is call_file.org:whoami()

Allow omitting org-generate-root

Hello, I've found this package in a reddit thread, and I'm glad to see you've created another project that would cover one of the features of my ceased one!

This project will be more useful if it supports multiple configuration files, as suggested by riscy in this comment.

Would you support configuration files without org-generate-root property (or allow parameters in it)? Because file paths like ~/dev/repos/hugo-src/content/blog/ are quite personal, I think this feature is essential if users share files with others.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.