From: Jean Privat Date: Sat, 7 Nov 2015 21:53:59 +0000 (-0500) Subject: nitcatalog: add option in inject piwik tracker X-Git-Tag: v0.8~95^2 X-Git-Url: http://nitlanguage.org nitcatalog: add option in inject piwik tracker Signed-off-by: Jean Privat --- diff --git a/src/nitcatalog.nit b/src/nitcatalog.nit index a42bd64..f629b4f 100644 --- a/src/nitcatalog.nit +++ b/src/nitcatalog.nit @@ -134,6 +134,37 @@ class CatalogPage """ end + # Inject piwik HTML code if required + private fun add_piwik + do + var tracker_url = catalog.piwik_tracker + if tracker_url == null then return + + var site_id = catalog.piwik_site_id + + tracker_url = tracker_url.trim + if tracker_url.chars.last != '/' then tracker_url += "/" + add """ + + + + +""" + + end + redef fun rendering do add """ @@ -141,6 +172,10 @@ class CatalogPage +""" + add_piwik + add """ + """ @@ -661,6 +696,13 @@ class Catalog res.add "\n" return res end + + # Piwik tracker URL, if any + var piwik_tracker: nullable String = null + + # Piwik site ID + # Used when `piwik_tracker` is set + var piwik_site_id: Int = 1 end # Execute a git command and return the result @@ -682,7 +724,13 @@ var opt_no_git = new OptionBool("Do not gather git information from the working var opt_no_parse = new OptionBool("Do not parse nit files (no importation information)", "--no-parse") var opt_no_model = new OptionBool("Do not analyse nit files (no class/method information)", "--no-model") -tc.option_context.add_option(opt_dir, opt_no_git, opt_no_parse, opt_no_model) +# Piwik tracker URL. +# If you want to monitor your visitors. +var opt_piwik_tracker = new OptionString("Piwik tracker URL (ex: `nitlanguage.org/piwik/`)", "--piwik-tracker") +# Piwik tracker site id. +var opt_piwik_site_id = new OptionString("Piwik site ID", "--piwik-site-id") + +tc.option_context.add_option(opt_dir, opt_no_git, opt_no_parse, opt_no_model, opt_piwik_tracker, opt_piwik_site_id) tc.process_options(sys.args) tc.keep_going = true @@ -690,6 +738,19 @@ tc.keep_going = true var modelbuilder = new ModelBuilder(model, tc) var catalog = new Catalog(modelbuilder) +catalog.piwik_tracker = opt_piwik_tracker.value +var piwik_site_id = opt_piwik_site_id.value +if piwik_site_id != null then + if catalog.piwik_tracker == null then + print_error "Warning: ignored `{opt_piwik_site_id}` because `{opt_piwik_tracker}` is not set." + else if piwik_site_id.is_int then + print_error "Warning: ignored `{opt_piwik_site_id}`, an integer is required." + else + catalog.piwik_site_id = piwik_site_id.to_i + end +end + + # Get files or groups var args = tc.option_context.rest if opt_no_parse.value then