Operand

_

gram: source

> ./main.livemd

# Source: read codebases.
```elixir
Mix.install([
# {:kino_vega_lite, "~> 0.1.11"},
{:source, path: "~/share/gram/source"},
# {:source, "~> 0.1.0"},
{:kino, "~> 0.19.0"},
{:cachex, "~> 4.0"},
{:kino_explorer, "~> 0.1"},
],
config: [
source: [
bases: [
{"~/share/gram/*", :gram},
{"~/page", :page},
{"~/read", :read}
],
local: true,
cache: false
] ] )

Config

There are a few config options you can use for this package. For this livebook, see the config options used in the earlier 'Notebook dependencies and setup'.

import Config
config :source,
bases: [
{"~/share/gram/*", :gram},
{"~/page", :page},
{"~/read", :read}
],
local: true,
cache: false

Index your codebases!

Begin by searching for codebases, using simple path globs:

Source.Index.scan("~/share/gram/*")

If you encoded your paths inside of config :source, bases: [], you can access them by the named scheme.

Source.Index.scheme(:page)
Source.call(:bases)
programs = Source.Index.scheme(:gram)

Choose a codebase from the index using named/1.

base = programs |> Source.Index.named("source")

Display a file, such as README.md.

base |> Source.Node.read("README.md")
|> Kino.Markdown.new

Choose files from a codebase based on composable filename regex filters:

base
|> Source.Node.all()
|> Enum.filter(& &1.address =~ ~r/\.md$/)

Example: Blog Entries. This sample parses through a codebase full of dated markdown files.

Source.Index.scheme(:page) |> hd
|> Source.Node.all
|> Source.Node.named(~r/\d{4}\-\d{2}\-\d{2}\./)
|> Source.Node.named(~r/\.md$/)
|> Enum.map(& &1.address)

Legacy Usage

Source.Index.scheme(:gram)
|> Enum.map(& Path.basename(&1.locus))
Source.Index.scheme(:gram)
|> Source.Index.named("nue")
|> Source.Node.read("README.md")
|> Kino.Markdown.new()
"```nu
#{
Source.Index.scheme(:gram)
|> Source.Index.named("nue")
|> Source.Node.read("cache.nu")
}
```"
|> Kino.Markdown.new()

Changelog Access

Source.Index.scheme(:gram)
|> Source.Index.named("nue")
|> Source.changes_by_day

Experimenting in YAML codebases.

base = (
Source.Index.scheme(:read)
|> Source.Index.named("read")
)
read = (
base
|> Source.Node.all()
|> Enum.map(& Source.Node.read(base, &1.address))
|> Enum.map(&YamlElixir.read_all_from_string!/1)
|> List.flatten()
)
read
|> Enum.filter(& &1)
|> Explorer.DataFrame.new
# |> Kino.Explorer.new