diff --git a/DESCRIPTION b/DESCRIPTION index 6149ecf..44da921 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Name: jsonstuff -Version: 0.3.0 +Version: 0.3.1 Date: 2019-01-29 Title: JsonStuff - JSON encoding and decoding Author: Andrew Janke diff --git a/inst/+jsonstuff/+internal/load_jsonstuff.m b/inst/+jsonstuff/+internal/load_jsonstuff.m new file mode 100644 index 0000000..361f471 --- /dev/null +++ b/inst/+jsonstuff/+internal/load_jsonstuff.m @@ -0,0 +1,33 @@ +function load_jsonstuff + % Load the jsonstuff library + + pkg_name = "jsonstuff"; + + this_dir = fileparts (fullfile (mfilename ("fullpath"))); + inst_dir = fileparts (fileparts (this_dir)); + shims_dir = fullfile (inst_dir, "shims", "compat"); + + % Load doco + + % When a package is installed, the doc/ directory is added as a subdir + % of the main installation dir, which contains the inst/ files. But when + % running from the repo, doc/ is a sibling of inst/. + + if exist (fullfile (inst_dir, "doc", [pkg_name ".qch"]), "file") + qhelp_file = fullfile (inst_dir, "doc", [pkg_name ".qch"]); + elseif exist (fullfile (fileparts (inst_dir), "doc", [pkg_name ".qch"]), "file") + qhelp_file = fullfile (fileparts (inst_dir), "doc", [pkg_name ".qch"]); + else + % Couldn't find doc file. Oh well. + qhelp_file = []; + endif + + if ! isempty (qhelp_file) + if compare_versions (version, "4.4.0", ">=") && compare_versions (version, "6.0.0", "<") + __octave_link_register_doc__ (qhelp_file); + elseif compare_versions (version, "6.0.0", ">=") + __event_manager_register_doc__ (qhelp_file); + endif + endif + +endfunction diff --git a/inst/+jsonstuff/+internal/unload_jsonstuff.m b/inst/+jsonstuff/+internal/unload_jsonstuff.m new file mode 100644 index 0000000..f1015f4 --- /dev/null +++ b/inst/+jsonstuff/+internal/unload_jsonstuff.m @@ -0,0 +1,30 @@ +function unload_jsonstuff + % Unload the jsonstuff library + + pkg_name = "jsonstuff"; + + this_dir = fileparts (fullfile (mfilename ("fullpath"))); + inst_dir = fileparts (fileparts (this_dir)); + shims_dir = fullfile (inst_dir, "shims", "compat"); + + % Unregister doco + + if exist (fullfile (inst_dir, "doc", [pkg_name ".qch"]), "file") + qhelp_file = fullfile (inst_dir, "doc", [pkg_name ".qch"]); + elseif exist (fullfile (fileparts (inst_dir), "doc", [pkg_name ".qch"]), "file") + qhelp_file = fullfile (fileparts (inst_dir), "doc", [pkg_name ".qch"]); + else + % Couldn't find doc file. Oh well. + qhelp_file = []; + endif + + if ! isempty (qhelp_file) + if compare_versions (version, "4.4.0", ">=") && compare_versions (version, "6.0.0", "<") + __octave_link_unregister_doc__ (qhelp_file); + elseif compare_versions (version, "6.0.0", ">=") + __event_manager_unregister_doc__ (qhelp_file); + endif + endif + + +endfunction diff --git a/inst/PKG_ADD b/inst/PKG_ADD index 660bf81..5754f74 100644 --- a/inst/PKG_ADD +++ b/inst/PKG_ADD @@ -1,41 +1 @@ -% Register package's QHelp with the doc browser - -% PKG_ADD is run in the base workspace, not in a function. So use "__" variable -% names to reduce risk of collision with user variables, and clear them all -% at the end. - -% Have to hardcode this since it's not available from context -__my_pkg_name = 'jsonstuff'; - -% We only want this to happen when we're called by 'pkg load', not when -% this code is just added to the path. -% Note: This detection is a hack and is brittle WRT changes in Octave's -% internal implementation. - -__stack = dbstack; -__is_loading = any (ismember ({__stack.name}, {'load_packages'})); -if ~__is_loading - return; -end - -% And we can only do this on Octave 4.4 and newer, because 4.2 has no -% __octave_link_register_doc___ -if compare_versions (version, '4.4.0', '>=') - - % When a package is installed, the doc/ directory is added as a subdir - % of the main installation dir, which contains the inst/ files - - __this_dir = fileparts (mfilename ('fullpath')); - __my_doc_dir = fullfile (__this_dir, 'doc'); - __my_qhelp_file = fullfile (__my_doc_dir, [__my_pkg_name '.qch']); - if ~exist (__my_qhelp_file, 'file') - warning('QHelp file for package %s is missing: %s', ... - __my_pkg_name, __my_qhelp_file); - return; - end - - __octave_link_register_doc__ (__my_qhelp_file); - -endif - -clear __my_pkg_name __is_loading __stack __this_dir __my_doc_dir __my_qhelp_file +jsonstuff.internal.load_jsonstuff diff --git a/inst/PKG_DEL b/inst/PKG_DEL index 82ce7f4..7c1c684 100644 --- a/inst/PKG_DEL +++ b/inst/PKG_DEL @@ -1,40 +1 @@ -% Unregister package's QHelp with the doc browser - -% PKG_DEL is run in the base workspace, not in a function. So use "__" variable -% names to reduce risk of collision with user variables, and clear them all -% at the end. - -% Have to hardcode this since it's not available from context -__my_pkg_name = 'jsonstuff'; - -% We only want this to happen when we're called by 'pkg unload', not when -% this code is just removed from the path. -% Note: This detection is a hack and is brittle WRT changes in Octave's -% internal implementation. - -__stack = dbstack; -__is_loading = any (ismember ({__stack.name}, {'unload_packages','uninstall'})); -if ~__is_loading - return; -end - -% And we can only do this on Octave 4.4 and newer, because 4.2 has no -% __octave_link_register_doc___ -if compare_versions (version, '4.4.0', '>=') - - % When a package is installed, the doc/ directory is added as a subdir - % of the main installation dir, which contains the inst/ files - - __this_dir = fileparts (mfilename ('fullpath')); - __my_doc_dir = fullfile (__this_dir, 'doc'); - __my_qhelp_file = fullfile (__my_doc_dir, [__my_pkg_name '.qch']); - if ~exist (__my_qhelp_file, 'file') - % Don't bother warning on unloads - return; - end - - __octave_link_unregister_doc__ (__my_qhelp_file); - -endif - -clear __my_pkg_name __stack __is_loading __this_dir __my_doc_dir __my_qhelp_file +jsonstuff.internal.unload_jsonstuff