Skip to content

Commit a4edea2

Browse files
author
ColinTree
committed
0.4.2: fix componentName not applied
1 parent 2ddb475 commit a4edea2

File tree

3 files changed

+70
-98
lines changed

3 files changed

+70
-98
lines changed

assets/plugin.js

Lines changed: 66 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -44,118 +44,90 @@ require(['gitbook', 'jQuery'], function(gitbook, $) {
4444
});
4545

4646
function render() {
47-
// METHOD
48-
$('div[ai2-method]').filter("[not-rendered]").each(function(){
47+
$('div[ai2-block]').filter("[not-rendered]").each(function(){
4948
$(this).removeAttr("not-rendered");
49+
5050
var block = getBlock(decodeURI($(this).attr("value")));
5151

52-
var name = block['name'];
53-
var param = block['param'] || block['arg'] || [];
54-
var output = block['output']===true;
55-
var scale = block['scale'] || CONF_SCALE_LEVEL;
56-
var margin_left = block['margin_left'] || block['margin'] || CONF_MARGIN_LEFT;
57-
var margin_top = block['margin_top'] || block['margin'] || CONF_MARGIN_TOP;
58-
var margin_right = block['margin_right'] || block['margin'] || CONF_MARGIN_RIGHT;
59-
var margin_bottom = block['margin_bottom'] || block['margin'] || CONF_MARGIN_BOTTOM;
60-
52+
// should be after getBlock(json) because blockId needs to be refreshed
6153
$(this).attr('id', blockId).show();
62-
63-
Blockly.Blocks['dynamicCreated_'+blockId] = {
64-
init: function() {
65-
this.appendDummyInput().appendField(CONF_TEXT_CALL).appendField(new Blockly.FieldDropdown([[ComponentName, 'OPTIONNAME']]), 'COMPONENT_SELECTOR').appendField('.'+name);
66-
for (var i=0; i<param.length; i++) {
67-
this.appendValueInput('NAME').setAlign(Blockly.ALIGN_RIGHT).appendField(param[i]);
68-
}
69-
this.setInputsInline(false);
70-
if (output) {
71-
this.setOutput(true, null);
72-
} else {
73-
this.setPreviousStatement(true, null);
74-
this.setNextStatement(true, null);
75-
}
76-
this.setColour(COLOUR_METHOD);
77-
this.setTooltip('');
78-
this.setHelpUrl('');
79-
}
80-
};
81-
82-
newBlockAndWorkspace(blockId, scale, margin_left, margin_top, margin_right, margin_bottom);
83-
});
84-
85-
// EVENT
86-
$('div[ai2-event]').filter("[not-rendered]").each(function(){
87-
$(this).removeAttr("not-rendered");
88-
var block = getBlock(decodeURI($(this).attr("value")));
8954

55+
var type = $(this).attr("ai2-block");
9056
var name = block['name'];
91-
var param = block['param'] || block['arg'] || [];
9257
var scale = block['scale'] || CONF_SCALE_LEVEL;
9358
var margin_left = block['margin_left'] || block['margin'] || CONF_MARGIN_LEFT;
9459
var margin_top = block['margin_top'] || block['margin'] || CONF_MARGIN_TOP;
9560
var margin_right = block['margin_right'] || block['margin'] || CONF_MARGIN_RIGHT;
9661
var margin_bottom = block['margin_bottom'] || block['margin'] || CONF_MARGIN_BOTTOM;
9762

98-
$(this).attr('id', blockId).show();
99-
100-
Blockly.Blocks['dynamicCreated_'+blockId] = {
101-
init: function() {
102-
this.appendDummyInput('').appendField(CONF_TEXT_WHEN).appendField(new Blockly.FieldDropdown([[ComponentName, 'OPTIONNAME']]), "COMPONENT_SELECTOR").appendField('.' + name);
103-
if (param.length > 0) {
104-
var paramInput = this.appendDummyInput('PARAMETERS').appendField(" ").setAlign(Blockly.ALIGN_LEFT);
63+
// METHODS
64+
if (type == 'method') {
65+
var param = block['param'] || block['arg'] || [];
66+
var output = block['output']===true;
67+
68+
Blockly.Blocks['dynamicCreated_'+blockId] = {
69+
init: function() {
70+
this.appendDummyInput().appendField(CONF_TEXT_CALL).appendField(new Blockly.FieldDropdown([[ComponentName, 'OPTIONNAME']]), 'COMPONENT_SELECTOR').appendField('.'+name);
10571
for (var i=0; i<param.length; i++) {
106-
paramInput.appendField(new Blockly.FieldTextInput(param[i]), 'VAR'+i).appendField(" ");
72+
this.appendValueInput('NAME').setAlign(Blockly.ALIGN_RIGHT).appendField(param[i]);
10773
}
74+
this.setInputsInline(false);
75+
if (output) {
76+
this.setOutput(true, null);
77+
} else {
78+
this.setPreviousStatement(true, null);
79+
this.setNextStatement(true, null);
80+
}
81+
this.setColour(COLOUR_METHOD);
10882
}
109-
this.appendStatementInput("DO").appendField(CONF_TEXT_DO);
110-
this.setInputsInline(false);
111-
this.setPreviousStatement(false, null);
112-
this.setNextStatement(false, null);
113-
this.setColour(COLOUR_EVENT);
114-
this.setTooltip('');
115-
this.setHelpUrl('');
116-
}
117-
};
83+
};
11884

119-
newBlockAndWorkspace(blockId, scale, margin_left, margin_top, margin_right, margin_bottom);
120-
});
121-
122-
// PROPERTY
123-
$('div[ai2-property]').filter("[not-rendered]").each(function(){
124-
$(this).removeAttr("not-rendered");
125-
var block = getBlock(decodeURI($(this).attr("value")));
126-
127-
var name = block['name'];
128-
var getter = block['getter'];
129-
if (getter !== true && getter !== false) {
130-
getter = true;
131-
}
132-
var scale = block['scale'] || CONF_SCALE_LEVEL;
133-
var margin_left = block['margin_left'] || block['margin'] || CONF_MARGIN_LEFT;
134-
var margin_top = block['margin_top'] || block['margin'] || CONF_MARGIN_TOP;
135-
var margin_right = block['margin_right'] || block['margin'] || CONF_MARGIN_RIGHT;
136-
var margin_bottom = block['margin_bottom'] || block['margin'] || CONF_MARGIN_BOTTOM;
137-
138-
$(this).attr('id', blockId).show();
139-
140-
Blockly.Blocks['dynamicCreated_'+blockId] = {
141-
init: function() {
142-
var input;
143-
if (getter) {
144-
input = this.appendDummyInput();
145-
this.setOutput(true, null);
146-
} else {
147-
input = this.appendValueInput("NAME").appendField(CONF_TEXT_SET);
148-
this.setPreviousStatement(true, null);
149-
this.setNextStatement(true, null);
85+
// EVENTS
86+
} else if (type == 'event') {
87+
var param = block['param'] || block['arg'] || [];
88+
89+
Blockly.Blocks['dynamicCreated_'+blockId] = {
90+
init: function() {
91+
this.appendDummyInput('').appendField(CONF_TEXT_WHEN).appendField(new Blockly.FieldDropdown([[ComponentName, 'OPTIONNAME']]), "COMPONENT_SELECTOR").appendField('.' + name);
92+
if (param.length > 0) {
93+
var paramInput = this.appendDummyInput('PARAMETERS').appendField(" ").setAlign(Blockly.ALIGN_LEFT);
94+
for (var i=0; i<param.length; i++) {
95+
paramInput.appendField(new Blockly.FieldTextInput(param[i]), 'VAR'+i).appendField(" ");
96+
}
97+
}
98+
this.appendStatementInput("DO").appendField(CONF_TEXT_DO);
99+
this.setInputsInline(false);
100+
this.setPreviousStatement(false, null);
101+
this.setNextStatement(false, null);
102+
this.setColour(COLOUR_EVENT);
150103
}
151-
input.appendField(new Blockly.FieldDropdown([[ComponentName, 'OPTIONNAME']]), "NAME")
152-
.appendField(".")
153-
.appendField(new Blockly.FieldDropdown([[name, "OPTIONNAME"]]), "NAME2");
154-
this.setColour(getter ? COLOUR_GET : COLOUR_SET);
155-
this.setTooltip('');
156-
this.setHelpUrl('');
104+
};
105+
106+
// PROPERTIES
107+
} else if (type == 'property') {
108+
var getter = block['getter'];
109+
if (getter !== true && getter !== false) {
110+
getter = true;
157111
}
158-
};
112+
113+
Blockly.Blocks['dynamicCreated_'+blockId] = {
114+
init: function() {
115+
var input;
116+
if (getter) {
117+
input = this.appendDummyInput();
118+
this.setOutput(true, null);
119+
} else {
120+
input = this.appendValueInput("NAME").appendField(CONF_TEXT_SET);
121+
this.setPreviousStatement(true, null);
122+
this.setNextStatement(true, null);
123+
}
124+
input.appendField(new Blockly.FieldDropdown([[ComponentName, 'OPTIONNAME']]), "NAME")
125+
.appendField(".")
126+
.appendField(new Blockly.FieldDropdown([[name, "OPTIONNAME"]]), "NAME2");
127+
this.setColour(getter ? COLOUR_GET : COLOUR_SET);
128+
}
129+
};
130+
}
159131

160132
newBlockAndWorkspace(blockId, scale, margin_left, margin_top, margin_right, margin_bottom);
161133
});

index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ module.exports = {
77
blocks: {
88
Ai2Method: {
99
process: function(blk) {
10-
return "<div ai2-method not-rendered value=\""+encodeURI(blk.body)+"\"></div>";
10+
return "<div ai2-block=\"method\" not-rendered value=\""+encodeURI(blk.body)+"\"></div>";
1111
}
1212
},
1313
Ai2Event: {
1414
process: function(blk) {
15-
return "<div ai2-event not-rendered value=\""+encodeURI(blk.body)+"\"></div>";
15+
return "<div ai2-block=\"event\" not-rendered value=\""+encodeURI(blk.body)+"\"></div>";
1616
}
1717
},
1818
Ai2Property: {
1919
process: function(blk) {
20-
return "<div ai2-property not-rendered value=\""+encodeURI(blk.body)+"\"></div>";
20+
return "<div ai2-block=\"property\" not-rendered value=\""+encodeURI(blk.body)+"\"></div>";
2121
}
2222
},
2323
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,5 @@
7070
"type": "git",
7171
"url": "git+https://github.com/ColinTree/gitbook-plugin-ai2-blocks.git"
7272
},
73-
"version": "0.4.1"
73+
"version": "0.4.2"
7474
}

0 commit comments

Comments
 (0)