Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

separation of taks

  • Loading branch information...
commit af5cbe5010140998eea8fd438cc8a3e3751f372f 1 parent aca128b
@sergot authored
Showing with 126 additions and 115 deletions.
  1. +4 −103 web/build.p6
  2. +12 −12 web/index.mojo
  3. +110 −0 web/mkjson.p6
View
107 web/build.p6
@@ -1,111 +1,12 @@
use v6;
-use Template::Mojo;
use JSON::Tiny;
-
-class Project {
- has $.URL = die "Every project needs an URL";
- has $.gitname = die "Every project needs an gitname";
-
- has $.name;
- has $.readme;
- has $.logo;
- has $.description;
-
- has Pair $.test-results is rw; # colour => description
-
- method has_tests() {
- return True if "$.gitname/t".IO.e;
- return False;
- }
-
- method is_fresh() {
- if qqx[ cd $.gitname; git log -n 1 --format='%ci' ] ~~ m/^(\d\d\d\d)\-(\d\d)\-(\d\d)\s+/ {
- return True if ((Date.today - Date.new(+$0, +$1, +$2)) <= 90);
- }
- return False;
- }
-
- submethod BUILD(:$!URL, :$!gitname, :$!name, :$!description, :$!logo, :$!readme) {
- my $url = $!URL;
- $url ~~ s:g/\//\\\//;
-
- qqx/ git clone $url /;
- #$gitname.IO.e ?? eval "qx/ cd $gitname; git pull /" !! eval "qx/ git clone $url /"; too slow
-
- my $item;
- try {
- $item = from-json(slurp "$!gitname/META.info")[0];
- }
-
- $!name = $item<name> or "error";
- $!description = $item<description> or "error";
-
- $!URL ~~ s/git\:\/\//https\:\/\//;
- $!URL ~~ s/\.git//;
-
- $!logo = $!URL~"/raw/master/logotype/logo_32x32.png" if "$!gitname/logotype/logo_32x32.png".IO.e;
-
- my $readme_file = readme_file($!gitname);
- $!readme = $readme_file ?? $!URL~"/blob/master/"~$readme_file !! False;
- }
-
- sub readme_file(Str $path) {
- for "", ".md", ".markdown", ".mkd" {
- return "README$_" if "$path/README$_".IO.e for "", ".md", ".markdown", ".mkd";
- }
- }
-
- method to_hash {
- my %hash = "name" => $.name,
- "URL" => $.URL,
- "gitname" => $.gitname,
- "readme" => $.readme,
- "description" => $.description,
- "has_tests" => self.has_tests,
- "is_fresh" => self.is_fresh,
- "logo" => $.logo;
- return %hash;
- }
-}
-
-my %test-results = from-json(slurp("results.json"));
-
-my $projects = slurp("modules.list").split("\n").map: {
- say $_;
- my $p = Project.new(URL => $_, gitname => ~$/[0]) if /\/\/.*?\/.*?\/(.*?)\.git/;
- next unless $p;
- say $p.perl;
- next unless $p.name;
- next unless %test-results{$p.name};
- $p.test-results = do given %test-results{$p.name} {
- when .<prereq> == False {
- red => 'Could not resolve dependencies'
- }
- when .<build> == False {
- red => 'Did not build successfully'
- }
- when .<test> == False {
- red => 'Some tests have failed'
- }
- when $p.has_tests == False {
- yellow => 'Has no tests'
- }
- default {
- green => 'Everything all right'
- }
- }
- $p;
-}
+use Template::Mojo;
my $last_update = DateTime.now.Str;
my $tmpl = slurp "index.mojo";
+my $projects = from-json(slurp("../proto.json")).values;
+
my $index = open "../index.html", :w;
-$index.say: Template::Mojo.new($tmpl).render($projects.list.sort( *.name).item, $last_update);
+$index.say: Template::Mojo.new($tmpl).render($projects, $last_update);
$index.close;
-
-my $json = open "../proto.json", :w;
-my %all;
-%all.push(.gitname => .to_hash) for $projects.list;
-$json.say: to-json(%all);
-$json.close;
View
24 web/index.mojo
@@ -104,37 +104,37 @@ dl.table-display {
<dl class="table-display">
% my ($projects, $last_update) = @_;
% for $projects.list {
-% if $_.description {
+% if $_<description> {
<dt>
-% if $_.logo {
- <img class="project-logo" src="<%= $_.logo %>" alt="<%= $_.name %> logo" />
+% if $_<logo> {
+ <img class="project-logo" src="<%= $_<logo> %>" alt="<%= $_<name> %> logo" />
% }
- <a href="<%= $_.URL %>"><%= $_.name %></a></dt>
+ <a href="<%= $_<URL> %>"><%= $_<name> %></a></dt>
<dd>
<div class='badges'>
-% if $_.readme {
- <a href="<%= $_.readme %>"><img src='readme.png' title='Has a README' alt="Readme badge" /></a>
+% if $_<readme> {
+ <a href="<%= $_<readme> %>"><img src='readme.png' title='Has a README' alt="Readme badge" /></a>
% } else {
<img src='unachieved.png' title="Doesn't have a README" alt="Unachieved badge" />
% }
-% if $_.has_tests {
+% if $_<has_tests> {
<img src='tests.png' title='Has tests' alt="Tests badge" />
% } else {
<img src='unachieved.png' title="Doesn't have tests" alt="Unachieved badge" />
% }
-% if $_.is_fresh {
+% if $_<is_fresh> {
<img src='fresh.png' title='Commits in the past 90 days' alt="Fresh badge" />
% } else {
<img src='unachieved.png' title='No commits in the past 90 days' alt="Unachieved badge" />
% }
-% my $tests = $_.test-results;
+% my $tests = $_<test-results>;
<span
- style="font-size:32px;color:<%= $tests.key %>">
+ style="font-size:32px;color:<%= $tests.keys[0] %>">
<abbr title="<%= sprintf 'Test results for %s: %s',
- $_.name, $tests.value %>">●</abbr>
+ $_<name>, $tests.values[0] %>">●</abbr>
</span>
</div>
- <%= $_.description %></dd>
+ <%= $_<description> %></dd>
% } # if
% } # for
</dl>
View
110 web/mkjson.p6
@@ -0,0 +1,110 @@
+use v6;
+#use Template::Mojo;
+use JSON::Tiny;
+
+class Project {
+ has $.URL = die "Every project needs an URL";
+ has $.gitname = die "Every project needs an gitname";
+
+ has $.name;
+ has $.readme;
+ has $.logo;
+ has $.description;
+
+ has Pair $.test-results is rw; # colour => description
+
+ method has_tests() {
+ return True if "$.gitname/t".IO.e;
+ return False;
+ }
+
+ method is_fresh() {
+ if qqx[ cd $.gitname; git log -n 1 --format='%ci' ] ~~ m/^(\d\d\d\d)\-(\d\d)\-(\d\d)\s+/ {
+ return True if ((Date.today - Date.new(+$0, +$1, +$2)) <= 90);
+ }
+ return False;
+ }
+
+ submethod BUILD(:$!URL, :$!gitname, :$!name, :$!description, :$!logo, :$!readme) {
+ my $url = $!URL;
+ $url ~~ s:g/\//\\\//;
+
+ qqx/ git clone $url /;
+ #$gitname.IO.e ?? eval "qx/ cd $gitname; git pull /" !! eval "qx/ git clone $url /"; too slow
+
+ my $item;
+ try {
+ $item = from-json(slurp "$!gitname/META.info")[0];
+ }
+
+ $!name = $item<name> or "error";
+ $!description = $item<description> or "error";
+
+ $!URL ~~ s/git\:\/\//https\:\/\//;
+ $!URL ~~ s/\.git//;
+
+ $!logo = $!URL~"/raw/master/logotype/logo_32x32.png" if "$!gitname/logotype/logo_32x32.png".IO.e;
+
+ my $readme_file = readme_file($!gitname);
+ $!readme = $readme_file ?? $!URL~"/blob/master/"~$readme_file !! False;
+ }
+
+ sub readme_file(Str $path) {
+ for "", ".md", ".markdown", ".mkd" {
+ return "README$_" if "$path/README$_".IO.e for "", ".md", ".markdown", ".mkd", ".mkdn", ".pod";
+ }
+ }
+
+ method to_hash {
+ my %hash = "name" => $.name,
+ "URL" => $.URL,
+ "gitname" => $.gitname,
+ "readme" => $.readme,
+ "description" => $.description,
+ "has_tests" => self.has_tests,
+ "is_fresh" => self.is_fresh,
+ "test-results" => $.test-results.hash,
+ "logo" => $.logo;
+ return %hash;
+ }
+}
+
+my %test-results = from-json(slurp("results.json"));
+
+my $projects = slurp("modules.list").split("\n").map: {
+ my $p = Project.new(URL => $_, gitname => ~$/[0]) if /\/\/.*?\/.*?\/(.*?)\.git/;
+ next unless $p;
+ next unless $p.name;
+ next unless %test-results{$p.name};
+ $p.test-results = do given %test-results{$p.name} {
+ when .<prereq> == False {
+ red => 'Could not resolve dependencies'
+ }
+ when .<build> == False {
+ red => 'Did not build successfully'
+ }
+ when .<test> == False {
+ red => 'Some tests have failed'
+ }
+ when $p.has_tests == False {
+ yellow => 'Has no tests'
+ }
+ default {
+ green => 'Everything all right'
+ }
+ }
+ $p;
+}
+
+#my $last_update = DateTime.now.Str;
+#my $tmpl = slurp "index.mojo";
+
+#my $index = open "../index.html", :w;
+#$index.say: Template::Mojo.new($tmpl).render($projects.list.sort( *.name).item, $last_update);
+#$index.close;
+
+my $json = open "../proto.json", :w;
+my %all;
+%all.push(.gitname => .to_hash) for $projects.list;
+$json.say: to-json(%all);
+$json.close;
Please sign in to comment.
Something went wrong with that request. Please try again.