Skip to content

Commit

Permalink
Merge branch 'configuration'
Browse files Browse the repository at this point in the history
  • Loading branch information
antoniogamiz committed Aug 9, 2019
2 parents 013523b + dcbc602 commit a1a01fa
Show file tree
Hide file tree
Showing 23 changed files with 490 additions and 576 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,4 @@ app-start
Makefile
.cache-*
.t

.*
16 changes: 10 additions & 6 deletions META6.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@
"Pod::Utilities:ver<0.0.1>",
"URI:ver<0.2.2>",
"File::Temp:ver<0.0.6>",
"Log::Timeline:ver<0.3>"
"Log::Timeline:ver<0.3>",
"JSON::Fast:ver<0.9.18>"
],
"description": "Represents a piece of Perl 6 that is documented.",
"license": "Artistic-2.0",
"name": "Perl6::Documentable",
"perl": "6.c",
"provides": {
"Perl6::Documentable": "lib/Perl6/Documentable.pm6",
"Perl6::Documentable::File": "lib/Perl6/Documentable/File.pm6",
"Perl6::Documentable::Derived": "lib/Perl6/Documentable/Derived.pm6",
"Perl6::Documentable::Config": "lib/Perl6/Documentable/Config.pm6",
"Perl6::Documentable::Primary": "lib/Perl6/Documentable/Primary.pm6",
"Perl6::Documentable::Secondary": "lib/Perl6/Documentable/Secondary.pm6",
"Perl6::Documentable::Index": "lib/Perl6/Documentable/Index.pm6",
"Perl6::Documentable::Registry": "lib/Perl6/Documentable/Registry.pm6",
"Perl6::Documentable::Heading::Grammar": "lib/Perl6/Documentable/Heading/Grammar.pm6",
Expand All @@ -35,6 +37,7 @@
"Perl6::Documentable::DocPage::Kind": "lib/Perl6/Documentable/DocPage/Kind.pm6",
"Perl6::Documentable::DocPage::Index": "lib/Perl6/Documentable/DocPage/Index.pm6",
"Perl6::Documentable::DocPage::Source": "lib/Perl6/Documentable/DocPage/Source.pm6",
"Perl6::Documentable::DocPage::Factory": "lib/Perl6/Documentable/DocPage/Factory.pm6",
"Perl6::Documentable::To::HTML::Wrapper": "lib/Perl6/Documentable/To/HTML/Wrapper.pm6",

"Perl6::Documentable::CLI": "lib/Perl6/Documentable/CLI.pm6",
Expand All @@ -47,7 +50,7 @@
"template/header.html",
"template/footer.html",
"template/search_template.js",
"language-order-control.json"
"config.json"
],
"source-url": "https://github.com/antoniogamiz/Perl6-Documentable.git",
"tags": [],
Expand All @@ -57,7 +60,8 @@
"Perl6::TypeGraph:ver<0.0.4>",
"Pod::To::HTML:ver<0.6.1>",
"Pod::To::Cached:<0.3.2>",
"URI:ver<0.2.2>"
"URI:ver<0.2.2>",
"JSON::Fast:ver<0.9.18>"
],
"version": "2.1.4"
"version": "2.2.0"
}
4 changes: 3 additions & 1 deletion lib/Perl6/Documentable.pm6
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
unit module Perl6::Documentable;

#| Enum to classify all "kinds" of Perl6::Documentable
enum Kind is export <Type Language Programs Syntax Reference Routine>;
enum Kind is export (Type => "type" , Language => "language",
Programs => "programs" , Syntax => "syntax" ,
Reference => "reference", Routine => "routine" );

#| List of the subdirectories that contain indexable pods by default
constant DOCUMENTABLE-DIRS is export = ["Language", "Type", "Programs", "Native"];
Expand Down
149 changes: 62 additions & 87 deletions lib/Perl6/Documentable/CLI.pm6
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use Perl6::Documentable;
use Perl6::Documentable::Registry;

use Perl6::Documentable::DocPage::Source;
use Perl6::Documentable::DocPage::Kind;
use Perl6::Documentable::DocPage::Index;
use Perl6::Documentable::To::HTML::Wrapper;
use Perl6::Documentable::Config;
use Perl6::Documentable::DocPage::Factory;

use Pod::Load;
use Pod::To::Cached;
Expand Down Expand Up @@ -44,18 +42,19 @@ package Perl6::Documentable::CLI {
#| Start the documentation generation with the specified options
multi MAIN (
"start" ,
Str :$topdir = "doc", #= Directory where the pod collection is stored
Bool :v(:verbose($v)) = False, #= Prints progress information
Bool :c(:$cache) = True , #= Enables the use of a precompiled cache
Bool :p(:pods($p)) = False, #= Generates the HTML files corresponding to sources
Bool :k(:kind($k)) = False, #= Generates per kind files
Bool :s(:search-index($s)) = False, #= Generates the search index
Bool :i(:indexes($i)) = False, #= Generates the indexes files
Bool :t(:type-images($t)) = False, #= Write typegraph visualizations
Bool :f(:force($f)) = False, #= Force the regeneration of the typegraph visualizations
Bool :$highlight = False, #= Highlights the code blocks
Bool :$manage = False, #= Sort Language page
Bool :a(:$all) = False #= Equivalent to -t -p -k -i -s
Str :$topdir = "doc", #= Directory where the pod collection is stored
Str :$conf = "config.json", #= Configuration file
Bool :v(:verbose($v)) = False, #= Prints progress information
Bool :c(:$cache) = True , #= Enables the use of a precompiled cache
Bool :p(:pods($p)) = False, #= Generates the HTML files corresponding to sources
Bool :k(:kind($k)) = False, #= Generates per kind files
Bool :s(:search-index($s)) = False, #= Generates the search index
Bool :i(:indexes($i)) = False, #= Generates the indexes files
Bool :t(:type-images($t)) = False, #= Write typegraph visualizations
Bool :f(:force($f)) = False, #= Force the regeneration of the typegraph visualizations
Bool :$highlight = False, #= Highlights the code blocks
Bool :$manage = False, #= Sort Language page
Bool :a(:$all) = False #= Equivalent to -t -p -k -i -s
) {
if (!"./html".IO.e || !"./assets".IO.e) {
say q:to/END/;
Expand All @@ -66,13 +65,17 @@ package Perl6::Documentable::CLI {
END
exit(1);
}
#===================================================================
my @docs; # all these doducments will be written in disk
#===================================================================

#==========================setup====================================

my $config = Perl6::Documentable::Config.new(filename => $conf);
# all these doducments will be written in disk
my @docs;
# to track the time
my $now;

#===================================================================

# highlights workaround
if ($highlight) {
DEBUG("Starting highlight process...", $v);
Expand Down Expand Up @@ -107,11 +110,13 @@ package Perl6::Documentable::CLI {
$registry.compose;
print-time("Processing pods", $now);

my $factory = Perl6::Documentable::DocPage::Factory.new(:$config, :$registry);

#===================================================================

DEBUG("Writing html/index.html and html/404.html...", $v);
spurt 'html/index.html', p2h(load($topdir~'/HomePage.pod6')[0], :pod-path('HomePage.pod6'));
spurt 'html/404.html', p2h(load($topdir~'/404.pod6')[0], :pod-path('404.pod6'));
@docs.push($factory.generate-home-page() );
@docs.push($factory.generate-error-page());

#===================================================================

Expand All @@ -120,17 +125,7 @@ package Perl6::Documentable::CLI {
DEBUG("Generating source files...", $v);

@docs.append: $registry.documentables.map(-> $doc {
given $doc.kind {
when Kind::Type {
Perl6::Documentable::DocPage::Source::Type.new.render($registry, $doc.name);
}
when Kind::Language {
Perl6::Documentable::DocPage::Source::Language.new.render($registry, $doc.name);
}
when Kind::Programs {
Perl6::Documentable::DocPage::Source::Programs.new.render($registry, $doc.name);
}
}
$factory.generate-primary($doc)
}).Slip;

print-time("Generate source files", $now);
Expand All @@ -142,8 +137,8 @@ package Perl6::Documentable::CLI {
$now = now;
DEBUG("Generating per kind files...", $v);
for Kind::Routine, Kind::Syntax -> $kind {
@docs.append: $registry.lookup($kind.gist, :by<kind>).map({.name}).unique.map(-> $name {
Perl6::Documentable::DocPage::Kind.new.render($registry, $name, $kind)
@docs.append: $registry.lookup($kind.Str, :by<kind>).map({.name}).unique.map(-> $name {
$factory.generate-secondary($kind, $name)
}).Slip;
}
print-time("Generate per kind files", $now);
Expand All @@ -155,21 +150,18 @@ package Perl6::Documentable::CLI {
$now = now;
DEBUG("Generating indexes...", $v);

# main indexes
@docs.push(Perl6::Documentable::DocPage::Index::Language.new.render($registry, $manage));
@docs.push(Perl6::Documentable::DocPage::Index::Programs.new.render($registry));
@docs.push(Perl6::Documentable::DocPage::Index::Type.new.render($registry));
@docs.push(Perl6::Documentable::DocPage::Index::Routine.new.render($registry));
@docs.push($factory.generate-index(Kind::Language, $manage));
@docs.push($factory.generate-index(Kind::Type ));
@docs.push($factory.generate-index(Kind::Programs ));
@docs.push($factory.generate-index(Kind::Routine ));

# subindexes
for <basic composite domain-specific exceptions> -> $category {
@docs.push(
Perl6::Documentable::DocPage::SubIndex::Type.new.render($registry, $category)
)}
@docs.push($factory.generate-subindex(Kind::Type, $category))
}
for <sub method term operator trait submethod> -> $category {
@docs.push(
Perl6::Documentable::DocPage::SubIndex::Routine.new.render($registry, $category)
)}
@docs.push( $factory.generate-subindex(Kind::Routine, $category))
}

print-time("Generating index files", $now);
}
Expand All @@ -194,19 +186,20 @@ package Perl6::Documentable::CLI {
#| Check which pod files have changed and regenerate its HTML files.
multi MAIN (
"update",
Str :$topdir = "doc", #= Directory where the pod collection is stored
:$manage = True #= Sort Language page
Str :$topdir = "doc", #= Directory where the pod collection is stored
Bool :$manage = True, #= Sort Language page
Str :$conf = "config.json" #= Configuration file
) {
DEBUG("Checking for changes...");
my $now = now;

my $cache = Pod::To::Cached.new(:path(".{$topdir}"), :verbose, :source($topdir));
my $cache = Pod::To::Cached.new(:path(".cache-{$topdir}"), :verbose, :source($topdir));
my @files = $cache.list-files(<Valid>);

{
if (! @files) {
DEBUG("Everything already updated. There are no changes.");
exit 0;
} unless @files;
}

DEBUG(+@files ~ " file(s) modified. Starting regeneratiion ...");

Expand All @@ -218,63 +211,46 @@ package Perl6::Documentable::CLI {
);
$registry.compose;

# configuration
my $config = Perl6::Documentable::Config.new(filename => $conf);
my $factory = Perl6::Documentable::DocPage::Factory.new(:$config, :$registry);
my @docs; # files to write
my @kinds; # to know what indexes to regenerate
# regenerate source files and per kind files
state %syntax-docs = $registry.lookup(Kind::Syntax.gist, :by<kind>)
.categorize({.name});
state %routine-docs = $registry.lookup(Kind::Routine.gist, :by<kind>)
.categorize({.name});

for @files -> $filename {
my $doc = $registry.documentables.grep({
.url.lc eq "/" ~ $filename.lc # language/something type/Any
}).first;

given $doc.kind { # source
when Kind::Type {
@docs.push(Perl6::Documentable::DocPage::Source::Type.new.render($registry, $doc.name));
}
when Kind::Language {
@docs.push(Perl6::Documentable::DocPage::Source::Language.new.render($registry, $doc.name));
}
when Kind::Programs {
@docs.push(Perl6::Documentable::DocPage::Source::Programs.new.render($registry, $doc.name));
}
}
@docs.push($factory.generate-primary($doc));

# per kind
my @routine-docs = $doc.defs.grep({.kind eq Kind::Routine}).map({.name});
@docs.push: @routine-docs.map(-> $name {
Perl6::Documentable::DocPage::Kind.new.render($registry, $name, Kind::Routine)
}).Slip;
@docs.push: @routine-docs.map(-> $name { $factory.generate-secondary(Kind::Routine, $name) }).Slip;

my @syntax-docs = $doc.defs.grep({.kind eq Kind::Syntax}).map({.name});
@docs.push: @syntax-docs.map(-> $name {
Perl6::Documentable::DocPage::Kind.new.render($registry, $name, Kind::Syntax)
}).Slip;
@docs.push: @syntax-docs.map(-> $name { $factory.generate-secondary(Kind::Syntax, $name) }).Slip;

}

#regenerate indexes
@docs.push(Perl6::Documentable::DocPage::Index::Routine.new.render($registry));
@docs.push($factory.generate-index(Kind::Routine));
for <sub method term operator trait submethod> -> $category {
@docs.push(
Perl6::Documentable::DocPage::SubIndex::Routine.new.render($registry, $category)
)}
@docs.push($factory.generate-subindex(Kind::Routine, $category));
}
for @kinds -> $kind {
given $kind {
when Kind::Language {
@docs.push(Perl6::Documentable::DocPage::Index::Language.new.render($registry, $manage));
}
when Kind::Programs {
@docs.push(Perl6::Documentable::DocPage::Index::Programs.new.render($registry));
}
when Kind::Language { @docs.push($factory.generate-index(Kind::Language, $manage)); }
when Kind::Programs { @docs.push($factory.generate-index(Kind::Programs)); }
when Kind::Type {
@docs.push(Perl6::Documentable::DocPage::Index::Type.new.render($registry));
@docs.push($factory.generate-index(Kind::Type));
for <basic composite domain-specific exceptions> -> $category {
@docs.push(
Perl6::Documentable::DocPage::SubIndex::Type.new.render($registry, $category)
)}
@docs.push( $factory.generate-subindex(Kind::Type, $category) )
}
}
}
}

@docs.map(-> $doc { spurt "html{$doc<url>}.html", $doc<document> });
print-time("Updating files", $now);
}
Expand All @@ -289,7 +265,6 @@ package Perl6::Documentable::CLI {
&& rm app.pl && rm app-start && rm Makefile \
&& rm -rf template
END

}
}

Expand Down
48 changes: 48 additions & 0 deletions lib/Perl6/Documentable/Config.pm6
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
unit module Perl6::Documentable::Config;

use Perl6::Documentable;
use Perl6::Documentable::Utils::IO;
use JSON::Fast;


class X::Documentable::Config::InvalidConfig is Exception {

has $.msg;

method message() {
$.msg;
}
}

class Perl6::Documentable::Config {

has %.config;
has @.kinds;
has $.filename;

submethod BUILD (Str :$filename) {
my $json = slurp zef-path($filename);
%!config = from-json($json);
@!kinds = %!config<kinds>.list;
die X::Documentable::Config::InvalidConfig.new("'kinds' entry missing")
unless %!config<kinds>;

for <language type routine programs> -> $kind {
die X::Documentable::Config::InvalidConfig.new("$kind entry missing inside 'kinds'")
unless %!config<kinds>.grep({.<kind> eq $kind});
}
}

method get-kind-config(Kind $kind) {
return %() unless $kind;
my @results = @!kinds.grep({.<kind> eq $kind.Str});
return @results.first if @results;
return %()
}

method get-categories(Kind $kind) {
my $kind-conf = self.get-kind-config($kind);
return $kind-conf<categories>.list if $kind-conf<categories>;
return ();
}
}
Loading

0 comments on commit a1a01fa

Please sign in to comment.