Page 1 of 2

Plugin code snippets in the KB

Posted: 15 Dec 2020 11:28
by ColeValleyGirl
I've reviewed the Plugin Code Snippets in the KB and marked most of them as compatible with FH7 as well as 5 & 6.

I have some queries if anyone cares to take a look:

https://fhug.org.uk/kb/code-snippet/uni ... functions/ We have utf8 support in Lua 5.3 plus the utf8 library included in the FH installation -- should we mark this one as compatible with FH7 (it will probably work, after all) or advise people to use lua 5.3 + utf8?

https://fhug.org.uk/kb/code-snippet/pla ... stitution/ Same query

If we do mark them FH7-compatible, somebody needs to review them to identify any changes or caveats needed.

Re: Plugin code snippets in the KB

Posted: 15 Dec 2020 13:51
by tatewise
They are both essentially what my plugins use for FH v5, v6, v7 compatibility.

The only change in the UTF8 string functions is for function substring(strTxt,i,j) to cater for %z

Code: Select all

		local strUTF8 = "([%z\1-\127\194-\244][\128-\191]*)"			-- Cater for Lua 5.1 %z or Lua 5.3 \0
		if fhGetAppVersion() > 6 then
			strUTF8 = "([\0-\127\194-\244][\128-\191]*)"
		end

		-- Supply character substring of UTF-8 text --
		function substring(strTxt,i,j)
			local strSub = ""
			j = j or -1
			if j < 0 then j = j + length(strTxt) + 1 end
			if i < 0 then i = i + length(strTxt) + 1 end
			for strChr in string.gmatch(strTxt or "",strUTF8) do
				if j <= 0 then break end
				j = j - 1
				i = i - 1
				if i <= 0 then strSub = strSub..strChr end
			end
			return strSub
		end -- function substring
For the general string functions, I have added a function inert(strTxt) to hide % symbols in gsub replacement strings where no captures are involved.

Code: Select all

	-- Hide % escape/capture symbols in replacement so they are inert
	function fh.inert(strTxt)
		strTxt = tostring(strTxt or ""):gsub("%%","%%%%")					-- Hide all % symbols
		return strTxt
	end -- function inert
Clearly, it is not possible to use the Lua 5.3 + utf8 options if backward compatibility is required.
I have not yet investigated those options for plugins that only support FH v7.

Re: Plugin code snippets in the KB

Posted: 15 Dec 2020 19:05
by shoshk
Am I mistaken, but didn't there used to be a listing for the snippets according to category? Or am I making it up in my head because that's what I would like to see?

Shosh

Re: Plugin code snippets in the KB

Posted: 15 Dec 2020 19:43
by ColeValleyGirl
Not for snippets, not. They're pretty hard to categorize... but if you want to suggest a et of categories and which snippets belong where, that would be fine.

Re: Plugin code snippets in the KB

Posted: 15 Dec 2020 19:45
by shoshk
I will think about it.

Re: Plugin code snippets in the KB

Posted: 15 Dec 2020 21:11
by tatewise
Code Snippets were always just listed alphabetically, but the other Downloads and Links were categorised as they are in the new KB.

Re: Plugin code snippets in the KB

Posted: 16 Dec 2020 07:05
by shoshk
This is a quick and dirty first attempt to get a discussion going.

I created a pdf version, but it's apparently too big... So here's the Word version.
Proposed Snippet Categories.docx
(21.78 KiB) Downloaded 117 times

Re: Plugin code snippets in the KB

Posted: 16 Dec 2020 08:00
by ColeValleyGirl
That breakdown looks fine to me, Shosh. I'll wait for others to comment, and when we have consensus, I'll set up the categories in the KB. I'd be grateful if somebody else would actually assign them -- I'm up to my neck at present.

Re: Plugin code snippets in the KB

Posted: 16 Dec 2020 08:01
by shoshk
I can assign them.

Re: Plugin code snippets in the KB

Posted: 16 Dec 2020 08:06
by ColeValleyGirl
Thanks -- let's let Mike T and anyone else who's interested weigh in.

Re: Plugin code snippets in the KB

Posted: 16 Dec 2020 08:07
by shoshk
Absolutely

Re: Plugin code snippets in the KB

Posted: 16 Dec 2020 11:15
by tatewise
All the categories look good, although I suspect many of those in Other would fit elsewhere:
File & Folder
Load String from File
Load Text File to Table
Save String to File
Word Load Data Direct Into
Plugin / Lua / Programming
InList Is a value in a list
Strings
Format Number
User Interface
Result Set Creation

The remainder of the snippets under Other could go under Project Database Admin
Ancestor & Descendant List
Build Data Refs
Copy Child Branch Fields
Flags Add and Remove Function
Last Updated Date and Time
Relationship Codes

Re: Plugin code snippets in the KB

Posted: 16 Dec 2020 12:00
by shoshk
I have no objections

Re: Plugin code snippets in the KB

Posted: 16 Dec 2020 12:21
by ColeValleyGirl
Give me a while to remember how to set it all up...

Re: Plugin code snippets in the KB

Posted: 16 Dec 2020 12:24
by shoshk
No pressure...

Re: Plugin code snippets in the KB

Posted: 16 Dec 2020 12:30
by ColeValleyGirl
Shosh, you should be able to categorise them now -- let me know when you've done a few with different categories and I can check how they're displaying.

Thanks.

Re: Plugin code snippets in the KB

Posted: 16 Dec 2020 12:34
by shoshk
I don't see any snippet categories. I am trying both 'quick edit' and 'edit.'

Re: Plugin code snippets in the KB

Posted: 16 Dec 2020 12:43
by ColeValleyGirl
I'm an idiot -- forgot to add all the categories. BRB...

Re: Plugin code snippets in the KB

Posted: 16 Dec 2020 12:51
by ColeValleyGirl
Try now. Don't forget you can put a plugin in two or more caregories if it makes sense to do so.

Re: Plugin code snippets in the KB

Posted: 16 Dec 2020 13:35
by shoshk
I can see the categories now, but can't assign them -- I get a 'forbidden' icon.

Tried it from both 'edit' and 'quick edit'

Re: Plugin code snippets in the KB

Posted: 16 Dec 2020 13:49
by ColeValleyGirl
Try now -- my brain is running on very low blood pressure today!

Re: Plugin code snippets in the KB

Posted: 16 Dec 2020 16:13
by shoshk
I assigned categories to one page full of snippets.

One thing that I notice in the display (kb->downloads>snippets) is that snippets that have not been assigned to a category do not show up anywhere.

Shosh

Re: Plugin code snippets in the KB

Posted: 16 Dec 2020 16:39
by ColeValleyGirl
It's expected the uncategorised snippets won't show up... I'll try to do a few myself.

Re: Plugin code snippets in the KB

Posted: 16 Dec 2020 16:53
by shoshk
I don't have a problem to do the work, but it'll have to wait until tomorrow morning (it's almost 19:00 here).

Is there someway to verify that all snippets are categorized, short of going through them manually and checking?

Re: Plugin code snippets in the KB

Posted: 16 Dec 2020 19:14
by ColeValleyGirl
I don't know of one, other than comparing counts... But let me know when you think you're finished and I'll try to double check.