Skip to content

Urigo/tortilla

Repository files navigation

Tortilla

tortilla

Tortilla is a framework for building tutorials based on git and NodeJS which will help you create AWESOME tutorials and upload them to any git-host which supports markdown rendering, like GitHub. Tortilla operates by simply wrapping an existing git project, thus providing you with some advanced git functions dedicated to create the most perfect and most beautiful tutorial in the world. In addition, Tortilla is easily accessible through a CLI, making it very convenient to use.

What's the advantages of using Tortilla over writing a simple blog-post?

  • The code and the instructions will always stay correlatively updated.
  • You can reference code snippets directly from the instructions.
  • You can use template-helpers to write complex instructions with minimal efforts.
  • You can take advantages of most git features like creating commits, tags and branches.
  • You can use neat features natively provided with the git host like reporting issues and opening pull requests.
  • The tutorial is linked directly to your git host account.
  • You can enjoy the great traffic of the git host.
  • You can easily navigate through the project at any specific point of the tutorial.
  • You can historicize different versions of your tutorial.
  • You can compare different versions of the tutorial and see the differences.
  • The list goes on and on and on...

Tutorials for example:

If you're not familiar with Tortilla I recommend you to go through the this README.md file since it contains everything you have to know about Tortilla in order to use it.

intro

Tutorial Structure

See:

Steps

Each commit should represent a single step in the tutorial, using the following message template:

Step (step index): (step description)

Here's a list of commits for example:

Step 2: Add todo-list
Step 2.3: Add todo-list controller
Step 2.2: Add todo-list view
Step 2.1: Add todo-list model
Step 1: Bundling
Step 1.3: Install the necessary packages for Webpack's build
Step 1.2: Add Webpack build to gulp tasks
Step 1.1: Create a basic Webpack config
How to create a todo list

As you can see, some of the commits represent a sub-step (e.g. step 1.1, 1.2) and some of them represent a super-step (e.g. step 1, 2); Together they form a whole single step. Note that the only exception is the root commit whose message can be whatever you'd like (will most likely be something which describes the tutorial), but the rest of the commits must follow these rules, otherwise you will encounter some unexpected behaviors.

Credit goes to @stubailo who originally came up with the commit templates concept.

Related CLI: tortilla-step CLI

Sub Step

A sub-step is a small portion of the whole step. Each sub-step should usually represent a small change which should be followed by an explanation in the tutorial. Sub-steps should be sorted by their chronological order; Sub-steps which assemble the same step should have the same super index, and a consecutive sub index separated by a period (e.g. 1.1, 1.2).

Super Step

A super-step should always come at the end of each step, and should be represented with a single index (e.g. 1, 2). The super-step should add a manual file which goes through the implementation of the associated step.

Manuals

Manuals are markdown files which should contain some handy instructions regards the implementation of each step in the tutorial. The manuals are located under the .tortilla/manuals directory, and are separated into 2 directories - templates and views. When writing manuals, we should never touch the views files, because they should be auto-generated by Tortilla's CLI. The templates directory, as the name suggests, should contain manual templates. Just so you can get the idea, here's an example of a .tortilla/manuals directory structure:

.tortilla/manuals
├─ templates
│  ├ root.tmpl
│  ├ step1.tmpl
│  ├ step2.tmpl
│  └ step3.tmpl
└─ views
   ├ root.md
   ├ step1.md
   ├ step2.md
   └ step3.md

The main difference between a manual template and a manual view is that templates are more simplified and will be most likely used for development purposes. They contain some handy template helpers we can be used to render complex markdown components, so our tutorial can be good-looking and easy-to-read, with minimum maintenance. As you can see in the files tree above, manual template files have an extension of .tmpl, unlike their belonging views which finish with an extension of .md. That's because the manual templates are not exactly markdown files, since they are packed with some extra syntactic abilities provided by Handlebars' simple yet powerful templating engine. Indeed, you can still use markdown's templating syntax, but just know that this is not a pure markdown we're talking about. The only template-view fs correlation exception is the root.tmpl file which should be mapped to the README.md file, so we can see a nice introduction for our tutorial when entering the repository. The root.md file is just a symbolic link to the main README.md file.

Note that manual templates shouldn't be written with a title, since it should be attached automatically when rendering the template's view using its belonging commit message. In addition, a navigation bar between steps should be appended at the end of the manual. For example, a root manual template which looks likes this:

- FOO
- BAR
- BAZ

And is matched with the commit message:

Les Trois Mousquetaires

Should result with the following view after rendering:

# Les Trois Mousquetaires

- FOO
- BAR
- BAZ

[{]: <helper> (navStep)

| [Begin Tutorial >](manuals/views/step1.md) |
|----------------------:|

[}]: #

Related CLI: tortilla-manual CLI

Translations

Manuals don't necessarily have to be written in English, and can be also be written in whatever language you'd choose. Translated manual templates are located under the templates/locales/your-language path, and their belonging views are localed under views/locales/your-language. Here's an example of a manuals directory with manuals which are translated into Hebrew (he):

.tortilla/manuals
├─ templates
│  ├ root.tmpl
│  ├ step1.tmpl
│  ├ step2.tmpl
│  ├ step3.tmpl
│  └ locales/he
│    ├ root.tmpl
│    ├ step1.tmpl
│    ├ step2.tmpl
│    └ step3.tmpl
└─ views
   ├ root.md
   ├ step1.md
   ├ step2.md
   ├ step3.md
   └ locales/he
     ├ root.md
     ├ step1.md
     ├ step2.md
     └ step3.md

Translations for step messages (and potentially other stuff) can be defined under the .tortilla/locales directory in a json file with the relevant language code (e.g. .tortilla/locales/he.json). Here's an example of a translation file which translates step messages:

{
  "step": {
    "root": "כיצד ליצור רשימת מטלות",
    "1.1": "יצירת קובץ הגדרות בסיסי ל Webpack",
    "1.2": "הוספת משימה של בנייה בעזרת Webpack לרשימת המשימות של gulp",
    "1.3": "התקנת החבילות הנחוצות בכדי שנוכל לבנות בעזרת Webpack",
    "1": "צרירת הפרוייקט",
    "2.1": "יצירת מודל למטלה יחידה",
    "2.2": "יצירת רשימת מטלות ויזואלית",
    "2.3": "יצירת רשימת מטלות לוגית",
    "2": "הוספת רשימת מטלות"
  }
}

Template Helpers

Template helpers are used when writing a manual file to make our lives a bit easier when it comes to formatting complex markdown components. The templates are rendered using Handlebars' templating, so I recommend you to go through its rules and syntax so you can be familiar with it, but just for the heck of demonstration, a manual template file which looks like this:

*Here's how we should use template-helpers*

{{{diffStep 1.1}}}

Should be rendered to:

*Here's how we should use template-helpers*

[{]: <helper> (diffStep 1.1)

#### Step 1.1: Demo commit

##### Added demo-file.js
\`\`\`diff
@@ -0,0 +1,3 @@
+┊ ┊1┊foo
+┊ ┊2┊bar
+┊ ┊3┊baz🚫↵
\`\`\`

[}]: #

🌟 Available {{view models}} 🌟

  • step - The number of the current step.

  • commit_message - The current commit message.

🌟 Available {{{template helpers}}} 🌟

  • navStep - A navigation bar between step manuals. Will present two buttons - "Previous step" and "Next step". This template helper may receives the following options:

    • prevRef - The reference which we will be redirected to once pressed on "Previous step" button.
    • nextRef - The reference which we will be redirected to once pressed on "Next step" button.
  • diffStep <step> - Will run git diff for the specified step's commit. This template helper may receives the following options:

    • files - A list of specific file paths separated by a comma (,) that we would like to present in our diff. The rest of the files in the diff will be ignored.
    • submodule - The name of the submodule which contains the step we would like to reference.

Releases

A Tortilla project may contain release tags which represent different versions of the tutorial in different time points. Here's a list of tags for example:

master@root@0.0.1
master@step1@0.0.1
master@0.0.1
master@root@0.1.0
master@step1@0.1.0
master@0.1.0
foo@root@0.0.1
foo@step1@0.0.1
foo@0.0.1

In addition, a stack of all the releases is available through history branches:

master-history
foo-history

Related CLI: tortilla-release CLI

Release Tags

A release tag should represent the tutorial at a specific state (e.g. step 2 of master branch) and time point (e.g. version 1.2.1). A release tag should contain the name of the branch, the step descriptor, if at all, and a semver version, separated with at (@) signs (e.g. master@step1@0.0.1, foo@0.1.0).

History Branches

The history is specific for a certain branch. Its name should end with history preceded by the branch name (e.g. master-history). Each commit in that branch represents all the changes made in a specific release, making the comparison between releases much easier (even if they have different roots!). Here's an example of a commits list in a history branch named master-history:

master@1.0.0: Add favorites page
master@0.0.2: Update step 2
master@0.0.1: Initial tutorial creation

Submodules

Often times, we would like to have a single repository where we include all the manual files, and the implementation logic would be implemented in different repositories which will be referenced from the main repository using git's submodules architecture; E.g. a single repository that includes submodules referencing the client and the server. Another advantage for that architecture is that we can implement similar applications using different stacks, or having a single back-end for multiple front-end applications, with almost identical instructions.

Related CLI: tortilla-submodule CLI

Checkouts

There would be cases where submodule's steps won't be correlated to the same step indices in the main repository; E.g. in manual file for step 3 the client would be set to step 1 and the server would be et to step 2. In-order to specify which steps should be checked out in the submodules for each step in the main repository, we would need to specify a checkouts.json file under the .tortilla directory. Here's an example checkouts file:

{
  "server": {
    "head": "master",
    "steps": ["root", "root", 1, 1]
  },
  "client": {
    "head": "master",
    "steps": ["root", 1, 1, 2]
  }
}

Each key represents a submodule name. The head property represents which branch should be checked out before looking for the steps at each submodule, and the steps property represents the steps that should be checked out at the submodule at each step at the main repository (e.g. "root" would be checked out at the server and step number 1 would be checked out in the client for step 1 in the main repository). Needless to say that submodules should be defined beforehand.

Quick Startup

First you will need to install Tortilla's CLI tool:

$ sudo npm install tortilla -g

Once you have it installed you can go ahead and create a new Tortilla project:

$ tortilla create my-tutorial -m "How to create my app"

This command will initialize a new Tortilla project called my-tutorial with an initial commit message of How to create my app.

After uploading this project and cloning it, be sure to initialize Tortilla so it can work properly:

$ git clone git@github.com:John/my-tutorial.git
$ tortilla init my-tutorial

A manual page for the usage of Tortilla's CLI tool can be brought any time by typing the following:

$ tortilla --help

For further information, I'd recommend you going through the CLI section.

CLI

See:

tortilla CLI

command: tortilla create [name]

Creates a new Tortilla project with the provided name.

  • option: -o, --output [path] - The output path of the newly created project.
  • option: -m, --message [message] - The created project's initial commit's message.
  • option: --override - Override project directory if already exists.

command: tortilla init [name]

Initializes Tortilla essentials in the provided project.

command: tortilla dump [out]

Dumps tutorial data as a JSON file. The default dump file name would be tutorial.json, although an optional output path might be provided. Here's a brief description of the schema of the generated dump file:

[
  {
    "branchName": "Current branch",
    "historyBranchName": "History branch matching current branch",
    "releases": [
      {
        "ReleaseVersion": "x.x.x",
        "tagName": "The name of the tag",
        "tagRevision": "The revision of the tag",
        "historyRevision": "Commit hash based on history branch",
        "manuals": [
          {
            "manualTitle": "Step commit message",
            "stepRevision": "Step commit revision",
            "manualView": "Manual view content"
          }
        ]
      }
    ]
  }
]
  • option: --filter [filter] - A list of branches we would like to filter separated with spaces.
  • option: --reject [reject] - A list of branches we would like to reject separated with spaces.
  • option: --override - Override file if already exists.

tortilla-manual CLI

For more information see the manuals section.

command: tortilla manual render [step]

Renders specified manual view.

  • option: --root - Render root manual (README.md).
  • option: --all - Render all manuals.

tortilla-release CLI

For more information see the releases section.

command: tortilla release bump <type>

Bumps the current release of the tutorial. This will create some new release tags accordingly and will update the associated history branch. The provided type represents a semver version type (major, minor and patch) we would like to bump.

  • option: -m, --message [message] - A message describing the newly created release. If not provided, and editor will be opened instead where we can type a full document.

command: tortilla release current

Prints the current release.

command: tortilla release diff <sourceRelease> <destinationRelease>

Runs git diff between 2 specified releases. This will also be able to run the operation between 2 different releases which are completely different from their root! You can also provide this command with some additional native git-diff options.

tortilla-step CLI

For more information see the steps section.

command: tortilla step push

Pushes a new step. Staged files will be committed along with this step.

  • option: -m, --message [message] - A message describing the newly created step.

command: tortilla step pop

Pops the most recent step. This will completely discard the step's changes.

command: tortilla step tag

Mark this step as finished and move on to the next one. This will increase the index of the super-step and zero the index of the sub-step.

  • option: -m, --message [message] - A message describing the newly created step.

command: tortilla step edit [step]

Edits the specified step/s. This will enter rebase mode where the step's hash is at. Once finished editing, you may proceed using git-rebase commands.

  • option: --root - Edit the root step (initial commit).
  • option: --udiff [path] - Updates the diffStep template helpers of manuals being rebased. Note that manuals prior to the current step being edited won't be updated, since the rebasing process never looks backwards. An optional can be provided which will be a reference to another repository which contains the current repository as a submodule; This will result in updating the provided repository's manuals rather than the current one. Note that submodule's package names located in package.json should be distinct.

command: tortilla step reword [step]

Rename the specified step's commit message.

  • option: -m, --message [message] - The new message of the reworded step. If not provided, and editor will be opened instead where we can type a full document.

tortilla-strict CLI

Strict mode determines whether Tortilla's git-hook validations are enabled or disabled. It's highly recommended to leave it on, since you might accidentally digress from Tortilla's strict project rules.

command: tortilla strict get

Prints whether strict mode is enabled or disabled.

command: tortilla strict set <mode>

Sets strict mode. Provided mode must be either a truthy value (e.g. 1, true) or a falsy value (0, false).

tortilla-submodule CLI

Submodules are useful whenever you would like to split the tutorial into different logical segments, e.g. we will have the repo with all the instructions manual referencing the backend repo and the frontend repo.

command: tortilla submodule add <remotes...>

Add a new submodules to the root commit. We can either provide a set of remotes or a remote following by its submodule name. A remote and a submodule will be differentiated based on whether they contain a / character or not, which indicates that a remote path was provided.

command: tortilla submodule remove [submodules...]

Remove submodules from the root commit. If non was provided - will remove all submodules.

command: tortilla submodule update [submodules...]

Update submodules in the root commit. If non was provided - will update all submodules.

command: tortilla submodule reset [submodules...]

Reset submodules in the root commit. If non was provided - will update all submodules. Unlike the update function, this will remove all the given submodules and re-add them, which will always result in the most recent submodules, event if the HEAD was rebased.

tortilla-package CLI

package.json related commands are useful when we wanna update our dependencies' versions all across the tutorial, without needing to deal with any conflicts across the process.

command: tortilla pacakge update-deps

This will start the dependencies updating process by creating a temporary file will contain a list of all our dependencies (merged with dev and peer) where we can specify the new versions that we would like to use in our tutorial. Once this file has been saved and closed Tortilla will handle the rebasing process.

License

MIT