-
-
Notifications
You must be signed in to change notification settings - Fork 178
031 Automatic import of custom code during compilation in JCB
A very smart new feature has lately been added to Component Builder that's called custom code.00:00:12 It is stored next to Dynamic Get. You'd hardly ever 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 the changes will be done in the editor. 00:00:39
What is the purpose of this new feature?
The feature is there for those who are used to coding in another editor. For example, they create a component in Component Builder, then once it is created, they do a compile and install it onto the same website as Component Builder to test it. 00:01:13 Then during testing, code is added into that compiled version that are installed onto the website. The new feature is able to, on compilation to extract that custom code , store it in this custom code area, and add it back into the component on the fly. Since there are some limitations, a demonstration of some rules and guidelines is necessary. 00:01:45 This is still in beta and quite a few improvements still need to be done. I would like it to be tested and would appreciate some feedback from you.
I'm going to compile the demo component since most of you might already have this component installed and can then use this as sort of a test area. I'm going to install it on to this current site and explain how to add custom scripting to that component by going to an editor. 00:02:28
Here in the editor can this root directory of the website be seen. Go to the back end of the components. Open administrator, components and then the demo component. To demonstrate: On the main index page some custom scripting is added. 00:03:04 There are some conventions and regulations that should be considered when the way to add custom scripting is explained.
Let me first show you the conventions. To insert Custom scripting you will use a tag like this(see video). You will use asterisks(*) instead of the X's that are in the code. The code has the X's in it but the actual way would be with the asterisks(*). So that will be to insert a new code. Use that place holder(///***[INSERT<>$$$$]***///) in the beginning of the area, then after a new line, insert the code, and then at the end of the code, insert this one(///***[INSERT<>$$$$]***///), to close the code. 00:03:50 There are two ways of adding code. One is to insert code and one is to replace existing code. So 'insert' code would simply at the same line insert that code into the existing code, where is 'replace' code will 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 to 'inserted', and will have this(23) new number at the end. 00:04:28This number is referencing the id of the code in the system.
NB. Do not change this number. Component Builder would interpret that it does not have one, and it needs to be created. It will be an error. It will add this at the end. 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 are the ones that activate it and makes it be parsed again. When Component Builder places the code back, it looks like this(///***[INSERT<>$$$$]***///). If it needs to be changed at a later stage, just add this diamond(<>), and it will then update the existing code in the database with the changes that had been made. 00:05:30<<<<<<<<<<<<<<<<<<<<<<
There are a few limitations. You cannot add code close to each other than I would say 6 lines. So if there are going to be code close to each other and it ends and starts within the parameter of 6 lines, you end up with a problem, especially at the end. I will demonstrate that somehow in our actual doing of this. 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 fingerprint of the code above this 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 is constantly being improved and that therefore it's code is moving around quite a lot. 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 never intended it to overwrite. So the only way we could solve this was creating what we call a fingerprint. A few lines above the insertion or the replacement and a few lines below the replacement. I'll demonstrate this in our demonstration in a moment. Just a heads up about that. To insert new code you will use this(///***[INSERT<>$$$$]***///). To replace new code or for the first time you would use that(///***[REPLACE<>$$$$]***///) 00:07:25 At the end of the code you would add these corresponding placeholders(///***[INSERT<>$$$$]***///) and(///***[REPLACE<>$$$$]***///) . I'll put these this little block(see video) into the comments of this tutorial. If any of you need to copy it down you could just copy it from there. When component builder adds it back, it will look like this(///***[INSERT<>$$$$]***///23) for the inserted and this(///***[INSERT<>$$$$]***///25) for the replaced. If you then come back all you need to do is just add that diamond(<>) in there for it to be updated in the database. 00:08:00
Let's see this in action. So here we have that demo components main document open. I'm going to add some replacement tags here. I'm not making any changes but I could add a few lines here - ///. Maybe another comment - 'hi it worked', 00:08:34 let's do - echo 'hi it worked' and that should do it. This is going to replace this area.
Let's go to the compiler and compile the component. See what happens. So in the compiler I'm going to compile a component again. 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 going to 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 it was a replacement. We can open that and there is the code that we want replaced. 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. All we will need to do on this area is click install. 00:10:00 Then that'll be the compiled version.
Now let's go back to the code. 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. It added the id after it. That targets it. I could go and say 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. 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 add that back in. Let's try again. 00:11:18 It worked it updated the code in the database. Let's install it. It updated in the code. So that's how easy it is to replace a certain section.
Let's look at inserting. 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 or either insert or replace another section of code. 00:11:58 The reason is because the fingerprint that it creates above the insertion, is sometimes up to 8 lines long. It could happen that it actually uses from there(see video). 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. Let's do an insertion over here(see video). We got that inserted there. I did put a comment. Let's save and compile.
Before we install it, we can just again go check whether everything was done as expected. Yes the insertion was grabbed. It was added to the database and it is there. 00:14:04 It has the hash target, 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. It did added the replacement script, change it from replace to replaced. It's added the inserted script from insert to inserted. 00:14:34 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 compile. Let's check whether the work was updated. Great it's updated the work in the database. So let's install the component. Let's go look at the code again. Wonderful it's added it back. All seems well. 00:15:18
We are working on another part of this implementation 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. 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. We are very happy to announce that component builder can now automatically extract custom code from your component while in development. 00:16:21 We'll 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, it will actually not add these placeholders anymore. Please give me your comments at Github. There is actually an issue open there called automatic import of custom code during compilation. 00:16:51 You'll see that there's quite a few been said. You can simply add your your comments and feedback to this ticket or to issue 37. Since the tutorial be on YouTube possibly by the time you view it, it is closed. You're still welcome to go and make any comments on the closed issue if you like.
- 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