-
-
Notifications
You must be signed in to change notification settings - Fork 178
031 Automatic import of custom code during compilation in JCB
Hi welcome to component builder. We've just added a very smart new feature to component builder 00:00:12 that's called custom code. You can find it here next to dynamic get. It's where it's stored. You'd hardly never need to go in here, unless you want to look at what is already been stored and make changes in the UI. Most of the time you will be doing the changes in your editor. So your editor will be where you will work. 00:00:39 So what is the purpose of this new feature? The feature is there for those who are used to coding in another editor. So what we can then say they create a component in component builder, then once they've created it, they do a compile and install it onto the same website as component builder to test it. Then during testing they are adding code into that 00:01:13 compiled version that are installed onto this website. Well the new feature could on compilation extract that custom code. Store it in this custom code area, and add it back into the component on the fly. I'm sure that is quite exciting. Let me do some demonstration give you some of the rules, guidelines, since there are some limitations. 00:01:45 This is still in beta there's quite a few things still to do. But I would like to get it out there have you guys tested and get some feedback.
I'm going to compile the demo component. Since most of you might already have this component installed. And you can then use this is so the test area. I'm going to install it on to this current site. I'm going to go and give you an explanation of how to add 00:02:28 custom scripting to that component by going to an editor.
Here in the editor you can see this is the root directory of the website. I'm going to do something on the back end of the components. I'll open administrator, components. There is the demo component. Let's just go to it's main index page. I'm going to add some custom scripting, just for the demonstration. 00:03:04 Now the way to add custom scripting, there are some conventions and some regulations.
??? Let me first show you the conventions. To insert custom scripting you will use a tag like so(see video). You will use asterisks instead of The X s that are in the code so the code has the X s in it but the actual They would be with the Asterix So that will be to insert new code you use that that place holder and the beginning of the Area then after a new line You will insert your code and then at the end of the code you will insert this one to close the code 00:03:50 Ok Then there are obviously two ways Of adding code, one is to insert code and one is to replace existing code So inserting code would simply at the same line insert that code into the existing code Where is replacing code will literally remove the old code and add the new code in its place So these are the two conventions Once component builder adds the code back The tag will change inserted Insert will change to inserted And will have this new number at the end this number is actually referencing the ID of the 00:04:28 Code in the system Now don't ever change this number or component Builder with think that it doesn't have one And it needs to be created So it will be an error it won't work so don't take this Number out Then It will add this at the end Now on other after compiling it and adding this string in it won't Compile it again because of these Opening and closing 00:04:56 Brackets not being there Greater and Lesser than signs They they are the ones that activate it and makes makes it Basically be parsed again So when component builder places the code back it looks like this When you then later come and want to change it again you would add this diamond in there And it will then update the existing Code in the database With the changes that you've made 00:05:30 That's basically it. There are a few limitations you cannot add Code Closer to each other than I would say 6 lines So if there are gonna be code Close to each other and it ends and starts within the parameter of 6 lines You end up with a problem So especially at the end I will demonstrate that somehow in our Actual doing of of this but the reason is Component Builder doesn't only use the line In which this is found to remember where to place it But actually creates a sort of a fingerprint of the code above the insertion and the code 00:06:14 Below this insertion to Accurately insert it in the future So that code changes and then Component Builder will give you a notice and will not insert the code This is because of the nature of JCB It actually is constantly improving it's constantly being improved and that therefore it's code is obviously moving Around quite a lot Now There was no other way for us to try and automate this 00:06:48 Because if we use the line it could possibly cause an accident by overwriting code you You never intended it to overwrite So the only way we could solve this was creating what we call a fingerprint Few lines above the insertion or the replacement and a few lines below there that replacement Now I'll demonstrate this in our in our demonstration in a moment Just a heads up about that So just quickly a recap To insert new code you will use this To replace new code or for the first time you would use that 00:07:25 Obviously at the end of the code you would add these Corresponding placeholders I'll put these this little block Into the comments of this tutorial So that if any of you need to copy it down you could just copy it from there Ok and so when Component builder adds it back It will look like this for the inserted and this for the replaced and if you then come back Obviously all you need to do is just add that diamond in there For it to be updated in the database 00:08:00 So let's see this in action So here we have that demo components Main Document Open So I'm gonna add some replacement tags here So there we go I'm basically not making any changes but I could I could add a few lines here Maybe another comment hi it worked And No space there 00:08:34 Let's do Echo Hi it Worked And that should do it so now this is just gonna replace this area So let's go to the compiler and compile the component See what happens So in the compiler I'm simply gonna compile a component again Ok it successfully compiled Now before I install it I could do a check to see whether it actually did get the code from the component 00:09:24 The way I'll do that is I'm just gonna open custom codes in a new tab And low and behold there is says component demo and the path in which the change was made And did it was it was a replacement so we can open that And there is the code that we want replaced Right And there is the hashtag For the start The fingerprint and the hashtag for the end The lines it's in a replacement and everything seems quite great so I will we need to do on this Area is actually click install 00:10:00 Then that'll be the compiled version Now let's go back To the code So as you can see It actually inserted the code in the correct place it moved the other code down enough lines And it changed it from replace to replaced And it added the ID After it That sort of targets it so I could go and say ok I don't actually want this in here like that Click save 00:10:32 And then go back to the compiler compile it again Here we go Install it again Go back here refresh this Oeps it didn't change let me quickly go see why I forgot to add in the diamond right You want to change the code you need to ensure that you add this back in Otherwise it will not even look for it So we at that back in Let's try again 00:11:18 Ok now it worked it updated the code in the database So let's install it And it updated in the code So that's how easy it is to replace a certain section now let's look at inserting Now remember as I said Don't put code close to each other within at least eight lines So 1 2 3 4 5 6 7 8 I could actually from this line insert another set of either insert or replace Another section of code 00:11:58 The reason is because the fingerprint that it creates Above the insertion It's sometimes up to 8 lines long Now It could happen that it actually uses from there And that could Possibly be an error when you make a change here It will think that this code is also been affected and it won't find it So that is one of the limitations that these code insertions that you do either by replacing or inserting as Chunk of text script can only be inserted up to eight lines apart 00:12:34 From each other So let's do an insertion over here Ok so we got that inserted there I did put a comment And let's save that And now let's compile Ok before we install it we can just again go check Whether everything was done as expected and yes the insertion was grabbed it was Added to the database and it is there Ok 00:14:04 It has hash target obviously with insertion we only need where it starts not where it ends And so We can close that Now simply install that component Let's go look at the code Ok so this added the replacement Script Change it from replace to replaced It's added the inserted script From insert to inserted it 00:14:34 Now if you want to make a change to it we're again Just add these diamonds here Make our change Save the file of course and then Then let's compile Let's check whether the work was updated Great it's updated the work in the database So let's install the component Ok let's go look at the code again Wonderful it's added it back All seems well 00:15:18 Now We are working on another part of this implementation that for if so for some reason this code above it Changes It will give you a notice On compilation That there is been a change to the fingerprint and it could not find the insertion area It will still add the code on the line number But it will be escaped So that it doesn't change or hurt any of the code that still there The same goes with replacement code 00:15:50 Since it is replacing code It is a little bit more tricky So we'll still add it into the line but we will not remove the old code Anyway I'm still going to be working a bit on that it needs some fine tuning I would like your feedback if you think There's a better way I'm always open for ideas Reality is We are very happy to announce that component builder can now Automatically extract custom code from your Component while In development 00:16:21 Will add a switch that when your ready to distribute your component You could simply say you know that it's no longer in production And then when you compile it will actually not add these placeholders Anymore Ok well thanks for watching Please give me your comments at Github There is actually an issue open there Called Automatic import of custom code during compilation And 00:16:51 You'll see that Yeah there's quite a few been said you can simply add your your comments and feedback to this ticket Or to this issue it's issue 37 Since the tutorial be on YouTube possibly by the time you view it closed but You're still welcome to go and make any comments on the closed issue if you like Anyway thanks for watching goodbye
- Home
- Beta Testing
- Custom Code
- PHP Settings
- Demo Component
-
Tutorials
- Hello World JCB
- Intro JCB Guide
- JCB Installation Steps
- Planning Components
- Field Type Overview
- Basic Fields Creation
- Admin View Management
- Advanced Field Usage
- Admin Component Integration
- Component Setting Customization
- Scripting Components
- Component FTP Options
- Dynamic Get Method
- Site View DynamicGet
- Site View Templates
- Template Setup Guide
- Layout Configuration Steps
- Custom Admin Management
- Adding Site Views
- Custom Admin Integration
- MySQL Demo Tweaking
- Global JCB Settings
- Custom Time Field
- User Helper Integration
- Email Helper Usage
- Message Store Email
- List View Unescape
- Export Import Customization
- Overwrite Custom Fields
- List Field Filtering
- Automatic Code Import
- Manual Code Implementation
- Component Export Import
- Custom Admin Buttons
- Translation Management
- Site View Permissions
- Component SQL Updates
- Site Edit Configuration
- JCB Backup System
- Helper Structure Integration
- JCB v2.5 Upgrade
- Tab Setup Guide
- JCB v2.6 Release
- Extended HelloWorld
- Field Rule Validation
- Community Snippets Intro
- Snippet Forking Tutorial
- Pull Request Snippets
- Library Manager Area
- Excel-based Translation
- Dynamic Router Details
- Database Auto Updates
- Subform Quick Demo
- VDM Package Import
- Dynamic File Inclusion
- File Field Upload
- Drag-n-Drop Upload
- Quick HelloWorld JCB
- Non-database Fields
- Dashboard Customization
- Menu Prefix Toggle
- Community JCB Packages
- Collaborative JCB Workflow
- JCB Package Install
- JCB JAB18 Event
- Convenient New Fields
- Component Language Strings
- Library Functionality Anticipation
- Join Field Relations
- License Template Change
- Code Reusability
- Local Dev Environment
- Extended Field Types
- Joomla Custom Fields
- Custom Field Expansion
- Site View Listing
- Run Expansion Method
- Form Site View
- Field URL Update
- Additional Helper Methods
- Field Validation Rules
- New Placeholder Feature
- Component Config Params
- Per-field Default Values