Updated 032 JCB manual custom code implementation (markdown)
parent
51fbf9a90d
commit
39c67a129b
@ -4,19 +4,25 @@
|
||||
|
||||
[00:00:00](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h00m00s)
|
||||
|
||||
Automatic import of custom code during compilation. This is one of the latest features that has been added to the JCB component. Although all its functionality is in place there is currently some limitations which exist that need to be explained. First, what does it accomplish? It actually mutated from that which its original purpose had been and became two things.[00:00:52](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h00m52s) The first thing is, (and this is obviously what was initially intended) that it will be possible to add code to the component, once it's been compiled and installed into that same Joomla website. That you be able to go into that code, and with a few placeholders add code, [00:01:21](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h01m21s) that once you compile the component again, JCB would dynamically grab that code, extract it into its database, store it there. And from there on forward continue to add it back into the component every time. The way we've done that, we have not used the line numbers as the main [00:01:50](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h01m50s) way of determining where that code must be added. Because of the reality that line numbers always will change. You might have the custom code that you're adding, you said line 105 or something, and if you make it change at line 20, that means all the code moves down of course and now we don't know where to add your code [00:02:19](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h02m19s) without either writing over or placing it before, there's all kinds of complications. So the only way we could resolve that is to create what we initially called the fingerprint, but later became a hash reference of the code, a few lines of code above the custom script, and a few lines of code below the customs. [00:02:50](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h02m50s) It varies from how many lines it uses. There is a reason for it.
|
||||
Automatic import of custom code during compilation. This is one of the latest features that has been added to the JCB component. Although all its functionality is in place there is currently some limitations which exist that need to be explained. First, what does it accomplish? It actually mutated from that which its original purpose had been and became two things.[00:00:52](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h00m52s) The first thing is, (and this is obviously what was initially intended) that it will be possible to add code to the component once it has been compiled and installed into that same Joomla website, then to be able to go into that code, with a few placeholders add code, that once the component is compiled again, JCB would dynamically grab that code, extract it into its database, store it there and from there on forward continue to add it back into the component every time. [00:01:43](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h01m43s)The way it have been done was that the line numbers had not been used as the main way of determining where that code must be added. The reality is that the line numbers will always change. It may be Custom code that is added, for instance line '105', and if it is made to change at line '20', that means all the code moves down of course and it is impossible to know where to add your code without either writing over or placing it before, there are all kinds of complications. So the only way to resolve that is to create what had been initially called the fingerprint, but later became a hash reference of the code, a few lines of code above the custom script, and a few lines of code below the customs. [00:02:50](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h02m50s) It varies from how many lines it uses. There is a reason for it.
|
||||
|
||||
### Updating Code From JCB In The Editor
|
||||
|
||||
If you want to see how we do it, there is the code is open source, so you can go look at it. So there is a function in the aget file, which is part of the [00:03:22](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h03m22s) compiler a set of files. The functions name is searchfilecontent. It's in this function that it really goes through every line of the code that is already on the Joomla website. When it finds it, it adds it to an array which eventually gets save to the database. This is the lines that actually does the work. [00:03:53](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h03m53s) There's lots of things that works with this function, but this is the center of everything. I'm very sure there are better ways to do this. We will constantly improve this as others makes suggestions, and make sure that it remains stable. But to to explain why it sometimes [00:04:27](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m27s) uses more or less of the lines above, it should never use more than 8 lines. Because here it is packing the fingerprint, taking the line content putting it into an array. Every time it passes, it checks whether that array if it is greater than 10, we cut it down to 6. [00:04:54](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m54s) This continues to happen over and over and over because we don't want this fingerprint array to become bigger then 10 lines. At some point when we find a placeholder, we actually take that fingerprint array, we create a hash from it, then we store that hash into the database. [00:05:24](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h05m24s) That means that amount of lines are changing. Because we have just cleared the array and we are at 6 lines. Then we add a 7th and now we find a placeholder and everything happens.
|
||||
[00:03:01](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h03m01s)
|
||||
|
||||
If you want to see how it had been done, the code is open source, it is possible to go and look at it. There is a function in the 'Aget' file, which is part of the compiler a set of files. The functions name is 'searchfilecontent'. It's in this function that it really goes through every line of the code that is already on the Joomla website. When it finds it, it adds it to an array which eventually gets saved to the database. This is the lines that actually does the work. [00:03:53](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h03m53s) There's lots of things that works with this function, but this is the center of everything. There are better ways to do this. It will constantly be improved and insured that it remains stable as suggestions is being made. [00:04:27](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m27s) It should never use more than 8 lines as it is here where it is packing the fingerprint and takes the line content and place it into an array. Every time it passes, it checks whether that array is greater than 10, and should be cut down to 6. [00:04:54](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h04m54s) This continues to happen over and over because this fingerprint array should not become bigger then 10 lines. At some point when a placeholder is found, the fingerprint array is taken, a hash gets created from it, then it is stored into the database. [00:05:24](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h05m24s) That means that amount of lines are changing. Because the array has been cleared and are at 6 lines. Then a 7th gets added and now we find a placeholder and everything happens.
|
||||
|
||||
### Quick Explanation - Insert/Replace
|
||||
|
||||
There are two ways in which the code is added. I have explain that in the previous tutorial, but I can do that again. [00:05:56](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h05m56s) In that same file there is a comment way at the top, which gives their explanation of the placeholders. The placeholders these X s here, must be asterisks. There like that one(///***[INSERT<>$$$$]***///). [00:06:26](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h06m26s) This is the one with which you would start either to insert or to replace.
|
||||
[00:05:43](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h05m43s)
|
||||
|
||||
There are two ways in which the code is added. It has been explained in the previous tutorial, and will be explained again. In that same file there is a comment way at the top, which gives the explanation of the placeholders. The placeholders, these X's here, must be asterisks. Like this one(///***[INSERT<>$$$$]***///). [00:06:26](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h06m26s) This is the one with which you would start either to insert or to replace.<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
### GitHub Explanation For Update And Insert Issue 37
|
||||
|
||||
There is also a note on GitHub about this which may be more logical. So here we are at Github. It's on issue 37 if you want to go look at it under the Joomla component on GitHub [00:06:55](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h06m55s) the component builder on GitHub. Basically to start inserting code, you would use this(///***[INSERT<>$$$$]***///) as a placeholder, then your code on a new line, then when you're finished this(///***[INSERT<>$$$$]***///) would close that code block. Sometimes you don't want insert code, you want to replace code that was generated by JCB. Then you'd use the replace code placeholder(///***[REPLACE<>$$$$]***///). And then again use this(///***[REPLACE<>$$$$]***///) one to end the code block. [00:07:25](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h07m25s) Now when component builder on compilation discovers these tags(///***[INSERT<>$$$$]***///)(///***[REPLACE<>$$$$]***///), they get converted to from insert to inserted and from replace from replaced. It adds it back without this diamond(<>) in between those dollar signs and inserted text or replaced text. [00:07:55](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h07m55s) It removes them because basically by doing that, it means that this code doesn't need to be updated. The moment you add those two back in there between those 2 values, next time component builder compiles. It actually knows this piece of code I need to check again and update whatever is in the database, because it's been changed. [00:08:25](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h08m25s) This diamond here tells it. There is a change you need to update. You will see that there is this new number being added next to the code. That number is actually the id of the database row [00:08:49](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h08m49s) that JCB is actually stored the code in. So if you change this number, you are going to have a problem. So don't change this number. JCB put this number in that he can know where to go update the code in the database. Once you've made any changes to the code, you would simply add this diamond(<>) back in, that's quite important otherwise it will not be [00:09:18](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h09m18s) be parsed, and it will be overwritten by what's in the database. That's the initial purpose of this new feature, was to be able in the editor, create code and then on the fly, have it become part of the JCB infrastructure for your component. Then in the future it will continue adding that code back in without you having to write it, or [00:09:47](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h09m47s) remember it. If you want to change the code you just add these diamonds(<>) either for the insert or for the replace depending on what you did. It will automatically know there's been a change and it will first update what is in the database, and then store it back into the new compiled version. That is exciting in itself I realize [00:10:12](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h10m12s) it's a real stunning new feature. We have been doing some teething on some of its implementation. You can even read down here. There's some comments and things. We are at the moment at version 2.3.2 which is not yet released. I'm busy working on it because this new version 2.3.2 will include [00:10:41](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h10m41s) the extra feature which wasn't ever really discussed here on the forum. Because it was a feature that I've been hoping for quite some time. I've build quite a number of components with JCB by now. I've always had this issue that I would develop a very smart function, a custom script, inside of some view or some field or somewhere in JCB. I would like to use it again elsewhere [00:11:15](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h11m15s) but then I have to copy it, go pasted there. And it will happen that I would improve it there. Add this little thing there and I debug this. Improve the whole function, maybe just pieces script or whatever, I just improves it. And then it where I took it from does I need to know copy again back there. It's always this copy and move and then obviously there's variables inside that needs to be different names. [00:11:47](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h11m47s) This always been a very unpleasant experience.
|
||||
There is also a note on GitHub about this which may be more logical. So here we are at Github. It's on issue 37 if you want to go look at it under the Joomla component on GitHub [00:06:55](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h06m55s) the component builder on GitHub. Basically to start inserting code, you would use this (///***[INSERT<>$$$$]***///)as a placeholder, then your code on a new line, then when you're finished this(///***[INSERT<>$$$$]***///) would close that code block. Sometimes you don't want insert code, you want to replace code that was generated by JCB. Then you'd use the replace code placeholder(///***[REPLACE<>$$$$]***///). And then again use this one(///***[REPLACE<>$$$$]***///) to end the code block. [00:07:25](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h07m25s) Now when component builder on compilation discovers these tags(///***[INSERT<>$$$$]***///)(///***[REPLACE<>$$$$]***///), they get converted to from insert to inserted and from replace from replaced. It adds it back without this diamond(<>) in between those dollar signs and inserted text or replaced text. [00:07:55](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h07m55s) It removes them because basically by doing that, it means that this code doesn't need to be updated. The moment you add those two back in there between those 2 values, next time component builder compiles. It actually knows this piece of code I need to check again and update whatever is in the database, because it's been changed. [00:08:25](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h08m25s) This diamond here tells it. There is a change you need to update. You will see that there is this new number being added next to the code. That number is actually the id of the database row [00:08:49](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h08m49s) that JCB is actually stored the code in. So if you change this number, you are going to have a problem. So don't change this number. JCB put this number in that he can know where to go update the code in the database. Once you've made any changes to the code, you would simply add this diamond(<>) back in, that's quite important otherwise it will not be [00:09:18](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h09m18s) be parsed, and it will be overwritten by what's in the database. That's the initial purpose of this new feature, was to be able in the editor, create code and then on the fly, have it become part of the JCB infrastructure for your component. Then in the future it will continue adding that code back in without you having to write it, or [00:09:47](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h09m47s) remember it. If you want to change the code you just add these diamonds(<>) either for the insert or for the replace depending on what you did. It will automatically know there's been a change and it will first update what is in the database, and then store it back into the new compiled version. That is exciting in itself I realize [00:10:12](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h10m12s) it's a real stunning new feature. We have been doing some teething on some of its implementation. You can even read down here. There's some comments and things. We are at the moment at version 2.3.2 which is not yet released. I'm busy working on it because this new version 2.3.2 will include [00:10:41](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h10m41s) the extra feature which wasn't ever really discussed here on the forum. Because it was a feature that I've been hoping for quite some time. I've build quite a number of components with JCB by now. I've always had this issue that I would develop a very smart function, a custom script, inside of some view or some field or somewhere in JCB. I would like to use it again elsewhere [00:11:15](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h11m15s) but then I have to copy it, go pasted there. And it will happen that I would improve it there. Add this little thing there and I debug this. Improve the whole function, maybe just pieces script or whatever, I just improves it. And then it where I took it from does I need to know copy again back there. It's always this copy and move and then obviously there's variables inside that needs to be different names. [00:11:47](https://www.youtube.com/watch?v=KiAtJawZ3oo&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&t=00h11m47s) This always been a very unpleasant experience.
|
||||
|
||||
### Custom Codes In JCB
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user