I am creating a spine-rails application and have 2 coffeescript files in lib folder. I wanted to inherit a parent class in another coffeescript file but unable to do so.
#= require coffeescript_file_1
Above statement finds the target coffeescript file but cannot find the parent class.
I found this utlity:
https://github.com/fairfieldt/coffeescript-concat
Just wanted to know if using it would be the correct way to find a parent class in a coffeescript file inside another file in a rails app.
I'm not using npm.
You need to "export" the class. CoffeeScript uses an IIFE wrapper to avoid polluting the scope.
in your application.js :
#= require coffee_parent
#= require coffee_child
in your coffee_parent.js.coffee :
#Parent = class Parent
doStuff: ->
in your coffee_child.js.coffee :
#Child = class Child extends #Parent
doStuff: -> super 1
Related
Given an .fxml include like:
<fx:include fx:id="header" source="Header.fxml" />
The Java FXML docs say to create two variables like:
#FXML private HBox header;
#FXML private HeaderController headerController;
What determines the controller variable name? Is it always just the include id followed by "Controller"?
Yes the field name the controller is injected to is always constructed by concatenating the fx:id of the <fx:include> tag with "Controller".
It's "hidden" in the documentation of the FXMLLoader.CONTROLLER_SUFFIX field.
A suffix for controllers of included fxml files. The full key is stored in namespace map.
(The namespace map contains all the objects by the field name they are injected to, if such a field exists.)
You can verify that it's value is "Controller" here: https://docs.oracle.com/javase/8/javafx/api/constant-values.html#javafx.fxml.FXMLLoader.CONTROLLER_SUFFIX
Logging Java in Intellij is easy with shortcuts such as 'logt', 'logd', 'loge'... and so on. But I moved to Kotlin, I noticed that those shortcuts doesn't work anymore. I don't know if it has something to do with my configuration, but if not, how can I fix this?
You should create separate templates to make them work correctly.
Here is the step-by-step guide:
Firstly, Copy and paste AndroidLog templates to Kotlin (Just select them and use CMD+C, CMD+V (or Ctrl+C, Ctrl+V)
Secondly, You have to adjust them manually:
1. logd (and others)
Select the logd item and press "Edit variables"
Change expression to: kotlinFunctionName()
Also, remove ; from the end of the template, as you don't need it in Kotlin.
Now your method name will be shown correctly
logt
This one is a bit trickier.
Solution 1 TAG = class name.
Template text :
private val TAG = "$className$"
Edit variables -> Expression:
groovyScript("_1.take(Math.min(23, _1.length()));", kotlinClassName())
Solution 2 TAG = file name (can be used inside Companion)
Template text :
private const val TAG = "$className$
or:
companion object {
private const val TAG = "$className$"
}
Edit variables -> Expression:
groovyScript("_1.take(Math.min(23, _1.length()));", fileNameWithoutExtension())
Edit 19.02.19
Also, it might be useful for someone.
In order to avoid creating the TAG variable, you can use the class name as a variable, for instance:
Log.d("BaseActivity", "onCreate: ")
Where BaseActivity is the class name.
The template will look now as:
android.util.Log.d("$CLASS_NAME$", "$METHOD_NAME$: $content$")
Where CLASS_NAME variable is:
groovyScript("_1.take(Math.min(23, _1.length()));", fileNameWithoutExtension())
These are provided in IntelliJ as a Live Template configuration for AndroidLog (found in Preferences -> Editor -> Live Templates), and are applicable specifically to Java code:
There isn't anything broken in your configuration, but if you want to make these Live Templates available for Kotlin you will need to add new Live Template for AndroidLog and make them applicable to Kotlin code.
https://www.jetbrains.com/help/idea/2017.1/creating-and-editing-live-templates.html
There's an open feature request to have them added as defaults here: https://youtrack.jetbrains.com/issue/KT-10464
Change the scope of the template in the applicable option.
In Android Studio 4.0 there's new AndroidLogKotlin block. You can implement #LeoDroidcoder's solution there.
Sylius 1.0.0-dev
I'm trying to modify the Quantity field of CartItemType.
Following the old docs I have created a new FormType on my Bundle and extends from original in Symfony/Bundle/CartBundle/Form/Type/CartItemType.
My custom CartItemType shows like this:
use Sylius\Bundle\CartBundle\Form\Type\CartItemType as BaseType;
use Symfony\Component\Form\FormBuilderInterface;
class CartItemType extends BaseType
{
/**
* {#inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->remove('quantity')
->add('quantity', 'hidden', [
'attr' => ['min' => 1, 'max' => 1],
'data' => '1',
'label' => 'sylius.form.cart_item.quantity',
])
->setDataMapper($this->orderItemQuantityDataMapper);
}
}
I want you can't buy more than one product quantity per order.
My config seems liike this:
sylius_cart:
resources:
cart_item:
classes:
form:
default: Dinamic\Bundle\SyliusRibBundle\Form\Type\CartItemType
When I open some product view i'm getting this error:
The option "product" does not exist. [...] in #SyliusShop/Product/Show/_inventory.html.twig at line 4
Any idea about why this is happening?
Instead of extending CartBundle CartItemType extend using this:
use Sylius\Bundle\CoreBundle\Form\Type\CartItemType as BaseType;
The CoreBundle CartItemType class extends the CartBundle CartItemType, so if you extend the wrong class it will break everything
Don't extend Symfony form types that way - extend Symfony\Component\Form\AbstractType instead, and implement getParent() in your custom type:
public function getParent()
{
return BaseType::class;
}
That way, the parent's options will be available to your custom type as well, and everything will be properly rendered/initialized.
Edit:
Technically, both approaches should work. However, using inheritance will completely override the parent form's behavior, while using getParent() will add your custom behavior to the parent's form.
getParent() will tell Symfony to build the form defined in that method first, and then use that as the base for your own implementation. So when using that, the FormBuilder in your buildForm() method will already contain the complete parent form, ready for your own modifications, the OptionsResolver in your configureOptions() method will already have the parent form's options and defaults defined, etc. which appears to be exactly what you want (otherwise your call to $builder->remove() makes very little sense). When using inheritance, you'll have to take care to do everything the parent form does which you want to do as well, which might very well break when the parent form changes.
Another difference is in Symfony's form extensions. When implementing getParent(), any form extensions applied to the parent form will be applied to your custom form as well. When using inheritance, that won't be the case.
The first point is easy to work with (parent::buildForm() will ensure you have the correct fields, for instance), but the second is not as easy. Generally you want these extensions to apply to your custom form type as well - in this case there's actually a decent chance the error is caused by a form extension not being applied to your custom type.
So basically, use getParent() whenever possible. Use inheritance for form types only if you want to completely override behaviour or you explicitly want form extensions not to apply to your custom type.
In a Prestashop 1.6 site I need add a dynamic class to the body element (just in frontend).
The class should be 'group-[group-name-id]' where group-name-id is the group name id of the visitor.
Default Groups in Presashop are:
'1'--'Visitor'
'2'--'Guest'
'3'--'Costumer'
Is there a way to do this?
I found this, but it seems outdated, since it is for PS 1.4: https://www.prestashop.com/forums/topic/179593-adding-category-class-id-to-product-page-body/
UPDATE:
I almost get it thanks to #TheDrot answer (just below).
The only problem is this: [0]. I get this error: "Parse error: syntax error, unexpected '[', expecting ')' in /home/temporal-4/www/override/classes/controller/FrontController.php on line 36".
If I remove '[0]' it works but then in the class I get "group-array". I need to print all the values of the array like class="group-1 group-2 group-3".
You need to override FrontControllerCore class so create a file FrontController.php in folder 'override/classes/controller/' and put in this code
class FrontController extends FrontControllerCore {
public function init()
{
parent::init();
$this->context->smarty->assign('group_id', $this->context->customer->getGroups()[0]; // user can exist in multiple groups, so for this example im just grabbing first group id
}
}
Then open header.tpl file in 'themes/your_theme/' and add code to body class
group-{$group_id}
If in body class you only see group-, be sure to delete class_index.php from cache folder and reload page.
For PS1.7 no need to override anything, perhaps it works for PS1.6
Add $groupid = "group-1" or "group-2", ect. to smarty params by using assign() function in your controller and in your template add on top
{$page["body_classes"][$groupid] = 'true'}
Let us know about this tricks
When writing a control, prior to it's rendering you can add css classes to it's html representation's root dom node:
FooLayout.prototype.init = function() {
this.addStyleClass('fooCssClass');
};
This will work assuming writeClasses is executed during rendering:
oRenderManager.writeClasses();
--
There is another RenderManager function writeStyles which can add in-line styles to the html string buffer:
oRenderManager.addStyle("color", "green");
oRenderManager.writeStyles();
But there doesn't seem to be an analogous function to addStyleClass for adding these at the control level to be picked up during rendering.
Is there a way I can hook into writeStyles outside of the renderer?
I have to ask: What styling cannot be applied on control level with a class that can be done with a specific style attribute?
Anyway, the "solution" (which I do not like) would be to add a delegate to the class and do something on onAfterRendering:
oControl.addDelegate({
onAfterRendering: function() {
this.$().css("opacity", "0.5");
}.bind(oControl)
});
Here is an example: http://jsbin.com/seqemaqedo/1/edit?js,output
But as I said, I would advice against it because using a good name for a class uses less code and is much easier to read:
oControl.addStyleClass("semiTransparent");
Update:
After our discussion in the comments, here is an example of how to wrap a control that does not support setting width and height.
You still have to write CSS that references the inner control structure, but in this case it is very unlikely that it will change:
http://jsbin.com/lohocaqixi/3/edit?html,js,output