summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@osg.samsung.com>2016-08-02 15:32:24 +0100
committerDaniel Kolesa <d.kolesa@osg.samsung.com>2016-08-02 15:32:50 +0100
commit3c34a53cb8b46d72da1f68c1f944f474e2662f75 (patch)
tree84499327fa7ac628c3d91fc81a0853455bb8725d
parentdde1299182de2234fe1d4a2d4e714e78d710ff94 (diff)
docs: add theme loader for graphs
-rw-r--r--src/scripts/elua/apps/docgen/writer.lua2
-rw-r--r--src/scripts/elua/apps/gendoc.lua107
2 files changed, 102 insertions, 7 deletions
diff --git a/src/scripts/elua/apps/docgen/writer.lua b/src/scripts/elua/apps/docgen/writer.lua
index 14e8baed5e..ce80419c8e 100644
--- a/src/scripts/elua/apps/docgen/writer.lua
+++ b/src/scripts/elua/apps/docgen/writer.lua
@@ -133,7 +133,7 @@ M.Writer = util.Object:clone {
133 end 133 end
134 134
135 local write_attrs = function(attrs) 135 local write_attrs = function(attrs)
136 if not v then 136 if not attrs then
137 return 137 return
138 end 138 end
139 self:write_raw(" [") 139 self:write_raw(" [")
diff --git a/src/scripts/elua/apps/gendoc.lua b/src/scripts/elua/apps/gendoc.lua
index 417ddf5c6a..828a732700 100644
--- a/src/scripts/elua/apps/gendoc.lua
+++ b/src/scripts/elua/apps/gendoc.lua
@@ -1,6 +1,8 @@
1local eolian = require("eolian") 1local eolian = require("eolian")
2local getopt = require("getopt") 2local getopt = require("getopt")
3 3
4local serializer = require("serializer")
5
4local eomap = require("docgen.mappings") 6local eomap = require("docgen.mappings")
5local stats = require("docgen.stats") 7local stats = require("docgen.stats")
6local dutil = require("docgen.util") 8local dutil = require("docgen.util")
@@ -557,6 +559,95 @@ local default_theme = {
557 bg_color = "transparent" 559 bg_color = "transparent"
558} 560}
559 561
562local current_theme = default_theme
563
564local validate_ctheme = function(tb, name)
565 if type(tb.classes[name]) ~= "table" then
566 return false
567 end
568 local t = tb.classes[name]
569 if type(t.style) ~= "string" then
570 return false
571 end
572 if type(t.color) ~= "string" then
573 return false
574 end
575 if type(t.fill_color) ~= "string" then
576 return false
577 end
578 if not t.primary_color then
579 t.primary_color = t.color
580 end
581 if not t.primary_fill_color then
582 t.primary_fill_color = t.fill_color
583 end
584 if type(t.primary_color) ~= "string" then
585 return false
586 end
587 if type(t.primary_fill_color) ~= "string" then
588 return false
589 end
590 return true
591end
592
593local validate_theme = function(tb)
594 if type(tb) ~= "table" then
595 return false
596 end
597 if type(tb.classes) ~= "table" then
598 return false
599 end
600 if not tb.node then
601 tb.node = default_theme.node
602 end
603 if not tb.edge then
604 tb.edge = default_theme.edge
605 end
606 if not tb.bg_color then
607 tb.bg_color = default_theme.bg_color
608 end
609 if type(tb.node) ~= "table" then
610 return false
611 end
612 if type(tb.edge) ~= "table" then
613 return false
614 end
615 if type(tb.bg_color) ~= "string" then
616 return false
617 end
618 if not validate_ctheme(tb, "regular") then
619 return false
620 end
621 if not validate_ctheme(tb, "abstract") then
622 return false
623 end
624 if not validate_ctheme(tb, "mixin") then
625 return false
626 end
627 if not validate_ctheme(tb, "interface") then
628 return false
629 end
630 return true
631end
632
633local set_theme = function(tname)
634 local tf = io.open(tname)
635 if tf then
636 local cont = tf:read("*all")
637 tf:close()
638 local tb, err = serializer.deserialize(cont)
639 if not tb then
640 error("error parsing theme '" .. tname .. "': " .. err)
641 end
642 if not validate_theme(tb) then
643 error("invalid theme '" .. tname .. "'")
644 end
645 current_theme = tb
646 else
647 error("theme '" .. tname .. "' does not exist")
648 end
649end
650
560local classt_to_theme = { 651local classt_to_theme = {
561 [eolian.class_type.REGULAR] = "regular", 652 [eolian.class_type.REGULAR] = "regular",
562 [eolian.class_type.ABSTRACT] = "abstract", 653 [eolian.class_type.ABSTRACT] = "abstract",
@@ -572,9 +663,9 @@ local class_to_node = function(cl, main)
572 663
573 local clr = classt_to_theme[cl:type_get()] 664 local clr = classt_to_theme[cl:type_get()]
574 665
575 ret.style = default_theme.classes[clr].style 666 ret.style = current_theme.classes[clr].style
576 ret.color = default_theme.classes[clr][main and "primary_color" or "color"] 667 ret.color = current_theme.classes[clr][main and "primary_color" or "color"]
577 ret.fillcolor = default_theme.classes[clr][main and "primary_fill_color" 668 ret.fillcolor = current_theme.classes[clr][main and "primary_fill_color"
578 or "fill_color"] 669 or "fill_color"]
579 670
580 -- FIXME: need a dokuwiki graphviz plugin with proper URL support 671 -- FIXME: need a dokuwiki graphviz plugin with proper URL support
@@ -605,10 +696,10 @@ local build_igraph = function(cl)
605 attrs = { 696 attrs = {
606 rankdir = "TB", 697 rankdir = "TB",
607 size = "6", 698 size = "6",
608 bgcolor = default_theme.bg_color 699 bgcolor = current_theme.bg_color
609 }, 700 },
610 node = default_theme.node, 701 node = current_theme.node,
611 edge = default_theme.edge 702 edge = current_theme.edge
612 } 703 }
613 704
614 local nbuf = {} 705 local nbuf = {}
@@ -991,6 +1082,7 @@ getopt.parse {
991 { category = "Generator" }, 1082 { category = "Generator" },
992 { "r", "root", true, help = "Root path of the docs." }, 1083 { "r", "root", true, help = "Root path of the docs." },
993 { "n", "namespace", true, help = "Root namespace of the docs." }, 1084 { "n", "namespace", true, help = "Root namespace of the docs." },
1085 { nil, "graph-theme", true, help = "Optional graph theme." },
994 { nil, "disable-graphviz", false, help = "Disable graphviz usage." }, 1086 { nil, "disable-graphviz", false, help = "Disable graphviz usage." },
995 { nil, "disable-notes", false, help = "Disable notes plugin usage." } 1087 { nil, "disable-notes", false, help = "Disable notes plugin usage." }
996 }, 1088 },
@@ -1002,6 +1094,9 @@ getopt.parse {
1002 if opts["h"] then 1094 if opts["h"] then
1003 return 1095 return
1004 end 1096 end
1097 if opts["graph-theme"] then
1098 set_theme(opts["graph-theme"])
1099 end
1005 use_dot = not opts["disable-graphviz"] 1100 use_dot = not opts["disable-graphviz"]
1006 local rootns = (not opts["n"] or opts["n"] == "") 1101 local rootns = (not opts["n"] or opts["n"] == "")
1007 and "efl" or opts["n"] 1102 and "efl" or opts["n"]