I'm using Cell and they are great, but I have some components in app/views/shared/ that I would like to use inside a Cell.
Is that possible ?
It was described on docs : )
Sometimes you need to render a global partial from app/views within a
cell. For instance, the gmaps4rails helper depends on a global
partial. While this breaks encapsulation it’s still possible in cells
- just add the global view path.
class MapCell < Cell::Rails
append_view_path "app/views"
( taken from: https://github.com/apotonick/cells )
Related
I am looking for several gtkmm methods/data types that are equivalent to some QT expressions:
given a widget container in QT (e.g. QBoxLayout), a simple method called count() returns the amout of widgets stored in the given container. The best way to exchange QBoxLayout or any QT widget container is Gtk::Grid. But there is no simple way to get the amount of widgets inside of it. Same with Gtk::Box.
I need that method to iterate the childs stored in the grid:
for(auto& it : layouts) { //layouts is a vector of Gtk::Grids
for(int i = 0; i < it->size(); ++i) {
if(it->get_child_at(0, i)) {
it->get_child_at(0, i)->set_visible((std::string(it->get_name())== StringID));
}
QT uses QWidget as an object unbounded to any widget type (such as a button or a checkbox..). That is not possible in gtkmm, because Widgets can only be initinalized with a reference to a widget type. Now I'm looking to replace a QT code with gtkmm, that has a vector of widgets. I used Gtk::Box to replace the QWidgets. Is that a reasonable replacement? I'm getting trouble replacing their scale, which was originally dealt with using QSize, expecting two numbers "hight" and "lenght". Now there is a Gtk::Scale class, but it works in a different way..
All Gtkmm containers (like Gtk::Grid) inherit from the Gtk::Container, which makes the following methods available:
std::vector<Widget*> get_children() // Non const: to modify the widgets
std::vector<const Widget*> get_children () const // const: for read operations
These methods return exactly what you want: a vector of widgets. You can use size() on the returned std::vector to count the number of wigets in the container.
Also, in my opinion, Gtk::Box is very rarely useful since it is very limited. Gtk::Grid is almost always a better choice.
Finally, in Qt, all graphical elements inherit from QWidget. In Gtkmm, all widgets inherit from Gtk::Widget, meaning that you can write something like:
Gtk::Widget* pButton = new Gtk::Button("My button");
and then use pButton, which is "unbounded to any widget type". See the reference for more information on Gtk::Widget.
Update for Gtkmm4
It seems Gtk::Container was removed in Gtkmm4 as documented here. There seems to be nothing to replace it. Unfortunately, it looks like in this version, child widgets tracking will have to be done manually.
I am working on a web app where users can work on a project. The structure of the app is as follows:
Component A (app)
Component B1-Bn (header, footer, main window etc., children of A)
Component C1 (Input area; with inputs for the user to work on the project, child of main window)
Component C2 (Output area; canvas which shows the result based on inputs from C1. In the future also a "graphical" input area that syncs with C1. Child of main window)
Component D1-Dn (Single parts of the input area like tables, advanced input components etc. Child of C1)
Now the project that the user is working on consists of an object stored in Component A. Component Dn needs to write to the object in Component A and also C2 in the future.
I can't get the v-model on input components Dn to work. I tried to pass the data from A down to C1 via props / v-bind and then in Dn, I v-model the prop from C1 (which originates from A) to the input-field. I also tried to use the sync modifier without sucess.
I seem to have a lack of understanding of the vue logic. I come from a desktop background where you just define the scope of variables.
I also found that other vue apprentices have the same understanding problem but somehow the answers I found where not sufficient.
I want a "global" variable that can be edited by every component and is linked to elements in the DOM. What would be the best way to achieve this?
Declare your variable at data when creating Vue Object in your root component (Component A) like
var app = new Vue({
data: function(){
return {
showSetting: {}
}
},
})
Now you can access this showSetting variable in any component like
app.showSetting;
//change it in any component
app.showSetting = {a:1,b:2};
//or append new value to object
Object.assign({d:3},app.showSetting);
Thanks for the answers so far. I guess both of them work. I found another solution because now I fully understand how data is passed in vue:Note that objects and arrays in JavaScript are passed by reference, so if the prop is an array or object, mutating the object or array itself inside the child component will affect parent state. I will pass all data as arrays in the future, as I only want references. The only question that remains is why the programmer is not allowed to define by himself whether the data is passed by reference or not...
Source: Vue.js Guide
Here is a widget class declared in a MyWidget.js module.
define(["dojo/Foo","myapp/Bar"], function(Foo, Bar) { return declare('MyWidget', [], {
postCreate:function() {
var bar = new Bar();
bar.sayHello();
}
})});
In this theoretical example, "myapp/Bar" is a class defined similarly by returning a declare call. Now let's assume that I have created "myapp/SpecialBar" by extending "myapp/Bar".
In another widget, I want to tell MyWidget to use "myapp/SpecialBar" instead of "myapp/Bar" like so:
require(["myapp/MyWidget","myapp/SpecialBar"], function(Foo, SpecialBar) {
//Now swap "myapp/Bar" module dependency of "myapp/MyWidget" to "myapp/SpecialBar"
var myWidget = new MyWidget();
});
I know ways to do this. For example, I could add a Bar attribute to "myapp/MyWidget" and assign the value of the Bar module. This would allow me to instantiate like this: new MyWidget({ Bar:SpecialBar }). However, this seems like too much ceremony. Is there a clean way to just swap an AMD dependency without any special treatment to the module definition?
That is the clean way. You cannot change the modules that a widget/module depends on, well, you could map them, but that's done globally, so then it always maps to a specific module.
If you could do that, you could break a lot of stuff as well, besides, such a feature does not exist in any language. Comparing require() with imports in Java and .NET, you will see a similar trend.
The only way to change the module, is by changing the behavior/state of the module, which means by overriding properties or functions. When a module is "swappable" it's often used as a property, examples where this occur:
The dojo/dnd/Moveable class allows you to set a custom dojo/dnd/Mover through the mover property. In this case the constructor is added as a property to the Moveable (reference guide)
All widgets with a dropdown inherit from dijit/_HasDropDown, which adds the dropdown widget itself as a property to the parent widget
The ScreenRender is initialised with ScreenRenderImpl in ScreenFacadeImpl.makeRender, while ScreenFacade is initialised in ExcecutionContextFactoryImpl. In some cases, I would like to add more functions in ScreenRender that can be invoked in Macro templates. Instead of overriding the ExecutionContextFactoryImpl and down to ScreenRenderImpl as well s MoquiContextListener, is there a way to simply inject a sub class of ScreenRenderImpl when ScreenFacade.makeRender?
A real case to get support of sri in macro template is:
I am trying to populate the options of select via list-options or entity-options or via manual option which return by sri.getFieldOptions(). But it is kind of bound to form fields. I want to use in non-form context. So I kind of want to extend ScreenRender to have a function like sri.getOptions().
I am working on ExtJS 4.2 now. There are 3 ways to access DOM elements - get, select, query.
I want to know the difference between them. Why three separate methods?
we have a question here: SVO
But it doesn't give me any clear answers. Looking for something specific / detailed answer.
Will be grateful if you can help with the explanation.
Thanks in advance :-)
EDIT based on answer below:
I am not much into jQuery so can't understand through comparison. Can anyone help me with the difference between an Ext.element and a composite element?
EDIT 2:
What is Ext.dom.Element? Any different from Ext.element? and if anyone could throw some light on "Ext.fx.Anim" package?
Ext.get
Ext.get is analogous to document.getElementById in that you can provide the ID of a DOM node and retrieve that element wrapped as Ext.dom.Element. You can also provide a DOM node or an existing Element.
// Main usage: DOM ID
var someEl = Ext.get('myDivId');
// Wrap a DOM node as an Element
var someDom = document.getElementById('myDivId');
someEl = Ext.get(someDom);
// Identity function, essentially
var sameEl = Ext.get(someEl);
Ext.query
Ext.query allows you to select an array of DOM nodes using CSS/XPath selectors. This is handy when working with custom components or data views and you need a more robust selection mechanism than DOM IDs.
// Get all DOM nodes with class "oddRow" that are children of
// my component's top-level element.
var someNodes = Ext.query('.oddRow', myCustomComponent.getEl().dom);
Ext.select
Ext.select is essentially Ext JS's answer to jQuery's selectors. Given some CSS/XPath selector, it returns a single object representing a collection of Elements. This CompositeElement has methods for filtering, iterating, slicing the collection.
Most importantly, the CompositeElement supports chainable versions of all methods of Ext.dom.Element and Ext.fx.Anim that operate on each element in the collection, making this method very powerful.
Edit 1: An Ext.Element represents a single DOM node, while an Ext.dom.CompositeElement represents a collection of DOM nodes that can be affected through a single interface. So, given the following example:
// Set the height of each table row using Ext.query
var tableRowNodes = Ext.query('tr', document.getElementById('myTable'));
Ext.Array.each(tableRowNodes, function (node) {
Ext.fly(node).setHeight(25);
});
// Set the height of each table row using Ext.select
var compositeEl = Ext.select('#myTable tr');
compositeEl.setHeight(25);
You can see how much easier it is to work with Ext.dom.CompositeElement.
Edit 2: Ext JS supports the concept of alternate class names. Think of them as shortcuts for commonly used classes. Ext.Element is the alternate class name for Ext.dom.Element and can be used interchangeably.
Ext.fx.Anim is a class representing an animation. Usually not used directly, it is created behind the scenes when performing animations on elements or components. For example, the first parameter of Ext.Component#hide is the animation target.